fix: Community importing notification fixes and improvements

This commit is contained in:
Igor Sirotin 2023-01-18 15:49:04 +03:00 committed by Igor Sirotin
parent 0242f943f2
commit 8736dd8a94
11 changed files with 63 additions and 48 deletions

View File

@ -35,13 +35,12 @@ proc init*(self: Controller) =
self.events.on(SIGNAL_COMMUNITY_DATA_IMPORTED) do(e:Args): self.events.on(SIGNAL_COMMUNITY_DATA_IMPORTED) do(e:Args):
let args = CommunityArgs(e) let args = CommunityArgs(e)
self.delegate.communityImported(args.community) self.delegate.communityDataImported(args.community)
self.events.on(SIGNAL_COMMUNITY_LOAD_DATA_FAILED) do(e: Args): self.events.on(SIGNAL_COMMUNITY_LOAD_DATA_FAILED) do(e: Args):
let args = CommunityArgs(e) let args = CommunityArgs(e)
self.delegate.onImportCommunityErrorOccured(args.community.id, args.error) self.delegate.onImportCommunityErrorOccured(args.community.id, args.error)
self.events.on(SIGNAL_CURATED_COMMUNITY_FOUND) do(e:Args): self.events.on(SIGNAL_CURATED_COMMUNITY_FOUND) do(e:Args):
let args = CuratedCommunityArgs(e) let args = CuratedCommunityArgs(e)
self.delegate.curatedCommunityAdded(args.curatedCommunity) self.delegate.curatedCommunityAdded(args.curatedCommunity)
@ -191,8 +190,8 @@ proc deleteCommunityCategory*(
categoryId: string) = categoryId: string) =
self.communityService.deleteCommunityCategory(communityId, categoryId) self.communityService.deleteCommunityCategory(communityId, categoryId)
proc requestCommunityInfo*(self: Controller, communityId: string) = proc requestCommunityInfo*(self: Controller, communityId: string, importing: bool) =
self.communityService.requestCommunityInfo(communityId) self.communityService.requestCommunityInfo(communityId, importing)
proc importCommunity*(self: Controller, communityKey: string) = proc importCommunity*(self: Controller, communityKey: string) =
self.communityService.importCommunity(communityKey) self.communityService.importCommunity(communityKey)

View File

