Skip to content

Commit

Permalink
feat(communities): Process declined requests
Browse files Browse the repository at this point in the history
Part of: #7072
  • Loading branch information
borismelnik committed Oct 27, 2022
1 parent b5e317d commit 3764681
Show file tree
Hide file tree
Showing 18 changed files with 128 additions and 15 deletions.
5 changes: 5 additions & 0 deletions src/app/core/signals/remote_signals/messages.nim
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type MessageSignal* = ref object of Signal
communities*: seq[CommunityDto]
communitiesSettings*: seq[CommunitySettingsDto]
membershipRequests*: seq[CommunityMembershipRequestDto]
declinedMembershipRequests*: seq[CommunityMembershipRequestDto]
activityCenterNotifications*: seq[ActivityCenterNotificationDto]
statusUpdates*: seq[StatusUpdateDto]
deletedMessages*: seq[RemovedMessageDto]
Expand Down Expand Up @@ -99,6 +100,10 @@ proc fromEvent*(T: type MessageSignal, event: JsonNode): MessageSignal =
if event["event"]{"requestsToJoinCommunity"} != nil:
for jsonCommunity in event["event"]["requestsToJoinCommunity"]:
signal.membershipRequests.add(jsonCommunity.toCommunityMembershipRequestDto())

if event["event"]{"declinedRequestsToJoinCommunity"} != nil:
for jsonCommunity in event["event"]["declinedRequestsToJoinCommunity"]:
signal.declinedMembershipRequests.add(jsonCommunity.toCommunityMembershipRequestDto())

if event["event"]{"removedMessages"} != nil:
for jsonRemovedMessage in event["event"]["removedMessages"]:
Expand Down
1 change: 0 additions & 1 deletion src/app/core/signals/signals_manager.nim
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ QtObject:
return

trace "Raw signal data", data = $jsonSignal

var signal:Signal
try:
signal = self.decode(jsonSignal)
Expand Down
7 changes: 7 additions & 0 deletions src/app/modules/main/communities/controller.nim
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ proc init*(self: Controller) =
self.delegate.communityEdited(community)
self.delegate.curatedCommunityEdited(CuratedCommunity(communityId: community.id, available: true, community:community))

self.events.on(SIGNAL_COMMUNITY_MY_REQUEST_REJECTED) do(e: Args):
var args = CommunityRequestArgs(e)
self.delegate.communityMembershipRequestRejected(args.communityRequest)

self.events.on(SIGNAL_COMMUNITY_MUTED) do(e:Args):
let args = CommunityMutedArgs(e)
self.delegate.communityMuted(args.communityId, args.muted)
Expand Down Expand Up @@ -200,6 +204,9 @@ proc userCanJoin*(self: Controller, communityId: string): bool =
proc isCommunityRequestPending*(self: Controller, communityId: string): bool =
return self.communityService.isCommunityRequestPending(communityId)

proc isCommunityRequestDeclined*(self: Controller, communityId: string): bool =
return self.communityService.isCommunityRequestDeclined(communityId)

proc getStatusForContactWithId*(self: Controller, publicKey: string): StatusUpdateDto =
return self.contactsService.getStatusForContactWithId(publicKey)

Expand Down
6 changes: 6 additions & 0 deletions src/app/modules/main/communities/io_interface.nim
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ method userCanJoin*(self: AccessInterface, communityId: string): bool {.base.} =
method isCommunityRequestPending*(self: AccessInterface, communityId: string): bool {.base.} =
raise newException(ValueError, "No implementation available")

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

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

method requestToJoinCommunity*(self: AccessInterface, communityId: string, ensName: string) {.base.} =
raise newException(ValueError, "No implementation available")

Expand Down
6 changes: 6 additions & 0 deletions src/app/modules/main/communities/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,12 @@ method userCanJoin*(self: Module, communityId: string): bool =
method isCommunityRequestPending*(self: Module, communityId: string): bool =
self.controller.isCommunityRequestPending(communityId)

method isCommunityRequestDeclined*(self: Module, communityId: string): bool =
self.controller.isCommunityRequestDeclined(communityId)

method communityMembershipRequestRejected*(self: Module, membershipRequest: CommunityMembershipRequestDto) =
self.view.communityMembershipRequestRejected(membershipRequest.communityId)

method deleteCommunityChat*(self: Module, communityId: string, channelId: string) =
self.controller.deleteCommunityChat(communityId, channelId)

Expand Down
5 changes: 5 additions & 0 deletions src/app/modules/main/communities/view.nim
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ QtObject:

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

