fix: activate community channel link (#12653)

This commit is contained in:
Igor Sirotin 2023-11-08 16:51:57 +00:00 committed by GitHub
parent 2910317c9a
commit 4c99ca3f76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 58 additions and 40 deletions

View File

@ -195,6 +195,7 @@ proc init*(self: Controller) =
setActive = args.fromUserAction setActive = args.fromUserAction
) )
self.delegate.onFinaliseOwnershipStatusChanged(args.isPendingOwnershipRequest, args.community.id) self.delegate.onFinaliseOwnershipStatusChanged(args.isPendingOwnershipRequest, args.community.id)
self.delegate.communitySpectated(args.community.id)
self.events.on(TOGGLE_SECTION) do(e:Args): self.events.on(TOGGLE_SECTION) do(e:Args):
let args = ToggleSectionArgs(e) let args = ToggleSectionArgs(e)

View File

@ -141,6 +141,9 @@ method activeSectionSet*(self: AccessInterface, sectionId: string) {.base.} =
method toggleSection*(self: AccessInterface, sectionType: SectionType) {.base.} = method toggleSection*(self: AccessInterface, sectionType: SectionType) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method communitySpectated*(self: AccessInterface, communityId: string) {.base.} =
raise newException(ValueError, "No implementation available")
method communityJoined*(self: AccessInterface, community: CommunityDto, events: EventEmitter, method communityJoined*(self: AccessInterface, community: CommunityDto, events: EventEmitter,
settingsService: settings_service.Service, settingsService: settings_service.Service,
nodeConfigurationService: node_configuration_service.Service, nodeConfigurationService: node_configuration_service.Service,

View File

@ -81,6 +81,10 @@ const STATUS_URL_ENS_RESOLVE_REASON = "StatusUrl"
const MAX_MEMBERS_IN_GROUP_CHAT_WITHOUT_ADMIN = 19 const MAX_MEMBERS_IN_GROUP_CHAT_WITHOUT_ADMIN = 19
type type
SpectateRequest = object
communityId*: string
channelUuid*: string
Module*[T: io_interface.DelegateInterface] = ref object of io_interface.AccessInterface Module*[T: io_interface.DelegateInterface] = ref object of io_interface.AccessInterface
delegate: T delegate: T
view: View view: View
@ -113,7 +117,7 @@ type
moduleLoaded: bool moduleLoaded: bool
chatsLoaded: bool chatsLoaded: bool
communityDataLoaded: bool communityDataLoaded: bool
statusUrlCommunityToSpectate: string pendingSpectateRequest: SpectateRequest
# Forward declaration # Forward declaration
method calculateProfileSectionHasNotification*[T](self: Module[T]): bool method calculateProfileSectionHasNotification*[T](self: Module[T]): bool
@ -812,7 +816,8 @@ method emitMailserverNotWorking*[T](self: Module[T]) =
self.view.emitMailserverNotWorking() self.view.emitMailserverNotWorking()
method setCommunityIdToSpectate*[T](self: Module[T], communityId: string) = method setCommunityIdToSpectate*[T](self: Module[T], communityId: string) =
self.statusUrlCommunityToSpectate = communityId self.pendingSpectateRequest.communityId = communityId
self.pendingSpectateRequest.channelUuid = ""
method getActiveSectionId*[T](self: Module[T]): string = method getActiveSectionId*[T](self: Module[T]): string =
return self.controller.getActiveSectionId() return self.controller.getActiveSectionId()
@ -943,6 +948,16 @@ method isConnected[T](self: Module[T]): bool =
method getAppSearchModule*[T](self: Module[T]): QVariant = method getAppSearchModule*[T](self: Module[T]): QVariant =
self.appSearchModule.getModuleAsVariant() self.appSearchModule.getModuleAsVariant()
method communitySpectated*[T](self: Module[T], communityId: string) =
if self.pendingSpectateRequest.communityId != communityId:
return
self.pendingSpectateRequest.communityId = ""
if self.pendingSpectateRequest.channelUuid == "":
return
let chatId = communityId & self.pendingSpectateRequest.channelUuid
self.pendingSpectateRequest.channelUuid = ""
self.controller.switchTo(communityId, chatId, "")
method communityJoined*[T]( method communityJoined*[T](
self: Module[T], self: Module[T],
community: CommunityDto, community: CommunityDto,
@ -1101,8 +1116,7 @@ method isEnsVerified*[T](self: Module[T], publicKey: string): bool =
return self.controller.getContact(publicKey).ensVerified return self.controller.getContact(publicKey).ensVerified
method communityDataImported*[T](self: Module[T], community: CommunityDto) = method communityDataImported*[T](self: Module[T], community: CommunityDto) =
if community.id == self.statusUrlCommunityToSpectate: if community.id == self.pendingSpectateRequest.communityId:
self.statusUrlCommunityToSpectate = ""
discard self.communitiesModule.spectateCommunity(community.id) discard self.communitiesModule.spectateCommunity(community.id)
method resolveENS*[T](self: Module[T], ensName: string, uuid: string, reason: string = "") = method resolveENS*[T](self: Module[T], ensName: string, uuid: string, reason: string = "") =
@ -1309,41 +1323,42 @@ proc switchToContactOrDisplayUserProfile[T](self: Module[T], publicKey: string)
else: else:
self.view.emitDisplayUserProfileSignal(publicKey) self.view.emitDisplayUserProfileSignal(publicKey)
method onStatusUrlRequested*[T](self: Module[T], action: StatusUrlAction, communityId: string, chatId: string, method onStatusUrlRequested*[T](self: Module[T], action: StatusUrlAction, communityId: string, channelId: string,
url: string, userId: string) = url: string, userId: string) =
if(action == StatusUrlAction.DisplayUserProfile): case action:
if singletonInstance.utils().isCompressedPubKey(userId): of StatusUrlAction.DisplayUserProfile:
let contactPk = singletonInstance.utils().getDecompressedPk(userId) if singletonInstance.utils().isCompressedPubKey(userId):
self.switchToContactOrDisplayUserProfile(contactPk) let contactPk = singletonInstance.utils().getDecompressedPk(userId)
else: self.switchToContactOrDisplayUserProfile(contactPk)
self.resolveENS(userId, "", STATUS_URL_ENS_RESOLVE_REASON & $StatusUrlAction.DisplayUserProfile) else:
self.resolveENS(userId, "", STATUS_URL_ENS_RESOLVE_REASON & $StatusUrlAction.DisplayUserProfile)
elif(action == 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():
# request community info and then spectate # request community info and then spectate
self.statusUrlCommunityToSpectate = communityId self.pendingSpectateRequest.communityId = communityId
self.communitiesModule.requestCommunityInfo(communityId, importing = false) self.pendingSpectateRequest.channelUuid = ""
else: self.communitiesModule.requestCommunityInfo(communityId, importing = false)
self.setActiveSection(item) return
self.controller.switchTo(communityId, "", "")
elif(action == StatusUrlAction.OpenCommunityChannel): of StatusUrlAction.OpenCommunityChannel:
var found = false let chatId = communityId & channelId
for cId, cModule in self.channelGroupModules.pairs: let item = self.view.model().getItemById(communityId)
if(cId == singletonInstance.userProfile.getPubKey()):
continue if item.isEmpty():
if(cModule.doesCatOrChatExist(chatId)): self.pendingSpectateRequest.communityId = communityId
let item = self.view.model().getItemById(cId) self.pendingSpectateRequest.channelUuid = channelId
self.setActiveSection(item) self.communitiesModule.requestCommunityInfo(communityId, importing = false)
cModule.makeChatWithIdActive(chatId) return
found = true
break self.controller.switchTo(communityId, chatId, "")
if not found:
let communityIdToSpectate = getCommunityIdFromFullChatId(chatId) else:
# request community info and then spectate return
self.statusUrlCommunityToSpectate = communityIdToSpectate
self.communitiesModule.requestCommunityInfo(communityIdToSpectate, importing = false)
# enable after MVP # enable after MVP
#else(action == StatusUrlAction.OpenLinkInBrowser and singletonInstance.localAccountSensitiveSettings.getIsBrowserEnabled()): #else(action == StatusUrlAction.OpenLinkInBrowser and singletonInstance.localAccountSensitiveSettings.getIsBrowserEnabled()):
@ -1477,15 +1492,15 @@ method checkAndPerformProfileMigrationIfNeeded*[T](self: Module[T]) =
method activateStatusDeepLink*[T](self: Module[T], statusDeepLink: string) = method activateStatusDeepLink*[T](self: Module[T], statusDeepLink: string) =
let urlData = self.sharedUrlsModule.parseSharedUrl(statusDeepLink) let urlData = self.sharedUrlsModule.parseSharedUrl(statusDeepLink)
if urlData.channel.uuid != "":
self.onStatusUrlRequested(StatusUrlAction.OpenCommunityChannel, urlData.community.communityId, urlData.channel.uuid, "", "")
return
if urlData.community.communityId != "": if urlData.community.communityId != "":
self.onStatusUrlRequested(StatusUrlAction.OpenCommunity, urlData.community.communityId, "", "", "") self.onStatusUrlRequested(StatusUrlAction.OpenCommunity, urlData.community.communityId, "", "", "")
return return
if urlData.contact.publicKey != "": if urlData.contact.publicKey != "":
self.onStatusUrlRequested(StatusUrlAction.DisplayUserProfile, "", "", "", urlData.contact.publicKey) self.onStatusUrlRequested(StatusUrlAction.DisplayUserProfile, "", "", "", urlData.contact.publicKey)
return return
if urlData.channel.uuid != "":
self.onStatusUrlRequested(StatusUrlAction.OpenCommunityChannel, "", urlData.channel.uuid, "", "")
return
let linkToActivate = self.urlsManager.convertExternalLinkToInternal(statusDeepLink) let linkToActivate = self.urlsManager.convertExternalLinkToInternal(statusDeepLink)
self.urlsManager.onUrlActivated(linkToActivate) self.urlsManager.onUrlActivated(linkToActivate)

View File

@ -1834,7 +1834,6 @@ QtObject:
if self.communityInfoRequests.hasKey(communityId): if self.communityInfoRequests.hasKey(communityId):
let lastRequestTime = self.communityInfoRequests[communityId] let lastRequestTime = self.communityInfoRequests[communityId]
let actualTimeSincLastRequest = now - lastRequestTime let actualTimeSincLastRequest = now - lastRequestTime
debug "requestCommunityInfo: TIME", communityId, now, lastRequestTime, requiredTimeSinceLastRequest, actualTimeSincLastRequest
if actualTimeSincLastRequest < requiredTimeSinceLastRequest: if actualTimeSincLastRequest < requiredTimeSinceLastRequest:
debug "requestCommunityInfo: skipping as required time has not passed yet since last request", communityId, actualTimeSincLastRequest, requiredTimeSinceLastRequest debug "requestCommunityInfo: skipping as required time has not passed yet since last request", communityId, actualTimeSincLastRequest, requiredTimeSinceLastRequest
return return

View File

@ -48,7 +48,7 @@ proc toCommunityChannelUrlDataDto*(jsonObj: JsonNode): CommunityChannelUrlDataDt
discard jsonObj.getProp("description", result.description) discard jsonObj.getProp("description", result.description)
discard jsonObj.getProp("emoji", result.emoji) discard jsonObj.getProp("emoji", result.emoji)
discard jsonObj.getProp("color", result.color) discard jsonObj.getProp("color", result.color)
discard jsonObj.getProp("uuid", result.uuid) discard jsonObj.getProp("channelUuid", result.uuid)
proc toContactUrlDataDto*(jsonObj: JsonNode): ContactUrlDataDto = proc toContactUrlDataDto*(jsonObj: JsonNode): ContactUrlDataDto =
result = ContactUrlDataDto() result = ContactUrlDataDto()