refactor: move communities functions to communities view in chat

This commit is contained in:
Jonathan Rainville 2021-02-11 15:37:31 -05:00 committed by Iuri Matias
parent 3cc62d65aa
commit b38d1df591
24 changed files with 351 additions and 312 deletions

View File

@ -1,5 +1,6 @@
import sugar, sequtils, times, strutils
import ../../status/chat/chat as status_chat
import ./views/communities
proc handleChatEvents(self: ChatController) =
# Display already saved messages
@ -27,9 +28,9 @@ proc handleChatEvents(self: ChatController) =
self.view.reactions.push(evArgs.emojiReactions)
if (evArgs.communities.len > 0):
for community in evArgs.communities:
self.view.addCommunityToList(community)
self.view.communities.addCommunityToList(community)
if (evArgs.communityMembershipRequests.len > 0):
self.view.addMembershipRequests(evArgs.communityMembershipRequests)
self.view.communities.addMembershipRequests(evArgs.communityMembershipRequests)
self.status.events.on("channelUpdate") do(e: Args):
var evArgs = ChatUpdateArgs(e)
@ -62,10 +63,10 @@ proc handleChatEvents(self: ChatController) =
if (evArgs.active == false):
self.view.restorePreviousActiveChannel()
else:
if (self.view.activeCommunity.communityItem.lastChannelSeen == ""):
if (self.view.communities.activeCommunity.communityItem.lastChannelSeen == ""):
self.view.setActiveChannelByIndex(0)
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):
var channel = ChannelArgs(e)

View File

@ -4,8 +4,6 @@ import ../../status/mailservers
import ../../status/libstatus/chat as libstatus_chat
import ../../status/libstatus/accounts/constants
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/utils as status_utils
import ../../status/accounts as status_accounts
@ -17,7 +15,7 @@ import ../../status/chat/[chat, message]
import ../../status/profile/profile
import web3/[conversions, ethtypes]
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 ../utils/image_utils
@ -43,12 +41,8 @@ QtObject:
transactions*: TransactionsView
activeChannel*: ChatItemView
contextChannel*: ChatItemView
communities*: CommunitiesView
previousActiveChannelIndex: int
activeCommunity*: CommunityItemView
observedCommunity*: CommunityItemView
communityList*: CommunityList
joinedCommunityList*: CommunityList
myCommunityRequests*: seq[CommunityMembershipRequest]
replyTo: string
channelOpenTime*: Table[string, int64]
connected: bool
@ -64,8 +58,6 @@ QtObject:
self.chats.delete
self.activeChannel.delete
self.contextChannel.delete
self.observedCommunity.delete
self.activeCommunity.delete
self.currentSuggestions.delete
for msg in self.messageList.values:
msg.delete
@ -74,6 +66,8 @@ QtObject:
self.groups.delete
self.transactions.delete
self.messageList = initOrderedTable[string, ChatMessageList]()
self.communities.delete
self.messageList = initTable[string, ChatMessageList]()
self.channelOpenTime = initTable[string, int64]()
self.QAbstractListModel.delete
@ -84,16 +78,13 @@ QtObject:
result.chats = newChannelsList(status)
result.activeChannel = newChatItemView(status)
result.contextChannel = newChatItemView(status)
result.activeCommunity = newCommunityItemView(status)
result.observedCommunity = newCommunityItemView(status)
result.currentSuggestions = newSuggestionsList()
result.messageList = initOrderedTable[string, ChatMessageList]()
result.reactions = newReactionView(status, result.messageList.addr, result.activeChannel)
result.stickers = newStickersView(status, result.activeChannel)
result.groups = newGroupsView(status,result.activeChannel)
result.communityList = newCommunityList(status)
result.joinedCommunityList = newCommunityList(status)
result.transactions = newTransactionsView(status)
result.communities = newCommunitiesView(status)
result.unreadMessageCnt = 0
result.loadingMessages = false
result.previousActiveChannelIndex = -1
@ -128,6 +119,12 @@ QtObject:
QtProperty[QVariant] chats:
read = getChatsList
proc getCommunities*(self: ChatsView): QVariant {.slot.} =
newQVariant(self.communities)
QtProperty[QVariant] communities:
read = getCommunities
proc getChannelColor*(self: ChatsView, channel: string): string {.slot.} =
self.chats.getChannelColor(channel)
@ -230,19 +227,20 @@ QtObject:
self.chats.clearUnreadMessagesCount(channel)
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 =
if (self.activeCommunity.active):
self.activeCommunity.chats.getChannel(index)
let selectedChannel =
if (self.communities.activeCommunity.active):
self.communities.activeCommunity.chats.getChannel(index)
else:
self.chats.getChannel(index)
self.clearUnreadIfNeeded(self.activeChannel.chatItem)
self.clearUnreadIfNeeded(selectedChannel)
if (self.activeCommunity.active and self.activeCommunity.communityItem.lastChannelSeen != selectedChannel.id):
self.activeCommunity.communityItem.lastChannelSeen = selectedChannel.id
self.joinedCommunityList.replaceCommunity(self.activeCommunity.communityItem)
if (self.communities.activeCommunity.active and self.communities.activeCommunity.communityItem.lastChannelSeen != selectedChannel.id):
self.communities.activeCommunity.communityItem.lastChannelSeen = selectedChannel.id
self.communities.joinedCommunityList.replaceCommunity(self.communities.activeCommunity.communityItem)
if self.activeChannel.id == selectedChannel.id: return
@ -254,8 +252,8 @@ QtObject:
self.status.chat.setActiveChannel(selectedChannel.id)
proc getActiveChannelIdx(self: ChatsView): int {.slot.} =
if (self.activeCommunity.active):
return self.activeCommunity.chats.chats.findIndexById(self.activeChannel.id)
if (self.communities.activeCommunity.active):
return self.communities.activeCommunity.chats.chats.findIndexById(self.activeChannel.id)
else:
return self.chats.chats.findIndexById(self.activeChannel.id)
@ -268,8 +266,8 @@ QtObject:
if(channel == ""): return
let selectedChannel =
if (self.activeCommunity.active):
self.activeCommunity.chats.getChannel(self.activeCommunity.chats.chats.findIndexById(channel))
if (self.communities.activeCommunity.active):
self.communities.activeCommunity.chats.getChannel(self.communities.activeCommunity.chats.chats.findIndexById(channel))
else:
self.chats.getChannel(self.chats.chats.findIndexById(channel))
@ -704,243 +702,6 @@ QtObject:
QtProperty[QVariant] transactions:
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 =
result = self.messageList.len
@ -959,6 +720,6 @@ QtObject:
proc getMessageListIndex(self: ChatsView):int {.slot.} =
var idx = -1
for msg in toSeq(self.messageList.values):
idx = idx + 1
if(self.activeChannel.id == msg.id): return idx
idx = idx + 1
return idx

