feat: use stacklayout for chat messages
This commit is contained in:
parent
750371a3f8
commit
b43122d7f3
|
@ -1,4 +1,4 @@
|
|||
import NimQml, Tables, json, sequtils, chronicles, times, re, sugar, strutils, os, strformat
|
||||
import NimQml, Tables, json, sequtils, chronicles, times, re, sugar, strutils, os, strformat, algorithm
|
||||
import ../../status/status
|
||||
import ../../status/mailservers
|
||||
import ../../status/libstatus/chat as libstatus_chat
|
||||
|
@ -24,6 +24,11 @@ import ../utils/image_utils
|
|||
logScope:
|
||||
topics = "chats-view"
|
||||
|
||||
|
||||
type
|
||||
ChatViewRoles {.pure.} = enum
|
||||
MessageList = UserRole + 1
|
||||
|
||||
QtObject:
|
||||
type
|
||||
ChatsView* = ref object of QAbstractListModel
|
||||
|
@ -31,7 +36,7 @@ QtObject:
|
|||
chats*: ChannelsList
|
||||
currentSuggestions*: SuggestionsList
|
||||
callResult: string
|
||||
messageList*: Table[string, ChatMessageList]
|
||||
messageList*: OrderedTable[string, ChatMessageList]
|
||||
reactions*: ReactionView
|
||||
stickers*: StickersView
|
||||
groups*: GroupsView
|
||||
|
@ -67,7 +72,7 @@ QtObject:
|
|||
self.stickers.delete
|
||||
self.groups.delete
|
||||
self.transactions.delete
|
||||
self.messageList = initTable[string, ChatMessageList]()
|
||||
self.messageList = initOrderedTable[string, ChatMessageList]()
|
||||
self.channelOpenTime = initTable[string, int64]()
|
||||
self.QAbstractListModel.delete
|
||||
|
||||
|
@ -81,7 +86,7 @@ QtObject:
|
|||
result.activeCommunity = newCommunityItemView(status)
|
||||
result.observedCommunity = newCommunityItemView(status)
|
||||
result.currentSuggestions = newSuggestionsList()
|
||||
result.messageList = initTable[string, ChatMessageList]()
|
||||
result.messageList = initOrderedTable[string, ChatMessageList]()
|
||||
result.reactions = newReactionView(status, result.messageList.addr, result.activeChannel)
|
||||
result.stickers = newStickersView(status, result.activeChannel)
|
||||
result.groups = newGroupsView(status,result.activeChannel)
|
||||
|
@ -312,8 +317,10 @@ QtObject:
|
|||
if self.status.chat.channels.hasKey(channel):
|
||||
chat = self.status.chat.channels[channel]
|
||||
if not self.messageList.hasKey(channel):
|
||||
self.beginInsertRows(newQModelIndex(), self.messageList.len, self.messageList.len)
|
||||
self.messageList[channel] = newChatMessageList(channel, self.status, not chat.isNil and chat.chatType != ChatType.Profile)
|
||||
self.channelOpenTime[channel] = now().toTime.toUnix * 1000
|
||||
self.endInsertRows();
|
||||
|
||||
proc messagePushed*(self: ChatsView, messageIndex: int) {.signal.}
|
||||
proc newMessagePushed*(self: ChatsView) {.signal.}
|
||||
|
@ -857,3 +864,25 @@ QtObject:
|
|||
except Exception as e:
|
||||
error "Error removing user from the community", msg = e.msg
|
||||
|
||||
|
||||
method rowCount*(self: ChatsView, index: QModelIndex = nil): int =
|
||||
result = self.messageList.len
|
||||
|
||||
method data(self: ChatsView, index: QModelIndex, role: int): QVariant =
|
||||
if not index.isValid:
|
||||
return
|
||||
if index.row < 0 or index.row >= self.messageList.len:
|
||||
return
|
||||
return newQVariant(toSeq(self.messageList.values)[index.row])
|
||||
|
||||
method roleNames(self: ChatsView): Table[int, string] =
|
||||
{
|
||||
ChatViewRoles.MessageList.int:"messages"
|
||||
}.toTable
|
||||
|
||||
proc getMessageListIndex(self: ChatsView):int {.slot.} =
|
||||
var idx = -1
|
||||
for msg in toSeq(self.messageList.values):
|
||||
idx = idx + 1
|
||||
if(self.activeChannel.id == msg.id): return idx
|
||||
return idx
|
||||
|
|
|
@ -42,7 +42,7 @@ QtObject:
|
|||
ChatMessageList* = ref object of QAbstractListModel
|
||||
messages*: seq[Message]
|
||||
status: Status
|
||||
id: string
|
||||
id*: string
|
||||
messageIndex: Table[string, int]
|
||||
messageReactions*: Table[string, string]
|
||||
timedoutMessages: HashSet[string]
|
||||
|
@ -281,3 +281,7 @@ QtObject:
|
|||
m.localName = c.localNickname
|
||||
|
||||
self.dataChanged(topLeft, bottomRight, @[ChatMessageRoles.Username.int])
|
||||
|
||||
|
||||
proc getID*(self: ChatMessageList):string {.slot.} =
|
||||
self.id
|
|
@ -10,7 +10,7 @@ logScope:
|
|||
|
||||
QtObject:
|
||||
type ReactionView* = ref object of QObject
|
||||
messageList: ptr Table[string, ChatMessageList]
|
||||
messageList: ptr OrderedTable[string, ChatMessageList]
|
||||
activeChannel: ChatItemView
|
||||
status: Status
|
||||
pubKey*: string
|
||||
|
@ -21,7 +21,7 @@ QtObject:
|
|||
proc delete*(self: ReactionView) =
|
||||
self.QObject.delete
|
||||
|
||||
proc newReactionView*(status: Status, messageList: ptr Table[string, ChatMessageList], activeChannel: ChatItemView): ReactionView =
|
||||
proc newReactionView*(status: Status, messageList: ptr OrderedTable[string, ChatMessageList], activeChannel: ChatItemView): ReactionView =
|
||||
new(result, delete)
|
||||
result = ReactionView()
|
||||
result.messageList = messageList
|
||||
|
|
|
@ -12,7 +12,6 @@ import "../Wallet"
|
|||
|
||||
StackLayout {
|
||||
id: chatColumnLayout
|
||||
property alias chatMessages: chatMessages
|
||||
|
||||
property int chatGroupsListViewCount: 0
|
||||
|
||||
|
@ -189,10 +188,26 @@ StackLayout {
|
|||
Layout.fillHeight: true
|
||||
Layout.alignment: Qt.AlignLeft | Qt.AlignTop
|
||||
spacing: 0
|
||||
ChatMessages {
|
||||
id: chatMessages
|
||||
messageList: chatsModel.messageList
|
||||
|
||||
Connections {
|
||||
target: chatsModel
|
||||
onActiveChannelChanged: {
|
||||
stackLayoutChatMessages.currentIndex = chatsModel.getMessageListIndex(chatsModel.activeChannelIndex)
|
||||
}
|
||||
}
|
||||
|
||||
StackLayout {
|
||||
id: stackLayoutChatMessages
|
||||
Repeater {
|
||||
model: chatsModel
|
||||
ChatMessages {
|
||||
id: chatMessages
|
||||
messageList: model.messages
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
StatusImageModal {
|
||||
|
|
|
@ -137,10 +137,6 @@ ScrollView {
|
|||
loadingMessages = false;
|
||||
}
|
||||
|
||||
onActiveChannelChanged: {
|
||||
Qt.callLater(chatLogView.scrollToBottom.bind(this, true))
|
||||
}
|
||||
|
||||
onSendingMessage: {
|
||||
chatLogView.scrollToBottom(true)
|
||||
}
|
||||
|
|
|
@ -423,10 +423,6 @@ RowLayout {
|
|||
|
||||
timelineLayoutContainer.active = this.children[currentIndex] == timelineLayoutContainer
|
||||
|
||||
if(this.children[currentIndex] === chatLayoutContainer){
|
||||
chatLayoutContainer.chatColumn.chatMessages.chatLogView.scrollToBottom(true);
|
||||
}
|
||||
|
||||
if(this.children[currentIndex] === walletLayoutContainer){
|
||||
walletLayoutContainer.showSigningPhrasePopup();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue