Skip to content

Commit

Permalink
fix: activate community channel link (#12653)
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-sirotin committed Nov 8, 2023
1 parent 2910317 commit 4c99ca3
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 41 deletions.
1 change: 1 addition & 0 deletions src/app/modules/main/controller.nim
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ proc init*(self: Controller) =
setActive = args.fromUserAction
)
self.delegate.onFinaliseOwnershipStatusChanged(args.isPendingOwnershipRequest, args.community.id)
self.delegate.communitySpectated(args.community.id)

self.events.on(TOGGLE_SECTION) do(e:Args):
let args = ToggleSectionArgs(e)
Expand Down
3 changes: 3 additions & 0 deletions src/app/modules/main/io_interface.nim
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ method activeSectionSet*(self: AccessInterface, sectionId: string) {.base.} =
method toggleSection*(self: AccessInterface, sectionType: SectionType) {.base.} =
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,
settingsService: settings_service.Service,
nodeConfigurationService: node_configuration_service.Service,
Expand Down
93 changes: 54 additions & 39 deletions src/app/modules/main/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ const STATUS_URL_ENS_RESOLVE_REASON = "StatusUrl"
const MAX_MEMBERS_IN_GROUP_CHAT_WITHOUT_ADMIN = 19

type
SpectateRequest = object
communityId*: string
channelUuid*: string

Module*[T: io_interface.DelegateInterface] = ref object of io_interface.AccessInterface
delegate: T
view: View
Expand Down Expand Up @@ -113,7 +117,7 @@ type
moduleLoaded: bool
chatsLoaded: bool
communityDataLoaded: bool
statusUrlCommunityToSpectate: string
pendingSpectateRequest: SpectateRequest

# Forward declaration
method calculateProfileSectionHasNotification*[T](self: Module[T]): bool
Expand Down Expand Up @@ -812,7 +816,8 @@ method emitMailserverNotWorking*[T](self: Module[T]) =
self.view.emitMailserverNotWorking()

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 =
return self.controller.getActiveSectionId()
Expand Down Expand Up @@ -943,6 +948,16 @@ method isConnected[T](self: Module[T]): bool =
method getAppSearchModule*[T](self: Module[T]): QVariant =
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](
self: Module[T],
community: CommunityDto,
Expand Down Expand Up @@ -1101,8 +1116,7 @@ method isEnsVerified*[T](self: Module[T], publicKey: string): bool =
return self.controller.getContact(publicKey).ensVerified

method communityDataImported*[T](self: Module[T], community: CommunityDto) =
if community.id == self.statusUrlCommunityToSpectate:
self.statusUrlCommunityToSpectate = ""
if community.id == self.pendingSpectateRequest.communityId:
discard self.communitiesModule.spectateCommunity(community.id)

method resolveENS*[T](self: Module[T], ensName: string, uuid: string, reason: string = "") =
Expand Down Expand Up @@ -1309,41 +1323,42 @@ proc switchToContactOrDisplayUserProfile[T](self: Module[T], publicKey: string)
else:
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) =

if(action == StatusUrlAction.DisplayUserProfile):
if singletonInstance.utils().isCompressedPubKey(userId):
let contactPk = singletonInstance.utils().getDecompressedPk(userId)
self.switchToContactOrDisplayUserProfile(contactPk)
else:
self.resolveENS(userId, "", STATUS_URL_ENS_RESOLVE_REASON & $StatusUrlAction.DisplayUserProfile)

elif(action == StatusUrlAction.OpenCommunity):
let item = self.view.model().getItemById(communityId)
if item.isEmpty():
# request community info and then spectate
self.statusUrlCommunityToSpectate = communityId
self.communitiesModule.requestCommunityInfo(communityId, importing = false)
case action:
of StatusUrlAction.DisplayUserProfile:
if singletonInstance.utils().isCompressedPubKey(userId):
let contactPk = singletonInstance.utils().getDecompressedPk(userId)
self.switchToContactOrDisplayUserProfile(contactPk)
else:
self.resolveENS(userId, "", STATUS_URL_ENS_RESOLVE_REASON & $StatusUrlAction.DisplayUserProfile)