@ -68,7 +68,7 @@ method cancelRequestToJoinCommunity*(self: AccessInterface, communityId: string)
method requestToJoinCommunity*(self: AccessInterface, communityId: string, ensName: string) {.base.} = method requestToJoinCommunity*(self: AccessInterface, communityId: string, ensName: string) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method requestCommunityInfo*(self: AccessInterface, communityId: string) {.base.} = method requestCommunityInfo*(self: AccessInterface, communityId: string, importing: bool) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method deleteCommunityChat*(self: AccessInterface, communityId: string, channelId: string) {.base.} = method deleteCommunityChat*(self: AccessInterface, communityId: string, channelId: string) {.base.} =
@ -113,6 +113,9 @@ method curatedCommunityEdited*(self: AccessInterface, community: CuratedCommunit
method communityImported*(self: AccessInterface, community: CommunityDto) {.base.} = method communityImported*(self: AccessInterface, community: CommunityDto) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method communityDataImported*(self: AccessInterface, community: CommunityDto) {.base.} =
raise newException(ValueError, "No implementation available")
method onImportCommunityErrorOccured*(self: AccessInterface, communityId: string, error: string) {.base.} = method onImportCommunityErrorOccured*(self: AccessInterface, communityId: string, error: string) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")

View File

@ -285,8 +285,8 @@ method cancelRequestToJoinCommunity*(self: Module, communityId: string) =
method requestToJoinCommunity*(self: Module, communityId: string, ensName: string) = method requestToJoinCommunity*(self: Module, communityId: string, ensName: string) =
self.controller.requestToJoinCommunity(communityId, ensName) self.controller.requestToJoinCommunity(communityId, ensName)
method requestCommunityInfo*(self: Module, communityId: string) = method requestCommunityInfo*(self: Module, communityId: string, importing: bool) =
self.controller.requestCommunityInfo(communityId) self.controller.requestCommunityInfo(communityId, importing)
method isUserMemberOfCommunity*(self: Module, communityId: string): bool = method isUserMemberOfCommunity*(self: Module, communityId: string): bool =
self.controller.isUserMemberOfCommunity(communityId) self.controller.isUserMemberOfCommunity(communityId)
@ -302,11 +302,14 @@ method deleteCommunityChat*(self: Module, communityId: string, channelId: string
method communityImported*(self: Module, community: CommunityDto) = method communityImported*(self: Module, community: CommunityDto) =
self.view.addItem(self.getCommunityItem(community)) self.view.addItem(self.getCommunityItem(community))
self.view.emitImportingCommunityStateChangedSignal(community.id, ImportCommunityState.Imported.int, "") self.view.emitImportingCommunityStateChangedSignal(community.id, ImportCommunityState.Imported.int, errorMsg = "")
method importCommunity*(self: Module, communityKey: string) = method communityDataImported*(self: Module, community: CommunityDto) =
self.view.emitImportingCommunityStateChangedSignal(communityKey, ImportCommunityState.ImportingInProgress.int, "") self.view.addItem(self.getCommunityItem(community))
self.controller.importCommunity(communityKey)
method importCommunity*(self: Module, communityId: string) =
self.view.emitImportingCommunityStateChangedSignal(communityId, ImportCommunityState.ImportingInProgress.int, errorMsg = "")
self.controller.importCommunity(communityId)
method onImportCommunityErrorOccured*(self: Module, communityId: string, error: string) = method onImportCommunityErrorOccured*(self: Module, communityId: string, error: string) =
self.view.emitImportingCommunityStateChangedSignal(communityId, ImportCommunityState.ImportingError.int, error) self.view.emitImportingCommunityStateChangedSignal(communityId, ImportCommunityState.ImportingError.int, error)

View File

@ -440,8 +440,8 @@ QtObject:
proc requestToJoinCommunity*(self: View, communityId: string, ensName: string) {.slot.} = proc requestToJoinCommunity*(self: View, communityId: string, ensName: string) {.slot.} =
self.delegate.requestToJoinCommunity(communityId, ensName) self.delegate.requestToJoinCommunity(communityId, ensName)
proc requestCommunityInfo*(self: View, communityId: string) {.slot.} = proc requestCommunityInfo*(self: View, communityId: string, importing: bool) {.slot.} =
self.delegate.requestCommunityInfo(communityId) self.delegate.requestCommunityInfo(communityId, importing)
proc getCommunityDetails*(self: View, communityId: string): string {.slot.} = proc getCommunityDetails*(self: View, communityId: string): string {.slot.} =
let communityItem = self.model.getItemById(communityId) let communityItem = self.model.getItemById(communityId)

View File

@ -937,7 +937,7 @@ method onStatusUrlRequested*[T](self: Module[T], action: StatusUrlAction, commun
if item.isEmpty(): if item.isEmpty():
# request community info and then spectate # request community info and then spectate
self.statusUrlCommunityToSpectate = communityId self.statusUrlCommunityToSpectate = communityId
self.communitiesModule.requestCommunityInfo(communityId) self.communitiesModule.requestCommunityInfo(communityId, importing = false)
else: else:
self.setActiveSection(item) self.setActiveSection(item)
@ -956,7 +956,7 @@ method onStatusUrlRequested*[T](self: Module[T], action: StatusUrlAction, commun
let communityIdToSpectate = getCommunityIdFromFullChatId(chatId) let communityIdToSpectate = getCommunityIdFromFullChatId(chatId)
# request community info and then spectate # request community info and then spectate
self.statusUrlCommunityToSpectate = communityIdToSpectate self.statusUrlCommunityToSpectate = communityIdToSpectate
self.communitiesModule.requestCommunityInfo(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()):

View File

@ -4,9 +4,10 @@ include ../../../app/core/tasks/common
type type
AsyncRequestCommunityInfoTaskArg = ref object of QObjectTaskArg AsyncRequestCommunityInfoTaskArg = ref object of QObjectTaskArg
communityId: string communityId: string
importing: bool
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)
let tpl: tuple[communityId: string, response: RpcResponse[JsonNode]] = (arg.communityId, response) let tpl: tuple[communityId: string, response: RpcResponse[JsonNode], importing: bool] = (arg.communityId, response, arg.importing)
arg.finish(tpl) arg.finish(tpl)

View File

@ -538,7 +538,7 @@ QtObject:
proc getCommunityById*(self: Service, communityId: string): CommunityDto = proc getCommunityById*(self: Service, communityId: string): CommunityDto =
if(not self.joinedCommunities.hasKey(communityId)): if(not self.joinedCommunities.hasKey(communityId)):
error "error: requested community doesn't exists" error "error: requested community doesn't exists", communityId
return return
return self.joinedCommunities[communityId] return self.joinedCommunities[communityId]
@ -1189,21 +1189,29 @@ QtObject:
return return
var community = rpcResponseObj{"response"}{"result"}.toCommunityDto() var community = rpcResponseObj{"response"}{"result"}.toCommunityDto()
if community.id != "":
self.allCommunities[community.id] = community if community.id == "":
self.events.emit(SIGNAL_COMMUNITY_DATA_IMPORTED, CommunityArgs(community: community))
else:
community.id = rpcResponseObj{"response"}{"communityId"}.getStr() community.id = rpcResponseObj{"response"}{"communityId"}.getStr()
self.events.emit(SIGNAL_COMMUNITY_LOAD_DATA_FAILED, CommunityArgs(community: community, error: "Couldn't find community info")) self.events.emit(SIGNAL_COMMUNITY_LOAD_DATA_FAILED, CommunityArgs(community: community, error: "Couldn't find community info"))
return
self.allCommunities[community.id] = community
if rpcResponseObj{"importing"}.getBool():
self.events.emit(SIGNAL_COMMUNITY_IMPORTED, CommunityArgs(community: community))
self.events.emit(SIGNAL_COMMUNITY_DATA_IMPORTED, CommunityArgs(community: community))
proc requestCommunityInfo*(self: Service, communityId: string) = proc requestCommunityInfo*(self: Service, communityId: string, importing = false) =
try: try:
let arg = AsyncRequestCommunityInfoTaskArg( let arg = AsyncRequestCommunityInfoTaskArg(
tptr: cast[ByteAddress](asyncRequestCommunityInfoTask), tptr: cast[ByteAddress](asyncRequestCommunityInfoTask),
vptr: cast[ByteAddress](self.vptr), vptr: cast[ByteAddress](self.vptr),
slot: "asyncCommunityInfoLoaded", slot: "asyncCommunityInfoLoaded",
communityId: communityId communityId: communityId,
importing: importing
) )
self.threadpool.start(arg) self.threadpool.start(arg)
except Exception as e: except Exception as e:

View File

@ -356,8 +356,8 @@ QtObject {
return communitiesList.getSectionByIdJson(id) return communitiesList.getSectionByIdJson(id)
} }
function requestCommunityInfo(id) { function requestCommunityInfo(id, importing = false) {
communitiesModuleInst.requestCommunityInfo(id) communitiesModuleInst.requestCommunityInfo(id, importing)
} }
function getCommunityDetailsAsJson(id) { function getCommunityDetailsAsJson(id) {

View File

@ -300,32 +300,34 @@ Item {
Connections { Connections {
target: root.store target: root.store
function onImportingCommunityStateChanged(communityId, state, errorMsg) { function onImportingCommunityStateChanged(communityId, state, errorMsg) {
const community = root.store.getCommunityDetailsAsJson(communityId)
let title = "" let title = ""
let subTitle = ""
let loading = false let loading = false
if (state === Constants.communityImported) switch (state)
{
title = qsTr("Community imported")
}
else if (state === Constants.communityImportingInProgress)
{ {
case Constants.communityImported:
title = qsTr("'%1' community imported").arg(community.name);
break
case Constants.communityImportingInProgress:
title = qsTr("Importing community is in progress") title = qsTr("Importing community is in progress")
loading = true loading = true
} break
else if (state === Constants.communityImportingError) case Constants.communityImportingError:
{ title = qsTr("Failed to import community '%1'").arg(community.name)
title = errorMsg subTitle = errorMsg
} break
default:
if(title == "") console.error("unknown state while importing community: %1").arg(state)
{
console.error("unknown state while importing community: ", state)
return return
} }
Global.displayToastMessage(title, Global.displayToastMessage(title,
"", subTitle,
"", "",
loading, loading,
Constants.ephemeralNotificationType.normal, Constants.ephemeralNotificationType.normal,

View File

@ -89,14 +89,12 @@ QtObject {
root.communitiesModuleInst.importCommunity(communityKey); root.communitiesModuleInst.importCommunity(communityKey);
} }
function requestCommunityInfo(communityKey) { function requestCommunityInfo(communityKey, importing = false) {
let publicKey = communityKey const publicKey = Utils.isCompressedPubKey(communityKey)
if (Utils.isCompressedPubKey(communityKey)) { ? Utils.changeCommunityKeyCompression(communityKey)
publicKey = Utils.changeCommunityKeyCompression(communityKey) : communityKey
}
root.mainModuleInst.setCommunityIdToSpectate(publicKey) root.mainModuleInst.setCommunityIdToSpectate(publicKey)
root.communitiesModuleInst.requestCommunityInfo(publicKey); root.communitiesModuleInst.requestCommunityInfo(publicKey, importing)
} }
function setActiveCommunity(communityId) { function setActiveCommunity(communityId) {

View File

@ -50,7 +50,8 @@ StatusDialog {
} }
if (d.isPublicKey) { if (d.isPublicKey) {
importButton.loading = true importButton.loading = true
root.store.requestCommunityInfo(communityKey) root.store.requestCommunityInfo(communityKey, true)
root.close();
} }
} }
} }