refactor: move communities functions to communities view in chat
This commit is contained in:
parent
3cc62d65aa
commit
b38d1df591
|
@ -1,5 +1,6 @@
|
||||||
import sugar, sequtils, times, strutils
|
import sugar, sequtils, times, strutils
|
||||||
import ../../status/chat/chat as status_chat
|
import ../../status/chat/chat as status_chat
|
||||||
|
import ./views/communities
|
||||||
|
|
||||||
proc handleChatEvents(self: ChatController) =
|
proc handleChatEvents(self: ChatController) =
|
||||||
# Display already saved messages
|
# Display already saved messages
|
||||||
|
@ -27,9 +28,9 @@ proc handleChatEvents(self: ChatController) =
|
||||||
self.view.reactions.push(evArgs.emojiReactions)
|
self.view.reactions.push(evArgs.emojiReactions)
|
||||||
if (evArgs.communities.len > 0):
|
if (evArgs.communities.len > 0):
|
||||||
for community in evArgs.communities:
|
for community in evArgs.communities:
|
||||||
self.view.addCommunityToList(community)
|
self.view.communities.addCommunityToList(community)
|
||||||
if (evArgs.communityMembershipRequests.len > 0):
|
if (evArgs.communityMembershipRequests.len > 0):
|
||||||
self.view.addMembershipRequests(evArgs.communityMembershipRequests)
|
self.view.communities.addMembershipRequests(evArgs.communityMembershipRequests)
|
||||||
|
|
||||||
self.status.events.on("channelUpdate") do(e: Args):
|
self.status.events.on("channelUpdate") do(e: Args):
|
||||||
var evArgs = ChatUpdateArgs(e)
|
var evArgs = ChatUpdateArgs(e)
|
||||||
|
@ -62,10 +63,10 @@ proc handleChatEvents(self: ChatController) =
|
||||||
if (evArgs.active == false):
|
if (evArgs.active == false):
|
||||||
self.view.restorePreviousActiveChannel()
|
self.view.restorePreviousActiveChannel()
|
||||||
else:
|
else:
|
||||||
if (self.view.activeCommunity.communityItem.lastChannelSeen == ""):
|
if (self.view.communities.activeCommunity.communityItem.lastChannelSeen == ""):
|
||||||
self.view.setActiveChannelByIndex(0)
|
self.view.setActiveChannelByIndex(0)
|
||||||
else:
|
else:
|
||||||
self.view.setActiveChannel(self.view.activeCommunity.communityItem.lastChannelSeen)
|
self.view.setActiveChannel(self.view.communities.activeCommunity.communityItem.lastChannelSeen)
|
||||||
|
|
||||||
self.status.events.on("channelJoined") do(e: Args):
|
self.status.events.on("channelJoined") do(e: Args):
|
||||||
var channel = ChannelArgs(e)
|
var channel = ChannelArgs(e)
|
||||||
|
|
|
@ -4,8 +4,6 @@ import ../../status/mailservers
|
||||||
import ../../status/libstatus/chat as libstatus_chat
|
import ../../status/libstatus/chat as libstatus_chat
|
||||||
import ../../status/libstatus/accounts/constants
|
import ../../status/libstatus/accounts/constants
|
||||||
import ../../status/libstatus/mailservers as status_mailservers
|
import ../../status/libstatus/mailservers as status_mailservers
|
||||||
import ../../status/libstatus/types
|
|
||||||
import ../../status/libstatus/core
|
|
||||||
import ../../status/libstatus/chat as core_chat
|
import ../../status/libstatus/chat as core_chat
|
||||||
import ../../status/libstatus/utils as status_utils
|
import ../../status/libstatus/utils as status_utils
|
||||||
import ../../status/accounts as status_accounts
|
import ../../status/accounts as status_accounts
|
||||||
|
@ -17,7 +15,7 @@ import ../../status/chat/[chat, message]
|
||||||
import ../../status/profile/profile
|
import ../../status/profile/profile
|
||||||
import web3/[conversions, ethtypes]
|
import web3/[conversions, ethtypes]
|
||||||
import ../../status/threads
|
import ../../status/threads
|
||||||
import views/[channels_list, message_list, chat_item, suggestions_list, reactions, stickers, groups, transactions, community_list, community_item, community_membership_request_list]
|
import views/[channels_list, message_list, chat_item, suggestions_list, reactions, stickers, groups, transactions, communities, community_list, community_item]
|
||||||
import json_serialization
|
import json_serialization
|
||||||
import ../utils/image_utils
|
import ../utils/image_utils
|
||||||
|
|
||||||
|
@ -43,12 +41,8 @@ QtObject:
|
||||||
transactions*: TransactionsView
|
transactions*: TransactionsView
|
||||||
activeChannel*: ChatItemView
|
activeChannel*: ChatItemView
|
||||||
contextChannel*: ChatItemView
|
contextChannel*: ChatItemView
|
||||||
|
communities*: CommunitiesView
|
||||||
previousActiveChannelIndex: int
|
previousActiveChannelIndex: int
|
||||||
activeCommunity*: CommunityItemView
|
|
||||||
observedCommunity*: CommunityItemView
|
|
||||||
communityList*: CommunityList
|
|
||||||
joinedCommunityList*: CommunityList
|
|
||||||
myCommunityRequests*: seq[CommunityMembershipRequest]
|
|
||||||
replyTo: string
|
replyTo: string
|
||||||
channelOpenTime*: Table[string, int64]
|
channelOpenTime*: Table[string, int64]
|
||||||
connected: bool
|
connected: bool
|
||||||
|
@ -64,8 +58,6 @@ QtObject:
|
||||||
self.chats.delete
|
self.chats.delete
|
||||||
self.activeChannel.delete
|
self.activeChannel.delete
|
||||||
self.contextChannel.delete
|
self.contextChannel.delete
|
||||||
self.observedCommunity.delete
|
|
||||||
self.activeCommunity.delete
|
|
||||||
self.currentSuggestions.delete
|
self.currentSuggestions.delete
|
||||||
for msg in self.messageList.values:
|
for msg in self.messageList.values:
|
||||||
msg.delete
|
msg.delete
|
||||||
|
@ -74,6 +66,8 @@ QtObject:
|
||||||
self.groups.delete
|
self.groups.delete
|
||||||
self.transactions.delete
|
self.transactions.delete
|
||||||
self.messageList = initOrderedTable[string, ChatMessageList]()
|
self.messageList = initOrderedTable[string, ChatMessageList]()
|
||||||
|
self.communities.delete
|
||||||
|
self.messageList = initTable[string, ChatMessageList]()
|
||||||
self.channelOpenTime = initTable[string, int64]()
|
self.channelOpenTime = initTable[string, int64]()
|
||||||
self.QAbstractListModel.delete
|
self.QAbstractListModel.delete
|
||||||
|
|
||||||
|
@ -84,16 +78,13 @@ QtObject:
|
||||||
result.chats = newChannelsList(status)
|
result.chats = newChannelsList(status)
|
||||||
result.activeChannel = newChatItemView(status)
|
result.activeChannel = newChatItemView(status)
|
||||||
result.contextChannel = newChatItemView(status)
|
result.contextChannel = newChatItemView(status)
|
||||||
result.activeCommunity = newCommunityItemView(status)
|
|
||||||
result.observedCommunity = newCommunityItemView(status)
|
|
||||||
result.currentSuggestions = newSuggestionsList()
|
result.currentSuggestions = newSuggestionsList()
|
||||||
result.messageList = initOrderedTable[string, ChatMessageList]()
|
result.messageList = initOrderedTable[string, ChatMessageList]()
|
||||||
result.reactions = newReactionView(status, result.messageList.addr, result.activeChannel)
|
result.reactions = newReactionView(status, result.messageList.addr, result.activeChannel)
|
||||||
result.stickers = newStickersView(status, result.activeChannel)
|
result.stickers = newStickersView(status, result.activeChannel)
|
||||||
result.groups = newGroupsView(status,result.activeChannel)
|
result.groups = newGroupsView(status,result.activeChannel)
|
||||||
result.communityList = newCommunityList(status)
|
|
||||||
result.joinedCommunityList = newCommunityList(status)
|
|
||||||
result.transactions = newTransactionsView(status)
|
result.transactions = newTransactionsView(status)
|
||||||
|
result.communities = newCommunitiesView(status)
|
||||||
result.unreadMessageCnt = 0
|
result.unreadMessageCnt = 0
|
||||||
result.loadingMessages = false
|
result.loadingMessages = false
|
||||||
result.previousActiveChannelIndex = -1
|
result.previousActiveChannelIndex = -1
|
||||||
|
@ -128,6 +119,12 @@ QtObject:
|
||||||
QtProperty[QVariant] chats:
|
QtProperty[QVariant] chats:
|
||||||
read = getChatsList
|
read = getChatsList
|
||||||
|
|
||||||
|
proc getCommunities*(self: ChatsView): QVariant {.slot.} =
|
||||||
|
newQVariant(self.communities)
|
||||||
|
|
||||||
|
QtProperty[QVariant] communities:
|
||||||
|
read = getCommunities
|
||||||
|
|
||||||
proc getChannelColor*(self: ChatsView, channel: string): string {.slot.} =
|
proc getChannelColor*(self: ChatsView, channel: string): string {.slot.} =
|
||||||
self.chats.getChannelColor(channel)
|
self.chats.getChannelColor(channel)
|
||||||
|
|
||||||
|
@ -230,19 +227,20 @@ QtObject:
|
||||||
self.chats.clearUnreadMessagesCount(channel)
|
self.chats.clearUnreadMessagesCount(channel)
|
||||||
|
|
||||||
proc setActiveChannelByIndex*(self: ChatsView, index: int) {.slot.} =
|
proc setActiveChannelByIndex*(self: ChatsView, index: int) {.slot.} =
|
||||||
if((self.activeCommunity.active and self.activeCommunity.chats.chats.len == 0) or (not self.activeCommunity.active and self.chats.chats.len == 0)): return
|
if((self.communities.activeCommunity.active and self.communities.activeCommunity.chats.chats.len == 0) or(not self.communities.activeCommunity.active and self.chats.chats.len == 0)): return
|
||||||
|
|
||||||
var selectedChannel =
|
let selectedChannel =
|
||||||
if (self.activeCommunity.active):
|
if (self.communities.activeCommunity.active):
|
||||||
self.activeCommunity.chats.getChannel(index)
|
self.communities.activeCommunity.chats.getChannel(index)
|
||||||
else:
|
else:
|
||||||
self.chats.getChannel(index)
|
self.chats.getChannel(index)
|
||||||
|
|
||||||
self.clearUnreadIfNeeded(self.activeChannel.chatItem)
|
self.clearUnreadIfNeeded(self.activeChannel.chatItem)
|
||||||
self.clearUnreadIfNeeded(selectedChannel)
|
self.clearUnreadIfNeeded(selectedChannel)
|
||||||
if (self.activeCommunity.active and self.activeCommunity.communityItem.lastChannelSeen != selectedChannel.id):
|
|
||||||
self.activeCommunity.communityItem.lastChannelSeen = selectedChannel.id
|
if (self.communities.activeCommunity.active and self.communities.activeCommunity.communityItem.lastChannelSeen != selectedChannel.id):
|
||||||
self.joinedCommunityList.replaceCommunity(self.activeCommunity.communityItem)
|
self.communities.activeCommunity.communityItem.lastChannelSeen = selectedChannel.id
|
||||||
|
self.communities.joinedCommunityList.replaceCommunity(self.communities.activeCommunity.communityItem)
|
||||||
|
|
||||||
if self.activeChannel.id == selectedChannel.id: return
|
if self.activeChannel.id == selectedChannel.id: return
|
||||||
|
|
||||||
|
@ -254,8 +252,8 @@ QtObject:
|
||||||
self.status.chat.setActiveChannel(selectedChannel.id)
|
self.status.chat.setActiveChannel(selectedChannel.id)
|
||||||
|
|
||||||
proc getActiveChannelIdx(self: ChatsView): int {.slot.} =
|
proc getActiveChannelIdx(self: ChatsView): int {.slot.} =
|
||||||
if (self.activeCommunity.active):
|
if (self.communities.activeCommunity.active):
|
||||||
return self.activeCommunity.chats.chats.findIndexById(self.activeChannel.id)
|
return self.communities.activeCommunity.chats.chats.findIndexById(self.activeChannel.id)
|
||||||
else:
|
else:
|
||||||
return self.chats.chats.findIndexById(self.activeChannel.id)
|
return self.chats.chats.findIndexById(self.activeChannel.id)
|
||||||
|
|
||||||
|
@ -268,8 +266,8 @@ QtObject:
|
||||||
if(channel == ""): return
|
if(channel == ""): return
|
||||||
|
|
||||||
let selectedChannel =
|
let selectedChannel =
|
||||||
if (self.activeCommunity.active):
|
if (self.communities.activeCommunity.active):
|
||||||
self.activeCommunity.chats.getChannel(self.activeCommunity.chats.chats.findIndexById(channel))
|
self.communities.activeCommunity.chats.getChannel(self.communities.activeCommunity.chats.chats.findIndexById(channel))
|
||||||
else:
|
else:
|
||||||
self.chats.getChannel(self.chats.chats.findIndexById(channel))
|
self.chats.getChannel(self.chats.chats.findIndexById(channel))
|
||||||
|
|
||||||
|
@ -704,243 +702,6 @@ QtObject:
|
||||||
QtProperty[QVariant] transactions:
|
QtProperty[QVariant] transactions:
|
||||||
read = getTransactions
|
read = getTransactions
|
||||||
|
|
||||||
proc pendingRequestsToJoinForCommunity*(self: ChatsView, communityId: string): seq[CommunityMembershipRequest] =
|
|
||||||
result = self.status.chat.pendingRequestsToJoinForCommunity(communityId)
|
|
||||||
|
|
||||||
proc membershipRequestPushed*(self: ChatsView, communityName: string, pubKey: string) {.signal.}
|
|
||||||
|
|
||||||
proc addMembershipRequests*(self: ChatsView, membershipRequests: seq[CommunityMembershipRequest]) =
|
|
||||||
var communityId: string
|
|
||||||
var community: Community
|
|
||||||
for request in membershipRequests:
|
|
||||||
communityId = request.communityId
|
|
||||||
community = self.joinedCommunityList.getCommunityById(communityId)
|
|
||||||
if (community.id == ""):
|
|
||||||
continue
|
|
||||||
let alreadyPresentRequestIdx = community.membershipRequests.findIndexById(request.id)
|
|
||||||
if (alreadyPresentRequestIdx == -1):
|
|
||||||
community.membershipRequests.add(request)
|
|
||||||
self.membershipRequestPushed(community.name, request.publicKey)
|
|
||||||
else:
|
|
||||||
community.membershipRequests[alreadyPresentRequestIdx] = request
|
|
||||||
self.joinedCommunityList.replaceCommunity(community)
|
|
||||||
|
|
||||||
# Add to active community list
|
|
||||||
if (communityId == self.activeCommunity.communityItem.id):
|
|
||||||
self.activeCommunity.communityMembershipRequestList.addCommunityMembershipRequestItemToList(request)
|
|
||||||
|
|
||||||
proc communitiesChanged*(self: ChatsView) {.signal.}
|
|
||||||
|
|
||||||
proc getCommunitiesIfNotFetched*(self: ChatsView): CommunityList =
|
|
||||||
if (not self.communityList.fetched):
|
|
||||||
let communities = self.status.chat.getAllComunities()
|
|
||||||
self.communityList.setNewData(communities)
|
|
||||||
self.communityList.fetched = true
|
|
||||||
return self.communityList
|
|
||||||
|
|
||||||
proc getComunities*(self: ChatsView): QVariant {.slot.} =
|
|
||||||
return newQVariant(self.getCommunitiesIfNotFetched())
|
|
||||||
|
|
||||||
QtProperty[QVariant] communities:
|
|
||||||
read = getComunities
|
|
||||||
notify = communitiesChanged
|
|
||||||
|
|
||||||
proc joinedCommunitiesChanged*(self: ChatsView) {.signal.}
|
|
||||||
|
|
||||||
proc getJoinedComunities*(self: ChatsView): QVariant {.slot.} =
|
|
||||||
if (not self.joinedCommunityList.fetched):
|
|
||||||
let communities = self.status.chat.getJoinedComunities()
|
|
||||||
self.joinedCommunityList.setNewData(communities)
|
|
||||||
self.joinedCommunityList.fetched = true
|
|
||||||
|
|
||||||
# Also fetch requests
|
|
||||||
self.myCommunityRequests = self.status.chat.myPendingRequestsToJoin()
|
|
||||||
|
|
||||||
return newQVariant(self.joinedCommunityList)
|
|
||||||
|
|
||||||
QtProperty[QVariant] joinedCommunities:
|
|
||||||
read = getJoinedComunities
|
|
||||||
notify = joinedCommunitiesChanged
|
|
||||||
|
|
||||||
proc activeCommunityChanged*(self: ChatsView) {.signal.}
|
|
||||||
|
|
||||||
proc setActiveCommunity*(self: ChatsView, communityId: string) {.slot.} =
|
|
||||||
if(communityId == ""): return
|
|
||||||
self.addMembershipRequests(self.pendingRequestsToJoinForCommunity(communityId))
|
|
||||||
self.activeCommunity.setCommunityItem(self.joinedCommunityList.getCommunityById(communityId))
|
|
||||||
self.activeCommunity.setActive(true)
|
|
||||||
self.activeCommunityChanged()
|
|
||||||
|
|
||||||
proc getActiveCommunity*(self: ChatsView): QVariant {.slot.} =
|
|
||||||
newQVariant(self.activeCommunity)
|
|
||||||
|
|
||||||
QtProperty[QVariant] activeCommunity:
|
|
||||||
read = getActiveCommunity
|
|
||||||
write = setActiveCommunity
|
|
||||||
notify = activeCommunityChanged
|
|
||||||
|
|
||||||
proc joinCommunity*(self: ChatsView, communityId: string, setActive: bool = true): string {.slot.} =
|
|
||||||
result = ""
|
|
||||||
try:
|
|
||||||
self.status.chat.joinCommunity(communityId)
|
|
||||||
self.joinedCommunityList.addCommunityItemToList(self.communityList.getCommunityById(communityId))
|
|
||||||
if (setActive):
|
|
||||||
self.setActiveCommunity(communityId)
|
|
||||||
except Exception as e:
|
|
||||||
error "Error joining the community", msg = e.msg
|
|
||||||
result = fmt"Error joining the community: {e.msg}"
|
|
||||||
|
|
||||||
proc membershipRequestChanged*(self: ChatsView, communityName: string, accepted: bool) {.signal.}
|
|
||||||
|
|
||||||
proc addCommunityToList*(self: ChatsView, community: Community) =
|
|
||||||
let communityCheck = self.communityList.getCommunityById(community.id)
|
|
||||||
if (communityCheck.id == ""):
|
|
||||||
self.communityList.addCommunityItemToList(community)
|
|
||||||
else:
|
|
||||||
self.communityList.replaceCommunity(community)
|
|
||||||
|
|
||||||
if (community.joined == true):
|
|
||||||
let joinedCommunityCheck = self.joinedCommunityList.getCommunityById(community.id)
|
|
||||||
if (joinedCommunityCheck.id == ""):
|
|
||||||
self.joinedCommunityList.addCommunityItemToList(community)
|
|
||||||
else:
|
|
||||||
self.joinedCommunityList.replaceCommunity(community)
|
|
||||||
elif (community.isMember == true):
|
|
||||||
discard self.joinCommunity(community.id, false)
|
|
||||||
var i = 0
|
|
||||||
for communityRequest in self.myCommunityRequests:
|
|
||||||
if (communityRequest.communityId == community.id):
|
|
||||||
self.membershipRequestChanged(community.name, true)
|
|
||||||
self.myCommunityRequests.delete(i, i)
|
|
||||||
break
|
|
||||||
i = i + 1
|
|
||||||
|
|
||||||
proc isCommunityRequestPending*(self: ChatsView, communityId: string): bool {.slot.} =
|
|
||||||
for communityRequest in self.myCommunityRequests:
|
|
||||||
if (communityRequest.communityId == communityId):
|
|
||||||
return true
|
|
||||||
return false
|
|
||||||
|
|
||||||
proc createCommunity*(self: ChatsView, name: string, description: string, access: int, ensOnly: bool, imagePath: string, aX: int, aY: int, bX: int, bY: int): string {.slot.} =
|
|
||||||
result = ""
|
|
||||||
try:
|
|
||||||
var image = image_utils.formatImagePath(imagePath)
|
|
||||||
let community = self.status.chat.createCommunity(name, description, access, ensOnly, image, aX, aY, bX, bY)
|
|
||||||
|
|
||||||
if (community.id == ""):
|
|
||||||
return "Community was not created. Please try again later"
|
|
||||||
|
|
||||||
self.communityList.addCommunityItemToList(community)
|
|
||||||
self.joinedCommunityList.addCommunityItemToList(community)
|
|
||||||
self.communitiesChanged()
|
|
||||||
except Exception as e:
|
|
||||||
error "Error creating the community", msg = e.msg
|
|
||||||
result = fmt"Error creating the community: {e.msg}"
|
|
||||||
|
|
||||||
proc createCommunityChannel*(self: ChatsView, communityId: string, name: string, description: string): string {.slot.} =
|
|
||||||
result = ""
|
|
||||||
try:
|
|
||||||
let chat = self.status.chat.createCommunityChannel(communityId, name, description)
|
|
||||||
|
|
||||||
if (chat.id == ""):
|
|
||||||
return "Chat was not created. Please try again later"
|
|
||||||
|
|
||||||
self.joinedCommunityList.addChannelToCommunity(communityId, chat)
|
|
||||||
discard self.activeCommunity.chats.addChatItemToList(chat)
|
|
||||||
except Exception as e:
|
|
||||||
error "Error creating the channel", msg = e.msg
|
|
||||||
result = fmt"Error creating the channel: {e.msg}"
|
|
||||||
|
|
||||||
proc observedCommunityChanged*(self: ChatsView) {.signal.}
|
|
||||||
|
|
||||||
proc setObservedCommunity*(self: ChatsView, communityId: string) {.slot.} =
|
|
||||||
if(communityId == ""): return
|
|
||||||
var community = self.communityList.getCommunityById(communityId)
|
|
||||||
if (community.id == ""):
|
|
||||||
discard self.getCommunitiesIfNotFetched()
|
|
||||||
community = self.communityList.getCommunityById(communityId)
|
|
||||||
self.observedCommunity.setCommunityItem(community)
|
|
||||||
self.observedCommunityChanged()
|
|
||||||
|
|
||||||
proc getObservedCommunity*(self: ChatsView): QVariant {.slot.} =
|
|
||||||
newQVariant(self.observedCommunity)
|
|
||||||
|
|
||||||
QtProperty[QVariant] observedCommunity:
|
|
||||||
read = getObservedCommunity
|
|
||||||
write = setObservedCommunity
|
|
||||||
notify = observedCommunityChanged
|
|
||||||
|
|
||||||
proc leaveCommunity*(self: ChatsView, communityId: string): string {.slot.} =
|
|
||||||
result = ""
|
|
||||||
try:
|
|
||||||
self.status.chat.leaveCommunity(communityId)
|
|
||||||
if (communityId == self.activeCommunity.communityItem.id):
|
|
||||||
self.activeCommunity.setActive(false)
|
|
||||||
self.joinedCommunityList.removeCommunityItemFromList(communityId)
|
|
||||||
var updatedCommunity = self.communityList.getCommunityById(communityId)
|
|
||||||
updatedCommunity.joined = false
|
|
||||||
self.communityList.replaceCommunity(updatedCommunity)
|
|
||||||
except Exception as e:
|
|
||||||
error "Error leaving the community", msg = e.msg
|
|
||||||
result = fmt"Error leaving the community: {e.msg}"
|
|
||||||
|
|
||||||
proc leaveCurrentCommunity*(self: ChatsView): string {.slot.} =
|
|
||||||
result = self.leaveCommunity(self.activeCommunity.communityItem.id)
|
|
||||||
|
|
||||||
proc inviteUserToCommunity*(self: ChatsView, pubKey: string): string {.slot.} =
|
|
||||||
try:
|
|
||||||
self.status.chat.inviteUserToCommunity(self.activeCommunity.id(), pubKey)
|
|
||||||
except Exception as e:
|
|
||||||
error "Error inviting to the community", msg = e.msg
|
|
||||||
result = fmt"Error inviting to the community: {e.msg}"
|
|
||||||
|
|
||||||
proc exportComumnity*(self: ChatsView): string {.slot.} =
|
|
||||||
try:
|
|
||||||
result = self.status.chat.exportCommunity(self.activeCommunity.communityItem.id)
|
|
||||||
except Exception as e:
|
|
||||||
error "Error exporting the community", msg = e.msg
|
|
||||||
result = fmt"Error exporting the community: {e.msg}"
|
|
||||||
|
|
||||||
proc importCommunity*(self: ChatsView, communityKey: string) {.slot.} =
|
|
||||||
try:
|
|
||||||
self.status.chat.importCommunity(communityKey)
|
|
||||||
except Exception as e:
|
|
||||||
error "Error importing the community", msg = e.msg
|
|
||||||
|
|
||||||
proc removeUserFromCommunity*(self: ChatsView, pubKey: string) {.slot.} =
|
|
||||||
try:
|
|
||||||
self.status.chat.removeUserFromCommunity(self.activeCommunity.id(), pubKey)
|
|
||||||
self.activeCommunity.removeMember(pubKey)
|
|
||||||
except Exception as e:
|
|
||||||
error "Error removing user from the community", msg = e.msg
|
|
||||||
|
|
||||||
|
|
||||||
proc requestToJoinCommunity*(self: ChatsView, communityId: string, ensName: string) {.slot.} =
|
|
||||||
try:
|
|
||||||
let requests = self.status.chat.requestToJoinCommunity(communityId, ensName)
|
|
||||||
for request in requests:
|
|
||||||
self.myCommunityRequests.add(request)
|
|
||||||
except Exception as e:
|
|
||||||
error "Error requesting to join the community", msg = e.msg
|
|
||||||
|
|
||||||
proc acceptRequestToJoinCommunity*(self: ChatsView, requestId: string): string {.slot.} =
|
|
||||||
try:
|
|
||||||
self.status.chat.acceptRequestToJoinCommunity(requestId)
|
|
||||||
self.activeCommunity.communityMembershipRequestList.removeCommunityMembershipRequestItemFromList(requestId)
|
|
||||||
except Exception as e:
|
|
||||||
error "Error accepting request to join the community", msg = e.msg
|
|
||||||
return "Error accepting request to join the community"
|
|
||||||
return ""
|
|
||||||
|
|
||||||
proc declineRequestToJoinCommunity*(self: ChatsView, requestId: string): string {.slot.} =
|
|
||||||
try:
|
|
||||||
self.status.chat.declineRequestToJoinCommunity(requestId)
|
|
||||||
self.activeCommunity.communityMembershipRequestList.removeCommunityMembershipRequestItemFromList(requestId)
|
|
||||||
except Exception as e:
|
|
||||||
error "Error declining request to join the community", msg = e.msg
|
|
||||||
return "Error declining request to join the community"
|
|
||||||
return ""
|
|
||||||
|
|
||||||
method rowCount*(self: ChatsView, index: QModelIndex = nil): int =
|
method rowCount*(self: ChatsView, index: QModelIndex = nil): int =
|
||||||
result = self.messageList.len
|
result = self.messageList.len
|
||||||
|
|
||||||
|
@ -959,6 +720,6 @@ QtObject:
|
||||||
proc getMessageListIndex(self: ChatsView):int {.slot.} =
|
proc getMessageListIndex(self: ChatsView):int {.slot.} =
|
||||||
var idx = -1
|
var idx = -1
|
||||||
for msg in toSeq(self.messageList.values):
|
for msg in toSeq(self.messageList.values):
|
||||||
idx = idx + 1
|
|
||||||
if(self.activeChannel.id == msg.id): return idx
|
if(self.activeChannel.id == msg.id): return idx
|
||||||
|
idx = idx + 1
|
||||||
return idx
|
return idx
|
||||||
|
|
|
@ -0,0 +1,277 @@
|
||||||
|
import NimQml, json, sequtils, chronicles, strutils, strformat
|
||||||
|
import ../../../status/status
|
||||||
|
import ../../../status/chat/chat
|
||||||
|
import ./community_list
|
||||||
|
import ./community_item
|
||||||
|
import ./community_membership_request_list
|
||||||
|
import ./channels_list
|
||||||
|
import ../../utils/image_utils
|
||||||
|
|
||||||
|
|
||||||
|
logScope:
|
||||||
|
topics = "communities-view"
|
||||||
|
|
||||||
|
QtObject:
|
||||||
|
type CommunitiesView* = ref object of QObject
|
||||||
|
status: Status
|
||||||
|
activeCommunity*: CommunityItemView
|
||||||
|
observedCommunity*: CommunityItemView
|
||||||
|
communityList*: CommunityList
|
||||||
|
joinedCommunityList*: CommunityList
|
||||||
|
myCommunityRequests*: seq[CommunityMembershipRequest]
|
||||||
|
|
||||||
|
proc setup(self: CommunitiesView) =
|
||||||
|
self.QObject.setup
|
||||||
|
|
||||||
|
proc delete*(self: CommunitiesView) =
|
||||||
|
self.observedCommunity.delete
|
||||||
|
self.activeCommunity.delete
|
||||||
|
self.communityList.delete
|
||||||
|
self.joinedCommunityList.delete
|
||||||
|
self.QObject.delete
|
||||||
|
|
||||||
|
proc newCommunitiesView*(status: Status): CommunitiesView =
|
||||||
|
new(result, delete)
|
||||||
|
result.status = status
|
||||||
|
result.activeCommunity = newCommunityItemView(status)
|
||||||
|
result.observedCommunity = newCommunityItemView(status)
|
||||||
|
result.communityList = newCommunityList(status)
|
||||||
|
result.joinedCommunityList = newCommunityList(status)
|
||||||
|
result.setup
|
||||||
|
|
||||||
|
proc pendingRequestsToJoinForCommunity*(self: CommunitiesView, communityId: string): seq[CommunityMembershipRequest] =
|
||||||
|
result = self.status.chat.pendingRequestsToJoinForCommunity(communityId)
|
||||||
|
|
||||||
|
proc membershipRequestPushed*(self: CommunitiesView, communityName: string, pubKey: string) {.signal.}
|
||||||
|
|
||||||
|
proc addMembershipRequests*(self: CommunitiesView, membershipRequests: seq[CommunityMembershipRequest]) =
|
||||||
|
var communityId: string
|
||||||
|
var community: Community
|
||||||
|
for request in membershipRequests:
|
||||||
|
communityId = request.communityId
|
||||||
|
community = self.joinedCommunityList.getCommunityById(communityId)
|
||||||
|
if (community.id == ""):
|
||||||
|
continue
|
||||||
|
let alreadyPresentRequestIdx = community.membershipRequests.findIndexById(request.id)
|
||||||
|
if (alreadyPresentRequestIdx == -1):
|
||||||
|
community.membershipRequests.add(request)
|
||||||
|
self.membershipRequestPushed(community.name, request.publicKey)
|
||||||
|
else:
|
||||||
|
community.membershipRequests[alreadyPresentRequestIdx] = request
|
||||||
|
self.joinedCommunityList.replaceCommunity(community)
|
||||||
|
|
||||||
|
# Add to active community list
|
||||||
|
if (communityId == self.activeCommunity.communityItem.id):
|
||||||
|
self.activeCommunity.communityMembershipRequestList.addCommunityMembershipRequestItemToList(request)
|
||||||
|
|
||||||
|
proc communitiesChanged*(self: CommunitiesView) {.signal.}
|
||||||
|
|
||||||
|
proc getCommunitiesIfNotFetched*(self: CommunitiesView): CommunityList =
|
||||||
|
if (not self.communityList.fetched):
|
||||||
|
let communities = self.status.chat.getAllComunities()
|
||||||
|
self.communityList.setNewData(communities)
|
||||||
|
self.communityList.fetched = true
|
||||||
|
return self.communityList
|
||||||
|
|
||||||
|
proc getComunities*(self: CommunitiesView): QVariant {.slot.} =
|
||||||
|
return newQVariant(self.getCommunitiesIfNotFetched())
|
||||||
|
|
||||||
|
QtProperty[QVariant] list:
|
||||||
|
read = getComunities
|
||||||
|
notify = communitiesChanged
|
||||||
|
|
||||||
|
proc joinedCommunitiesChanged*(self: CommunitiesView) {.signal.}
|
||||||
|
|
||||||
|
proc getJoinedComunities*(self: CommunitiesView): QVariant {.slot.} =
|
||||||
|
if (not self.joinedCommunityList.fetched):
|
||||||
|
let communities = self.status.chat.getJoinedComunities()
|
||||||
|
self.joinedCommunityList.setNewData(communities)
|
||||||
|
self.joinedCommunityList.fetched = true
|
||||||
|
|
||||||
|
# Also fetch requests
|
||||||
|
self.myCommunityRequests = self.status.chat.myPendingRequestsToJoin()
|
||||||
|
|
||||||
|
return newQVariant(self.joinedCommunityList)
|
||||||
|
|
||||||
|
QtProperty[QVariant] joinedCommunities:
|
||||||
|
read = getJoinedComunities
|
||||||
|
notify = joinedCommunitiesChanged
|
||||||
|
|
||||||
|
proc activeCommunityChanged*(self: CommunitiesView) {.signal.}
|
||||||
|
|
||||||
|
proc setActiveCommunity*(self: CommunitiesView, communityId: string) {.slot.} =
|
||||||
|
if(communityId == ""): return
|
||||||
|
self.addMembershipRequests(self.pendingRequestsToJoinForCommunity(communityId))
|
||||||
|
self.activeCommunity.setCommunityItem(self.joinedCommunityList.getCommunityById(communityId))
|
||||||
|
self.activeCommunity.setActive(true)
|
||||||
|
self.activeCommunityChanged()
|
||||||
|
|
||||||
|
proc getActiveCommunity*(self: CommunitiesView): QVariant {.slot.} =
|
||||||
|
newQVariant(self.activeCommunity)
|
||||||
|
|
||||||
|
QtProperty[QVariant] activeCommunity:
|
||||||
|
read = getActiveCommunity
|
||||||
|
write = setActiveCommunity
|
||||||
|
notify = activeCommunityChanged
|
||||||
|
|
||||||
|
proc joinCommunity*(self: CommunitiesView, communityId: string, setActive: bool = true): string {.slot.} =
|
||||||
|
result = ""
|
||||||
|
try:
|
||||||
|
self.status.chat.joinCommunity(communityId)
|
||||||
|
self.joinedCommunityList.addCommunityItemToList(self.communityList.getCommunityById(communityId))
|
||||||
|
if (setActive):
|
||||||
|
self.setActiveCommunity(communityId)
|
||||||
|
except Exception as e:
|
||||||
|
error "Error joining the community", msg = e.msg
|
||||||
|
result = fmt"Error joining the community: {e.msg}"
|
||||||
|
|
||||||
|
proc membershipRequestChanged*(self: CommunitiesView, communityName: string, accepted: bool) {.signal.}
|
||||||
|
|
||||||
|
proc addCommunityToList*(self: CommunitiesView, community: Community) =
|
||||||
|
let communityCheck = self.communityList.getCommunityById(community.id)
|
||||||
|
if (communityCheck.id == ""):
|
||||||
|
self.communityList.addCommunityItemToList(community)
|
||||||
|
else:
|
||||||
|
self.communityList.replaceCommunity(community)
|
||||||
|
|
||||||
|
if (community.joined == true):
|
||||||
|
let joinedCommunityCheck = self.joinedCommunityList.getCommunityById(community.id)
|
||||||
|
if (joinedCommunityCheck.id == ""):
|
||||||
|
self.joinedCommunityList.addCommunityItemToList(community)
|
||||||
|
else:
|
||||||
|
self.joinedCommunityList.replaceCommunity(community)
|
||||||
|
elif (community.isMember == true):
|
||||||
|
discard self.joinCommunity(community.id, false)
|
||||||
|
var i = 0
|
||||||
|
for communityRequest in self.myCommunityRequests:
|
||||||
|
if (communityRequest.communityId == community.id):
|
||||||
|
self.membershipRequestChanged(community.name, true)
|
||||||
|
self.myCommunityRequests.delete(i, i)
|
||||||
|
break
|
||||||
|
i = i + 1
|
||||||
|
|
||||||
|
proc isCommunityRequestPending*(self: CommunitiesView, communityId: string): bool {.slot.} =
|
||||||
|
for communityRequest in self.myCommunityRequests:
|
||||||
|
if (communityRequest.communityId == communityId):
|
||||||
|
return true
|
||||||
|
return false
|
||||||
|
|
||||||
|
proc createCommunity*(self: CommunitiesView, name: string, description: string, access: int, ensOnly: bool, imagePath: string, aX: int, aY: int, bX: int, bY: int): string {.slot.} =
|
||||||
|
result = ""
|
||||||
|
try:
|
||||||
|
var image = image_utils.formatImagePath(imagePath)
|
||||||
|
let community = self.status.chat.createCommunity(name, description, access, ensOnly, image, aX, aY, bX, bY)
|
||||||
|
|
||||||
|
if (community.id == ""):
|
||||||
|
return "Community was not created. Please try again later"
|
||||||
|
|
||||||
|
self.communityList.addCommunityItemToList(community)
|
||||||
|
self.joinedCommunityList.addCommunityItemToList(community)
|
||||||
|
self.communitiesChanged()
|
||||||
|
except Exception as e:
|
||||||
|
error "Error creating the community", msg = e.msg
|
||||||
|
result = fmt"Error creating the community: {e.msg}"
|
||||||
|
|
||||||
|
proc createCommunityChannel*(self: CommunitiesView, communityId: string, name: string, description: string): string {.slot.} =
|
||||||
|
result = ""
|
||||||
|
try:
|
||||||
|
let chat = self.status.chat.createCommunityChannel(communityId, name, description)
|
||||||
|
|
||||||
|
if (chat.id == ""):
|
||||||
|
return "Chat was not created. Please try again later"
|
||||||
|
|
||||||
|
self.joinedCommunityList.addChannelToCommunity(communityId, chat)
|
||||||
|
discard self.activeCommunity.chats.addChatItemToList(chat)
|
||||||
|
except Exception as e:
|
||||||
|
error "Error creating the channel", msg = e.msg
|
||||||
|
result = fmt"Error creating the channel: {e.msg}"
|
||||||
|
|
||||||
|
proc observedCommunityChanged*(self: CommunitiesView) {.signal.}
|
||||||
|
|
||||||
|
proc setObservedCommunity*(self: CommunitiesView, communityId: string) {.slot.} =
|
||||||
|
if(communityId == ""): return
|
||||||
|
var community = self.communityList.getCommunityById(communityId)
|
||||||
|
if (community.id == ""):
|
||||||
|
discard self.getCommunitiesIfNotFetched()
|
||||||
|
community = self.communityList.getCommunityById(communityId)
|
||||||
|
self.observedCommunity.setCommunityItem(community)
|
||||||
|
self.observedCommunityChanged()
|
||||||
|
|
||||||
|
proc getObservedCommunity*(self: CommunitiesView): QVariant {.slot.} =
|
||||||
|
newQVariant(self.observedCommunity)
|
||||||
|
|
||||||
|
QtProperty[QVariant] observedCommunity:
|
||||||
|
read = getObservedCommunity
|
||||||
|
write = setObservedCommunity
|
||||||
|
notify = observedCommunityChanged
|
||||||
|
|
||||||
|
proc leaveCommunity*(self: CommunitiesView, communityId: string): string {.slot.} =
|
||||||
|
result = ""
|
||||||
|
try:
|
||||||
|
self.status.chat.leaveCommunity(communityId)
|
||||||
|
if (communityId == self.activeCommunity.communityItem.id):
|
||||||
|
self.activeCommunity.setActive(false)
|
||||||
|
self.joinedCommunityList.removeCommunityItemFromList(communityId)
|
||||||
|
var updatedCommunity = self.communityList.getCommunityById(communityId)
|
||||||
|
updatedCommunity.joined = false
|
||||||
|
self.communityList.replaceCommunity(updatedCommunity)
|
||||||
|
except Exception as e:
|
||||||
|
error "Error leaving the community", msg = e.msg
|
||||||
|
result = fmt"Error leaving the community: {e.msg}"
|
||||||
|
|
||||||
|
proc leaveCurrentCommunity*(self: CommunitiesView): string {.slot.} =
|
||||||
|
result = self.leaveCommunity(self.activeCommunity.communityItem.id)
|
||||||
|
|
||||||
|
proc inviteUserToCommunity*(self: CommunitiesView, pubKey: string): string {.slot.} =
|
||||||
|
try:
|
||||||
|
self.status.chat.inviteUserToCommunity(self.activeCommunity.id(), pubKey)
|
||||||
|
except Exception as e:
|
||||||
|
error "Error inviting to the community", msg = e.msg
|
||||||
|
result = fmt"Error inviting to the community: {e.msg}"
|
||||||
|
|
||||||
|
proc exportComumnity*(self: CommunitiesView): string {.slot.} =
|
||||||
|
try:
|
||||||
|
result = self.status.chat.exportCommunity(self.activeCommunity.communityItem.id)
|
||||||
|
except Exception as e:
|
||||||
|
error "Error exporting the community", msg = e.msg
|
||||||
|
result = fmt"Error exporting the community: {e.msg}"
|
||||||
|
|
||||||
|
proc importCommunity*(self: CommunitiesView, communityKey: string) {.slot.} =
|
||||||
|
try:
|
||||||
|
self.status.chat.importCommunity(communityKey)
|
||||||
|
except Exception as e:
|
||||||
|
error "Error importing the community", msg = e.msg
|
||||||
|
|
||||||
|
proc removeUserFromCommunity*(self: CommunitiesView, pubKey: string) {.slot.} =
|
||||||
|
try:
|
||||||
|
self.status.chat.removeUserFromCommunity(self.activeCommunity.id(), pubKey)
|
||||||
|
self.activeCommunity.removeMember(pubKey)
|
||||||
|
except Exception as e:
|
||||||
|
error "Error removing user from the community", msg = e.msg
|
||||||
|
|
||||||
|
|
||||||
|
proc requestToJoinCommunity*(self: CommunitiesView, communityId: string, ensName: string) {.slot.} =
|
||||||
|
try:
|
||||||
|
let requests = self.status.chat.requestToJoinCommunity(communityId, ensName)
|
||||||
|
for request in requests:
|
||||||
|
self.myCommunityRequests.add(request)
|
||||||
|
except Exception as e:
|
||||||
|
error "Error requesting to join the community", msg = e.msg
|
||||||
|
|
||||||
|
proc acceptRequestToJoinCommunity*(self: CommunitiesView, requestId: string): string {.slot.} =
|
||||||
|
try:
|
||||||
|
self.status.chat.acceptRequestToJoinCommunity(requestId)
|
||||||
|
self.activeCommunity.communityMembershipRequestList.removeCommunityMembershipRequestItemFromList(requestId)
|
||||||
|
except Exception as e:
|
||||||
|
error "Error accepting request to join the community", msg = e.msg
|
||||||
|
return "Error accepting request to join the community"
|
||||||
|
return ""
|
||||||
|
|
||||||
|
proc declineRequestToJoinCommunity*(self: CommunitiesView, requestId: string): string {.slot.} =
|
||||||
|
try:
|
||||||
|
self.status.chat.declineRequestToJoinCommunity(requestId)
|
||||||
|
self.activeCommunity.communityMembershipRequestList.removeCommunityMembershipRequestItemFromList(requestId)
|
||||||
|
except Exception as e:
|
||||||
|
error "Error declining request to join the community", msg = e.msg
|
||||||
|
return "Error declining request to join the community"
|
||||||
|
return ""
|
|
@ -1,4 +1,4 @@
|
||||||
import NimQml, Tables, std/wrapnils
|
import NimQml, std/wrapnils
|
||||||
import ../../../status/[chat/chat, status]
|
import ../../../status/[chat/chat, status]
|
||||||
import channels_list
|
import channels_list
|
||||||
import ../../../eventemitter
|
import ../../../eventemitter
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import NimQml, Tables, chronicles
|
import NimQml, Tables, chronicles
|
||||||
import ../../../status/chat/[chat, message]
|
import ../../../status/chat/chat
|
||||||
import ../../../status/status
|
import ../../../status/status
|
||||||
import ../../../status/ens
|
|
||||||
import ../../../status/accounts
|
import ../../../status/accounts
|
||||||
import strutils
|
import strutils
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import NimQml, Tables,
|
import NimQml, Tables,
|
||||||
../../../status/[chat/chat, status, ens]
|
../../../status/[status, ens]
|
||||||
import ../../../status/accounts as status_accounts
|
import ../../../status/accounts as status_accounts
|
||||||
type
|
type
|
||||||
CommunityMembersRoles {.pure.} = enum
|
CommunityMembersRoles {.pure.} = enum
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import NimQml, Tables, chronicles
|
import NimQml, Tables, chronicles
|
||||||
import ../../../status/chat/[chat, message]
|
import ../../../status/chat/chat
|
||||||
import ../../../status/status
|
import ../../../status/status
|
||||||
import ../../../status/ens
|
|
||||||
import ../../../status/accounts
|
import ../../../status/accounts
|
||||||
import strutils
|
import strutils
|
||||||
|
|
||||||
|
|
|
@ -280,7 +280,7 @@ StackLayout {
|
||||||
StatusChatInput {
|
StatusChatInput {
|
||||||
id: chatInput
|
id: chatInput
|
||||||
visible: {
|
visible: {
|
||||||
const community = chatsModel.activeCommunity
|
const community = chatsModel.communities.activeCommunity
|
||||||
if (chatsModel.activeChannel.chatType !== Constants.chatTypePrivateGroupChat &&
|
if (chatsModel.activeChannel.chatType !== Constants.chatTypePrivateGroupChat &&
|
||||||
(!community.active ||
|
(!community.active ||
|
||||||
community.access === Constants.communityChatPublicAccess ||
|
community.access === Constants.communityChatPublicAccess ||
|
||||||
|
|
|
@ -201,8 +201,12 @@ ScrollView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onMembershipRequestChanged: function (communityName, accepted) {
|
Connections {
|
||||||
|
target: chatsModel.communities
|
||||||
|
|
||||||
|
onMembershipRequestChanged: function (communityName, accepted) {
|
||||||
systemTray.showMessage("Status",
|
systemTray.showMessage("Status",
|
||||||
accepted ? qsTr("You have been accepted into the ‘%1’ community").arg(communityName) :
|
accepted ? qsTr("You have been accepted into the ‘%1’ community").arg(communityName) :
|
||||||
qsTr("Your request to join the ‘%1’ community was declined").arg(communityName),
|
qsTr("Your request to join the ‘%1’ community was declined").arg(communityName),
|
||||||
|
|
|
@ -15,9 +15,9 @@ Item {
|
||||||
height: childrenRect.height
|
height: childrenRect.height
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
chatsModel.setObservedCommunity(communityId)
|
chatsModel.communities.setObservedCommunity(communityId)
|
||||||
|
|
||||||
root.invitedCommunity = chatsModel.observedCommunity
|
root.invitedCommunity = chatsModel.communities.observedCommunity
|
||||||
}
|
}
|
||||||
|
|
||||||
UserImage {
|
UserImage {
|
||||||
|
@ -144,7 +144,7 @@ Item {
|
||||||
//% "Join"
|
//% "Join"
|
||||||
qsTrId("join")
|
qsTrId("join")
|
||||||
onClicked: {
|
onClicked: {
|
||||||
chatsModel.joinCommunity(communityId)
|
chatsModel.communities.joinCommunity(communityId)
|
||||||
root.joined = true
|
root.joined = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ SplitView {
|
||||||
SplitView.preferredWidth: Style.current.leftTabPrefferedSize
|
SplitView.preferredWidth: Style.current.leftTabPrefferedSize
|
||||||
SplitView.minimumWidth: Style.current.leftTabMinimumWidth
|
SplitView.minimumWidth: Style.current.leftTabMinimumWidth
|
||||||
SplitView.maximumWidth: Style.current.leftTabMaximumWidth
|
SplitView.maximumWidth: Style.current.leftTabMaximumWidth
|
||||||
sourceComponent: appSettings.communitiesEnabled && chatsModel.activeCommunity.active ? communtiyColumnComponent : contactsColumnComponent
|
sourceComponent: appSettings.communitiesEnabled && chatsModel.communities.activeCommunity.active ? communtiyColumnComponent : contactsColumnComponent
|
||||||
}
|
}
|
||||||
|
|
||||||
Component {
|
Component {
|
||||||
|
|
|
@ -40,7 +40,7 @@ Item {
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.leftMargin: Style.current.bigPadding
|
anchors.leftMargin: Style.current.bigPadding
|
||||||
anchors.verticalCenter: communityHeaderButton.verticalCenter
|
anchors.verticalCenter: communityHeaderButton.verticalCenter
|
||||||
onClicked: chatsModel.activeCommunity.active = false
|
onClicked: chatsModel.communities.activeCommunity.active = false
|
||||||
}
|
}
|
||||||
|
|
||||||
CommunityHeaderButton {
|
CommunityHeaderButton {
|
||||||
|
@ -72,7 +72,7 @@ Item {
|
||||||
icon.source: "../../img/hash.svg"
|
icon.source: "../../img/hash.svg"
|
||||||
icon.width: 20
|
icon.width: 20
|
||||||
icon.height: 20
|
icon.height: 20
|
||||||
onTriggered: openPopup(createChannelPopup, {communityId: chatsModel.activeCommunity.id})
|
onTriggered: openPopup(createChannelPopup, {communityId: chatsModel.communities.activeCommunity.id})
|
||||||
}
|
}
|
||||||
|
|
||||||
Action {
|
Action {
|
||||||
|
@ -82,7 +82,7 @@ Item {
|
||||||
icon.color: Style.current.red
|
icon.color: Style.current.red
|
||||||
icon.width: 20
|
icon.width: 20
|
||||||
icon.height: 20
|
icon.height: 20
|
||||||
onTriggered: chatsModel.leaveCurrentCommunity()
|
onTriggered: chatsModel.communities.leaveCurrentCommunity()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ Item {
|
||||||
Loader {
|
Loader {
|
||||||
id: membershipRequestsLoader
|
id: membershipRequestsLoader
|
||||||
width: parent.width
|
width: parent.width
|
||||||
active: chatsModel.activeCommunity.admin
|
active: chatsModel.communities.activeCommunity.admin
|
||||||
anchors.top: communityHeader.bottom
|
anchors.top: communityHeader.bottom
|
||||||
anchors.topMargin: item && item.visible ? Style.current.halfPadding : 0
|
anchors.topMargin: item && item.visible ? Style.current.halfPadding : 0
|
||||||
|
|
||||||
|
@ -119,12 +119,12 @@ Item {
|
||||||
ChannelList {
|
ChannelList {
|
||||||
id: channelList
|
id: channelList
|
||||||
searchStr: ""
|
searchStr: ""
|
||||||
channelModel: chatsModel.activeCommunity.chats
|
channelModel: chatsModel.communities.activeCommunity.chats
|
||||||
}
|
}
|
||||||
|
|
||||||
CommunityWelcomeBanner {
|
CommunityWelcomeBanner {
|
||||||
id: emptyViewAndSuggestions
|
id: emptyViewAndSuggestions
|
||||||
visible: chatsModel.activeCommunity.admin
|
visible: chatsModel.communities.activeCommunity.admin
|
||||||
width: parent.width
|
width: parent.width
|
||||||
anchors.top: channelList.bottom
|
anchors.top: channelList.bottom
|
||||||
anchors.topMargin: Style.current.padding
|
anchors.topMargin: Style.current.padding
|
||||||
|
|
|
@ -68,7 +68,7 @@ ModalPopup {
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
model: chatsModel.communities
|
model: chatsModel.communities.list
|
||||||
delegate: Item {
|
delegate: Item {
|
||||||
// TODO add the search for the name and category once they exist
|
// TODO add the search for the name and category once they exist
|
||||||
visible: {
|
visible: {
|
||||||
|
@ -126,9 +126,9 @@ ModalPopup {
|
||||||
cursorShape: Qt.PointingHandCursor
|
cursorShape: Qt.PointingHandCursor
|
||||||
onClicked: {
|
onClicked: {
|
||||||
if (joined && isMember) {
|
if (joined && isMember) {
|
||||||
chatsModel.setActiveCommunity(id)
|
chatsModel.communities.setActiveCommunity(id)
|
||||||
} else {
|
} else {
|
||||||
chatsModel.setObservedCommunity(id)
|
chatsModel.communities.setObservedCommunity(id)
|
||||||
openPopup(communityDetailPopup)
|
openPopup(communityDetailPopup)
|
||||||
}
|
}
|
||||||
popup.close()
|
popup.close()
|
||||||
|
|
|
@ -89,7 +89,7 @@ Rectangle {
|
||||||
communityButton.hovered = false
|
communityButton.hovered = false
|
||||||
}
|
}
|
||||||
onClicked: {
|
onClicked: {
|
||||||
chatsModel.setActiveCommunity(communityId)
|
chatsModel.communities.setActiveCommunity(communityId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ import "../../../../shared/status"
|
||||||
import "../ContactsColumn"
|
import "../ContactsColumn"
|
||||||
|
|
||||||
ModalPopup {
|
ModalPopup {
|
||||||
property QtObject community: chatsModel.observedCommunity
|
property QtObject community: chatsModel.communities.observedCommunity
|
||||||
property string communityId: community.id
|
property string communityId: community.id
|
||||||
property string name: community.name
|
property string name: community.name
|
||||||
property string description: community.description
|
property string description: community.description
|
||||||
|
@ -185,7 +185,7 @@ ModalPopup {
|
||||||
if (access !== Constants.communityChatOnRequestAccess) {
|
if (access !== Constants.communityChatOnRequestAccess) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return chatsModel.isCommunityRequestPending(communityId)
|
return chatsModel.communities.isCommunityRequestPending(communityId)
|
||||||
}
|
}
|
||||||
text: {
|
text: {
|
||||||
if (ensOnly && !profileModel.profile.ensVerified) {
|
if (ensOnly && !profileModel.profile.ensVerified) {
|
||||||
|
@ -221,14 +221,14 @@ ModalPopup {
|
||||||
onClicked: {
|
onClicked: {
|
||||||
let error
|
let error
|
||||||
if (access === Constants.communityChatOnRequestAccess) {
|
if (access === Constants.communityChatOnRequestAccess) {
|
||||||
error = chatsModel.requestToJoinCommunity(popup.communityId,
|
error = chatsModel.communities.requestToJoinCommunity(popup.communityId,
|
||||||
profileModel.profile.ensVerified ? profileModel.profile.username : "")
|
profileModel.profile.ensVerified ? profileModel.profile.username : "")
|
||||||
if (!error) {
|
if (!error) {
|
||||||
enabled = false
|
enabled = false
|
||||||
text = qsTr("Pending")
|
text = qsTr("Pending")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
error = chatsModel.joinCommunity(popup.communityId)
|
error = chatsModel.communities.joinCommunity(popup.communityId)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
|
|
|
@ -28,7 +28,7 @@ Button {
|
||||||
|
|
||||||
StyledText {
|
StyledText {
|
||||||
id: communityName
|
id: communityName
|
||||||
text: chatsModel.activeCommunity.name
|
text: chatsModel.communities.activeCommunity.name
|
||||||
anchors.left: communityImage.right
|
anchors.left: communityImage.right
|
||||||
anchors.leftMargin: Style.current.halfPadding
|
anchors.leftMargin: Style.current.halfPadding
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
|
@ -38,11 +38,9 @@ Button {
|
||||||
|
|
||||||
StyledText {
|
StyledText {
|
||||||
id: communityNbMember
|
id: communityNbMember
|
||||||
text: chatsModel.activeCommunity.nbMembers === 1 ?
|
text: chatsModel.communities.activeCommunity.nbMembers === 1 ?
|
||||||
//% "1 member"
|
qsTr("1 member") :
|
||||||
qsTrId("1-member") :
|
qsTr("%1 members").arg(chatsModel.communities.activeCommunity.nbMembers)
|
||||||
//% "%1 members"
|
|
||||||
qsTrId("-1-members").arg(chatsModel.activeCommunity.nbMembers)
|
|
||||||
anchors.left: communityName.left
|
anchors.left: communityName.left
|
||||||
anchors.top: communityName.bottom
|
anchors.top: communityName.bottom
|
||||||
font.pixelSize: 12
|
font.pixelSize: 12
|
||||||
|
|
|
@ -19,7 +19,7 @@ Item {
|
||||||
visible: height > 10
|
visible: height > 10
|
||||||
width:parent.width
|
width:parent.width
|
||||||
interactive: false
|
interactive: false
|
||||||
model: chatsModel.joinedCommunities
|
model: chatsModel.communities.joinedCommunities
|
||||||
delegate: CommunityButton {
|
delegate: CommunityButton {
|
||||||
communityId: model.id
|
communityId: model.id
|
||||||
name: model.name
|
name: model.name
|
||||||
|
|
|
@ -9,7 +9,7 @@ import "../components"
|
||||||
|
|
||||||
ModalPopup {
|
ModalPopup {
|
||||||
id: popup
|
id: popup
|
||||||
property QtObject community: chatsModel.activeCommunity
|
property QtObject community: chatsModel.communities.activeCommunity
|
||||||
|
|
||||||
header: Item {
|
header: Item {
|
||||||
height: childrenRect.height
|
height: childrenRect.height
|
||||||
|
|
|
@ -8,7 +8,7 @@ import "../../../../shared/status"
|
||||||
import "../ContactsColumn"
|
import "../ContactsColumn"
|
||||||
|
|
||||||
ModalPopup {
|
ModalPopup {
|
||||||
property QtObject community: chatsModel.activeCommunity
|
property QtObject community: chatsModel.communities.activeCommunity
|
||||||
property string communityId: community.id
|
property string communityId: community.id
|
||||||
property string name: community.name
|
property string name: community.name
|
||||||
property string description: community.description
|
property string description: community.description
|
||||||
|
@ -130,7 +130,7 @@ ModalPopup {
|
||||||
}
|
}
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
property int nbRequests: chatsModel.activeCommunity.communityMembershipRequests.nbRequests
|
property int nbRequests: chatsModel.communities.activeCommunity.communityMembershipRequests.nbRequests
|
||||||
|
|
||||||
id: memberBlock
|
id: memberBlock
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
|
@ -268,7 +268,7 @@ ModalPopup {
|
||||||
//% "Export community"
|
//% "Export community"
|
||||||
label: qsTrId("export-community")
|
label: qsTrId("export-community")
|
||||||
iconName: "../fetch"
|
iconName: "../fetch"
|
||||||
onClicked: exportResult = chatsModel.exportComumnity()
|
onClicked: exportResult = chatsModel.communities.exportComumnity()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -137,7 +137,7 @@ ModalPopup {
|
||||||
scrollView.scrollBackUp()
|
scrollView.scrollBackUp()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const error = chatsModel.createCommunityChannel(communityId,
|
const error = chatsModel.communities.createCommunityChannel(communityId,
|
||||||
Utils.filterXSS(nameInput.text),
|
Utils.filterXSS(nameInput.text),
|
||||||
Utils.filterXSS(descriptionTextArea.text))
|
Utils.filterXSS(descriptionTextArea.text))
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ ModalPopup {
|
||||||
bY: 1
|
bY: 1
|
||||||
})
|
})
|
||||||
|
|
||||||
property QtObject community: chatsModel.activeCommunity
|
property QtObject community: chatsModel.communities.activeCommunity
|
||||||
|
|
||||||
property bool isEdit: false
|
property bool isEdit: false
|
||||||
|
|
||||||
|
@ -357,7 +357,7 @@ ModalPopup {
|
||||||
if(isEdit) {
|
if(isEdit) {
|
||||||
console.log("TODO: implement this (not available in status-go yet)");
|
console.log("TODO: implement this (not available in status-go yet)");
|
||||||
} else {
|
} else {
|
||||||
error = chatsModel.createCommunity(Utils.filterXSS(nameInput.text),
|
error = chatsModel.communities.createCommunity(Utils.filterXSS(nameInput.text),
|
||||||
Utils.filterXSS(descriptionTextArea.text),
|
Utils.filterXSS(descriptionTextArea.text),
|
||||||
membershipRequirementSettingPopup.checkedMembership,
|
membershipRequirementSettingPopup.checkedMembership,
|
||||||
ensOnlySwitch.switchChecked,
|
ensOnlySwitch.switchChecked,
|
||||||
|
|
|
@ -55,7 +55,7 @@ ModalPopup {
|
||||||
communityKey = "0x" + communityKey
|
communityKey = "0x" + communityKey
|
||||||
}
|
}
|
||||||
|
|
||||||
const error = chatsModel.importCommunity(communityKey)
|
const error = chatsModel.communities.importCommunity(communityKey)
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
creatingError.text = error
|
creatingError.text = error
|
||||||
|
|
|
@ -8,7 +8,7 @@ import "../components"
|
||||||
import "./"
|
import "./"
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
property int nbRequests: chatsModel.activeCommunity.communityMembershipRequests.nbRequests
|
property int nbRequests: chatsModel.communities.activeCommunity.communityMembershipRequests.nbRequests
|
||||||
|
|
||||||
id: membershipRequestsBtn
|
id: membershipRequestsBtn
|
||||||
visible: nbRequests > 0
|
visible: nbRequests > 0
|
||||||
|
|
|
@ -64,7 +64,7 @@ ModalPopup {
|
||||||
|
|
||||||
ListView {
|
ListView {
|
||||||
id: membershipRequestList
|
id: membershipRequestList
|
||||||
model: chatsModel.activeCommunity.communityMembershipRequests
|
model: chatsModel.communities.activeCommunity.communityMembershipRequests
|
||||||
anchors.top: errorText.bottom
|
anchors.top: errorText.bottom
|
||||||
anchors.topMargin: Style.current.smallPadding
|
anchors.topMargin: Style.current.smallPadding
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
|
@ -120,7 +120,7 @@ ModalPopup {
|
||||||
cursorShape: Qt.PointingHandCursor
|
cursorShape: Qt.PointingHandCursor
|
||||||
onClicked: {
|
onClicked: {
|
||||||
errorText.text = ""
|
errorText.text = ""
|
||||||
const error = chatsModel.acceptRequestToJoinCommunity(id)
|
const error = chatsModel.communities.acceptRequestToJoinCommunity(id)
|
||||||
if (error) {
|
if (error) {
|
||||||
errorText.text = error
|
errorText.text = error
|
||||||
}
|
}
|
||||||
|
@ -142,7 +142,7 @@ ModalPopup {
|
||||||
cursorShape: Qt.PointingHandCursor
|
cursorShape: Qt.PointingHandCursor
|
||||||
onClicked: {
|
onClicked: {
|
||||||
errorText.text = ""
|
errorText.text = ""
|
||||||
const error = chatsModel.declineRequestToJoinCommunity(id)
|
const error = chatsModel.communities.declineRequestToJoinCommunity(id)
|
||||||
if (error) {
|
if (error) {
|
||||||
errorText.text = error
|
errorText.text = error
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue