Skip to content

Commit

Permalink
fix: Community importing notification fixes and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-sirotin committed Jan 20, 2023
1 parent 0242f94 commit 8736dd8
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 48 deletions.
7 changes: 3 additions & 4 deletions src/app/modules/main/communities/controller.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion src/app/modules/main/communities/io_interface.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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.} =
Expand Down Expand Up @@ -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")

Expand Down
15 changes: 9 additions & 6 deletions src/app/modules/main/communities/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/app/modules/main/communities/view.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/app/modules/main/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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()):
Expand Down
3 changes: 2 additions & 1 deletion src/app_service/service/community/async_tasks.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
22 changes: 15 additions & 7 deletions src/app_service/service/community/service.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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, importing = false) =

proc requestCommunityInfo*(self: Service, communityId: string) =
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:
Expand Down
4 changes: 2 additions & 2 deletions ui/app/AppLayouts/Chat/stores/RootStore.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
32 changes: 17 additions & 15 deletions ui/app/AppLayouts/Chat/views/ContactsColumnView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 5 additions & 7 deletions ui/app/AppLayouts/CommunitiesPortal/stores/CommunitiesStore.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion ui/imports/shared/popups/ImportCommunityPopup.qml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ StatusDialog {
}
if (d.isPublicKey) {
importButton.loading = true
root.store.requestCommunityInfo(communityKey)
root.store.requestCommunityInfo(communityKey, true)
root.close();
}
}
}
Expand Down

0 comments on commit 8736dd8

Please sign in to comment.