fix(@community): Fix community join bubble

fixes #6133

When restarting the app, the community is not in the list
and data needs to be requested
This commit is contained in:
Anthony Laibe 2022-06-20 13:39:40 +02:00 committed by Iuri Matias
parent 52b0112a0f
commit 6b9b5f20a8
5 changed files with 38 additions and 21 deletions

View File

@ -8,5 +8,4 @@ type
const asyncRequestCommunityInfoTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} = const asyncRequestCommunityInfoTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
let arg = decode[AsyncRequestCommunityInfoTaskArg](argEncoded) let arg = decode[AsyncRequestCommunityInfoTaskArg](argEncoded)
let response = status_go.requestCommunityInfo(arg.communityId) let response = status_go.requestCommunityInfo(arg.communityId)
arg.finish(response)
arg.finish(response)

View File

@ -132,6 +132,7 @@ QtObject:
chatService: chat_service.Service chatService: chat_service.Service
): Service = ): Service =
result = Service() result = Service()
result.QObject.setup
result.events = events result.events = events
result.threadpool = threadpool result.threadpool = threadpool
result.chatService = chatService result.chatService = chatService
@ -938,24 +939,26 @@ QtObject:
error "Error reordering category channel", msg = e.msg, communityId, categoryId, position error "Error reordering category channel", msg = e.msg, communityId, categoryId, position
proc asyncActivityNotificationLoad*(self: Service, communityId: string) =
let arg = AsyncRequestCommunityInfoTaskArg(
tptr: cast[ByteAddress](asyncRequestCommunityInfoTask),
vptr: cast[ByteAddress](self.vptr),
slot: "asyncCommunityInfoLoaded",
communityId: communityId
)
self.threadpool.start(arg)
proc asyncCommunityInfoLoaded*(self: Service, rpcResponse: string) {.slot.} = proc asyncCommunityInfoLoaded*(self: Service, rpcResponse: string) {.slot.} =
let rpcResponseObj = rpcResponse.parseJson let rpcResponseObj = rpcResponse.parseJson
if (rpcResponseObj{"error"}.kind != JNull): if (rpcResponseObj{"error"}.kind != JNull):
let error = Json.decode($rpcResponseObj["error"], RpcError) let error = Json.decode($rpcResponseObj["error"], RpcError)
error "Error requesting community info", msg = error.message error "Error requesting community info", msg = error.message
return
let community = rpcResponseObj{"result"}.toCommunityDto()
self.allCommunities[community.id] = community
self.events.emit(SIGNAL_COMMUNITY_DATA_IMPORTED, CommunityArgs(community: community))
proc requestCommunityInfo*(self: Service, communityId: string) = proc requestCommunityInfo*(self: Service, communityId: string) =
try: try:
self.asyncActivityNotificationLoad(communityId) let arg = AsyncRequestCommunityInfoTaskArg(
tptr: cast[ByteAddress](asyncRequestCommunityInfoTask),
vptr: cast[ByteAddress](self.vptr),
slot: "asyncCommunityInfoLoaded",
communityId: communityId
)
self.threadpool.start(arg)
except Exception as e: except Exception as e:
error "Error requesting community info", msg = e.msg, communityId error "Error requesting community info", msg = e.msg, communityId

View File

@ -232,7 +232,7 @@ proc deleteCommunityCategory*(
}]) }])
proc requestCommunityInfo*(communityId: string): RpcResponse[JsonNode] {.raises: [Exception].} = proc requestCommunityInfo*(communityId: string): RpcResponse[JsonNode] {.raises: [Exception].} =
result = callPrivateRPC("requestCommunityInfoFromMailserverAsync".prefix, %*[communityId]) result = callPrivateRPC("requestCommunityInfoFromMailserver".prefix, %*[communityId])
proc importCommunity*(communityKey: string): RpcResponse[JsonNode] {.raises: [Exception].} = proc importCommunity*(communityKey: string): RpcResponse[JsonNode] {.raises: [Exception].} =
result = callPrivateRPC("importCommunity".prefix, %*[communityKey]) result = callPrivateRPC("importCommunity".prefix, %*[communityKey])

View File

@ -359,6 +359,10 @@ QtObject {
return communitiesList.getSectionByIdJson(id) return communitiesList.getSectionByIdJson(id)
} }
function requestCommunityInfo(id) {
communitiesModuleInst.requestCommunityInfo(id)
}
function getLinkTitleAndCb(link) { function getLinkTitleAndCb(link) {
const result = { const result = {
title: "Status", title: "Status",

View File

@ -26,7 +26,9 @@ Item {
function getCommunity() { function getCommunity() {
try { try {
const communityJson = root.store.getSectionByIdJson(communityId) const communityJson = root.store.getSectionByIdJson(communityId)
if (!communityJson) { if (!communityJson) {
root.store.requestCommunityInfo(communityId)
return null return null
} }
@ -42,14 +44,23 @@ Item {
root.invitedCommunity = getCommunity() root.invitedCommunity = getCommunity()
} }
Connections { Connections {
target: root.store.communitiesModuleInst target: root.store.communitiesModuleInst
onCommunityChanged: function (communityId) { onCommunityChanged: function (communityId) {
if (communityId === root.communityId) { if (communityId === root.communityId) {
root.invitedCommunity = getCommunity() root.invitedCommunity = getCommunity()
} }
} }
} }
Connections {
target: root.store.communitiesModuleInst
onCommunityAdded: function (communityId) {
if (communityId === root.communityId) {
root.invitedCommunity = getCommunity()
}
}
}
Component { Component {
id: communityIntroDialog id: communityIntroDialog