parent
95f829665b
commit
8332a685c4
|
@ -14,7 +14,9 @@ type RequestToJoinType* {.pure.}= enum
|
|||
Pending = 1,
|
||||
Declined = 2,
|
||||
Accepted = 3,
|
||||
Canceled = 4
|
||||
Canceled = 4,
|
||||
AcceptedPending = 5,
|
||||
DeclinedPending = 6,
|
||||
|
||||
type MutedType* {.pure.}= enum
|
||||
For15min = 1,
|
||||
|
|
|
@ -226,10 +226,12 @@ QtObject:
|
|||
proc handleCommunityUpdates(self: Service, communities: seq[CommunityDto], updatedChats: seq[ChatDto], removedChats: seq[string])
|
||||
proc handleCommunitiesSettingsUpdates(self: Service, communitiesSettings: seq[CommunitySettingsDto])
|
||||
proc pendingRequestsToJoinForCommunity*(self: Service, communityId: string): seq[CommunityMembershipRequestDto]
|
||||
proc allPendingRequestsToJoinForCommunity*(self: Service, communityId: string): seq[CommunityMembershipRequestDto]
|
||||
proc declinedRequestsToJoinForCommunity*(self: Service, communityId: string): seq[CommunityMembershipRequestDto]
|
||||
proc canceledRequestsToJoinForCommunity*(self: Service, communityId: string): seq[CommunityMembershipRequestDto]
|
||||
proc getPendingRequestIndex(self: Service, communityId: string, requestId: string): int
|
||||
proc removeMembershipRequestFromCommunityAndGetMemberPubkey*(self: Service, communityId: string, requestId: string, updatedCommunity: CommunityDto): string
|
||||
proc updateMembershipRequestToNewState*(self: Service, communityId: string, requestId: string,
|
||||
updatedCommunity: CommunityDto, newState: RequestToJoinType)
|
||||
proc getUserPubKeyFromPendingRequest*(self: Service, communityId: string, requestId: string): string
|
||||
|
||||
proc delete*(self: Service) =
|
||||
|
@ -297,24 +299,21 @@ QtObject:
|
|||
continue
|
||||
var community = self.communities[membershipRequest.communityId]
|
||||
|
||||
case RequestToJoinType(membershipRequest.state):
|
||||
of RequestToJoinType.Pending:
|
||||
let requestToJoinState = RequestToJoinType(membershipRequest.state)
|
||||
|
||||
if self.getPendingRequestIndex(membershipRequest.communityId, membershipRequest.id) == -1:
|
||||
community.pendingRequestsToJoin.add(membershipRequest)
|
||||
self.communities[membershipRequest.communityId] = community
|
||||
self.events.emit(SIGNAL_COMMUNITY_EDITED, CommunityArgs(community: community))
|
||||
self.events.emit(SIGNAL_NEW_REQUEST_TO_JOIN_COMMUNITY, CommunityRequestArgs(communityRequest: membershipRequest))
|
||||
self.events.emit(SIGNAL_NEW_REQUEST_TO_JOIN_COMMUNITY,
|
||||
CommunityRequestArgs(communityRequest: membershipRequest))
|
||||
else:
|
||||
try:
|
||||
self.updateMembershipRequestToNewState(membershipRequest.communityId, membershipRequest.id, community,
|
||||
requestToJoinState)
|
||||
except Exception as e:
|
||||
error "Unknown request", msg = e.msg
|
||||
|
||||
of RequestToJoinType.Canceled:
|
||||
let indexPending = self.getPendingRequestIndex(membershipRequest.communityId, membershipRequest.id)
|
||||
if (indexPending != -1):
|
||||
community.pendingRequestsToJoin.delete(indexPending)
|
||||
self.communities[membershipRequest.communityId] = community
|
||||
self.events.emit(SIGNAL_COMMUNITY_EDITED, CommunityArgs(community: community))
|
||||
|
||||
of RequestToJoinType.Declined:
|
||||
break
|
||||
of RequestToJoinType.Accepted:
|
||||
break
|
||||
self.events.emit(SIGNAL_COMMUNITY_EDITED, CommunityArgs(community: self.communities[membershipRequest.communityId]))
|
||||
|
||||
self.events.on(SignalType.DiscordCategoriesAndChannelsExtracted.event) do(e: Args):
|
||||
var receivedData = DiscordCategoriesAndChannelsExtractedSignal(e)
|
||||
|
@ -679,7 +678,7 @@ QtObject:
|
|||
for community in communities:
|
||||
self.communities[community.id] = community
|
||||
if community.memberRole == MemberRole.Owner or community.memberRole == MemberRole.Admin:
|
||||
self.communities[community.id].pendingRequestsToJoin = self.pendingRequestsToJoinForCommunity(community.id)
|
||||
self.communities[community.id].pendingRequestsToJoin = self.allPendingRequestsToJoinForCommunity(community.id)
|
||||
self.communities[community.id].declinedRequestsToJoin = self.declinedRequestsToJoinForCommunity(community.id)
|
||||
self.communities[community.id].canceledRequestsToJoin = self.canceledRequestsToJoinForCommunity(community.id)
|
||||
|
||||
|
@ -909,6 +908,17 @@ QtObject:
|
|||
except Exception as e:
|
||||
error "Error fetching community requests", msg = e.msg
|
||||
|
||||
proc allPendingRequestsToJoinForCommunity*(self: Service, communityId: string): seq[CommunityMembershipRequestDto] =
|
||||
try:
|
||||
let response = status_go.allPendingRequestsToJoinForCommunity(communityId)
|
||||
|
||||
result = @[]
|
||||
if response.result.kind != JNull:
|
||||
for jsonCommunityReqest in response.result:
|
||||
result.add(jsonCommunityReqest.toCommunityMembershipRequestDto())
|
||||
except Exception as e:
|
||||
error "Error fetching community requests", msg = e.msg
|
||||
|
||||
proc declinedRequestsToJoinForCommunity*(self: Service, communityId: string): seq[CommunityMembershipRequestDto] =
|
||||
try:
|
||||
let response = status_go.declinedRequestsToJoinForCommunity(communityId)
|
||||
|
@ -1546,28 +1556,37 @@ QtObject:
|
|||
let errorMessage = rpcResponseObj{"error"}.getStr
|
||||
|
||||
if errorMessage.contains("has no permission to join"):
|
||||
self.events.emit(SIGNAL_ACCEPT_REQUEST_TO_JOIN_FAILED_NO_PERMISSION, CommunityMemberArgs(communityId: communityId, pubKey: userKey, requestId: requestId))
|
||||
self.events.emit(SIGNAL_ACCEPT_REQUEST_TO_JOIN_FAILED_NO_PERMISSION,
|
||||
CommunityMemberArgs(communityId: communityId, pubKey: userKey, requestId: requestId))
|
||||
else:
|
||||
self.events.emit(SIGNAL_ACCEPT_REQUEST_TO_JOIN_FAILED, CommunityMemberArgs(communityId: communityId, pubKey: userKey, requestId: requestId))
|
||||
self.events.emit(SIGNAL_ACCEPT_REQUEST_TO_JOIN_FAILED,
|
||||
CommunityMemberArgs(communityId: communityId, pubKey: userKey, requestId: requestId))
|
||||
return
|
||||
|
||||
discard self.removeMembershipRequestFromCommunityAndGetMemberPubkey(communityId, requestId,
|
||||
rpcResponseObj["response"]["result"]["communities"][0].toCommunityDto)
|
||||
let updatedCommunity = rpcResponseObj["response"]["result"]["communities"][0].toCommunityDto
|
||||
let requestToJoin = rpcResponseObj["response"]["result"]["requestsToJoinCommunity"][0].toCommunityMembershipRequestDto
|
||||
|
||||
self.updateMembershipRequestToNewState(communityId, requestId, updatedCommunity,
|
||||
RequestToJoinType(requestToJoin.state))
|
||||
|
||||
if (userKey == ""):
|
||||
error "Did not find pubkey in the pending request"
|
||||
return
|
||||
|
||||
self.events.emit(SIGNAL_COMMUNITY_EDITED, CommunityArgs(community: self.communities[communityId]))
|
||||
self.events.emit(SIGNAL_COMMUNITY_MEMBER_APPROVED, CommunityMemberArgs(communityId: communityId, pubKey: userKey, requestId: requestId))
|
||||
self.events.emit(SIGNAL_COMMUNITY_MEMBER_APPROVED,
|
||||
CommunityMemberArgs(communityId: communityId, pubKey: userKey, requestId: requestId))
|
||||
|
||||
if rpcResponseObj["response"]["result"]{"activityCenterNotifications"}.kind != JNull:
|
||||
self.activityCenterService.parseActivityCenterNotifications(rpcResponseObj["response"]["result"]["activityCenterNotifications"])
|
||||
self.activityCenterService.parseActivityCenterNotifications(
|
||||
rpcResponseObj["response"]["result"]["activityCenterNotifications"]
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
let errMsg = e.msg
|
||||
error "error accepting request to join: ", errMsg
|
||||
self.events.emit(SIGNAL_ACCEPT_REQUEST_TO_JOIN_FAILED, CommunityMemberArgs(communityId: communityId, pubKey: userKey, requestId: requestId))
|
||||
self.events.emit(SIGNAL_ACCEPT_REQUEST_TO_JOIN_FAILED,
|
||||
CommunityMemberArgs(communityId: communityId, pubKey: userKey, requestId: requestId))
|
||||
|
||||
proc asyncLoadCuratedCommunities*(self: Service) =
|
||||
self.events.emit(SIGNAL_CURATED_COMMUNITIES_LOADING, Args())
|
||||
|
@ -1766,8 +1785,8 @@ QtObject:
|
|||
i.inc()
|
||||
return -1
|
||||
|
||||
proc removeMembershipRequestFromCommunityAndGetMemberPubkey*(self: Service, communityId: string, requestId: string,
|
||||
updatedCommunity: CommunityDto): string =
|
||||
proc updateMembershipRequestToNewState*(self: Service, communityId: string, requestId: string,
|
||||
updatedCommunity: CommunityDto, newState: RequestToJoinType) =
|
||||
let indexPending = self.getPendingRequestIndex(communityId, requestId)
|
||||
let indexDeclined = self.getDeclinedRequestIndex(communityId, requestId)
|
||||
|
||||
|
@ -1777,28 +1796,20 @@ QtObject:
|
|||
var community = self.communities[communityId]
|
||||
|
||||
if (indexPending != -1):
|
||||
result = community.pendingRequestsToJoin[indexPending].publicKey
|
||||
if @[RequestToJoinType.Declined, RequestToJoinType.Accepted, RequestToJoinType.Canceled].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)
|
||||
elif (indexDeclined != -1):
|
||||
result = community.declinedRequestsToJoin[indexDeclined].publicKey
|
||||
else:
|
||||
community.pendingRequestsToJoin[indexPending].state = newState.int
|
||||
else:
|
||||
community.declinedRequestsToJoin.delete(indexDeclined)
|
||||
|
||||
community.members = updatedCommunity.members
|
||||
self.communities[communityId] = community
|
||||
|
||||
proc moveRequestToDeclined*(self: Service, communityId: string, requestId: string) =
|
||||
let indexPending = self.getPendingRequestIndex(communityId, requestId)
|
||||
if (indexPending == -1):
|
||||
raise newException(RpcException, fmt"Community request not found: {requestId}")
|
||||
|
||||
var community = self.communities[communityId]
|
||||
|
||||
let itemToMove = community.pendingRequestsToJoin[indexPending]
|
||||
community.declinedRequestsToJoin.add(itemToMove)
|
||||
community.pendingRequestsToJoin.delete(indexPending)
|
||||
|
||||
self.communities[communityId] = community
|
||||
|
||||
proc cancelRequestToJoinCommunity*(self: Service, communityId: string) =
|
||||
try:
|
||||
var i = 0
|
||||
|
@ -1824,7 +1835,10 @@ QtObject:
|
|||
let response = status_go.declineRequestToJoinCommunity(requestId)
|
||||
self.activityCenterService.parseActivityCenterResponse(response)
|
||||
|
||||
self.moveRequestToDeclined(communityId, requestId)
|
||||
let requestToJoin = response.result["requestsToJoinCommunity"][0].toCommunityMembershipRequestDto
|
||||
|
||||
self.updateMembershipRequestToNewState(communityId, requestId, self.communities[communityId],
|
||||
RequestToJoinType(requestToJoin.state))
|
||||
|
||||
self.events.emit(SIGNAL_COMMUNITY_EDITED, CommunityArgs(community: self.communities[communityId]))
|
||||
except Exception as e:
|
||||
|
@ -1976,11 +1990,15 @@ QtObject:
|
|||
|
||||
proc getUserPubKeyFromPendingRequest*(self: Service, communityId: string, requestId: string): string =
|
||||
let indexPending = self.getPendingRequestIndex(communityId, requestId)
|
||||
if (indexPending == -1):
|
||||
let indexDeclined = self.getDeclinedRequestIndex(communityId, requestId)
|
||||
if (indexPending == -1 and indexDeclined == -1):
|
||||
raise newException(RpcException, fmt"Community request not found: {requestId}")
|
||||
|
||||
let community = self.communities[communityId]
|
||||
if (indexPending != -1):
|
||||
return community.pendingRequestsToJoin[indexPending].publicKey
|
||||
else:
|
||||
return community.declinedRequestsToJoin[indexDeclined].publicKey
|
||||
|
||||
proc checkChatHasPermissions*(self: Service, communityId: string, chatId: string): bool =
|
||||
let community = self.getCommunityById(communityId)
|
||||
|
|
|
@ -99,6 +99,9 @@ proc myCanceledRequestsToJoin*(): RpcResponse[JsonNode] {.raises: [Exception].}
|
|||
proc pendingRequestsToJoinForCommunity*(communityId: string): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
result = callPrivateRPC("pendingRequestsToJoinForCommunity".prefix, %*[communityId])
|
||||
|
||||
proc allPendingRequestsToJoinForCommunity*(communityId: string): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
result = callPrivateRPC("allPendingRequestsToJoinForCommunity".prefix, %*[communityId])
|
||||
|
||||
proc declinedRequestsToJoinForCommunity*(communityId: string): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
result = callPrivateRPC("declinedRequestsToJoinForCommunity".prefix, %*[communityId])
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ SettingsPage {
|
|||
property var declinedMemberRequestsModel
|
||||
property string communityName
|
||||
|
||||
property int memberRole
|
||||
property bool editable: true
|
||||
|
||||
signal membershipRequestsClicked()
|
||||
|
@ -107,6 +108,7 @@ SettingsPage {
|
|||
MembersTabPanel {
|
||||
model: root.membersModel
|
||||
rootStore: root.rootStore
|
||||
memberRole: root.memberRole
|
||||
placeholderText: {
|
||||
if (root.membersModel.count === 0)
|
||||
return qsTr("No members to search")
|
||||
|
@ -134,6 +136,7 @@ SettingsPage {
|
|||
MembersTabPanel {
|
||||
model: root.pendingMemberRequestsModel
|
||||
rootStore: root.rootStore
|
||||
memberRole: root.memberRole
|
||||
placeholderText: {
|
||||
if (root.pendingMemberRequestsModel.count === 0)
|
||||
return qsTr("No pending requests to search")
|
||||
|
@ -152,6 +155,7 @@ SettingsPage {
|
|||
MembersTabPanel {
|
||||
model: root.declinedMemberRequestsModel
|
||||
rootStore: root.rootStore
|
||||
memberRole: root.memberRole
|
||||
placeholderText: {
|
||||
if (root.declinedMemberRequestsModel.count === 0)
|
||||
return qsTr("No rejected members to search")
|
||||
|
@ -169,6 +173,7 @@ SettingsPage {
|
|||
MembersTabPanel {
|
||||
model: root.bannedMembersModel
|
||||
rootStore: root.rootStore
|
||||
memberRole: root.memberRole
|
||||
placeholderText: {
|
||||
if (root.bannedMembersModel.count === 0)
|
||||
return qsTr("No banned members to search")
|
||||
|
|
|
@ -21,6 +21,10 @@ Item {
|
|||
property string placeholderText
|
||||
property var model
|
||||
property var rootStore
|
||||
property int memberRole: Constants.memberRole.none
|
||||
|
||||
readonly property bool isOwner: memberRole === Constants.memberRole.owner
|
||||
readonly property bool isTokenMaster: memberRole === Constants.memberRole.tokenMaster
|
||||
|
||||
signal kickUserClicked(string id, string name)
|
||||
signal banUserClicked(string id, string name)
|
||||
|
@ -107,7 +111,21 @@ Item {
|
|||
|
||||
readonly property bool itsMe: model.pubKey.toLowerCase() === Global.userProfile.pubKey.toLowerCase()
|
||||
readonly property bool isHovered: memberItem.sensor.containsMouse
|
||||
readonly property bool canBeBanned: !memberItem.itsMe && (model.memberRole !== Constants.memberRole.owner && model.memberRole !== Constants.memberRole.admin)
|
||||
readonly property bool canBeBanned: {
|
||||
if (memberItem.itsMe) {
|
||||
return false
|
||||
}
|
||||
switch (model.memberRole) {
|
||||
// Owner can't be banned
|
||||
case Constants.memberRole.owner: return false
|
||||
// TokenMaster can only be banned by owner
|
||||
case Constants.memberRole.tokenMaster: return root.isOwner
|
||||
// Admin can only be banned by owner and tokenMaster
|
||||
case Constants.memberRole.admin: return root.isOwner || root.isTokenMaster
|
||||
// All normal members can be banned by all privileged users
|
||||
default: return true
|
||||
}
|
||||
}
|
||||
readonly property bool showOnHover: isHovered && ctaAllowed
|
||||
|
||||
/// Button visibility ///
|
||||
|
|
|
@ -249,6 +249,7 @@ StatusSectionLayout {
|
|||
pendingMemberRequestsModel: root.community.pendingMemberRequests
|
||||
declinedMemberRequestsModel: root.community.declinedMemberRequests
|
||||
editable: root.isAdmin
|
||||
memberRole: community.memberRole
|
||||
communityName: root.community.name
|
||||
|
||||
onKickUserClicked: root.rootStore.removeUserFromCommunity(id)
|
||||
|
|
|
@ -1145,8 +1145,9 @@ QtObject {
|
|||
enum CommunityMembershipRequestState {
|
||||
None = 0,
|
||||
Pending,
|
||||
Accepted,
|
||||
Rejected,
|
||||
Accepted,
|
||||
Canceled,
|
||||
AcceptedPending,
|
||||
RejectedPending,
|
||||
Banned,
|
||||
|
|
Loading…
Reference in New Issue