fix(@desktop/chat): can't join to group chat by clicking [Join chat] or decline invitation with [Decline invitation]

Fixes #4766
This commit is contained in:
Sale Djenic 2022-02-11 17:01:36 +01:00 committed by Iuri Matias
parent 9495956a53
commit 9ed6c6235c
10 changed files with 117 additions and 10 deletions

View File

@ -148,11 +148,17 @@ method init*(self: Controller) =
self.delegate.onPreviewDataLoaded(args.response)
self.events.on(SIGNAL_MAKE_SECTION_CHAT_ACTIVE) do(e: Args):
var args = ActiveSectionChatArgs(e)
let args = ActiveSectionChatArgs(e)
if(self.sectionId != args.sectionId or self.chatId != args.chatId):
return
self.delegate.scrollToMessage(args.messageId)
self.events.on(SIGNAL_CHAT_MEMBER_UPDATED) do(e: Args):
let args = ChatMemberUpdatedArgs(e)
if (args.chatId != self.chatId):
return
self.delegate.onChatMemberUpdated(args.id, args.admin, args.joined)
method getMySectionId*(self: Controller): string =
return self.sectionId
@ -241,3 +247,9 @@ method getTransactionDetails*(self: Controller, message: MessageDto): (string,st
method getWalletAccounts*(self: Controller): seq[wallet_account_service.WalletAccountDto] =
return self.messageService.getWalletAccounts()
method joinGroupChat*(self: Controller) =
self.chatService.confirmJoiningGroup(self.chatId)
method leaveChat*(self: Controller) =
self.chatService.leaveChat(self.chatId)

View File

@ -102,3 +102,9 @@ method getTransactionDetails*(self: AccessInterface, message: MessageDto): (stri
method getWalletAccounts*(self: AccessInterface): seq[WalletAccountDto] =
raise newException(ValueError, "No implementation available")
method joinGroupChat*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method leaveChat*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -430,3 +430,31 @@ method requestMoreMessages*(self: Module) =
method fillGaps*(self: Module, messageId: string) =
self.controller.fillGaps(messageId)
method joinGroupChat*(self: Module) =
self.controller.joinGroupChat()
method leaveChat*(self: Module) =
self.controller.leaveChat()
method didIJoinedChat*(self: Module): bool =
let chatDto = self.controller.getChatDetails()
if(chatDto.chatType != ChatType.PrivateGroupChat):
return true
let myPublicKey = singletonInstance.userProfile.getPubKey()
for member in chatDto.members:
if (member.id == myPublicKey):
return member.joined
return true
method onChatMemberUpdated*(self: Module, publicKey: string, admin: bool, joined: bool) =
let chatDto = self.controller.getChatDetails()
if(chatDto.chatType != ChatType.PrivateGroupChat):
return
let myPublicKey = singletonInstance.userProfile.getPubKey()
if(publicKey != myPublicKey):
return
self.view.model().refreshItemWithId(CHAT_IDENTIFIER_MESSAGE_ID)

View File

@ -40,3 +40,6 @@ method setLoadingHistoryMessagesInProgress*(self: AccessInterface, isLoading: bo
method scrollToMessage*(self: AccessInterface, messageId: string) {.base.} =
raise newException(ValueError, "No implementation available")
method onChatMemberUpdated*(self: AccessInterface, id: string, admin: bool, joined: bool) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -45,3 +45,12 @@ method requestMoreMessages*(self: AccessInterface) {.base.} =
method fillGaps*(self: AccessInterface, messageId: string) {.base.} =
raise newException(ValueError, "No implementation available")
method joinGroupChat*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method leaveChat*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method didIJoinedChat*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -148,3 +148,12 @@ QtObject:
proc fillGaps(self: View, messageId: string) {.slot.} =
self.delegate.fillGaps(messageId)
proc joinGroupChat*(self: View) {.slot.} =
self.delegate.joinGroupChat()
proc leaveChat*(self: View) {.slot.} =
self.delegate.leaveChat()
proc didIJoinedChat(self: View): bool {.slot.} =
return self.delegate.didIJoinedChat()

View File

@ -37,6 +37,7 @@ QtObject:
type
Model* = ref object of QAbstractListModel
items: seq[Item]
allKeys: seq[int]
proc delete(self: Model) =
self.items = @[]
@ -49,6 +50,11 @@ QtObject:
new(result, delete)
result.setup
# This is just a clean way to have all roles in a seq, without typing long seq manualy, and this way we're sure that
# all new added roles will be included here as well.
for i in result.roleNames().keys:
result.allKeys.add(i)
proc `$`*(self: Model): string =
result = "MessageModel:\n"
for i in 0 ..< self.items.len:
@ -373,3 +379,11 @@ QtObject:
self.items = @[]
self.endResetModel()
self.countChanged()
proc refreshItemWithId*(self: Model, messageId: string) =
let ind = self.findIndexForMessageId(messageId)
if(ind == -1):
return
let index = self.createIndex(ind, 0, nil)
self.dataChanged(index, index, self.allKeys)

View File

@ -205,4 +205,22 @@ QtObject {
return
return messageModule.fillGaps(messageId);
}
function joinGroupChat() {
if(!messageModule)
return
messageModule.joinGroupChat();
}
function leaveChat() {
if(!messageModule)
return
messageModule.leaveChat();
}
function didIJoinedChat() {
if(!messageModule)
return true
return messageModule.didIJoinedChat();
}
}

View File

@ -17,6 +17,10 @@ Column {
property string chatColor: ""
property string chatIcon: ""
property bool chatIconIsIdenticon: true
property bool didIJoinedChat: true
signal joinChatClicked()
signal rejectJoiningChatClicked()
Rectangle {
id: circleId
@ -84,11 +88,11 @@ Column {
}
Item {
visible: root.chatType === Constants.chatType.privateGroupChat && !root.amIChatAdmin
id: joinOrDecline
visible: root.chatType === Constants.chatType.privateGroupChat && !root.amIChatAdmin && !root.didIJoinedChat
anchors.horizontalCenter: parent.horizontalCenter
width: visible ? joinChat.width : 0
height: visible ? 100 : 0
id: joinOrDecline
StyledText {
id: joinChat
@ -102,8 +106,8 @@ Column {
cursorShape: Qt.PointingHandCursor
anchors.fill: parent
onClicked: {
//NEED TO CHECK THIS
// root.store.chatsModelInst.groups.join()
root.joinChatClicked()
joinOrDecline.visible = false // Once we start getting member `joined` updates from `status-go` we can remove this
}
}
}
@ -120,8 +124,8 @@ Column {
cursorShape: Qt.PointingHandCursor
anchors.fill: parent
onClicked: {
//NEED TO CHECK THIS
// root.store.chatsModelInst.channelView.leaveActiveChat()
root.rejectJoiningChatClicked()
joinOrDecline.visible = false // Once we start getting member `joined` updates from `status-go` we can remove this
}
}
}

View File

@ -270,11 +270,15 @@ Column {
id: channelIdentifierComponent
ChannelIdentifierView {
chatName: root.senderDisplayName
chatType: messageStore.getChatType()
chatColor: messageStore.getChatColor()
amIChatAdmin: messageStore.amIChatAdmin()
chatType: root.messageStore.getChatType()
chatColor: root.messageStore.getChatColor()
amIChatAdmin: root.messageStore.amIChatAdmin()
chatIcon: root.senderIcon
chatIconIsIdenticon: root.isSenderIconIdenticon
didIJoinedChat: root.messageStore.didIJoinedChat()
onJoinChatClicked: root.messageStore.joinGroupChat()
onRejectJoiningChatClicked: root.messageStore.leaveChat()
}
}