View File

@ -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 ""

View File

@ -1,4 +1,4 @@
import NimQml, Tables, std/wrapnils
import NimQml, std/wrapnils
import ../../../status/[chat/chat, status]
import channels_list
import ../../../eventemitter

View File

@ -1,7 +1,6 @@
import NimQml, Tables, chronicles
import ../../../status/chat/[chat, message]
import ../../../status/chat/chat
import ../../../status/status
import ../../../status/ens
import ../../../status/accounts
import strutils

View File

@ -1,5 +1,5 @@
import NimQml, Tables,
../../../status/[chat/chat, status, ens]
../../../status/[status, ens]
import ../../../status/accounts as status_accounts
type
CommunityMembersRoles {.pure.} = enum

View File

@ -1,7 +1,6 @@
import NimQml, Tables, chronicles
import ../../../status/chat/[chat, message]
import ../../../status/chat/chat
import ../../../status/status
import ../../../status/ens
import ../../../status/accounts
import strutils

View File

@ -280,7 +280,7 @@ StackLayout {
StatusChatInput {
id: chatInput
visible: {
const community = chatsModel.activeCommunity
const community = chatsModel.communities.activeCommunity
if (chatsModel.activeChannel.chatType !== Constants.chatTypePrivateGroupChat &&
(!community.active ||
community.access === Constants.communityChatPublicAccess ||

View File

@ -201,8 +201,12 @@ ScrollView {
}
}
}
}
onMembershipRequestChanged: function (communityName, accepted) {
Connections {
target: chatsModel.communities
onMembershipRequestChanged: function (communityName, accepted) {
systemTray.showMessage("Status",
accepted ? qsTr("You have been accepted into the %1 community").arg(communityName) :
qsTr("Your request to join the %1 community was declined").arg(communityName),

View File

@ -15,9 +15,9 @@ Item {
height: childrenRect.height
Component.onCompleted: {
chatsModel.setObservedCommunity(communityId)
chatsModel.communities.setObservedCommunity(communityId)
root.invitedCommunity = chatsModel.observedCommunity
root.invitedCommunity = chatsModel.communities.observedCommunity
}
UserImage {
@ -144,7 +144,7 @@ Item {
//% "Join"
qsTrId("join")
onClicked: {
chatsModel.joinCommunity(communityId)
chatsModel.communities.joinCommunity(communityId)
root.joined = true
}
}

View File

@ -61,7 +61,7 @@ SplitView {
SplitView.preferredWidth: Style.current.leftTabPrefferedSize
SplitView.minimumWidth: Style.current.leftTabMinimumWidth
SplitView.maximumWidth: Style.current.leftTabMaximumWidth
sourceComponent: appSettings.communitiesEnabled && chatsModel.activeCommunity.active ? communtiyColumnComponent : contactsColumnComponent
sourceComponent: appSettings.communitiesEnabled && chatsModel.communities.activeCommunity.active ? communtiyColumnComponent : contactsColumnComponent
}
Component {

View File

@ -40,7 +40,7 @@ Item {
anchors.left: parent.left
anchors.leftMargin: Style.current.bigPadding
anchors.verticalCenter: communityHeaderButton.verticalCenter
onClicked: chatsModel.activeCommunity.active = false
onClicked: chatsModel.communities.activeCommunity.active = false
}
CommunityHeaderButton {
@ -72,7 +72,7 @@ Item {
icon.source: "../../img/hash.svg"
icon.width: 20
icon.height: 20
onTriggered: openPopup(createChannelPopup, {communityId: chatsModel.activeCommunity.id})
onTriggered: openPopup(createChannelPopup, {communityId: chatsModel.communities.activeCommunity.id})
}
Action {
@ -82,7 +82,7 @@ Item {
icon.color: Style.current.red
icon.width: 20
icon.height: 20
onTriggered: chatsModel.leaveCurrentCommunity()
onTriggered: chatsModel.communities.leaveCurrentCommunity()
}
}
}
@ -90,7 +90,7 @@ Item {
Loader {
id: membershipRequestsLoader
width: parent.width
active: chatsModel.activeCommunity.admin
active: chatsModel.communities.activeCommunity.admin
anchors.top: communityHeader.bottom
anchors.topMargin: item && item.visible ? Style.current.halfPadding : 0
@ -119,12 +119,12 @@ Item {
ChannelList {
id: channelList
searchStr: ""
channelModel: chatsModel.activeCommunity.chats
channelModel: chatsModel.communities.activeCommunity.chats
}
CommunityWelcomeBanner {
id: emptyViewAndSuggestions
visible: chatsModel.activeCommunity.admin
visible: chatsModel.communities.activeCommunity.admin
width: parent.width
anchors.top: channelList.bottom
anchors.topMargin: Style.current.padding

View File

@ -68,7 +68,7 @@ ModalPopup {
}
]
model: chatsModel.communities
model: chatsModel.communities.list
delegate: Item {
// TODO add the search for the name and category once they exist
visible: {
@ -126,9 +126,9 @@ ModalPopup {
cursorShape: Qt.PointingHandCursor
onClicked: {
if (joined && isMember) {
chatsModel.setActiveCommunity(id)
chatsModel.communities.setActiveCommunity(id)
} else {
chatsModel.setObservedCommunity(id)
chatsModel.communities.setObservedCommunity(id)
openPopup(communityDetailPopup)
}
popup.close()

View File

@ -89,7 +89,7 @@ Rectangle {
communityButton.hovered = false
}
onClicked: {
chatsModel.setActiveCommunity(communityId)
chatsModel.communities.setActiveCommunity(communityId)
}
}

View File

@ -6,7 +6,7 @@ import "../../../../shared/status"
import "../ContactsColumn"
ModalPopup {
property QtObject community: chatsModel.observedCommunity
property QtObject community: chatsModel.communities.observedCommunity
property string communityId: community.id
property string name: community.name
property string description: community.description
@ -185,7 +185,7 @@ ModalPopup {
if (access !== Constants.communityChatOnRequestAccess) {
return false
}
return chatsModel.isCommunityRequestPending(communityId)
return chatsModel.communities.isCommunityRequestPending(communityId)
}
text: {
if (ensOnly && !profileModel.profile.ensVerified) {
@ -221,14 +221,14 @@ ModalPopup {
onClicked: {
let error
if (access === Constants.communityChatOnRequestAccess) {
error = chatsModel.requestToJoinCommunity(popup.communityId,
error = chatsModel.communities.requestToJoinCommunity(popup.communityId,
profileModel.profile.ensVerified ? profileModel.profile.username : "")
if (!error) {
enabled = false
text = qsTr("Pending")
}
} else {
error = chatsModel.joinCommunity(popup.communityId)
error = chatsModel.communities.joinCommunity(popup.communityId)
}
if (error) {

View File

@ -28,7 +28,7 @@ Button {
StyledText {
id: communityName
text: chatsModel.activeCommunity.name
text: chatsModel.communities.activeCommunity.name
anchors.left: communityImage.right
anchors.leftMargin: Style.current.halfPadding
anchors.top: parent.top
@ -38,11 +38,9 @@ Button {
StyledText {
id: communityNbMember
text: chatsModel.activeCommunity.nbMembers === 1 ?
//% "1 member"
qsTrId("1-member") :
//% "%1 members"
qsTrId("-1-members").arg(chatsModel.activeCommunity.nbMembers)
text: chatsModel.communities.activeCommunity.nbMembers === 1 ?
qsTr("1 member") :
qsTr("%1 members").arg(chatsModel.communities.activeCommunity.nbMembers)
anchors.left: communityName.left
anchors.top: communityName.bottom
font.pixelSize: 12

View File

@ -19,7 +19,7 @@ Item {
visible: height > 10
width:parent.width
interactive: false
model: chatsModel.joinedCommunities
model: chatsModel.communities.joinedCommunities
delegate: CommunityButton {
communityId: model.id
name: model.name

View File

@ -9,7 +9,7 @@ import "../components"
ModalPopup {
id: popup
property QtObject community: chatsModel.activeCommunity
property QtObject community: chatsModel.communities.activeCommunity
header: Item {
height: childrenRect.height

View File

@ -8,7 +8,7 @@ import "../../../../shared/status"
import "../ContactsColumn"
ModalPopup {
property QtObject community: chatsModel.activeCommunity
property QtObject community: chatsModel.communities.activeCommunity
property string communityId: community.id
property string name: community.name
property string description: community.description
@ -130,7 +130,7 @@ ModalPopup {
}
Item {
property int nbRequests: chatsModel.activeCommunity.communityMembershipRequests.nbRequests
property int nbRequests: chatsModel.communities.activeCommunity.communityMembershipRequests.nbRequests
id: memberBlock
anchors.top: parent.top
@ -268,7 +268,7 @@ ModalPopup {
//% "Export community"
label: qsTrId("export-community")
iconName: "../fetch"
onClicked: exportResult = chatsModel.exportComumnity()
onClicked: exportResult = chatsModel.communities.exportComumnity()
}
}

View File

@ -137,7 +137,7 @@ ModalPopup {
scrollView.scrollBackUp()
return
}
const error = chatsModel.createCommunityChannel(communityId,
const error = chatsModel.communities.createCommunityChannel(communityId,
Utils.filterXSS(nameInput.text),
Utils.filterXSS(descriptionTextArea.text))

View File

@ -19,7 +19,7 @@ ModalPopup {
bY: 1
})
property QtObject community: chatsModel.activeCommunity
property QtObject community: chatsModel.communities.activeCommunity
property bool isEdit: false
@ -357,7 +357,7 @@ ModalPopup {
if(isEdit) {
console.log("TODO: implement this (not available in status-go yet)");
} else {
error = chatsModel.createCommunity(Utils.filterXSS(nameInput.text),
error = chatsModel.communities.createCommunity(Utils.filterXSS(nameInput.text),
Utils.filterXSS(descriptionTextArea.text),
membershipRequirementSettingPopup.checkedMembership,
ensOnlySwitch.switchChecked,

View File

@ -55,7 +55,7 @@ ModalPopup {
communityKey = "0x" + communityKey
}
const error = chatsModel.importCommunity(communityKey)
const error = chatsModel.communities.importCommunity(communityKey)
if (error) {
creatingError.text = error

View File

@ -8,7 +8,7 @@ import "../components"
import "./"
Rectangle {
property int nbRequests: chatsModel.activeCommunity.communityMembershipRequests.nbRequests
property int nbRequests: chatsModel.communities.activeCommunity.communityMembershipRequests.nbRequests
id: membershipRequestsBtn
visible: nbRequests > 0

View File

@ -64,7 +64,7 @@ ModalPopup {
ListView {
id: membershipRequestList
model: chatsModel.activeCommunity.communityMembershipRequests
model: chatsModel.communities.activeCommunity.communityMembershipRequests
anchors.top: errorText.bottom
anchors.topMargin: Style.current.smallPadding
anchors.left: parent.left
@ -120,7 +120,7 @@ ModalPopup {
cursorShape: Qt.PointingHandCursor
onClicked: {
errorText.text = ""
const error = chatsModel.acceptRequestToJoinCommunity(id)
const error = chatsModel.communities.acceptRequestToJoinCommunity(id)
if (error) {
errorText.text = error
}
@ -142,7 +142,7 @@ ModalPopup {
cursorShape: Qt.PointingHandCursor
onClicked: {
errorText.text = ""
const error = chatsModel.declineRequestToJoinCommunity(id)
const error = chatsModel.communities.declineRequestToJoinCommunity(id)
if (error) {
errorText.text = error
}