fix: fix warning and inconsistencies with spectating (#14041)

Kinda fixes #13957
This commit is contained in:
Jonathan Rainville 2024-03-20 13:58:46 -04:00 committed by GitHub
parent a09defbef7
commit 19c283be8b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 83 additions and 56 deletions

View File

@ -503,8 +503,8 @@ method activeItemSet*(self: Module, itemId: string) =
return return
# update view maintained by this module # update view maintained by this module
self.view.chatsModel().setActiveItem(itemId)
self.view.activeItemSet(chat_item) self.view.activeItemSet(chat_item)
self.view.chatsModel().setActiveItem(itemId)
self.updateActiveChatMembership() self.updateActiveChatMembership()
@ -536,7 +536,7 @@ method getModuleAsVariant*(self: Module): QVariant =
method getChatContentModule*(self: Module, chatId: string): QVariant = method getChatContentModule*(self: Module, chatId: string): QVariant =
if(not self.chatContentModules.contains(chatId)): if(not self.chatContentModules.contains(chatId)):
error "unexisting chat key", chatId, methodName="getChatContentModule" error "getChatContentModule: unexisting chat key", chatId, methodName="getChatContentModule"
return return
return self.chatContentModules[chatId].getModuleAsVariant() return self.chatContentModules[chatId].getModuleAsVariant()

View File

@ -545,6 +545,9 @@ proc switchTo*(self: Controller, sectionId, chatId, messageId: string) =
proc getCommunityById*(self: Controller, communityId: string): CommunityDto = proc getCommunityById*(self: Controller, communityId: string): CommunityDto =
return self.communityService.getCommunityById(communityId) return self.communityService.getCommunityById(communityId)
proc spectateCommunity*(self: Controller, communityId: string) =
discard self.communityService.spectateCommunity(communityId)
proc getStatusForContactWithId*(self: Controller, publicKey: string): StatusUpdateDto = proc getStatusForContactWithId*(self: Controller, publicKey: string): StatusUpdateDto =
return self.contactsService.getStatusForContactWithId(publicKey) return self.contactsService.getStatusForContactWithId(publicKey)

View File

@ -1013,9 +1013,8 @@ method communityJoined*[T](
if setActive: if setActive:
self.setActiveSection(communitySectionItem) self.setActiveSection(communitySectionItem)
if(channelGroup.chats.len > 0): if channelGroup.chats.len > 0:
let chatId = channelGroup.chats[0].id self.channelGroupModules[community.id].setActiveItem(channelGroup.chats[0].id)
self.channelGroupModules[community.id].setActiveItem(chatId)
method communityLeft*[T](self: Module[T], communityId: string) = method communityLeft*[T](self: Module[T], communityId: string) =
if(not self.channelGroupModules.contains(communityId)): if(not self.channelGroupModules.contains(communityId)):
@ -1038,6 +1037,8 @@ method communityLeft*[T](self: Module[T], communityId: string) =
method communityEdited*[T]( method communityEdited*[T](
self: Module[T], self: Module[T],
community: CommunityDto) = community: CommunityDto) =
if(not self.channelGroupModules.contains(community.id)):
return
let channelGroup = community.toChannelGroupDto() let channelGroup = community.toChannelGroupDto()
var channelGroupItem = self.createChannelGroupItem(channelGroup) var channelGroupItem = self.createChannelGroupItem(channelGroup)
# We need to calculate the unread counts because the community update doesn't come with it # We need to calculate the unread counts because the community update doesn't come with it
@ -1411,6 +1412,9 @@ method onStatusUrlRequested*[T](self: Module[T], action: StatusUrlAction, commun
of StatusUrlAction.OpenCommunity: of StatusUrlAction.OpenCommunity:
let item = self.view.model().getItemById(communityId) let item = self.view.model().getItemById(communityId)
if item.isEmpty(): if item.isEmpty():
if self.controller.getCommunityById(communityId).id != "":
self.controller.spectateCommunity(communityId)
return
# request community info and then spectate # request community info and then spectate
self.pendingSpectateRequest.communityId = communityId self.pendingSpectateRequest.communityId = communityId
self.pendingSpectateRequest.channelUuid = "" self.pendingSpectateRequest.channelUuid = ""

View File

@ -930,7 +930,7 @@ QtObject:
error "trying to get community categories for an unexisting community id" error "trying to get community categories for an unexisting community id"
return return
let categories = self.communities[communityId].categories let categories = self.getCommunityById(communityId).categories
let categoryIndex = findIndexById(categoryId, categories) let categoryIndex = findIndexById(categoryId, categories)
return categories[categoryIndex] return categories[categoryIndex]
@ -939,7 +939,7 @@ QtObject:
error "trying to get community categories for an unexisting community id" error "trying to get community categories for an unexisting community id"
return return
result = self.communities[communityId].categories result = self.getCommunityById(communityId).categories
if(order == SortOrder.Ascending): if(order == SortOrder.Ascending):
result.sort(sortAsc[Category]) result.sort(sortAsc[Category])
else: else:
@ -971,7 +971,7 @@ QtObject:
error "trying to get all community chats for an unexisting community id", communityId error "trying to get all community chats for an unexisting community id", communityId
return return
result = self.communities[communityId].chats result = self.getCommunityById(communityId).chats
if(order == SortOrder.Ascending): if(order == SortOrder.Ascending):
result.sort(sortAsc[ChatDto]) result.sort(sortAsc[ChatDto])
@ -1048,7 +1048,9 @@ QtObject:
self.events.emit(SIGNAL_COMMUNITY_SPECTATED, CommunityArgs(community: updatedCommunity, fromUserAction: true, isPendingOwnershipRequest: (ownerTokenNotification != nil))) self.events.emit(SIGNAL_COMMUNITY_SPECTATED, CommunityArgs(community: updatedCommunity, fromUserAction: true, isPendingOwnershipRequest: (ownerTokenNotification != nil)))
for k, chat in updatedCommunity.chats: for k, chat in updatedCommunity.chats:
let fullChatId = communityId & chat.id var fullChatId = chat.id
if not chat.id.startsWith(communityId):
fullChatId = communityId & chat.id
let currentChat = self.chatService.getChatById(fullChatId, showWarning = false) let currentChat = self.chatService.getChatById(fullChatId, showWarning = false)
if (currentChat.id != ""): if (currentChat.id != ""):
@ -1387,7 +1389,7 @@ QtObject:
let prev_chat_idx = findIndexById(chat.id, self.communities[communityId].chats) let prev_chat_idx = findIndexById(chat.id, self.communities[communityId].chats)
if prev_chat_idx == -1: if prev_chat_idx == -1:
continue continue
let prev_chat = self.communities[communityId].chats[prev_chat_idx] let prev_chat = self.getCommunityById(communityId).chats[prev_chat_idx]
# we are free to do this cause channel must be created before we add it to a category # we are free to do this cause channel must be created before we add it to a category
var chatDetails = self.chatService.getChatById(chat.id) var chatDetails = self.chatService.getChatById(chat.id)
@ -1974,7 +1976,7 @@ QtObject:
error "Error slowing down archives import: ", msg = e.msg error "Error slowing down archives import: ", msg = e.msg
proc getPendingRequestIndex(self: Service, communityId: string, requestId: string): int = proc getPendingRequestIndex(self: Service, communityId: string, requestId: string): int =
let community = self.communities[communityId] let community = self.getCommunityById(communityId)
var i = 0 var i = 0
for pendingRequest in community.pendingRequestsToJoin: for pendingRequest in community.pendingRequestsToJoin:
if (pendingRequest.id == requestId): if (pendingRequest.id == requestId):
@ -1983,7 +1985,7 @@ QtObject:
return -1 return -1
proc getDeclinedRequestIndex(self: Service, communityId: string, requestId: string): int = proc getDeclinedRequestIndex(self: Service, communityId: string, requestId: string): int =
let community = self.communities[communityId] let community = self.getCommunityById(communityId)
var i = 0 var i = 0
for declinedRequest in community.declinedRequestsToJoin: for declinedRequest in community.declinedRequestsToJoin:
if (declinedRequest.id == requestId): if (declinedRequest.id == requestId):
@ -1992,7 +1994,7 @@ QtObject:
return -1 return -1
proc getWaitingForSharedAddressesRequestIndex(self: Service, communityId: string, requestId: string): int = proc getWaitingForSharedAddressesRequestIndex(self: Service, communityId: string, requestId: string): int =
let community = self.communities[communityId] let community = self.getCommunityById(communityId)
for i in 0 ..< len(community.waitingForSharedAddressesRequestsToJoin): for i in 0 ..< len(community.waitingForSharedAddressesRequestsToJoin):
if (community.waitingForSharedAddressesRequestsToJoin[i].id == requestId): if (community.waitingForSharedAddressesRequestsToJoin[i].id == requestId):
return i return i
@ -2007,7 +2009,7 @@ QtObject:
if (indexPending == -1 and indexDeclined == -1 and indexAwaitingAddresses == -1): if (indexPending == -1 and indexDeclined == -1 and indexAwaitingAddresses == -1):
raise newException(RpcException, fmt"Community request not found: {requestId}") raise newException(RpcException, fmt"Community request not found: {requestId}")
var community = self.communities[communityId] var community = self.getCommunityById(communityId)
if (indexPending != -1): if (indexPending != -1):
if @[RequestToJoinType.Declined, RequestToJoinType.Accepted, RequestToJoinType.Canceled].any(x => x == newState): if @[RequestToJoinType.Declined, RequestToJoinType.Accepted, RequestToJoinType.Canceled].any(x => x == newState):
@ -2040,7 +2042,7 @@ QtObject:
error "Cancel request to join community failed: unknown community", communityId=communityId error "Cancel request to join community failed: unknown community", communityId=communityId
return return
var community = self.communities[communityId] var community = self.getCommunityById(communityId)
let myPublicKey = singletonInstance.userProfile.getPubKey() let myPublicKey = singletonInstance.userProfile.getPubKey()
var i = 0 var i = 0
for myPendingRequest in community.pendingRequestsToJoin: for myPendingRequest in community.pendingRequestsToJoin:
@ -2206,7 +2208,7 @@ QtObject:
return false return false
let myPublicKey = singletonInstance.userProfile.getPubKey() let myPublicKey = singletonInstance.userProfile.getPubKey()
var community = self.communities[communityId] var community = self.getCommunityById(communityId)
for pendingRequest in community.pendingRequestsToJoin: for pendingRequest in community.pendingRequestsToJoin:
if pendingRequest.publicKey == myPublicKey: if pendingRequest.publicKey == myPublicKey:
return true return true
@ -2218,7 +2220,7 @@ QtObject:
return false return false
let myPublicKey = singletonInstance.userProfile.getPubKey() let myPublicKey = singletonInstance.userProfile.getPubKey()
var community = self.communities[communityId] var community = self.getCommunityById(communityId)
for request in community.waitingForSharedAddressesRequestsToJoin: for request in community.waitingForSharedAddressesRequestsToJoin:
if request.publicKey == myPublicKey: if request.publicKey == myPublicKey:
return true return true
@ -2281,7 +2283,7 @@ QtObject:
if (indexPending == -1 and indexDeclined == -1): if (indexPending == -1 and indexDeclined == -1):
raise newException(RpcException, fmt"Community request not found: {requestId}") raise newException(RpcException, fmt"Community request not found: {requestId}")
let community = self.communities[communityId] let community = self.getCommunityById(communityId)
if (indexPending != -1): if (indexPending != -1):
return community.pendingRequestsToJoin[indexPending].publicKey return community.pendingRequestsToJoin[indexPending].publicKey
else: else:

View File

@ -59,15 +59,15 @@ StackLayout {
Loader { Loader {
id: mainViewLoader id: mainViewLoader
readonly property var chatItem: root.rootStore.chatCommunitySectionModule readonly property var sectionItem: root.rootStore.chatCommunitySectionModule
sourceComponent: { sourceComponent: {
if (chatItem.isCommunity() && !chatItem.amIMember) { if (sectionItem.isCommunity() && !sectionItem.amIMember) {
if (sectionItemModel.amIBanned) { if (sectionItemModel.amIBanned) {
return communityBanComponent return communityBanComponent
} else if (chatItem.isWaitingOnNewCommunityOwnerToConfirmRequestToRejoin) { } else if (sectionItem.isWaitingOnNewCommunityOwnerToConfirmRequestToRejoin) {
return controlNodeOfflineComponent return controlNodeOfflineComponent
} else if (chatItem.requiresTokenPermissionToJoin) { } else if (sectionItem.requiresTokenPermissionToJoin) {
return joinCommunityViewComponent return joinCommunityViewComponent
} }
} }
@ -149,7 +149,7 @@ StackLayout {
ChatView { ChatView {
id: chatView id: chatView
readonly property var chatItem: root.rootStore.chatCommunitySectionModule readonly property var sectionItem: root.rootStore.chatCommunitySectionModule
readonly property string communityId: root.sectionItemModel.id readonly property string communityId: root.sectionItemModel.id
emojiPopup: root.emojiPopup emojiPopup: root.emojiPopup
@ -162,7 +162,7 @@ StackLayout {
walletAssetsStore: root.walletAssetsStore walletAssetsStore: root.walletAssetsStore
currencyStore: root.currencyStore currencyStore: root.currencyStore
sectionItemModel: root.sectionItemModel sectionItemModel: root.sectionItemModel
amIMember: chatItem.amIMember amIMember: sectionItem.amIMember
amISectionAdmin: root.sectionItemModel.memberRole === Constants.memberRole.owner || amISectionAdmin: root.sectionItemModel.memberRole === Constants.memberRole.owner ||
root.sectionItemModel.memberRole === Constants.memberRole.admin || root.sectionItemModel.memberRole === Constants.memberRole.admin ||
root.sectionItemModel.memberRole === Constants.memberRole.tokenMaster root.sectionItemModel.memberRole === Constants.memberRole.tokenMaster

View File

@ -75,7 +75,7 @@ QtObject {
readonly property var oneToOneChatContact: _d.oneToOneChatContact readonly property var oneToOneChatContact: _d.oneToOneChatContact
// Since qml component doesn't follow encaptulation from the backend side, we're introducing // Since qml component doesn't follow encaptulation from the backend side, we're introducing
// a method which will return appropriate chat content module for selected chat/channel // a method which will return appropriate chat content module for selected chat/channel
function currentChatContentModule(){ function currentChatContentModule() {
// When we decide to have the same struct as it's on the backend we will remove this function. // When we decide to have the same struct as it's on the backend we will remove this function.
// So far this is a way to deal with refactored backend from the current qml structure. // So far this is a way to deal with refactored backend from the current qml structure.
chatCommunitySectionModule.prepareChatContentModuleForChatId(chatCommunitySectionModule.activeItem.id) chatCommunitySectionModule.prepareChatContentModuleForChatId(chatCommunitySectionModule.activeItem.id)

View File

@ -82,12 +82,15 @@ Item {
readonly property var activeChatContentModule: d.getChatContentModule(root.activeChatId) readonly property var activeChatContentModule: d.getChatContentModule(root.activeChatId)
readonly property var urlsList: { readonly property var urlsList: {
if (!d.activeChatContentModule) {
return
}
urlsModelChangeTracker.revision urlsModelChangeTracker.revision
ModelUtils.modelToFlatArray(d.activeChatContentModule.inputAreaModule.urlsModel, "url") ModelUtils.modelToFlatArray(d.activeChatContentModule.inputAreaModule.urlsModel, "url")
} }
readonly property ModelChangeTracker urlsModelChangeTracker: ModelChangeTracker { readonly property ModelChangeTracker urlsModelChangeTracker: ModelChangeTracker {
model: d.activeChatContentModule.inputAreaModule.urlsModel model: !!d.activeChatContentModule ? d.activeChatContentModule.inputAreaModule.urlsModel : null
} }
readonly property UsersStore activeUsersStore: UsersStore { readonly property UsersStore activeUsersStore: UsersStore {
@ -126,6 +129,9 @@ Item {
} }
function restoreInputReply() { function restoreInputReply() {
if (!d.activeChatContentModule) {
return
}
const replyMessageId = d.activeChatContentModule.inputAreaModule.preservedProperties.replyMessageId const replyMessageId = d.activeChatContentModule.inputAreaModule.preservedProperties.replyMessageId
if (replyMessageId) if (replyMessageId)
d.showReplyArea(replyMessageId) d.showReplyArea(replyMessageId)
@ -134,6 +140,9 @@ Item {
} }
function restoreInputAttachments() { function restoreInputAttachments() {
if (!d.activeChatContentModule) {
return
}
const filesJson = d.activeChatContentModule.inputAreaModule.preservedProperties.fileUrlsAndSourcesJson const filesJson = d.activeChatContentModule.inputAreaModule.preservedProperties.fileUrlsAndSourcesJson
let filesList = [] let filesList = []
if (filesJson) { if (filesJson) {
@ -164,6 +173,9 @@ Item {
} }
readonly property var updateLinkPreviews: { readonly property var updateLinkPreviews: {
if (!d.activeChatContentModule) {
return
}
return Backpressure.debounce(this, 250, () => { return Backpressure.debounce(this, 250, () => {
const messageText = root.rootStore.cleanMessageText(chatInput.textInput.text) const messageText = root.rootStore.cleanMessageText(chatInput.textInput.text)
d.activeChatContentModule.inputAreaModule.setText(messageText) d.activeChatContentModule.inputAreaModule.setText(messageText)
@ -171,10 +183,11 @@ Item {
} }
onActiveChatContentModuleChanged: { onActiveChatContentModuleChanged: {
let preservedText = "" if (!d.activeChatContentModule) {
if (d.activeChatContentModule) { return
preservedText = d.activeChatContentModule.inputAreaModule.preservedProperties.text
} }
let preservedText = ""
preservedText = d.activeChatContentModule.inputAreaModule.preservedProperties.text
d.activeChatContentModule.inputAreaModule.clearLinkPreviewCache() d.activeChatContentModule.inputAreaModule.clearLinkPreviewCache()
// Call later to make sure activeUsersStore and activeMessagesStore bindings are updated // Call later to make sure activeUsersStore and activeMessagesStore bindings are updated
@ -203,33 +216,38 @@ Item {
id: chatRepeater id: chatRepeater
model: parentModule && parentModule.model model: parentModule && parentModule.model
ChatContentView { Loader {
width: parent.width width: parent.width
height: parent.height height: parent.height
visible: !root.rootStore.openCreateChat && model.active active: model.type !== Constants.chatType.category && model.type !== Constants.chatType.unknown
chatId: model.itemId sourceComponent: ChatContentView {
chatType: model.type width: parent.width
chatMessagesLoader.active: model.loaderActive height: parent.height
rootStore: root.rootStore visible: !root.rootStore.openCreateChat && model.active
contactsStore: root.contactsStore chatId: model.itemId
emojiPopup: root.emojiPopup chatType: model.type
stickersPopup: root.stickersPopup chatMessagesLoader.active: model.loaderActive
stickersLoaded: root.stickersLoaded rootStore: root.rootStore
isBlocked: model.blocked contactsStore: root.contactsStore
onOpenStickerPackPopup: { emojiPopup: root.emojiPopup
root.openStickerPackPopup(stickerPackId) stickersPopup: root.stickersPopup
} stickersLoaded: root.stickersLoaded
onShowReplyArea: (messageId) => { isBlocked: model.blocked
d.showReplyArea(messageId) onOpenStickerPackPopup: {
} root.openStickerPackPopup(stickerPackId)
onForceInputFocus: { }
chatInput.forceInputActiveFocus() onShowReplyArea: (messageId) => {
} d.showReplyArea(messageId)
}
onForceInputFocus: {
chatInput.forceInputActiveFocus()
}
Component.onCompleted: { Component.onCompleted: {
chatContentModule = d.getChatContentModule(model.itemId) chatContentModule = d.getChatContentModule(model.itemId)
chatSectionModule = root.parentModule chatSectionModule = root.parentModule
root.checkForCreateChatOptions(model.itemId) root.checkForCreateChatOptions(model.itemId)
}
} }
} }
} }
@ -264,7 +282,7 @@ Item {
store: root.rootStore store: root.rootStore
usersStore: d.activeUsersStore usersStore: d.activeUsersStore
linkPreviewModel: d.activeChatContentModule.inputAreaModule.linkPreviewModel linkPreviewModel: !!d.activeChatContentModule ? d.activeChatContentModule.inputAreaModule.linkPreviewModel : null
urlsList: d.urlsList urlsList: d.urlsList
askToEnableLinkPreview: { askToEnableLinkPreview: {
if(!d.activeChatContentModule || !d.activeChatContentModule.inputAreaModule || !d.activeChatContentModule.inputAreaModule.preservedProperties) if(!d.activeChatContentModule || !d.activeChatContentModule.inputAreaModule || !d.activeChatContentModule.inputAreaModule.preservedProperties)
@ -274,7 +292,7 @@ Item {
} }
textInput.placeholderText: { textInput.placeholderText: {
if (!channelPostRestrictions.visible) { if (!channelPostRestrictions.visible) {
if (d.activeChatContentModule.chatDetails.blocked) if (d.activeChatContentModule && d.activeChatContentModule.chatDetails.blocked)
return qsTr("This user has been blocked.") return qsTr("This user has been blocked.")
if (!root.rootStore.sectionDetails.joined || root.rootStore.sectionDetails.amIBanned) { if (!root.rootStore.sectionDetails.joined || root.rootStore.sectionDetails.amIBanned) {
return qsTr("You need to join this community to send messages") return qsTr("You need to join this community to send messages")

View File

@ -206,7 +206,7 @@ Control {
if (d.communityJoined || d.communitySpectated) { if (d.communityJoined || d.communitySpectated) {
root.store.setActiveCommunity(communityId) root.store.setActiveCommunity(communityId)
} else { } else {
root.store.spectateCommunity(communityId, userProfile.name) root.store.spectateCommunity(communityId)
} }
} }
} }