feat(@desktop/community): add new CommunityMemberState - CommunityMemberBanWithAllMessagesDelete (#14028)

This commit is contained in:
Mykhailo Prakhov 2024-03-19 16:17:02 +01:00 committed by GitHub
parent 0958860bc9
commit f3d2d0a809
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 57 additions and 39 deletions

View File

@ -258,7 +258,8 @@ proc getCuratedCommunityItem(self: Module, community: CommunityDto): CuratedComm
let myPublicKey = singletonInstance.userProfile.getPubKey() let myPublicKey = singletonInstance.userProfile.getPubKey()
var amIbanned = false var amIbanned = false
if myPublicKey in community.pendingAndBannedMembers: if myPublicKey in community.pendingAndBannedMembers:
amIbanned = community.pendingAndBannedMembers[myPublicKey] == CommunityMemberPendingBanOrKick.Banned let state = community.pendingAndBannedMembers[myPublicKey]
amIbanned = isBanned(state)
return initCuratedCommunityItem( return initCuratedCommunityItem(
community.id, community.id,

View File

@ -407,7 +407,7 @@ proc init*(self: Controller) =
self.events.on(SIGNAL_COMMUNITY_MEMBER_STATUS_CHANGED) do(e: Args): self.events.on(SIGNAL_COMMUNITY_MEMBER_STATUS_CHANGED) do(e: Args):
let args = CommunityMemberStatusUpdatedArgs(e) let args = CommunityMemberStatusUpdatedArgs(e)
self.delegate.onMembershipStatusUpdated(args.communityId, args.memberPubkey, args.status) self.delegate.onMembershipStateUpdated(args.communityId, args.memberPubkey, args.state)
self.events.on(SIGNAL_COMMUNITY_MEMBERS_CHANGED) do(e: Args): self.events.on(SIGNAL_COMMUNITY_MEMBERS_CHANGED) do(e: Args):
let args = CommunityMembersArgs(e) let args = CommunityMembersArgs(e)

View File

@ -376,7 +376,7 @@ method onAcceptRequestToJoinLoading*(self: AccessInterface, communityId: string,
method onAcceptRequestToJoinSuccess*(self: AccessInterface, communityId: string, memberKey: string, requestId: string) {.base.} = method onAcceptRequestToJoinSuccess*(self: AccessInterface, communityId: string, memberKey: string, requestId: string) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method onMembershipStatusUpdated*(self: AccessInterface, communityId: string, memberPubkey: string, status: MembershipRequestState) {.base.} = method onMembershipStateUpdated*(self: AccessInterface, communityId: string, memberPubkey: string, state: MembershipRequestState) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method onDeactivateChatLoader*(self: AccessInterface, sectionId: string, chatId: string) {.base.} = method onDeactivateChatLoader*(self: AccessInterface, sectionId: string, chatId: string) {.base.} =

View File

@ -348,8 +348,11 @@ proc createChannelGroupItem[T](self: Module[T], channelGroup: ChannelGroupDto):
var bannedMembers = newSeq[MemberItem]() var bannedMembers = newSeq[MemberItem]()
for memberId, memberState in communityDetails.pendingAndBannedMembers.pairs: for memberId, memberState in communityDetails.pendingAndBannedMembers.pairs:
let state = memberState.toMembershipRequestState() let state = memberState.toMembershipRequestState()
if state == MembershipRequestState.Banned or state == MembershipRequestState.UnbannedPending: case state:
bannedMembers.add(self.createMemberItem(memberId, state, MemberRole.None)) of MembershipRequestState.Banned, MembershipRequestState.BannedWithAllMessagesDelete, MembershipRequestState.UnbannedPending:
bannedMembers.add(self.createMemberItem(memberId, state, MemberRole.None))
else:
discard
result = initItem( result = initItem(
channelGroup.id, channelGroup.id,
@ -1233,13 +1236,13 @@ method onAcceptRequestToJoinSuccess*[T](self: Module[T], communityId: string, me
if item.id != "": if item.id != "":
item.updatePendingRequestLoadingState(memberKey, false) item.updatePendingRequestLoadingState(memberKey, false)
method onMembershipStatusUpdated*[T](self: Module[T], communityId: string, memberPubkey: string, status: MembershipRequestState) = method onMembershipStateUpdated*[T](self: Module[T], communityId: string, memberPubkey: string, state: MembershipRequestState) =
let myPublicKey = singletonInstance.userProfile.getPubKey() let myPublicKey = singletonInstance.userProfile.getPubKey()
let communityDto = self.controller.getCommunityById(communityId) let communityDto = self.controller.getCommunityById(communityId)
if myPublicKey == memberPubkey: if myPublicKey == memberPubkey:
case status: case state:
of MembershipRequestState.Banned: of MembershipRequestState.Banned, MembershipRequestState.BannedWithAllMessagesDelete:
singletonInstance.globalEvents.showCommunityMemberBannedNotification(fmt "You've been banned from {communityDto.name}", "", communityId) singletonInstance.globalEvents.showCommunityMemberBannedNotification(fmt "You've been banned from {communityDto.name}", "", communityId)
of MembershipRequestState.Kicked: of MembershipRequestState.Kicked:
singletonInstance.globalEvents.showCommunityMemberKickedNotification(fmt "You were kicked from {communityDto.name}", "", communityId) singletonInstance.globalEvents.showCommunityMemberKickedNotification(fmt "You were kicked from {communityDto.name}", "", communityId)
@ -1251,9 +1254,13 @@ method onMembershipStatusUpdated*[T](self: Module[T], communityId: string, membe
let (contactName, _, _) = self.controller.getContactNameAndImage(memberPubkey) let (contactName, _, _) = self.controller.getContactNameAndImage(memberPubkey)
let item = self.view.model().getItemById(communityId) let item = self.view.model().getItemById(communityId)
if item.id != "": if item.id != "":
item.updateMembershipStatus(memberPubkey, status) item.updateMembershipStatus(memberPubkey, state)
if status == MembershipRequestState.Banned or status == MembershipRequestState.Kicked or status == MembershipRequestState.Unbanned: case state:
self.view.emitCommunityMemberStatusEphemeralNotification(communityDto.name, contactName, status.int) of MembershipRequestState.Banned, MembershipRequestState.Kicked,
MembershipRequestState.Unbanned, MembershipRequestState.BannedWithAllMessagesDelete:
self.view.emitCommunityMemberStatusEphemeralNotification(communityDto.name, contactName, state.int)
else:
discard
method calculateProfileSectionHasNotification*[T](self: Module[T]): bool = method calculateProfileSectionHasNotification*[T](self: Module[T]): bool =
return not self.controller.isMnemonicBackedUp() return not self.controller.isMnemonicBackedUp()

View File

@ -380,11 +380,12 @@ proc communityTokens*(self: SectionItem): community_tokens_model.TokenModel {.in
proc updatePendingRequestLoadingState*(self: SectionItem, memberKey: string, loading: bool) {.inline.} = proc updatePendingRequestLoadingState*(self: SectionItem, memberKey: string, loading: bool) {.inline.} =
self.pendingMemberRequestsModel.updateLoadingState(memberKey, loading) self.pendingMemberRequestsModel.updateLoadingState(memberKey, loading)
proc updateMembershipStatus*(self: SectionItem, memberKey: string, status: MembershipRequestState) {.inline.} = proc updateMembershipStatus*(self: SectionItem, memberKey: string, state: MembershipRequestState) {.inline.} =
if status == MembershipRequestState.UnbannedPending or status == MembershipRequestState.Banned: case state:
self.bannedMembersModel.updateMembershipStatus(memberKey, status) of MembershipRequestState.Banned, MembershipRequestState.BannedWithAllMessagesDelete, MembershipRequestState.UnbannedPending:
else: self.bannedMembersModel.updateMembershipStatus(memberKey, state)
self.membersModel.updateMembershipStatus(memberKey, status) else:
self.membersModel.updateMembershipStatus(memberKey, state)
proc pubsubTopic*(self: SectionItem): string {.inline.} = proc pubsubTopic*(self: SectionItem): string {.inline.} =
self.pubsubTopic self.pubsubTopic

View File

@ -72,6 +72,7 @@ type MembershipRequestState* {.pure} = enum
KickedPending = 10, KickedPending = 10,
AwaitingAddress = 11, AwaitingAddress = 11,
Unbanned = 12, Unbanned = 12,
BannedWithAllMessagesDelete = 13
type type
ContractTransactionStatus* {.pure.} = enum ContractTransactionStatus* {.pure.} = enum

View File

@ -40,9 +40,11 @@ type
Banned = 0, Banned = 0,
BanPending, BanPending,
UnbanPending, UnbanPending,
KickPending KickPending,
Unbanned, BannedWithAllMessagesDelete
Kicked
proc isBanned*(state: CommunityMemberPendingBanOrKick): bool =
return state == CommunityMemberPendingBanOrKick.Banned or state == CommunityMemberPendingBanOrKick.BannedWithAllMessagesDelete
type CommunityMembershipRequestDto* = object type CommunityMembershipRequestDto* = object
id*: string id*: string
@ -481,6 +483,8 @@ proc toMembershipRequestState*(state: CommunityMemberPendingBanOrKick): Membersh
return MembershipRequestState.UnbannedPending return MembershipRequestState.UnbannedPending
of CommunityMemberPendingBanOrKick.KickPending: of CommunityMemberPendingBanOrKick.KickPending:
return MembershipRequestState.KickedPending return MembershipRequestState.KickedPending
of CommunityMemberPendingBanOrKick.BannedWithAllMessagesDelete:
return MembershipRequestState.BannedWithAllMessagesDelete
else: else:
return MembershipRequestState.None return MembershipRequestState.None
@ -526,7 +530,7 @@ proc contains(arrayToSearch: seq[int], searched: int): bool =
proc getBannedMembersIds*(self: CommunityDto): seq[string] = proc getBannedMembersIds*(self: CommunityDto): seq[string] =
var bannedIds: seq[string] = @[] var bannedIds: seq[string] = @[]
for memberId, state in self.pendingAndBannedMembers: for memberId, state in self.pendingAndBannedMembers:
if state == CommunityMemberPendingBanOrKick.Banned: if isBanned(state):
bannedIds.add(memberId) bannedIds.add(memberId)
return bannedIds return bannedIds

View File

@ -161,7 +161,7 @@ type
CommunityMemberStatusUpdatedArgs* = ref object of Args CommunityMemberStatusUpdatedArgs* = ref object of Args
communityId*: string communityId*: string
memberPubkey*: string memberPubkey*: string
status*: MembershipRequestState state*: MembershipRequestState
CommunityShardSetArgs* = ref object of Args CommunityShardSetArgs* = ref object of Args
communityId*: string communityId*: string
@ -745,15 +745,16 @@ QtObject:
else: else:
# We were kicked or banned, leave the community # We were kicked or banned, leave the community
self.events.emit(SIGNAL_COMMUNITY_LEFT, CommunityIdArgs(communityId: community.id)) self.events.emit(SIGNAL_COMMUNITY_LEFT, CommunityIdArgs(communityId: community.id))
var status = MembershipRequestState.Kicked var state = MembershipRequestState.Kicked
if community.pendingAndBannedMembers.hasKey(myPublicKey) and if community.pendingAndBannedMembers.hasKey(myPublicKey):
community.pendingAndBannedMembers[myPublicKey] == CommunityMemberPendingBanOrKick.Banned: let status = community.pendingAndBannedMembers[myPublicKey]
status = MembershipRequestState.Banned if isBanned(status):
state = status.toMembershipRequestState()
self.events.emit(SIGNAL_COMMUNITY_MEMBER_STATUS_CHANGED, CommunityMemberStatusUpdatedArgs( self.events.emit(SIGNAL_COMMUNITY_MEMBER_STATUS_CHANGED, CommunityMemberStatusUpdatedArgs(
communityId: community.id, communityId: community.id,
memberPubkey: myPublicKey, memberPubkey: myPublicKey,
status: status)) state: state))
# Check if we were unbanned # Check if we were unbanned
if not wasJoined and not community.joined and prevCommunity.pendingAndBannedMembers.hasKey(myPublicKey) and not if not wasJoined and not community.joined and prevCommunity.pendingAndBannedMembers.hasKey(myPublicKey) and not
@ -761,7 +762,7 @@ QtObject:
self.events.emit(SIGNAL_COMMUNITY_MEMBER_STATUS_CHANGED, CommunityMemberStatusUpdatedArgs( self.events.emit(SIGNAL_COMMUNITY_MEMBER_STATUS_CHANGED, CommunityMemberStatusUpdatedArgs(
communityId: community.id, communityId: community.id,
memberPubkey: myPublicKey, memberPubkey: myPublicKey,
status: MembershipRequestState.Unbanned)) state: MembershipRequestState.Unbanned))
except Exception as e: except Exception as e:
error "Error handling community updates", msg = e.msg error "Error handling community updates", msg = e.msg
@ -2166,21 +2167,21 @@ QtObject:
var community = communityJArr[0].toCommunityDto() var community = communityJArr[0].toCommunityDto()
var status: MembershipRequestState = MembershipRequestState.None var state: MembershipRequestState = MembershipRequestState.None
if community.pendingAndBannedMembers.hasKey(memberPubkey): if community.pendingAndBannedMembers.hasKey(memberPubkey):
status = community.pendingAndBannedMembers[memberPubkey].toMembershipRequestState() state = community.pendingAndBannedMembers[memberPubkey].toMembershipRequestState()
if status == MembershipRequestState.None: if state == MembershipRequestState.None:
let prevCommunity = self.communities[community.id] let prevCommunity = self.communities[community.id]
if prevCommunity.pendingAndBannedMembers.hasKey(memberPubkey): if prevCommunity.pendingAndBannedMembers.hasKey(memberPubkey):
status = MembershipRequestState.Unbanned state = MembershipRequestState.Unbanned
elif len(prevCommunity.members) > len(community.members): elif len(prevCommunity.members) > len(community.members):
status = MembershipRequestState.Kicked state = MembershipRequestState.Kicked
self.events.emit(SIGNAL_COMMUNITY_MEMBER_STATUS_CHANGED, CommunityMemberStatusUpdatedArgs( self.events.emit(SIGNAL_COMMUNITY_MEMBER_STATUS_CHANGED, CommunityMemberStatusUpdatedArgs(
communityId: community.id, communityId: community.id,
memberPubkey: memberPubkey, memberPubkey: memberPubkey,
status: status state: state
)) ))
except Exception as e: except Exception as e:

View File

@ -104,7 +104,8 @@ Item {
readonly property bool isBanPending: model.membershipRequestState === Constants.CommunityMembershipRequestState.BannedPending readonly property bool isBanPending: model.membershipRequestState === Constants.CommunityMembershipRequestState.BannedPending
readonly property bool isUnbanPending: model.membershipRequestState === Constants.CommunityMembershipRequestState.UnbannedPending readonly property bool isUnbanPending: model.membershipRequestState === Constants.CommunityMembershipRequestState.UnbannedPending
readonly property bool isKickPending: model.membershipRequestState === Constants.CommunityMembershipRequestState.KickedPending readonly property bool isKickPending: model.membershipRequestState === Constants.CommunityMembershipRequestState.KickedPending
readonly property bool isBanned: model.membershipRequestState === Constants.CommunityMembershipRequestState.Banned readonly property bool isBanned: model.membershipRequestState === Constants.CommunityMembershipRequestState.Banned ||
model.membershipRequestState === Constants.CommunityMembershipRequestState.BannedWithAllMessagesDelete
readonly property bool isKicked: model.membershipRequestState === Constants.CommunityMembershipRequestState.Kicked readonly property bool isKicked: model.membershipRequestState === Constants.CommunityMembershipRequestState.Kicked
// TODO: Connect to backend when available // TODO: Connect to backend when available

View File

@ -229,6 +229,7 @@ Item {
var text = "" var text = ""
switch (state) { switch (state) {
case Constants.CommunityMembershipRequestState.Banned: case Constants.CommunityMembershipRequestState.Banned:
case Constants.CommunityMembershipRequestState.BannedWithAllMessagesDelete:
text = qsTr("%1 was banned from %2").arg(memberName).arg(communityName) text = qsTr("%1 was banned from %2").arg(memberName).arg(communityName)
break break
case Constants.CommunityMembershipRequestState.Unbanned: case Constants.CommunityMembershipRequestState.Unbanned:

View File

@ -1226,7 +1226,8 @@ QtObject {
UnbannedPending, UnbannedPending,
KickedPending, KickedPending,
AwaitingAddress, AwaitingAddress,
Unbanned Unbanned,
BannedWithAllMessagesDelete
} }
readonly property QtObject walletAccountColors: QtObject { readonly property QtObject walletAccountColors: QtObject {

2
vendor/status-go vendored

@ -1 +1 @@
Subproject commit f0d6a4f64f882fe249626a5fec8eaafba3f97824 Subproject commit a1033f466a7814d8194938f49abe28ea322272d5