proc communityMembershipRequestRejected*(self: View, communityId: string) {.signal.}

proc setDiscordImportWarningsCount*(self: View, count: int) {.slot.} =
if (self.discordImportWarningsCount == count): return
self.discordImportWarningsCount = count
Expand Down Expand Up @@ -413,6 +415,9 @@ QtObject:
proc isCommunityRequestPending*(self: View, communityId: string): bool {.slot.} =
self.delegate.isCommunityRequestPending(communityId)

proc isCommunityRequestDeclined*(self: View, communityId: string): bool {.slot.} =
self.delegate.isCommunityRequestDeclined(communityId)

proc deleteCommunityChat*(self: View, communityId: string, channelId: string) {.slot.} =
self.delegate.deleteCommunityChat(communityId, channelId)

Expand Down
4 changes: 4 additions & 0 deletions src/app/modules/main/controller.nim
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ proc init*(self: Controller) =
var args = NotificationArgs(e)
self.delegate.displayEphemeralNotification(args.title, args.message, args.details)

self.events.on(SIGNAL_COMMUNITY_MY_REQUEST_REJECTED) do(e: Args):
var args = CommunityRequestArgs(e)
self.delegate.onCommunityMyRequestRejected(args.communityRequest)

self.events.on(SIGNAL_NEW_REQUEST_TO_JOIN_COMMUNITY) do(e: Args):
var args = CommunityRequestArgs(e)
self.delegate.newCommunityMembershipRequestReceived(args.communityRequest)
Expand Down
1 change: 1 addition & 0 deletions src/app/modules/main/ephemeral_notification_item.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ type
EphemeralNotificationType* {.pure.} = enum
Default = 0
Success
Fail

