fix: crash when request to join fails + add error toast when it fails

Fixes #11514

The problem was that we were not handling the error from request to join correctly.

Then I added an event that sends a signal to the QML to show a toast about an error. I don't show the actual error to the user because usually it's not super helpful. It will be in the logs.

The status-go change makes it so that we don't save the request to join if the permission check failed.
This commit is contained in:
Jonathan Rainville 2023-07-12 16:26:27 -04:00
parent f5693d0136
commit 5f1483a595
6 changed files with 38 additions and 6 deletions

View File

@ -90,6 +90,10 @@ proc init*(self: Controller) =
let args = CommunityRequestArgs(e) let args = CommunityRequestArgs(e)
self.delegate.communityAccessRequested(args.communityRequest.communityId) self.delegate.communityAccessRequested(args.communityRequest.communityId)
self.events.on(SIGNAL_COMMUNITY_MY_REQUEST_FAILED) do(e:Args):
let args = CommunityRequestFailedArgs(e)
self.delegate.communityAccessFailed(args.communityId, args.error)
self.events.on(SIGNAL_DISCORD_CATEGORIES_AND_CHANNELS_EXTRACTED) do(e:Args): self.events.on(SIGNAL_DISCORD_CATEGORIES_AND_CHANNELS_EXTRACTED) do(e:Args):
let args = DiscordCategoriesAndChannelsArgs(e) let args = DiscordCategoriesAndChannelsArgs(e)
self.delegate.discordCategoriesAndChannelsExtracted(args.categories, args.channels, args.oldestMessageTimestamp, args.errors, args.errorsCount) self.delegate.discordCategoriesAndChannelsExtracted(args.categories, args.channels, args.oldestMessageTimestamp, args.errors, args.errorsCount)

View File

@ -118,6 +118,9 @@ method communityMuted*(self: AccessInterface, communityId: string, muted: bool)
method communityAccessRequested*(self: AccessInterface, communityId: string) {.base.} = method communityAccessRequested*(self: AccessInterface, communityId: string) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method communityAccessFailed*(self: AccessInterface, communityId: string, error: string) {.base.} =
raise newException(ValueError, "No implementation available")
method requestExtractDiscordChannelsAndCategories*(self: AccessInterface, filesToImport: seq[string]) {.base.} = method requestExtractDiscordChannelsAndCategories*(self: AccessInterface, filesToImport: seq[string]) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")

View File

@ -270,6 +270,9 @@ method communityMuted*(self: Module, communityId: string, muted: bool) =
method communityAccessRequested*(self: Module, communityId: string) = method communityAccessRequested*(self: Module, communityId: string) =
self.view.communityAccessRequested(communityId) self.view.communityAccessRequested(communityId)
method communityAccessFailed*(self: Module, communityId, error: string) =
self.view.communityAccessFailed(communityId, error)
method communityHistoryArchivesDownloadStarted*(self: Module, communityId: string) = method communityHistoryArchivesDownloadStarted*(self: Module, communityId: string) =
self.view.setDownloadingCommunityHistoryArchives(true) self.view.setDownloadingCommunityHistoryArchives(true)

View File

@ -109,6 +109,7 @@ QtObject:
proc discordOldestMessageTimestampChanged*(self: View) {.signal.} proc discordOldestMessageTimestampChanged*(self: View) {.signal.}
proc discordImportErrorsCountChanged*(self: View) {.signal.} proc discordImportErrorsCountChanged*(self: View) {.signal.}
proc communityAccessRequested*(self: View, communityId: string) {.signal.} proc communityAccessRequested*(self: View, communityId: string) {.signal.}
proc communityAccessFailed*(self: View, communityId: string, error: string) {.signal.}
proc communityInfoAlreadyRequested*(self: View) {.signal.} proc communityInfoAlreadyRequested*(self: View) {.signal.}
proc communityTagsChanged*(self: View) {.signal.} proc communityTagsChanged*(self: View) {.signal.}

View File