of StatusUrlAction.OpenCommunity:
let item = self.view.model().getItemById(communityId)
if item.isEmpty():
# request community info and then spectate
self.pendingSpectateRequest.communityId = communityId
self.pendingSpectateRequest.channelUuid = ""
self.communitiesModule.requestCommunityInfo(communityId, importing = false)
return

self.controller.switchTo(communityId, "", "")

of StatusUrlAction.OpenCommunityChannel:
let chatId = communityId & channelId
let item = self.view.model().getItemById(communityId)

if item.isEmpty():
self.pendingSpectateRequest.communityId = communityId
self.pendingSpectateRequest.channelUuid = channelId
self.communitiesModule.requestCommunityInfo(communityId, importing = false)
return

self.controller.switchTo(communityId, chatId, "")

else:
self.setActiveSection(item)

elif(action == StatusUrlAction.OpenCommunityChannel):
var found = false
for cId, cModule in self.channelGroupModules.pairs:
if(cId == singletonInstance.userProfile.getPubKey()):
continue
if(cModule.doesCatOrChatExist(chatId)):
let item = self.view.model().getItemById(cId)
self.setActiveSection(item)
cModule.makeChatWithIdActive(chatId)
found = true
break
if not found:
let communityIdToSpectate = getCommunityIdFromFullChatId(chatId)
# request community info and then spectate
self.statusUrlCommunityToSpectate = communityIdToSpectate
self.communitiesModule.requestCommunityInfo(communityIdToSpectate, importing = false)
return

# enable after MVP
#else(action == StatusUrlAction.OpenLinkInBrowser and singletonInstance.localAccountSensitiveSettings.getIsBrowserEnabled()):
Expand Down Expand Up @@ -1477,15 +1492,15 @@ method checkAndPerformProfileMigrationIfNeeded*[T](self: Module[T]) =

method activateStatusDeepLink*[T](self: Module[T], statusDeepLink: string) =
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 != "":
self.onStatusUrlRequested(StatusUrlAction.OpenCommunity, urlData.community.communityId, "", "", "")
return
if urlData.contact.publicKey != "":
self.onStatusUrlRequested(StatusUrlAction.DisplayUserProfile, "", "", "", urlData.contact.publicKey)
return
if urlData.channel.uuid != "":
self.onStatusUrlRequested(StatusUrlAction.OpenCommunityChannel, "", urlData.channel.uuid, "", "")
return
let linkToActivate = self.urlsManager.convertExternalLinkToInternal(statusDeepLink)
self.urlsManager.onUrlActivated(linkToActivate)

Expand Down
1 change: 0 additions & 1 deletion src/app_service/service/community/service.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1834,7 +1834,6 @@ QtObject:
if self.communityInfoRequests.hasKey(communityId):
let lastRequestTime = self.communityInfoRequests[communityId]
let actualTimeSincLastRequest = now - lastRequestTime
debug "requestCommunityInfo: TIME", communityId, now, lastRequestTime, requiredTimeSinceLastRequest, actualTimeSincLastRequest
if actualTimeSincLastRequest < requiredTimeSinceLastRequest:
debug "requestCommunityInfo: skipping as required time has not passed yet since last request", communityId, actualTimeSincLastRequest, requiredTimeSinceLastRequest
return
Expand Down
2 changes: 1 addition & 1 deletion src/app_service/service/shared_urls/dto/url_data.nim
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ proc toCommunityChannelUrlDataDto*(jsonObj: JsonNode): CommunityChannelUrlDataDt
discard jsonObj.getProp("description", result.description)
discard jsonObj.getProp("emoji", result.emoji)
discard jsonObj.getProp("color", result.color)
discard jsonObj.getProp("uuid", result.uuid)
discard jsonObj.getProp("channelUuid", result.uuid)

proc toContactUrlDataDto*(jsonObj: JsonNode): ContactUrlDataDto =
result = ContactUrlDataDto()
Expand Down

0 comments on commit 4c99ca3

Please sign in to comment.