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):
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):
let args = CommunityArgs(e)
self.delegate.onImportCommunityErrorOccured(args.community.id, args.error)
self.events.on(SIGNAL_CURATED_COMMUNITY_FOUND) do(e:Args):
let args = CuratedCommunityArgs(e)
self.delegate.curatedCommunityAdded(args.curatedCommunity)
@ -191,8 +190,8 @@ proc deleteCommunityCategory*(
categoryId: string) =
self.communityService.deleteCommunityCategory(communityId, categoryId)
proc requestCommunityInfo*(self: Controller, communityId: string) =
self.communityService.requestCommunityInfo(communityId)
proc requestCommunityInfo*(self: Controller, communityId: string, importing: bool) =
self.communityService.requestCommunityInfo(communityId, importing)
proc importCommunity*(self: Controller, communityKey: string) =
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.} =
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")
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.} =
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.} =
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) =
self.controller.requestToJoinCommunity(communityId, ensName)
method requestCommunityInfo*(self: Module, communityId: string) =
self.controller.requestCommunityInfo(communityId)
method requestCommunityInfo*(self: Module, communityId: string, importing: bool) =
self.controller.requestCommunityInfo(communityId, importing)
method isUserMemberOfCommunity*(self: Module, communityId: string): bool =
self.controller.isUserMemberOfCommunity(communityId)
@ -302,11 +302,14 @@ method deleteCommunityChat*(self: Module, communityId: string, channelId: string
method communityImported*(self: Module, community: CommunityDto) =
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) =
self.view.emitImportingCommunityStateChangedSignal(communityKey, ImportCommunityState.ImportingInProgress.int, "")
self.controller.importCommunity(communityKey)
method communityDataImported*(self: Module, community: CommunityDto) =
self.view.addItem(self.getCommunityItem(community))
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) =
self.view.emitImportingCommunityStateChangedSignal(communityId, ImportCommunityState.ImportingError.int, error)

View File

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

View File

@ -937,7 +937,7 @@ method onStatusUrlRequested*[T](self: Module[T], action: StatusUrlAction, commun
if item.isEmpty():
# request community info and then spectate
self.statusUrlCommunityToSpectate = communityId
self.communitiesModule.requestCommunityInfo(communityId)
self.communitiesModule.requestCommunityInfo(communityId, importing = false)
else:
self.setActiveSection(item)
@ -956,7 +956,7 @@ method onStatusUrlRequested*[T](self: Module[T], action: StatusUrlAction, commun
let communityIdToSpectate = getCommunityIdFromFullChatId(chatId)
# request community info and then spectate
self.statusUrlCommunityToSpectate = communityIdToSpectate
self.communitiesModule.requestCommunityInfo(communityIdToSpectate)
self.communitiesModule.requestCommunityInfo(communityIdToSpectate, importing = false)
# enable after MVP
#else(action == StatusUrlAction.OpenLinkInBrowser and singletonInstance.localAccountSensitiveSettings.getIsBrowserEnabled()):

View File

@ -4,9 +4,10 @@ include ../../../app/core/tasks/common
type
AsyncRequestCommunityInfoTaskArg = ref object of QObjectTaskArg
communityId: string
importing: bool
const asyncRequestCommunityInfoTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
let arg = decode[AsyncRequestCommunityInfoTaskArg](argEncoded)
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)

View File

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

View File

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

View File

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

View File

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

View File

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