ui(chat): don't repeat user info for the same user

Closes #129
This commit is contained in:
Pascal Precht 2020-05-28 12:21:29 +02:00 committed by Iuri Matias
parent a2e255e72c
commit 37cce5b9f3
3 changed files with 15 additions and 4 deletions

View File

@ -8,6 +8,7 @@ type
Timestamp = UserRole + 3
Identicon = UserRole + 4
IsCurrentUser = UserRole + 5
RepeatMessageInfo = UserRole + 6
QtObject:
type
@ -37,6 +38,7 @@ QtObject:
if index.row < 0 or index.row >= self.messages.len:
return
let message = self.messages[index.row]
let repeatMessageInfo = (index.row == 0) or message.fromAuthor != self.messages[index.row - 1].fromAuthor
let chatMessageRole = role.ChatMessageRoles
case chatMessageRole:
of ChatMessageRoles.UserName: result = newQVariant(message.userName)
@ -44,6 +46,7 @@ QtObject:
of ChatMessageRoles.Timestamp: result = newQVariant(message.timestamp)
of ChatMessageRoles.Identicon: result = newQVariant(message.identicon)
of ChatMessageRoles.IsCurrentUser: result = newQVariant(message.isCurrentUser)
of ChatMessageRoles.RepeatMessageInfo: result = newQVariant(repeatMessageInfo)
method roleNames(self: ChatMessageList): Table[int, string] =
{
@ -51,10 +54,12 @@ QtObject:
ChatMessageRoles.Message.int:"message",
ChatMessageRoles.Timestamp.int:"timestamp",
ChatMessageRoles.Identicon.int:"identicon",
ChatMessageRoles.IsCurrentUser.int:"isCurrentUser"
ChatMessageRoles.IsCurrentUser.int:"isCurrentUser",
ChatMessageRoles.RepeatMessageInfo.int:"repeatMessageInfo"
}.toTable
proc add*(self: ChatMessageList, message: ChatMessage) =
self.beginInsertRows(newQModelIndex(), self.messages.len, self.messages.len)
self.messages.add(message)
self.endInsertRows()

View File

@ -4,6 +4,7 @@ import ../../signals/types
type ChatMessage* = ref object
userName*: string
message*: string
fromAuthor*: string
timestamp*: string
identicon*: string
isCurrentUser*: bool
@ -15,6 +16,7 @@ proc newChatMessage*(): ChatMessage =
result = ChatMessage()
result.userName = ""
result.message = ""
result.fromAuthor = ""
result.timestamp = "0"
result.identicon = ""
result.isCurrentUser = false
@ -31,6 +33,7 @@ proc toChatMessage*(payload: JsonNode): ChatMessage =
proc toChatMessage*(message: Message): ChatMessage =
result = ChatMessage(
userName: message.alias,
fromAuthor: message.fromAuthor,
message: message.text,
timestamp: message.timestamp,
identicon: message.identicon,

View File

@ -8,7 +8,7 @@ import "../../../../imports"
Rectangle {
id: chatBox
height: 60 + chatText.height
height: repeatMessageInfo ? 60 + chatText.height : 5 + chatText.height
color: "#00000000"
border.color: "#00000000"
Layout.alignment: Qt.AlignLeft | Qt.AlignTop
@ -27,6 +27,7 @@ Rectangle {
anchors.topMargin: Theme.padding
fillMode: Image.PreserveAspectFit
source: identicon
visible: repeatMessageInfo
}
TextEdit {
@ -43,6 +44,7 @@ Rectangle {
readOnly: true
wrapMode: Text.WordWrap
selectByMouse: true
visible: repeatMessageInfo
}
TextEdit {
@ -55,7 +57,7 @@ Rectangle {
anchors.rightMargin: !isCurrentUser ? 60 : 0
anchors.left: !isCurrentUser ? chatName.left : parent.left
anchors.leftMargin: !isCurrentUser ? 0 : 60
anchors.top: chatName.bottom
anchors.top: repeatMessageInfo ? chatName.bottom : parent.top
anchors.topMargin: Theme.padding
font.pixelSize: 14
readOnly: true
@ -77,5 +79,6 @@ Rectangle {
font.pixelSize: 10
readOnly: true
selectByMouse: true
visible: repeatMessageInfo
}
}