feat(@desktop/community): add new CommunityMemberState - CommunityMemberBanWithAllMessagesDelete (#14028)
This commit is contained in:
parent
0958860bc9
commit
f3d2d0a809
|
@ -258,7 +258,8 @@ proc getCuratedCommunityItem(self: Module, community: CommunityDto): CuratedComm
|
|||
let myPublicKey = singletonInstance.userProfile.getPubKey()
|
||||
var amIbanned = false
|
||||
if myPublicKey in community.pendingAndBannedMembers:
|
||||
amIbanned = community.pendingAndBannedMembers[myPublicKey] == CommunityMemberPendingBanOrKick.Banned
|
||||
let state = community.pendingAndBannedMembers[myPublicKey]
|
||||
amIbanned = isBanned(state)
|
||||
|
||||
return initCuratedCommunityItem(
|
||||
community.id,
|
||||
|
|
|
@ -407,7 +407,7 @@ proc init*(self: Controller) =
|
|||
|
||||
self.events.on(SIGNAL_COMMUNITY_MEMBER_STATUS_CHANGED) do(e: Args):
|
||||
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):
|
||||
let args = CommunityMembersArgs(e)
|
||||
|
|
|
@ -376,7 +376,7 @@ method onAcceptRequestToJoinLoading*(self: AccessInterface, communityId: string,
|
|||
method onAcceptRequestToJoinSuccess*(self: AccessInterface, communityId: string, memberKey: string, requestId: string) {.base.} =
|
||||
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")
|
||||
|
||||
method onDeactivateChatLoader*(self: AccessInterface, sectionId: string, chatId: string) {.base.} =
|
||||
|
|
|
@ -348,8 +348,11 @@ proc createChannelGroupItem[T](self: Module[T], channelGroup: ChannelGroupDto):
|
|||
var bannedMembers = newSeq[MemberItem]()
|
||||
for memberId, memberState in communityDetails.pendingAndBannedMembers.pairs:
|
||||
let state = memberState.toMembershipRequestState()
|
||||
if state == MembershipRequestState.Banned or state == MembershipRequestState.UnbannedPending:
|
||||
bannedMembers.add(self.createMemberItem(memberId, state, MemberRole.None))
|
||||
case state:
|
||||
of MembershipRequestState.Banned, MembershipRequestState.BannedWithAllMessagesDelete, MembershipRequestState.UnbannedPending:
|
||||
bannedMembers.add(self.createMemberItem(memberId, state, MemberRole.None))
|
||||
else:
|
||||
discard
|
||||
|
||||
result = initItem(
|
||||
channelGroup.id,
|
||||
|
@ -1233,13 +1236,13 @@ method onAcceptRequestToJoinSuccess*[T](self: Module[T], communityId: string, me
|
|||
if item.id != "":
|
||||
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 communityDto = self.controller.getCommunityById(communityId)
|
||||
|
||||
if myPublicKey == memberPubkey:
|
||||
case status:
|
||||
of MembershipRequestState.Banned:
|
||||
case state:
|
||||
of MembershipRequestState.Banned, MembershipRequestState.BannedWithAllMessagesDelete:
|
||||
singletonInstance.globalEvents.showCommunityMemberBannedNotification(fmt "You've been banned from {communityDto.name}", "", communityId)
|
||||
of MembershipRequestState.Kicked:
|
||||
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 item = self.view.model().getItemById(communityId)
|
||||
if item.id != "":
|
||||
item.updateMembershipStatus(memberPubkey, status)
|
||||
if status == MembershipRequestState.Banned or status == MembershipRequestState.Kicked or status == MembershipRequestState.Unbanned:
|
||||
self.view.emitCommunityMemberStatusEphemeralNotification(communityDto.name, contactName, status.int)
|
||||
item.updateMembershipStatus(memberPubkey, state)
|
||||
case state:
|
||||
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 =
|
||||
return not self.controller.isMnemonicBackedUp()
|
||||
|
|
|
@ -287,10 +287,10 @@ proc access*(self: SectionItem): int {.inline.} =
|
|||
proc ensOnly*(self: SectionItem): bool {.inline.} =
|
||||
self.ensOnly
|
||||
|
||||
proc muted*(self: SectionItem): bool {.inline.} =
|
||||
proc muted*(self: SectionItem): bool {.inline.} =
|
||||
self.muted
|
||||
|
||||
proc `muted=`*(self: var SectionItem, value: bool) {.inline.} =
|
||||
proc `muted=`*(self: var SectionItem, value: bool) {.inline.} =
|
||||
self.muted = value
|
||||
|
||||
proc members*(self: SectionItem): member_model.Model {.inline.} =
|
||||
|
@ -380,11 +380,12 @@ proc communityTokens*(self: SectionItem): community_tokens_model.TokenModel {.in
|
|||
proc updatePendingRequestLoadingState*(self: SectionItem, memberKey: string, loading: bool) {.inline.} =
|
||||
self.pendingMemberRequestsModel.updateLoadingState(memberKey, loading)
|
||||
|
||||
proc updateMembershipStatus*(self: SectionItem, memberKey: string, status: MembershipRequestState) {.inline.} =
|
||||
if status == MembershipRequestState.UnbannedPending or status == MembershipRequestState.Banned:
|
||||
self.bannedMembersModel.updateMembershipStatus(memberKey, status)
|
||||
else:
|
||||
self.membersModel.updateMembershipStatus(memberKey, status)
|
||||
proc updateMembershipStatus*(self: SectionItem, memberKey: string, state: MembershipRequestState) {.inline.} =
|
||||
case state:
|
||||
of MembershipRequestState.Banned, MembershipRequestState.BannedWithAllMessagesDelete, MembershipRequestState.UnbannedPending:
|
||||
self.bannedMembersModel.updateMembershipStatus(memberKey, state)
|
||||
else:
|
||||
self.membersModel.updateMembershipStatus(memberKey, state)
|
||||
|
||||
proc pubsubTopic*(self: SectionItem): string {.inline.} =
|
||||
self.pubsubTopic
|
||||
|
|
|
@ -72,6 +72,7 @@ type MembershipRequestState* {.pure} = enum
|
|||
KickedPending = 10,
|
||||
AwaitingAddress = 11,
|
||||
Unbanned = 12,
|
||||
BannedWithAllMessagesDelete = 13
|
||||
|
||||
type
|
||||
ContractTransactionStatus* {.pure.} = enum
|
||||
|
|
|
@ -40,9 +40,11 @@ type
|
|||
Banned = 0,
|
||||
BanPending,
|
||||
UnbanPending,
|
||||
KickPending
|
||||
Unbanned,
|
||||
Kicked
|
||||
KickPending,
|
||||
BannedWithAllMessagesDelete
|
||||
|
||||
proc isBanned*(state: CommunityMemberPendingBanOrKick): bool =
|
||||
return state == CommunityMemberPendingBanOrKick.Banned or state == CommunityMemberPendingBanOrKick.BannedWithAllMessagesDelete
|
||||
|
||||
type CommunityMembershipRequestDto* = object
|
||||
id*: string
|
||||
|
@ -481,6 +483,8 @@ proc toMembershipRequestState*(state: CommunityMemberPendingBanOrKick): Membersh
|
|||
return MembershipRequestState.UnbannedPending
|
||||
of CommunityMemberPendingBanOrKick.KickPending:
|
||||
return MembershipRequestState.KickedPending
|
||||
of CommunityMemberPendingBanOrKick.BannedWithAllMessagesDelete:
|
||||
return MembershipRequestState.BannedWithAllMessagesDelete
|
||||
else:
|
||||
return MembershipRequestState.None
|
||||
|
||||
|
@ -526,7 +530,7 @@ proc contains(arrayToSearch: seq[int], searched: int): bool =
|
|||
proc getBannedMembersIds*(self: CommunityDto): seq[string] =
|
||||
var bannedIds: seq[string] = @[]
|
||||
for memberId, state in self.pendingAndBannedMembers:
|
||||
if state == CommunityMemberPendingBanOrKick.Banned:
|
||||
if isBanned(state):
|
||||
bannedIds.add(memberId)
|
||||
return bannedIds
|
||||
|
||||
|
@ -646,4 +650,4 @@ proc findOwner*(self: CommunityDto): ChatMember =
|
|||
for member in self.members:
|
||||
if member.role == MemberRole.Owner:
|
||||
return member
|
||||
raise newException(ValueError, "No owner found in members list")
|
||||
raise newException(ValueError, "No owner found in members list")
|
||||
|
|
|
@ -161,7 +161,7 @@ type
|
|||
CommunityMemberStatusUpdatedArgs* = ref object of Args
|
||||
communityId*: string
|
||||
memberPubkey*: string
|
||||
status*: MembershipRequestState
|
||||
state*: MembershipRequestState
|
||||
|
||||
CommunityShardSetArgs* = ref object of Args
|
||||
communityId*: string
|
||||
|
@ -745,15 +745,16 @@ QtObject:
|
|||
else:
|
||||
# We were kicked or banned, leave the community
|
||||
self.events.emit(SIGNAL_COMMUNITY_LEFT, CommunityIdArgs(communityId: community.id))
|
||||
var status = MembershipRequestState.Kicked
|
||||
if community.pendingAndBannedMembers.hasKey(myPublicKey) and
|
||||
community.pendingAndBannedMembers[myPublicKey] == CommunityMemberPendingBanOrKick.Banned:
|
||||
status = MembershipRequestState.Banned
|
||||
var state = MembershipRequestState.Kicked
|
||||
if community.pendingAndBannedMembers.hasKey(myPublicKey):
|
||||
let status = community.pendingAndBannedMembers[myPublicKey]
|
||||
if isBanned(status):
|
||||
state = status.toMembershipRequestState()
|
||||
|
||||
self.events.emit(SIGNAL_COMMUNITY_MEMBER_STATUS_CHANGED, CommunityMemberStatusUpdatedArgs(
|
||||
communityId: community.id,
|
||||
memberPubkey: myPublicKey,
|
||||
status: status))
|
||||
state: state))
|
||||
|
||||
# Check if we were unbanned
|
||||
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(
|
||||
communityId: community.id,
|
||||
memberPubkey: myPublicKey,
|
||||
status: MembershipRequestState.Unbanned))
|
||||
state: MembershipRequestState.Unbanned))
|
||||
|
||||
except Exception as e:
|
||||
error "Error handling community updates", msg = e.msg
|
||||
|
@ -2166,21 +2167,21 @@ QtObject:
|
|||
|
||||
var community = communityJArr[0].toCommunityDto()
|
||||
|
||||
var status: MembershipRequestState = MembershipRequestState.None
|
||||
var state: MembershipRequestState = MembershipRequestState.None
|
||||
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]
|
||||
if prevCommunity.pendingAndBannedMembers.hasKey(memberPubkey):
|
||||
status = MembershipRequestState.Unbanned
|
||||
state = MembershipRequestState.Unbanned
|
||||
elif len(prevCommunity.members) > len(community.members):
|
||||
status = MembershipRequestState.Kicked
|
||||
state = MembershipRequestState.Kicked
|
||||
|
||||
self.events.emit(SIGNAL_COMMUNITY_MEMBER_STATUS_CHANGED, CommunityMemberStatusUpdatedArgs(
|
||||
communityId: community.id,
|
||||
memberPubkey: memberPubkey,
|
||||
status: status
|
||||
state: state
|
||||
))
|
||||
|
||||
except Exception as e:
|
||||
|
|
|
@ -104,7 +104,8 @@ Item {
|
|||
readonly property bool isBanPending: model.membershipRequestState === Constants.CommunityMembershipRequestState.BannedPending
|
||||
readonly property bool isUnbanPending: model.membershipRequestState === Constants.CommunityMembershipRequestState.UnbannedPending
|
||||
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
|
||||
|
||||
// TODO: Connect to backend when available
|
||||
|
|
|
@ -229,6 +229,7 @@ Item {
|
|||
var text = ""
|
||||
switch (state) {
|
||||
case Constants.CommunityMembershipRequestState.Banned:
|
||||
case Constants.CommunityMembershipRequestState.BannedWithAllMessagesDelete:
|
||||
text = qsTr("%1 was banned from %2").arg(memberName).arg(communityName)
|
||||
break
|
||||
case Constants.CommunityMembershipRequestState.Unbanned:
|
||||
|
|
|
@ -1226,7 +1226,8 @@ QtObject {
|
|||
UnbannedPending,
|
||||
KickedPending,
|
||||
AwaitingAddress,
|
||||
Unbanned
|
||||
Unbanned,
|
||||
BannedWithAllMessagesDelete
|
||||
}
|
||||
|
||||
readonly property QtObject walletAccountColors: QtObject {
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit f0d6a4f64f882fe249626a5fec8eaafba3f97824
|
||||
Subproject commit a1033f466a7814d8194938f49abe28ea322272d5
|
Loading…
Reference in New Issue