feat: enable removing member and fix invites
This commit is contained in:
parent
b3844d4012
commit
7b03da2967
|
@ -313,7 +313,9 @@ QtObject:
|
|||
self.messageList[msg.chatId].add(msg)
|
||||
self.messagePushed()
|
||||
if self.channelOpenTime.getOrDefault(msg.chatId, high(int64)) < msg.timestamp.parseFloat.fromUnixFloat.toUnix:
|
||||
let channel = self.status.chat.channels[msg.chatId]
|
||||
let channel = self.chats.getChannelById(msg.chatId)
|
||||
if (channel == nil):
|
||||
continue
|
||||
let isAddedContact = channel.chatType.isOneToOne and self.status.contacts.isAdded(channel.id)
|
||||
if not channel.muted:
|
||||
self.messageNotificationPushed(
|
||||
|
@ -608,11 +610,18 @@ QtObject:
|
|||
notify = joinedCommunitiesChanged
|
||||
|
||||
proc addCommunityToList*(self: ChatsView, community: Community) =
|
||||
let communityCheck = self.joinedCommunityList.getCommunityById(community.id)
|
||||
let communityCheck = self.communityList.getCommunityById(community.id)
|
||||
if (communityCheck.id == ""):
|
||||
self.joinedCommunityList.addCommunityItemToList(community)
|
||||
self.communityList.addCommunityItemToList(community)
|
||||
else:
|
||||
self.joinedCommunityList.replaceCommunity(community)
|
||||
self.communityList.replaceCommunity(community)
|
||||
|
||||
if (community.joined == true):
|
||||
let joinedCommunityCheck = self.joinedCommunityList.getCommunityById(community.id)
|
||||
if (joinedCommunityCheck.id == ""):
|
||||
self.joinedCommunityList.addCommunityItemToList(community)
|
||||
else:
|
||||
self.joinedCommunityList.replaceCommunity(community)
|
||||
|
||||
proc createCommunity*(self: ChatsView, name: string, description: string, color: string, imagePath: string): string {.slot.} =
|
||||
result = ""
|
||||
|
@ -728,4 +737,11 @@ QtObject:
|
|||
try:
|
||||
self.status.chat.importCommunity(communityKey)
|
||||
except Exception as e:
|
||||
error "Error importing the community", msg = e.msg
|
||||
error "Error importing the community", msg = e.msg
|
||||
|
||||
proc removeUserFromCommunity*(self: ChatsView, pubKey: string) {.slot.} =
|
||||
try:
|
||||
self.status.chat.removeUserFromCommunity(self.activeCommunity.id(), pubKey)
|
||||
self.activeCommunity.removeMember(pubKey)
|
||||
except Exception as e:
|
||||
error "Error removing user from the community", msg = e.msg
|
|
@ -40,6 +40,12 @@ QtObject:
|
|||
self.status.events.emit("communityActiveChanged", Args())
|
||||
self.activeChanged()
|
||||
|
||||
proc nbMembersChanged*(self: CommunityItemView) {.signal.}
|
||||
|
||||
proc removeMember*(self: CommunityItemView, pubKey: string) =
|
||||
self.members.removeMember(pubKey)
|
||||
self.nbMembersChanged()
|
||||
|
||||
proc active*(self: CommunityItemView): bool {.slot.} = result = ?.self.active
|
||||
|
||||
QtProperty[bool] active:
|
||||
|
@ -86,6 +92,7 @@ QtObject:
|
|||
|
||||
QtProperty[int] nbMembers:
|
||||
read = nbMembers
|
||||
notify = nbMembersChanged
|
||||
|
||||
proc getChats*(self: CommunityItemView): QVariant {.slot.} =
|
||||
result = newQVariant(self.chats)
|
||||
|
|
|
@ -30,6 +30,22 @@ QtObject:
|
|||
self.members = members
|
||||
self.endResetModel()
|
||||
|
||||
proc getIndexFromPubKey*(self: CommunityMembersView, pubKey: string): int =
|
||||
var i = 0
|
||||
for memberPubKey in self.members:
|
||||
if (memberPubKey == pubKey):
|
||||
return i
|
||||
i = i + 1
|
||||
return -1
|
||||
|
||||
proc removeMember*(self: CommunityMembersView, pubKey: string) =
|
||||
let memberIndex = self.getIndexFromPubKey(pubKey)
|
||||
if (memberIndex == -1):
|
||||
return
|
||||
self.beginRemoveRows(newQModelIndex(), memberIndex, memberIndex)
|
||||
self.members.delete(memberIndex)
|
||||
self.endRemoveRows()
|
||||
|
||||
method rowCount(self: CommunityMembersView, index: QModelIndex = nil): int = self.members.len
|
||||
|
||||
proc userName(self: CommunityMembersView, pk: string, alias: string): string =
|
||||
|
|
|
@ -224,19 +224,21 @@ proc getLinkPreviewData*(self: ChatModel, link: string): JsonNode =
|
|||
proc setActiveChannel*(self: ChatModel, chatId: string) =
|
||||
self.events.emit("activeChannelChanged", ChatIdArg(chatId: chatId))
|
||||
|
||||
proc processMessageUpdateAfterSend(self: ChatModel, response: string): (seq[Chat], seq[Message]) =
|
||||
proc processMessageUpdateAfterSend(self: ChatModel, response: string, forceActiveChat: bool = false): (seq[Chat], seq[Message]) =
|
||||
result = self.processChatUpdate(parseJson(response))
|
||||
var (chats, messages) = result
|
||||
if chats.len == 0 or messages.len == 0:
|
||||
self.events.emit("sendingMessageFailed", MessageArgs())
|
||||
else:
|
||||
if (forceActiveChat):
|
||||
chats[0].isActive = true
|
||||
self.events.emit("chatUpdate", ChatUpdateArgs(messages: messages, chats: chats, contacts: @[]))
|
||||
for msg in messages:
|
||||
self.events.emit("sendingMessage", MessageArgs(id: msg.id, channel: msg.chatId))
|
||||
|
||||
proc sendMessage*(self: ChatModel, chatId: string, msg: string, replyTo: string = "", contentType: int = ContentType.Message.int, communityId: string = "") =
|
||||
proc sendMessage*(self: ChatModel, chatId: string, msg: string, replyTo: string = "", contentType: int = ContentType.Message.int, communityId: string = "", forceActiveChat: bool = false) =
|
||||
var response = status_chat.sendChatMessage(chatId, msg, replyTo, contentType, communityId)
|
||||
discard self.processMessageUpdateAfterSend(response)
|
||||
discard self.processMessageUpdateAfterSend(response, forceActiveChat)
|
||||
|
||||
proc sendImage*(self: ChatModel, chatId: string, image: string) =
|
||||
var response = status_chat.sendImageMessage(chatId, image)
|
||||
|
@ -396,7 +398,10 @@ proc leaveCommunity*(self: ChatModel, communityId: string) =
|
|||
proc inviteUserToCommunity*(self: ChatModel, communityId: string, pubKey: string) =
|
||||
status_chat.inviteUserToCommunity(communityId, pubKey)
|
||||
# After sending the invite, we send a message with the community ID so they can join
|
||||
self.sendMessage(pubKey, "Upgrade here to see an invitation to community", "", ContentType.Community.int, communityId)
|
||||
self.sendMessage(pubKey, "Upgrade here to see an invitation to community", "", ContentType.Community.int, communityId, true)
|
||||
|
||||
proc removeUserFromCommunity*(self: ChatModel, communityId: string, pubKey: string) =
|
||||
status_chat.removeUserFromCommunity(communityId, pubKey)
|
||||
|
||||
proc exportCommunity*(self: ChatModel, communityId: string): string =
|
||||
result = status_chat.exportCommunity(communityId)
|
||||
|
|
|
@ -211,7 +211,6 @@ proc getLinkPreviewData*(link: string): JsonNode =
|
|||
|
||||
response.result
|
||||
|
||||
|
||||
proc getAllComunities*(): seq[Community] =
|
||||
var communities: seq[Community] = @[]
|
||||
let rpcResult = callPrivateRPC("communities".prefix).parseJSON()
|
||||
|
@ -280,12 +279,6 @@ proc createCommunityChannel*(communityId: string, name: string, description: str
|
|||
if rpcResult{"result"}.kind != JNull:
|
||||
result = rpcResult["result"]["chats"][0].toChat()
|
||||
|
||||
|
||||
#{\"jsonrpc\":\"2.0\",\"id\":0,\"result\":{\"chats\":[{\"id\":\"0x03537a54bd6f697f282ae848452f25ce656026cd8d0b3d3489178c76d3bf9ddf20cbf03afb-89ab-444e-96e9-e23b6c1266c0\",\"name\":\"general\",\"color\":\"#887af9\",\"active\":true,\"chatType\":6,\"timestamp\":1606424570375,\"lastClockValue\":0,\"deletedAtClockValue\":0,\"unviewedMessagesCount\":0,\"lastMessage\":null,\"members\":null,\"membershipUpdateEvents\":null,\"identicon\":\"\",\"communityId\":\"0x03537a54bd6f697f282ae848452f25ce656026cd8d0b3d3489178c76d3bf9ddf20\"}],\"communities\":[{\"id\":\"0x03537a54bd6f697f282ae848452f25ce656026cd8d0b3d3489178c76d3bf9ddf20\",\"description\":{\"clock\":2,\"permissions\":{\"access\":1},\"identity\":{\"display_name\":\"Jo2\",\"description\":\"Jo again\"},\"chats\":{\"cbf03afb-89ab-444e-96e9-e23b6c1266c0\":{\"permissions\":{\"access\":1},\"identity\":{\"display_name\":\"general\",\"description\":\"general channel\"}}}},\"admin\":true,\"verified\":false,\"joined\":true}],\"communitiesChanges\":[{\"MembersAdded\":{},\"MembersRemoved\":{},\"ChatsRemoved\":{},\"ChatsAdded\":{\"cbf03afb-89ab-444e-96e9-e23b6c1266c0\":{\"permissions\":{\"access\":1},\"identity\":{\"display_name\":\"general\",\"description\":\"general channel\"}}},\"ChatsModified\":{}}],\"filters\":[{\"chatId\":\"0x03537a54bd6f697f282ae848452f25ce656026cd8d0b3d3489178c76d3bf9ddf20cbf03afb-89ab-444e-96e9-e23b6c1266c0\",\"filterId\":\"eb220a77bde14d967462529d0ec7c1fa09a0ece4efebefb388ea6e0ecf9a1950\",\"symKeyId\":\"0f08b999ab6571429f79c4762bd922f2b7db38c80ba99cd4a5ac15ef75357d0e\",\"oneToOne\":false,\"identity\":\"\",\"topic\":\"0x46a1c2be\",\"discovery\":false,\"negotiated\":false,\"listen\":true}]}}
|
||||
|
||||
# if rpcResult{"result"}.kind != JNull:
|
||||
# result = rpcResult["result"]["communities"][0].toCommunity()
|
||||
|
||||
proc joinCommunity*(communityId: string) =
|
||||
discard callPrivateRPC("joinCommunity".prefix, %*[communityId])
|
||||
|
||||
|
@ -299,4 +292,7 @@ proc exportCommunity*(communityId: string):string =
|
|||
result = callPrivateRPC("exportCommunity".prefix, %*[communityId]).parseJson()["result"].getStr
|
||||
|
||||
proc importCommunity*(communityKey: string) =
|
||||
discard callPrivateRPC("importCommunity".prefix, %*[communityKey])
|
||||
discard callPrivateRPC("importCommunity".prefix, %*[communityKey])
|
||||
|
||||
proc removeUserFromCommunity*(communityId: string, pubKey: string) =
|
||||
discard callPrivateRPC("removeUserFromCommunity".prefix, %*[communityId, pubKey])
|
|
@ -12,9 +12,6 @@ Item {
|
|||
|
||||
id: root
|
||||
anchors.left: parent.left
|
||||
// anchors.leftMargin: isCurrentUser ? 0 :
|
||||
// appSettings.compactMode ? Style.current.padding : 48;
|
||||
width: childrenRect.width
|
||||
height: childrenRect.height
|
||||
|
||||
Component.onCompleted: {
|
||||
|
|
|
@ -136,7 +136,7 @@ ModalPopup {
|
|||
icon.height: 16
|
||||
icon.color: Style.current.red
|
||||
text: qsTr("Kick")
|
||||
onTriggered: console.log("TODO")
|
||||
onTriggered: chatsModel.removeUserFromCommunity(model.pubKey)
|
||||
}
|
||||
Action {
|
||||
icon.source: "../../../img/communities/menu/ban.svg"
|
||||
|
|
Loading…
Reference in New Issue