@ -46,6 +46,10 @@ type
CommunityRequestArgs* = ref object of Args CommunityRequestArgs* = ref object of Args
communityRequest*: CommunityMembershipRequestDto communityRequest*: CommunityMembershipRequestDto
CommunityRequestFailedArgs* = ref object of Args
communityId*: string
error*: string
CommunityChatOrderArgs* = ref object of Args CommunityChatOrderArgs* = ref object of Args
communityId*: string communityId*: string
chat*: ChatDto chat*: ChatDto
@ -122,6 +126,7 @@ const SIGNAL_COMMUNITY_DATA_LOADED* = "communityDataLoaded"
const SIGNAL_COMMUNITY_JOINED* = "communityJoined" const SIGNAL_COMMUNITY_JOINED* = "communityJoined"
const SIGNAL_COMMUNITY_SPECTATED* = "communitySpectated" const SIGNAL_COMMUNITY_SPECTATED* = "communitySpectated"
const SIGNAL_COMMUNITY_MY_REQUEST_ADDED* = "communityMyRequestAdded" const SIGNAL_COMMUNITY_MY_REQUEST_ADDED* = "communityMyRequestAdded"
const SIGNAL_COMMUNITY_MY_REQUEST_FAILED* = "communityMyRequestFailed"
const SIGNAL_COMMUNITY_LEFT* = "communityLeft" const SIGNAL_COMMUNITY_LEFT* = "communityLeft"
const SIGNAL_COMMUNITY_CREATED* = "communityCreated" const SIGNAL_COMMUNITY_CREATED* = "communityCreated"
const SIGNAL_COMMUNITY_ADDED* = "communityAdded" const SIGNAL_COMMUNITY_ADDED* = "communityAdded"
@ -1415,21 +1420,23 @@ QtObject:
error "Error request to join community", msg = e.msg error "Error request to join community", msg = e.msg
proc onAsyncRequestToJoinCommunityDone*(self: Service, communityIdAndRpcResponse: string) {.slot.} = proc onAsyncRequestToJoinCommunityDone*(self: Service, communityIdAndRpcResponse: string) {.slot.} =
let rpcResponseObj = communityIdAndRpcResponse.parseJson
try: try:
let rpcResponseObj = communityIdAndRpcResponse.parseJson if (rpcResponseObj{"error"}.kind != JNull and rpcResponseObj{"error"}.getStr != ""):
if (rpcResponseObj{"response"}{"error"}.kind != JNull): raise newException(CatchableError, rpcResponseObj{"error"}.getStr)
let error = Json.decode($rpcResponseObj["response"]["error"], RpcError)
error "Error requesting to join community", msg = error.message
return
let rpcResponse = Json.decode($rpcResponseObj["response"], RpcResponse[JsonNode]) let rpcResponse = Json.decode($rpcResponseObj["response"], RpcResponse[JsonNode])
self.activityCenterService.parseActivityCenterResponse(rpcResponse) self.activityCenterService.parseActivityCenterResponse(rpcResponse)
if not self.processRequestsToJoinCommunity(rpcResponse.result): if not self.processRequestsToJoinCommunity(rpcResponse.result):
error "error: ", procName="onAsyncRequestToJoinCommunityDone", errDesription = "no 'requestsToJoinCommunity' key in response" raise newException(CatchableError, "no 'requestsToJoinCommunity' key in response")
except Exception as e: except Exception as e:
error "Error requesting to join the community", msg = e.msg error "Error requesting to join the community", msg = e.msg
self.events.emit(SIGNAL_COMMUNITY_MY_REQUEST_FAILED, CommunityRequestFailedArgs(
communityId: rpcResponseObj["communityId"].getStr,
error: e.msg
))
proc asyncAcceptRequestToJoinCommunity*(self: Service, communityId: string, requestId: string) = proc asyncAcceptRequestToJoinCommunity*(self: Service, communityId: string, requestId: string) =
try: try:

View File

@ -87,6 +87,7 @@ Item {
} }
Connections { Connections {
enabled: joinCommunityButton.loading
target: root.store.communitiesModuleInst target: root.store.communitiesModuleInst
function onCommunityAccessRequested(communityId: string) { function onCommunityAccessRequested(communityId: string) {
if (communityId === communityData.id) { if (communityId === communityData.id) {
@ -94,9 +95,22 @@ Item {
joinCommunityButton.loading = false joinCommunityButton.loading = false
} }
} }
function onCommunityAccessFailed(communityId: string) {
if (communityId === communityData.id) {
joinCommunityButton.invitationPending = false
joinCommunityButton.loading = false
Global.displayToastMessage(qsTr("Request to join failed"),
qsTr("Please try again later"),
"",
false,
Constants.ephemeralNotificationType.normal,
"")
}
}
} }
Connections { Connections {
enabled: joinCommunityButton.loading
target: communitySectionModule target: communitySectionModule
function onUserAuthenticationCanceled() { function onUserAuthenticationCanceled() {
joinCommunityButton.invitationPending = false joinCommunityButton.invitationPending = false