type
Item* = object
Expand Down
3 changes: 3 additions & 0 deletions src/app/modules/main/io_interface.nim
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ method newCommunityMembershipRequestReceived*(self: AccessInterface, membershipR
{.base.} =
raise newException(ValueError, "No implementation available")

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

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

Expand Down
6 changes: 6 additions & 0 deletions src/app/modules/main/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,8 @@ method displayEphemeralNotification*[T](self: Module[T], title: string, subTitle
var finalEphNotifType = EphemeralNotificationType.Default
if(ephNotifType == EphemeralNotificationType.Success.int):
finalEphNotifType = EphemeralNotificationType.Success
if(ephNotifType == EphemeralNotificationType.Fail.int):
finalEphNotifType = EphemeralNotificationType.Fail
let item = ephemeral_notification_item.initItem(id, title, TOAST_MESSAGE_VISIBILITY_DURATION_IN_MS, subTitle, icon,
loading, finalEphNotifType, url, details)
self.view.ephemeralNotificationModel().addItem(item)
Expand Down Expand Up @@ -978,3 +980,7 @@ method onDisplayKeycardSharedModuleFlow*[T](self: Module[T]) =
method activateStatusDeepLink*[T](self: Module[T], statusDeepLink: string) =
let linkToActivate = self.urlsManager.convertExternalLinkToInternal(statusDeepLink)
self.urlsManager.onUrlActivated(linkToActivate)

method onCommunityMyRequestRejected*[T](self: Module[T], membershipRequest: CommunityMembershipRequestDto) =
let communityDetails = self.controller.getCommunityById(membershipRequest.communityId)
self.displayEphemeralNotification(fmt "{communityDetails.name} membership rejected ", "", conf.COMMUNITIESPORTAL_SECTION_ICON, false, EphemeralNotificationType.Fail.int, "")
6 changes: 3 additions & 3 deletions src/app_service/service/community/dto/community.nim
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ include ../../../common/json_utils
import ../../chat/dto/chat

type RequestToJoinType* {.pure.}= enum
Pending = 0,
Declined = 1,
Accepted = 2
Pending = 1,
Declined = 2,
Accepted = 3

type Member* = object
id*: string
Expand Down
34 changes: 32 additions & 2 deletions src/app_service/service/community/service.nim
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ type
const SIGNAL_COMMUNITY_JOINED* = "communityJoined"
const SIGNAL_COMMUNITY_SPECTATED* = "communitySpectated"
const SIGNAL_COMMUNITY_MY_REQUEST_ADDED* = "communityMyRequestAdded"
const SIGNAL_COMMUNITY_MY_REQUEST_REJECTED* = "communityMyRequestRejected"
const SIGNAL_COMMUNITY_LEFT* = "communityLeft"
const SIGNAL_COMMUNITY_CREATED* = "communityCreated"
const SIGNAL_COMMUNITY_ADDED* = "communityAdded"
Expand Down Expand Up @@ -139,10 +140,12 @@ QtObject:
proc loadCuratedCommunities(self: Service): seq[CuratedCommunity]
proc loadCommunitiesSettings(self: Service): seq[CommunitySettingsDto]
proc loadMyPendingRequestsToJoin*(self: Service)
proc loadMyDeclinedRequestsToJoin*(self: Service)
proc handleCommunityUpdates(self: Service, communities: seq[CommunityDto], updatedChats: seq[ChatDto])
proc handleCommunitiesSettingsUpdates(self: Service, communitiesSettings: seq[CommunitySettingsDto])
proc pendingRequestsToJoinForCommunity*(self: Service, communityId: string): seq[CommunityMembershipRequestDto]
proc declinedRequestsToJoinForCommunity*(self: Service, communityId: string): seq[CommunityMembershipRequestDto]
proc getPendingRequestIndex(self: Service, communityId: string, requestId: string): int

proc delete*(self: Service) =
discard
Expand Down Expand Up @@ -197,8 +200,16 @@ QtObject:
community.pendingRequestsToJoin.add(membershipRequest)
self.joinedCommunities[membershipRequest.communityId] = community
self.events.emit(SIGNAL_COMMUNITY_EDITED, CommunityArgs(community: community))

self.events.emit(SIGNAL_NEW_REQUEST_TO_JOIN_COMMUNITY, CommunityRequestArgs(communityRequest: membershipRequest))

if(receivedData.declinedMembershipRequests.len > 0):
for membershipRequest in receivedData.declinedMembershipRequests:
# remove my pending requests
keepIf(self.myCommunityRequests, request => request.communityId != membershipRequest.communityId)
self.myCommunityRequests.add(membershipRequest)
self.events.emit(SIGNAL_COMMUNITY_MY_REQUEST_REJECTED, CommunityRequestArgs(communityRequest: membershipRequest))
singletonInstance.globalEvents.myRequestToJoinCommunityRejected("Community Request Rejected",
fmt "Your request to join community is rejected", membershipRequest.communityId)

self.events.on(SignalType.DiscordCategoriesAndChannelsExtracted.event) do(e: Args):
var receivedData = DiscordCategoriesAndChannelsExtractedSignal(e)
Expand Down Expand Up @@ -418,6 +429,7 @@ QtObject:
self.joinedCommunities[settings.id].settings = settings

self.loadMyPendingRequestsToJoin()
self.loadMyDeclinedRequestsToJoin()

proc loadCommunityTags(self: Service): string =
let response = status_go.getCommunityTags()
Expand Down Expand Up @@ -639,6 +651,18 @@ QtObject:
except Exception as e:
error "Error fetching my community requests", msg = e.msg

proc loadMyDeclinedRequestsToJoin*(self: Service) =
try:
let response = status_go.myDeclinedRequestsToJoin()

if response.result.kind != JNull:
for jsonCommunityReqest in response.result:
let communityRequest = jsonCommunityReqest.toCommunityMembershipRequestDto()
self.myCommunityRequests.add(communityRequest)
self.events.emit(SIGNAL_COMMUNITY_MY_REQUEST_ADDED, CommunityRequestArgs(communityRequest: communityRequest))
except Exception as e:
error "Error fetching my declined community requests", msg = e.msg

proc pendingRequestsToJoinForCommunity*(self: Service, communityId: string): seq[CommunityMembershipRequestDto] =
try:
let response = status_go.pendingRequestsToJoinForCommunity(communityId)
Expand Down Expand Up @@ -1304,7 +1328,13 @@ QtObject:
proc isCommunityRequestPending*(self: Service, communityId: string): bool {.slot.} =
for communityRequest in self.myCommunityRequests:
if (communityRequest.communityId == communityId):
return true
return communityRequest.state == RequestToJoinType.Pending.int
return false

proc isCommunityRequestDeclined*(self: Service, communityId: string): bool {.slot.} =
for communityRequest in self.myCommunityRequests:
if (communityRequest.communityId == communityId):
return communityRequest.state == RequestToJoinType.Declined.int
return false

proc requestExtractDiscordChannelsAndCategories*(self: Service, filesToImport: seq[string]) =
Expand Down
3 changes: 3 additions & 0 deletions src/backend/communities.nim
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ proc requestToJoinCommunity*(communityId: string, ensName: string): RpcResponse[
proc myPendingRequestsToJoin*(): RpcResponse[JsonNode] {.raises: [Exception].} =
result = callPrivateRPC("myPendingRequestsToJoin".prefix)

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

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

Expand Down
39 changes: 32 additions & 7 deletions ui/StatusQ/src/StatusQ/Components/StatusToastMessage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ Control {
property int type: StatusToastMessage.Type.Default
enum Type {
Default,
Success
Success,
Fail
}

/*!
Expand Down Expand Up @@ -231,8 +232,16 @@ Control {
implicitHeight: 32
Layout.alignment: Qt.AlignVCenter
radius: (root.width/2)
color: (root.type === StatusToastMessage.Type.Success) ?
Theme.palette.successColor2 : Theme.palette.primaryColor3
color: {
switch (root.type) {
case StatusToastMessage.Type.Success:
return Theme.palette.successColor2
case StatusToastMessage.Type.Fail:
return Theme.palette.dangerColor2
default:
return Theme.palette.primaryColor3
}
}
visible: loader.sourceComponent != undefined
Loader {
id: loader
Expand All @@ -244,8 +253,16 @@ Control {
Component {
id: loadingInd
StatusLoadingIndicator {
color: (root.type === StatusToastMessage.Type.Success) ?
Theme.palette.successColor1 : Theme.palette.primaryColor1
color: {
switch (root.type) {
case StatusToastMessage.Type.Success:
return Theme.palette.successColor1
case StatusToastMessage.Type.Fail:
return Theme.palette.dangerColor1
default:
return Theme.palette.primaryColor1
}
}
}
}
Component {
Expand All @@ -254,8 +271,16 @@ Control {
anchors.centerIn: parent
width: root.icon.width
height: root.icon.height
color: (root.type === StatusToastMessage.Type.Success) ?
Theme.palette.successColor1 : Theme.palette.primaryColor1
color: {
switch (root.type) {
case StatusToastMessage.Type.Success:
return Theme.palette.successColor1
case StatusToastMessage.Type.Fail:
return Theme.palette.dangerColor1
default:
return Theme.palette.primaryColor1
}
}
icon: root.icon.name
}
}
Expand Down
4 changes: 4 additions & 0 deletions ui/app/AppLayouts/Chat/stores/RootStore.qml
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,10 @@ QtObject {
return communitiesModuleInst.isCommunityRequestPending(id)
}

function isCommunityRequestDeclined(id) {
return communitiesModuleInst.isCommunityRequestDeclined(id)
}

function getSectionNameById(id) {
return communitiesList.getSectionNameById(id)
}
Expand Down
10 changes: 9 additions & 1 deletion ui/app/AppLayouts/Chat/views/CommunityColumnView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,19 @@ Item {
id: joinCommunityButton

property bool invitationPending: root.store.isCommunityRequestPending(communityData.id)
property bool invitationDeclined: root.store.isCommunityRequestDeclined(communityData.id)

anchors.top: communityHeader.bottom
anchors.topMargin: 8
anchors.bottomMargin: Style.current.halfPadding
anchors.horizontalCenter: parent.horizontalCenter

visible: !communityData.joined
enabled: !invitationPending
enabled: !invitationPending && !invitationDeclined

text: {
if (invitationPending) return qsTr("Pending")
if (invitationDeclined) return qsTr("Membership Request Rejected")
return root.communityData.access === Constants.communityChatOnRequestAccess ?
qsTr("Request to join") : qsTr("Join Community")
}
Expand All @@ -124,6 +126,12 @@ Item {
joinCommunityButton.invitationPending = root.store.isCommunityRequestPending(communityData.id)
}
}
onCommunityMembershipRequestRejected: function (communityId) {
if (communityId === communityData.id) {
joinCommunityButton.invitationPending = root.store.isCommunityRequestPending(communityData.id)
joinCommunityButton.invitationDeclined = root.store.isCommunityRequestDeclined(communityData.id)
}
}
}

CommunityIntroDialog {
Expand Down
1 change: 1 addition & 0 deletions ui/imports/utils/Constants.qml
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ QtObject {
readonly property QtObject ephemeralNotificationType: QtObject {
readonly property int normal: 0
readonly property int success: 1
readonly property int fail: 2
}

readonly property QtObject transactionEstimatedTime: QtObject {
Expand Down
2 changes: 1 addition & 1 deletion vendor/status-go
Submodule status-go updated 935 files

0 comments on commit 3764681

Please sign in to comment.