Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: info msg if owner is not awailable after community ownership change #12560

Merged
merged 2 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/app/modules/main/chat_section/controller.nim
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ proc newController*(delegate: io_interface.AccessInterface, sectionId: string, i
result.walletAccountService = walletAccountService
result.tokenService = tokenService
result.communityTokensService = communityTokensService

proc delete*(self: Controller) =
self.events.disconnect()

Expand Down Expand Up @@ -304,6 +304,11 @@ proc init*(self: Controller) =
if args.communityId == self.sectionId:
self.delegate.setPermissionsToJoinCheckOngoing(false)

self.events.on(SIGNAL_WAITING_ON_NEW_COMMUNITY_OWNER_TO_CONFIRM_REQUEST_TO_REJOIN) do(e: Args):
let args = CommunityIdArgs(e)
if args.communityId == self.sectionId:
self.delegate.onWaitingOnNewCommunityOwnerToConfirmRequestToRejoin()

self.events.on(SignalType.Wallet.event, proc(e: Args) =
var data = WalletSignal(e)
if data.eventType == backend_collectibles.eventCollectiblesOwnershipUpdateFinished:
Expand Down Expand Up @@ -676,4 +681,7 @@ proc collectCommunityMetricsMessagesTimestamps*(self: Controller, intervals: str
self.communityService.collectCommunityMetricsMessagesTimestamps(self.getMySectionId(), intervals)

proc collectCommunityMetricsMessagesCount*(self: Controller, intervals: string) =
self.communityService.collectCommunityMetricsMessagesCount(self.getMySectionId(), intervals)
self.communityService.collectCommunityMetricsMessagesCount(self.getMySectionId(), intervals)

proc waitingOnNewCommunityOwnerToConfirmRequestToRejoin*(self: Controller, communityId: string): bool =
self.communityService.waitingOnNewCommunityOwnerToConfirmRequestToRejoin(communityId)
3 changes: 3 additions & 0 deletions src/app/modules/main/chat_section/io_interface.nim
Original file line number Diff line number Diff line change
Expand Up @@ -405,3 +405,6 @@ method setChannelsPermissionsCheckOngoing*(self: AccessInterface, value: bool) {

method getChannelsPermissionsCheckOngoing*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")

method onWaitingOnNewCommunityOwnerToConfirmRequestToRejoin*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
7 changes: 7 additions & 0 deletions src/app/modules/main/chat_section/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ method onChatsLoaded*(
else:
let community = self.controller.getMyCommunity()
self.view.setAmIMember(community.joined)
self.view.setWaitingOnNewCommunityOwnerToConfirmRequestToRejoin(self.controller.waitingOnNewCommunityOwnerToConfirmRequestToRejoin(community.id))
self.initCommunityTokenPermissionsModel(channelGroup)
self.onCommunityCheckAllChannelsPermissionsResponse(channelGroup.channelPermissions)
self.controller.asyncCheckPermissionsToJoin()
Expand Down Expand Up @@ -889,9 +890,12 @@ method onCommunityCheckAllChannelsPermissionsResponse*(self: Module, checkAllCha

method onKickedFromCommunity*(self: Module) =
self.view.setAmIMember(false)
let communityId = self.controller.getMySectionId()
self.view.setWaitingOnNewCommunityOwnerToConfirmRequestToRejoin(self.controller.waitingOnNewCommunityOwnerToConfirmRequestToRejoin(communityId))

method onJoinedCommunity*(self: Module) =
self.view.setAmIMember(true)
self.view.setWaitingOnNewCommunityOwnerToConfirmRequestToRejoin(false)

method onMarkAllMessagesRead*(self: Module, chat: ChatDto) =
self.updateBadgeNotifications(chat, hasUnreadMessages=false, unviewedMentionsCount=0)
Expand Down Expand Up @@ -1342,3 +1346,6 @@ method setChannelsPermissionsCheckOngoing*(self: Module, value: bool) =
for chatId, cModule in self.chatContentModules:
if self.view.chatsModel().getItemPermissionsRequired(chatId):
cModule.setPermissionsCheckOngoing(true)

method onWaitingOnNewCommunityOwnerToConfirmRequestToRejoin*(self: Module) =
self.view.setWaitingOnNewCommunityOwnerToConfirmRequestToRejoin(true)
17 changes: 17 additions & 0 deletions src/app/modules/main/chat_section/view.nim
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ QtObject:
chatsLoaded: bool
communityMetrics: string # NOTE: later this should be replaced with QAbstractListModel-based model
permissionsCheckOngoing: bool
isWaitingOnNewCommunityOwnerToConfirmRequestToRejoin: bool

proc delete*(self: View) =
self.model.delete
Expand Down Expand Up @@ -67,6 +68,7 @@ QtObject:
result.requiresTokenPermissionToJoin = false
result.chatsLoaded = false
result.communityMetrics = "[]"
result.isWaitingOnNewCommunityOwnerToConfirmRequestToRejoin = false

proc load*(self: View) =
self.delegate.viewDidLoad()
Expand Down Expand Up @@ -446,3 +448,18 @@ QtObject:
return
self.permissionsCheckOngoing = value
self.permissionsCheckOngoingChanged()

proc getWaitingOnNewCommunityOwnerToConfirmRequestToRejoin*(self: View): bool {.slot.} =
return self.isWaitingOnNewCommunityOwnerToConfirmRequestToRejoin

proc isWaitingOnNewCommunityOwnerToConfirmRequestToRejoinChanged*(self: View) {.signal.}

proc setWaitingOnNewCommunityOwnerToConfirmRequestToRejoin*(self: View, value: bool) =
if (value == self.isWaitingOnNewCommunityOwnerToConfirmRequestToRejoin):
return
self.isWaitingOnNewCommunityOwnerToConfirmRequestToRejoin = value
self.isWaitingOnNewCommunityOwnerToConfirmRequestToRejoinChanged()

QtProperty[bool] isWaitingOnNewCommunityOwnerToConfirmRequestToRejoin:
read = getWaitingOnNewCommunityOwnerToConfirmRequestToRejoin
notify = isWaitingOnNewCommunityOwnerToConfirmRequestToRejoinChanged
1 change: 1 addition & 0 deletions src/app/modules/main/controller.nim
Original file line number Diff line number Diff line change
Expand Up @@ -543,3 +543,4 @@ proc asyncGetRevealedAccountsForAllMembers*(self: Controller, communityId: strin

proc asyncReevaluateCommunityMembersPermissions*(self: Controller, communityId: string) =
self.communityService.asyncReevaluateCommunityMembersPermissions(communityId)

13 changes: 7 additions & 6 deletions src/app/modules/main/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1155,12 +1155,13 @@ method onRemoteDestructed*[T](self: Module[T], communityId: string, chainId: int
method onRequestReevaluateMembersPermissionsIfRequired*[T](self: Module[T], communityId: string, chainId: int, contractAddress: string) =
let communityDto = self.controller.getCommunityById(communityId)
for _, tokenPermission in communityDto.tokenPermissions.pairs:
for tokenCriteria in tokenPermission.tokenCriteria:
if tokenCriteria.contractAddresses.hasKey(chainId):
let actualAddress = tokenCriteria.contractAddresses[chainId]
if actualAddress == contractAddress:
self.controller.asyncReevaluateCommunityMembersPermissions(communityId)
return
if tokenPermission.type != TokenPermissionType.BecomeTokenOwner:
for tokenCriteria in tokenPermission.tokenCriteria:
if tokenCriteria.contractAddresses.hasKey(chainId):
let actualAddress = tokenCriteria.contractAddresses[chainId]
if actualAddress == contractAddress:
self.controller.asyncReevaluateCommunityMembersPermissions(communityId)
return

method onAcceptRequestToJoinLoading*[T](self: Module[T], communityId: string, memberKey: string) =
let item = self.view.model().getItemById(communityId)
Expand Down
2 changes: 2 additions & 0 deletions src/app_service/service/community/async_tasks.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ const asyncLoadCommunitiesDataTask: Task = proc(argEncoded: string) {.gcsafe, ni
let responseCommunities = status_go.getAllCommunities()
let responseSettings = status_go.getCommunitiesSettings()
let responseMyPendingRequestsToJoin = status_go.myPendingRequestsToJoin()
let responseMyAwaitingAddressesRequestsToJoin = status_go.myAwaitingAddressesRequestsToJoin()

arg.finish(%* {
"tags": responseTags,
"communities": responseCommunities,
"settings": responseSettings,
"myPendingRequestsToJoin": responseMyPendingRequestsToJoin,
"myAwaitingAddressesRequestsToJoin": responseMyAwaitingAddressesRequestsToJoin,
"error": "",
})
except Exception as e:
Expand Down
1 change: 1 addition & 0 deletions src/app_service/service/community/dto/community.nim
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type RequestToJoinType* {.pure.}= enum
Canceled = 4,
AcceptedPending = 5,
DeclinedPending = 6,
AwaitingAddress = 7,

type MutedType* {.pure.}= enum
For15min = 1,
Expand Down
38 changes: 31 additions & 7 deletions src/app_service/service/community/service.nim
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ const SIGNAL_COMMUNITY_MEMBERS_CHANGED* = "communityMembersChanged"
const SIGNAL_COMMUNITY_KICKED* = "communityKicked"
const SIGNAL_NEW_REQUEST_TO_JOIN_COMMUNITY* = "newRequestToJoinCommunity"
const SIGNAL_REQUEST_TO_JOIN_COMMUNITY_CANCELED* = "requestToJoinCommunityCanceled"
const SIGNAL_WAITING_ON_NEW_COMMUNITY_OWNER_TO_CONFIRM_REQUEST_TO_REJOIN* = "waitingOnNewCommunityOwnerToConfirmRequestToRejoin"
const SIGNAL_CURATED_COMMUNITY_FOUND* = "curatedCommunityFound"
const SIGNAL_CURATED_COMMUNITIES_UPDATED* = "curatedCommunitiesUpdated"
const SIGNAL_COMMUNITY_MUTED* = "communityMuted"
Expand Down Expand Up @@ -232,6 +233,7 @@ QtObject:
historyArchiveDownloadTaskCommunityIds*: HashSet[string]
requestedCommunityIds*: HashSet[string]
communityMetrics: Table[string, CommunityMetricsDto]
myAwaitingAddressesRequestsToJoin: Table[string, CommunityMembershipRequestDto]

# Forward declaration
proc asyncLoadCuratedCommunities*(self: Service)
Expand Down Expand Up @@ -328,6 +330,8 @@ QtObject:
try:
self.updateMembershipRequestToNewState(membershipRequest.communityId, membershipRequest.id, community,
requestToJoinState)
if requestToJoinState == RequestToJoinType.AwaitingAddress:
self.events.emit(SIGNAL_WAITING_ON_NEW_COMMUNITY_OWNER_TO_CONFIRM_REQUEST_TO_REJOIN, CommunityIdArgs(communityId: membershipRequest.communityId))
except Exception as e:
error "Unknown request", msg = e.msg

Expand Down Expand Up @@ -431,6 +435,7 @@ QtObject:
proc saveUpdatedCommunity(self: Service, community: var CommunityDto) =
# Community data we get from the signals and responses don't contgain the pending requests
# therefore, we must keep the old one

community.pendingRequestsToJoin = self.communities[community.id].pendingRequestsToJoin
community.declinedRequestsToJoin = self.communities[community.id].declinedRequestsToJoin
community.canceledRequestsToJoin = self.communities[community.id].canceledRequestsToJoin
Expand Down Expand Up @@ -660,6 +665,9 @@ QtObject:

# If the community was not joined before but is now, we signal it
if(not wasJoined and community.joined and community.isMember):
if community.id in self.myAwaitingAddressesRequestsToJoin:
self.myAwaitingAddressesRequestsToJoin.del(community.id)

self.events.emit(SIGNAL_COMMUNITY_JOINED, CommunityArgs(community: community, fromUserAction: false))

self.events.emit(SIGNAL_COMMUNITIES_UPDATE, CommunitiesArgs(communities: @[community]))
Expand Down Expand Up @@ -712,11 +720,19 @@ QtObject:

# My pending requests
let myPendingRequestResponse = responseObj["myPendingRequestsToJoin"]

if myPendingRequestResponse{"result"}.kind != JNull:
for jsonCommunityReqest in myPendingRequestResponse["result"]:
let communityRequest = jsonCommunityReqest.toCommunityMembershipRequestDto()
self.myCommunityRequests.add(communityRequest)

let myAwaitingRequestResponse = responseObj["myAwaitingAddressesRequestsToJoin"]

if myAwaitingRequestResponse{"result"}.kind != JNull:
for jsonCommunityReqest in myAwaitingRequestResponse["result"]:
let communityRequest = jsonCommunityReqest.toCommunityMembershipRequestDto()
self.myAwaitingAddressesRequestsToJoin[communityRequest.communityId] = communityRequest

self.events.emit(SIGNAL_COMMUNITY_DATA_LOADED, Args())
except Exception as e:
let errDesription = e.msg
Expand Down Expand Up @@ -1641,7 +1657,7 @@ QtObject:
error "error loading curated communities: ", errMsg
self.events.emit(SIGNAL_CURATED_COMMUNITIES_LOADING_FAILED, Args())

proc getCommunityMetrics*(self: Service, communityId: string, metricsType: CommunityMetricsType): CommunityMetricsDto =
proc getCommunityMetrics*(self: Service, communityId: string, metricsType: CommunityMetricsType): CommunityMetricsDto =
# NOTE: use metricsType when other metrics types added
if self.communityMetrics.hasKey(communityId):
return self.communityMetrics[communityId]
Expand Down Expand Up @@ -1807,12 +1823,17 @@ QtObject:
var community = self.communities[communityId]

if (indexPending != -1):
if @[RequestToJoinType.Declined, RequestToJoinType.Accepted, RequestToJoinType.Canceled].any(x => x == newState):
if @[RequestToJoinType.Declined, RequestToJoinType.Accepted, RequestToJoinType.Canceled, RequestToJoinType.AwaitingAddress].any(x => x == newState):
# If the state is now declined, add to the declined requests
if newState == RequestToJoinType.Declined:
community.declinedRequestsToJoin.add(community.pendingRequestsToJoin[indexPending])

# If the state is no longer pending, delete the request
community.pendingRequestsToJoin.delete(indexPending)
# Delete if control node changed status for awaiting addresses request to join
if communityId in self.myAwaitingAddressesRequestsToJoin:
self.myAwaitingAddressesRequestsToJoin.del(communityId)

else:
community.pendingRequestsToJoin[indexPending].state = newState.int
else:
Expand Down Expand Up @@ -1979,10 +2000,13 @@ QtObject:

proc isCommunityRequestPending*(self: Service, communityId: string): bool {.slot.} =
for communityRequest in self.myCommunityRequests:
if (communityRequest.communityId == communityId):
if (communityRequest.communityId == communityId and RequestToJoinType(communityRequest.state) == RequestToJoinType.Pending):
return true
return false

proc waitingOnNewCommunityOwnerToConfirmRequestToRejoin*(self: Service, communityId: string): bool {.slot.} =
return communityId in self.myAwaitingAddressesRequestsToJoin

proc requestExtractDiscordChannelsAndCategories*(self: Service, filesToImport: seq[string]) =
try:
discard status_go.requestExtractDiscordChannelsAndCategories(filesToImport)
Expand Down Expand Up @@ -2120,7 +2144,7 @@ QtObject:
memberPubkey: memberPubkey,
)
self.threadpool.start(arg)

proc onAsyncGetRevealedAccountsForMemberCompleted*(self: Service, response: string) {.slot.} =
try:
let rpcResponseObj = response.parseJson
Expand Down Expand Up @@ -2150,7 +2174,7 @@ QtObject:
communityId: communityId,
)
self.threadpool.start(arg)

proc onAsyncGetRevealedAccountsForAllMembersCompleted*(self: Service, response: string) {.slot.} =
try:
let rpcResponseObj = response.parseJson
Expand Down Expand Up @@ -2179,13 +2203,13 @@ QtObject:
communityId: communityId,
)
self.threadpool.start(arg)

proc onAsyncReevaluateCommunityMembersPermissionsCompleted*(self: Service, response: string) {.slot.} =
try:
let rpcResponseObj = response.parseJson

if rpcResponseObj{"error"}.kind != JNull and rpcResponseObj{"error"}.getStr != "":
raise newException(RpcException, rpcResponseObj["error"].getStr)

except Exception as e:
error "error while reevaluating community members permissions", msg = e.msg
18 changes: 12 additions & 6 deletions src/backend/communities.nim
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export response_type

proc getCommunityTags*(): RpcResponse[JsonNode] {.raises: [Exception].} =
result = callPrivateRPC("communityTags".prefix)

proc muteCategory*(communityId: string, categoryId: string, interval: int): RpcResponse[JsonNode] {.raises: [Exception].} =
result = callPrivateRPC("muteCommunityCategory".prefix, %* [
{
Expand Down Expand Up @@ -82,7 +82,7 @@ proc reevaluateCommunityMembersPermissions*(
result = callPrivateRPC("reevaluateCommunityMembersPermissions".prefix, %*[{
"communityId": communityId
}])

proc checkCommunityChannelPermissions*(communityId: string, chatId: string): RpcResponse[JsonNode] {.raises: [Exception].} =
result = callPrivateRPC("checkCommunityChannelPermissions".prefix, %*[{
"communityId": communityId,
Expand All @@ -98,6 +98,9 @@ proc checkAllCommunityChannelsPermissions*(communityId: string, addresses: seq[s
proc myPendingRequestsToJoin*(): RpcResponse[JsonNode] {.raises: [Exception].} =
result = callPrivateRPC("myPendingRequestsToJoin".prefix)

proc myAwaitingAddressesRequestsToJoin*(): RpcResponse[JsonNode] {.raises: [Exception].} =
result = callPrivateRPC("myAwaitingAddressesRequestsToJoin".prefix)

proc myCanceledRequestsToJoin*(): RpcResponse[JsonNode] {.raises: [Exception].} =
result = callPrivateRPC("myCanceledRequestsToJoin".prefix)

Expand Down Expand Up @@ -255,7 +258,7 @@ proc deleteCommunityTokenPermission*(communityId: string, permissionId: string):
"communityId": communityId,
"permissionId": permissionId
}])

proc requestCancelDiscordCommunityImport*(communityId: string): RpcResponse[JsonNode] {.raises: [Exception].} =
result = callPrivateRPC("requestCancelDiscordCommunityImport".prefix, %*[communityId])

Expand Down Expand Up @@ -423,9 +426,9 @@ proc unbanUserFromCommunity*(communityId: string, pubKey: string): RpcResponse[J
}])

proc setCommunityMuted*(communityId: string, mutedType: int): RpcResponse[JsonNode] {.raises: [Exception].} =
return callPrivateRPC("setCommunityMuted".prefix, %*[{
"communityId": communityId,
"mutedType": mutedType
return callPrivateRPC("setCommunityMuted".prefix, %*[{
"communityId": communityId,
"mutedType": mutedType
}])

proc shareCommunityToUsers*(communityId: string, pubKeys: seq[string], inviteMessage: string): RpcResponse[JsonNode] {.raises: [Exception].} =
Expand Down Expand Up @@ -467,3 +470,6 @@ proc getCommunityPublicKeyFromPrivateKey*(communityPrivateKey: string,): RpcResp

proc getCommunityMembersForWalletAddresses*(communityId: string, chainId: int): RpcResponse[JsonNode] {.raises: [Exception].} =
return callPrivateRPC("getCommunityMembersForWalletAddresses".prefix, %* [communityId, chainId])

proc promoteSelfToControlNode*(communityId: string): RpcResponse[JsonNode] {.raises: [Exception].} =
return callPrivateRPC("promoteSelfToControlNode".prefix, %* [communityId])
31 changes: 30 additions & 1 deletion ui/app/AppLayouts/Chat/ChatLayout.qml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,17 @@ StackLayout {
Loader {
id: mainViewLoader
readonly property var chatItem: root.rootStore.chatCommunitySectionModule
sourceComponent: chatItem.isCommunity() && chatItem.requiresTokenPermissionToJoin && !chatItem.amIMember ? joinCommunityViewComponent : chatViewComponent

sourceComponent: {
if (chatItem.isCommunity() && !chatItem.amIMember) {
if (chatItem.isWaitingOnNewCommunityOwnerToConfirmRequestToRejoin) {
return controlNodeOfflineComponent
} else if (chatItem.requiresTokenPermissionToJoin) {
return joinCommunityViewComponent
}
}
return chatViewComponent
}
}

Component {
Expand Down Expand Up @@ -324,6 +334,25 @@ StackLayout {
}
}
}

Component {
id: controlNodeOfflineComponent
ControlNodeOfflineCommunityView {
id: controlNodeOfflineView
readonly property var communityData: sectionItemModel
readonly property string communityId: communityData.id
name: communityData.name
communityDesc: communityData.description
color: communityData.color
image: communityData.image
membersCount: communityData.members.count
communityItemsModel: root.rootStore.communityItemsModel
notificationCount: activityCenterStore.unreadNotificationsCount
hasUnseenNotifications: activityCenterStore.hasUnseenNotifications
onNotificationButtonClicked: Global.openActivityCenterPopup()
onAdHocChatButtonClicked: rootStore.openCloseCreateChatView()
}
}
// End of components related to transfer community ownership flow.

Connections {
Expand Down
Loading