mirror of
https://github.com/status-im/status-desktop.git
synced 2025-02-17 00:56:39 +00:00
fix: group member list
This commit is contained in:
parent
9f21740bae
commit
9de0b95c3d
@ -4,7 +4,8 @@ import # std libs
|
||||
import # status-desktop libs
|
||||
../../status/chat/chat as status_chat, ./views/communities,
|
||||
../../status/tasks/marathon,
|
||||
../../status/tasks/marathon/mailserver/worker
|
||||
../../status/tasks/marathon/mailserver/worker,
|
||||
./views/messages
|
||||
|
||||
proc handleChatEvents(self: ChatController) =
|
||||
# Display already saved messages
|
||||
@ -36,7 +37,7 @@ proc handleChatEvents(self: ChatController) =
|
||||
self.view.hideLoadingIndicator()
|
||||
self.view.updateUsernames(evArgs.contacts)
|
||||
self.view.updateChats(evArgs.chats)
|
||||
self.view.pushMessages(evArgs.messages)
|
||||
self.view.pushMessages(evArgs.messages, evArgs.chats)
|
||||
|
||||
# TODO: update current user status (once it's possible to switch between ONLINE and DO_NOT_DISTURB)
|
||||
|
||||
@ -102,6 +103,8 @@ proc handleChatEvents(self: ChatController) =
|
||||
# Do not add community chats to the normal chat list
|
||||
elif channel.chat.chatType != ChatType.Profile and channel.chat.chatType != status_chat.ChatType.CommunityChat:
|
||||
discard self.view.channelView.chats.addChatItemToList(channel.chat)
|
||||
self.view.messageView.upsertChannel(channel.chat.id)
|
||||
self.view.messageView.messageList[channel.chat.id].addChatUpdate(channel.chat)
|
||||
|
||||
if channel.chat.chatType == status_chat.ChatType.CommunityChat:
|
||||
self.view.communities.updateCommunityChat(channel.chat)
|
||||
|
@ -438,8 +438,8 @@ QtObject:
|
||||
let task = RequestMessagesTaskArg( `method`: "requestMoreMessages", chatId: self.channelView.activeChannel.id)
|
||||
mailserverWorker.start(task)
|
||||
|
||||
proc pushMessages*(self: ChatsView, messages: var seq[Message]) =
|
||||
self.messageView.pushMessages(messages)
|
||||
proc pushMessages*(self: ChatsView, messages: var seq[Message], chats: seq[Chat] = @[]) =
|
||||
self.messageView.pushMessages(messages, chats)
|
||||
|
||||
proc pushPinnedMessages*(self: ChatsView, pinnedMessages: var seq[Message]) =
|
||||
self.messageView.pushPinnedMessages(pinnedMessages)
|
||||
|
@ -58,7 +58,7 @@ QtObject:
|
||||
method roleNames(self: ChatMembersView): Table[int, string] =
|
||||
{
|
||||
ChatMemberRoles.UserName.int:"userName",
|
||||
ChatMemberRoles.PubKey.int:"pubKey",
|
||||
ChatMemberRoles.PubKey.int:"publicKey",
|
||||
ChatMemberRoles.IsAdmin.int: "isAdmin",
|
||||
ChatMemberRoles.Joined.int: "joined",
|
||||
ChatMemberRoles.Identicon.int: "identicon",
|
||||
|
@ -1,8 +1,8 @@
|
||||
import NimQml, Tables, sets, json, sugar, chronicles, sequtils
|
||||
import ../../../status/status
|
||||
import ../../../status/accounts
|
||||
import ../../../status/chat
|
||||
import ../../../status/chat/[message,stickers]
|
||||
import ../../../status/chat as status_chat
|
||||
import ../../../status/chat/[message,stickers,chat]
|
||||
import ../../../status/profile/profile
|
||||
import ../../../status/ens
|
||||
import strutils
|
||||
@ -287,6 +287,11 @@ QtObject:
|
||||
proc contains*(self: ChatMessageList, message: Message):bool =
|
||||
return self.messageIndex.hasKey(message.id)
|
||||
|
||||
proc addChatUpdate*(self: ChatMessageList, chat: Chat) =
|
||||
# Using chat update to add/remove members to a group chat
|
||||
if chat.chatType == ChatType.PrivateGroupChat:
|
||||
self.userList.add(chat.members)
|
||||
|
||||
proc add*(self: ChatMessageList, message: Message) =
|
||||
if self.messageIndex.hasKey(message.id) and message.editedAt == "0": return # duplicated msg
|
||||
|
||||
|
@ -229,7 +229,7 @@ QtObject:
|
||||
|
||||
proc messageNotificationPushed*(self: MessageView, chatId: string, text: string, contentType: int, chatType: int, timestamp: string, identicon: string, username: string, hasMention: bool, isAddedContact: bool, channelName: string) {.signal.}
|
||||
|
||||
proc pushMessages*(self:MessageView, messages: var seq[Message]) =
|
||||
proc pushMessages*(self:MessageView, messages: var seq[Message], chats: seq[Chat] = @[]) =
|
||||
for msg in messages.mitems:
|
||||
self.upsertChannel(msg.chatId)
|
||||
msg.userName = self.status.chat.getUserName(msg.fromAuthor, msg.alias)
|
||||
@ -263,6 +263,10 @@ QtObject:
|
||||
if not channel.muted and not isEdit and not isGroupSelf:
|
||||
let isAddedContact = channel.chatType.isOneToOne and self.isAddedContact(channel.id)
|
||||
self.messageNotificationPushed(msg.chatId, escape_html(msg.text), msg.contentType.int, channel.chatType.int, msg.timestamp, msg.identicon, msg.userName, msg.hasMention, isAddedContact, channel.name)
|
||||
|
||||
for chat in chats:
|
||||
if chat.chatType == ChatType.PrivateGroupChat and self.messageList.hasKey(chat.id):
|
||||
self.messageList[chat.id].addChatUpdate(chat)
|
||||
|
||||
proc markMessageAsSent*(self:MessageView, chat: string, messageId: string) =
|
||||
if self.messageList.contains(chat):
|
||||
|
@ -1,8 +1,10 @@
|
||||
import NimQml, Tables, json, chronicles, sequtils
|
||||
import ../../../status/status
|
||||
import ../../../status/accounts
|
||||
import ../../../status/chat
|
||||
import ../../../status/chat/[message]
|
||||
import ../../../status/chat as status_chat
|
||||
import ../../../status/chat/[message, chat]
|
||||
import ../../../status/ens
|
||||
|
||||
import strutils
|
||||
|
||||
type
|
||||
@ -70,6 +72,58 @@ QtObject:
|
||||
UserListRoles.Identicon.int:"identicon"
|
||||
}.toTable
|
||||
|
||||
proc add*(self: UserListView, members: seq[ChatMember]) =
|
||||
# Adding chat members
|
||||
for m in members:
|
||||
let pk = m.id
|
||||
if self.userDetails.hasKey(pk): continue
|
||||
|
||||
var userName: string
|
||||
var alias: string
|
||||
var identicon: string
|
||||
var localName: string
|
||||
|
||||
if self.status.chat.contacts.hasKey(pk):
|
||||
userName = ens.userNameOrAlias(self.status.chat.contacts[pk])
|
||||
alias = self.status.chat.contacts[pk].alias
|
||||
identicon = self.status.chat.contacts[pk].identicon
|
||||
localName = self.status.chat.contacts[pk].localNickname
|
||||
else:
|
||||
userName = m.username
|
||||
alias = m.username
|
||||
identicon = m.identicon
|
||||
localName = ""
|
||||
|
||||
self.beginInsertRows(newQModelIndex(), self.users.len, self.users.len)
|
||||
self.userDetails[pk] = User(
|
||||
userName: userName,
|
||||
alias: alias,
|
||||
localName: localName,
|
||||
lastSeen: "0",
|
||||
identicon: identicon
|
||||
)
|
||||
self.users.add(pk)
|
||||
self.endInsertRows()
|
||||
|
||||
# Checking for removed members
|
||||
var toDelete: seq[string]
|
||||
for userPublicKey in self.users:
|
||||
var found = false
|
||||
for m in members:
|
||||
if m.id == userPublicKey:
|
||||
found = true
|
||||
break
|
||||
if not found:
|
||||
toDelete.add(userPublicKey)
|
||||
|
||||
# Removing deleted members
|
||||
if toDelete.len > 0:
|
||||
self.beginResetModel()
|
||||
for pkToDelete in toDelete:
|
||||
self.users.del(self.users.find(pkToDelete))
|
||||
self.userDetails.del(pkToDelete)
|
||||
self.endResetModel()
|
||||
|
||||
proc add*(self: UserListView, message: Message) =
|
||||
if self.userDetails.hasKey(message.fromAuthor):
|
||||
self.beginResetModel()
|
||||
|
@ -31,7 +31,7 @@ ModalPopup {
|
||||
const contacts = getContactListObject()
|
||||
|
||||
contacts.forEach(function (contact) {
|
||||
if(popup.channel.contains(contact.pubKey) ||
|
||||
if(popup.channel.contains(contact.publicKey) ||
|
||||
!contact.isContact) {
|
||||
return;
|
||||
}
|
||||
@ -278,12 +278,12 @@ ModalPopup {
|
||||
width: parent.width
|
||||
height: identicon.height
|
||||
|
||||
property string nickname: appMain.getUserNickname(model.pubKey)
|
||||
property string nickname: appMain.getUserNickname(model.publicKey)
|
||||
|
||||
StatusImageIdenticon {
|
||||
id: identicon
|
||||
anchors.left: parent.left
|
||||
source: appMain.getProfileImage(model.pubKey)|| model.identicon
|
||||
source: appMain.getProfileImage(model.publicKey)|| model.identicon
|
||||
}
|
||||
|
||||
StyledText {
|
||||
@ -295,7 +295,7 @@ ModalPopup {
|
||||
font.pixelSize: 17
|
||||
|
||||
StyledText {
|
||||
visible: model.pubKey === profileModel.profile.pubKey
|
||||
visible: model.publicKey === profileModel.profile.pubKey
|
||||
anchors.left: parent.right
|
||||
anchors.leftMargin: 5
|
||||
//% "(You)"
|
||||
@ -307,8 +307,8 @@ ModalPopup {
|
||||
anchors.fill: parent
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onClicked: {
|
||||
const userProfileImage = appMain.getProfileImage(model.pubKey)
|
||||
openProfilePopup(model.userName, model.pubKey, userProfileImage || model.identicon, '', contactRow.nickname, popup)
|
||||
const userProfileImage = appMain.getProfileImage(model.publicKey)
|
||||
openProfilePopup(model.userName, model.publicKey, userProfileImage || model.identicon, '', contactRow.nickname, popup)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -348,7 +348,7 @@ ModalPopup {
|
||||
icon.height: 16
|
||||
//% "Make Admin"
|
||||
text: qsTrId("make-admin")
|
||||
onTriggered: chatsModel.groups.makeAdmin(popup.channel.id, model.pubKey)
|
||||
onTriggered: chatsModel.groups.makeAdmin(popup.channel.id, model.publicKey)
|
||||
}
|
||||
Action {
|
||||
icon.source: "../../../img/remove-from-group.svg"
|
||||
@ -357,7 +357,7 @@ ModalPopup {
|
||||
icon.color: Style.current.red
|
||||
//% "Remove From Group"
|
||||
text: qsTrId("remove-from-group")
|
||||
onTriggered: chatsModel.groups.kickMember(popup.channel.id, model.pubKey)
|
||||
onTriggered: chatsModel.groups.kickMember(popup.channel.id, model.publicKey)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user