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.delegate.onPreviewDataLoaded(args.response)
self.events.on(SIGNAL_MAKE_SECTION_CHAT_ACTIVE) do(e: Args): 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): if(self.sectionId != args.sectionId or self.chatId != args.chatId):
return return
self.delegate.scrollToMessage(args.messageId) 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 = method getMySectionId*(self: Controller): string =
return self.sectionId return self.sectionId
@ -241,3 +247,9 @@ method getTransactionDetails*(self: Controller, message: MessageDto): (string,st
method getWalletAccounts*(self: Controller): seq[wallet_account_service.WalletAccountDto] = method getWalletAccounts*(self: Controller): seq[wallet_account_service.WalletAccountDto] =
return self.messageService.getWalletAccounts() 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] = method getWalletAccounts*(self: AccessInterface): seq[WalletAccountDto] =
raise newException(ValueError, "No implementation available") 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) = method fillGaps*(self: Module, messageId: string) =
self.controller.fillGaps(messageId) 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.} = method scrollToMessage*(self: AccessInterface, messageId: string) {.base.} =
raise newException(ValueError, "No implementation available") 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.} = method fillGaps*(self: AccessInterface, messageId: string) {.base.} =
raise newException(ValueError, "No implementation available") 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.} = proc fillGaps(self: View, messageId: string) {.slot.} =
self.delegate.fillGaps(messageId) 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 type
Model* = ref object of QAbstractListModel Model* = ref object of QAbstractListModel
items: seq[Item] items: seq[Item]
allKeys: seq[int]
proc delete(self: Model) = proc delete(self: Model) =
self.items = @[] self.items = @[]
@ -49,6 +50,11 @@ QtObject:
new(result, delete) new(result, delete)
result.setup 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 = proc `$`*(self: Model): string =
result = "MessageModel:\n" result = "MessageModel:\n"
for i in 0 ..< self.items.len: for i in 0 ..< self.items.len:
@ -373,3 +379,11 @@ QtObject:
self.items = @[] self.items = @[]
self.endResetModel() self.endResetModel()
self.countChanged() 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
return messageModule.fillGaps(messageId); 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 chatColor: ""
property string chatIcon: "" property string chatIcon: ""
property bool chatIconIsIdenticon: true property bool chatIconIsIdenticon: true
property bool didIJoinedChat: true
signal joinChatClicked()
signal rejectJoiningChatClicked()
Rectangle { Rectangle {
id: circleId id: circleId
@ -84,11 +88,11 @@ Column {
} }
Item { 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 anchors.horizontalCenter: parent.horizontalCenter
width: visible ? joinChat.width : 0 width: visible ? joinChat.width : 0
height: visible ? 100 : 0 height: visible ? 100 : 0
id: joinOrDecline
StyledText { StyledText {
id: joinChat id: joinChat
@ -102,8 +106,8 @@ Column {
cursorShape: Qt.PointingHandCursor cursorShape: Qt.PointingHandCursor
anchors.fill: parent anchors.fill: parent
onClicked: { onClicked: {
//NEED TO CHECK THIS root.joinChatClicked()
// root.store.chatsModelInst.groups.join() 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 cursorShape: Qt.PointingHandCursor
anchors.fill: parent anchors.fill: parent
onClicked: { onClicked: {
//NEED TO CHECK THIS root.rejectJoiningChatClicked()
// root.store.chatsModelInst.channelView.leaveActiveChat() 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 id: channelIdentifierComponent
ChannelIdentifierView { ChannelIdentifierView {
chatName: root.senderDisplayName chatName: root.senderDisplayName
chatType: messageStore.getChatType() chatType: root.messageStore.getChatType()
chatColor: messageStore.getChatColor() chatColor: root.messageStore.getChatColor()
amIChatAdmin: messageStore.amIChatAdmin() amIChatAdmin: root.messageStore.amIChatAdmin()
chatIcon: root.senderIcon chatIcon: root.senderIcon
chatIconIsIdenticon: root.isSenderIconIdenticon chatIconIsIdenticon: root.isSenderIconIdenticon
didIJoinedChat: root.messageStore.didIJoinedChat()
onJoinChatClicked: root.messageStore.joinGroupChat()
onRejectJoiningChatClicked: root.messageStore.leaveChat()
} }
} }