parent
a2e255e72c
commit
37cce5b9f3
|
@ -8,6 +8,7 @@ type
|
||||||
Timestamp = UserRole + 3
|
Timestamp = UserRole + 3
|
||||||
Identicon = UserRole + 4
|
Identicon = UserRole + 4
|
||||||
IsCurrentUser = UserRole + 5
|
IsCurrentUser = UserRole + 5
|
||||||
|
RepeatMessageInfo = UserRole + 6
|
||||||
|
|
||||||
QtObject:
|
QtObject:
|
||||||
type
|
type
|
||||||
|
@ -37,6 +38,7 @@ QtObject:
|
||||||
if index.row < 0 or index.row >= self.messages.len:
|
if index.row < 0 or index.row >= self.messages.len:
|
||||||
return
|
return
|
||||||
let message = self.messages[index.row]
|
let message = self.messages[index.row]
|
||||||
|
let repeatMessageInfo = (index.row == 0) or message.fromAuthor != self.messages[index.row - 1].fromAuthor
|
||||||
let chatMessageRole = role.ChatMessageRoles
|
let chatMessageRole = role.ChatMessageRoles
|
||||||
case chatMessageRole:
|
case chatMessageRole:
|
||||||
of ChatMessageRoles.UserName: result = newQVariant(message.userName)
|
of ChatMessageRoles.UserName: result = newQVariant(message.userName)
|
||||||
|
@ -44,6 +46,7 @@ QtObject:
|
||||||
of ChatMessageRoles.Timestamp: result = newQVariant(message.timestamp)
|
of ChatMessageRoles.Timestamp: result = newQVariant(message.timestamp)
|
||||||
of ChatMessageRoles.Identicon: result = newQVariant(message.identicon)
|
of ChatMessageRoles.Identicon: result = newQVariant(message.identicon)
|
||||||
of ChatMessageRoles.IsCurrentUser: result = newQVariant(message.isCurrentUser)
|
of ChatMessageRoles.IsCurrentUser: result = newQVariant(message.isCurrentUser)
|
||||||
|
of ChatMessageRoles.RepeatMessageInfo: result = newQVariant(repeatMessageInfo)
|
||||||
|
|
||||||
method roleNames(self: ChatMessageList): Table[int, string] =
|
method roleNames(self: ChatMessageList): Table[int, string] =
|
||||||
{
|
{
|
||||||
|
@ -51,10 +54,12 @@ QtObject:
|
||||||
ChatMessageRoles.Message.int:"message",
|
ChatMessageRoles.Message.int:"message",
|
||||||
ChatMessageRoles.Timestamp.int:"timestamp",
|
ChatMessageRoles.Timestamp.int:"timestamp",
|
||||||
ChatMessageRoles.Identicon.int:"identicon",
|
ChatMessageRoles.Identicon.int:"identicon",
|
||||||
ChatMessageRoles.IsCurrentUser.int:"isCurrentUser"
|
ChatMessageRoles.IsCurrentUser.int:"isCurrentUser",
|
||||||
|
ChatMessageRoles.RepeatMessageInfo.int:"repeatMessageInfo"
|
||||||
}.toTable
|
}.toTable
|
||||||
|
|
||||||
proc add*(self: ChatMessageList, message: ChatMessage) =
|
proc add*(self: ChatMessageList, message: ChatMessage) =
|
||||||
self.beginInsertRows(newQModelIndex(), self.messages.len, self.messages.len)
|
self.beginInsertRows(newQModelIndex(), self.messages.len, self.messages.len)
|
||||||
self.messages.add(message)
|
self.messages.add(message)
|
||||||
self.endInsertRows()
|
self.endInsertRows()
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import ../../signals/types
|
||||||
type ChatMessage* = ref object
|
type ChatMessage* = ref object
|
||||||
userName*: string
|
userName*: string
|
||||||
message*: string
|
message*: string
|
||||||
|
fromAuthor*: string
|
||||||
timestamp*: string
|
timestamp*: string
|
||||||
identicon*: string
|
identicon*: string
|
||||||
isCurrentUser*: bool
|
isCurrentUser*: bool
|
||||||
|
@ -15,6 +16,7 @@ proc newChatMessage*(): ChatMessage =
|
||||||
result = ChatMessage()
|
result = ChatMessage()
|
||||||
result.userName = ""
|
result.userName = ""
|
||||||
result.message = ""
|
result.message = ""
|
||||||
|
result.fromAuthor = ""
|
||||||
result.timestamp = "0"
|
result.timestamp = "0"
|
||||||
result.identicon = ""
|
result.identicon = ""
|
||||||
result.isCurrentUser = false
|
result.isCurrentUser = false
|
||||||
|
@ -31,6 +33,7 @@ proc toChatMessage*(payload: JsonNode): ChatMessage =
|
||||||
proc toChatMessage*(message: Message): ChatMessage =
|
proc toChatMessage*(message: Message): ChatMessage =
|
||||||
result = ChatMessage(
|
result = ChatMessage(
|
||||||
userName: message.alias,
|
userName: message.alias,
|
||||||
|
fromAuthor: message.fromAuthor,
|
||||||
message: message.text,
|
message: message.text,
|
||||||
timestamp: message.timestamp,
|
timestamp: message.timestamp,
|
||||||
identicon: message.identicon,
|
identicon: message.identicon,
|
||||||
|
|
|
@ -8,7 +8,7 @@ import "../../../../imports"
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: chatBox
|
id: chatBox
|
||||||
height: 60 + chatText.height
|
height: repeatMessageInfo ? 60 + chatText.height : 5 + chatText.height
|
||||||
color: "#00000000"
|
color: "#00000000"
|
||||||
border.color: "#00000000"
|
border.color: "#00000000"
|
||||||
Layout.alignment: Qt.AlignLeft | Qt.AlignTop
|
Layout.alignment: Qt.AlignLeft | Qt.AlignTop
|
||||||
|
@ -27,6 +27,7 @@ Rectangle {
|
||||||
anchors.topMargin: Theme.padding
|
anchors.topMargin: Theme.padding
|
||||||
fillMode: Image.PreserveAspectFit
|
fillMode: Image.PreserveAspectFit
|
||||||
source: identicon
|
source: identicon
|
||||||
|
visible: repeatMessageInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
TextEdit {
|
TextEdit {
|
||||||
|
@ -43,6 +44,7 @@ Rectangle {
|
||||||
readOnly: true
|
readOnly: true
|
||||||
wrapMode: Text.WordWrap
|
wrapMode: Text.WordWrap
|
||||||
selectByMouse: true
|
selectByMouse: true
|
||||||
|
visible: repeatMessageInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
TextEdit {
|
TextEdit {
|
||||||
|
@ -55,7 +57,7 @@ Rectangle {
|
||||||
anchors.rightMargin: !isCurrentUser ? 60 : 0
|
anchors.rightMargin: !isCurrentUser ? 60 : 0
|
||||||
anchors.left: !isCurrentUser ? chatName.left : parent.left
|
anchors.left: !isCurrentUser ? chatName.left : parent.left
|
||||||
anchors.leftMargin: !isCurrentUser ? 0 : 60
|
anchors.leftMargin: !isCurrentUser ? 0 : 60
|
||||||
anchors.top: chatName.bottom
|
anchors.top: repeatMessageInfo ? chatName.bottom : parent.top
|
||||||
anchors.topMargin: Theme.padding
|
anchors.topMargin: Theme.padding
|
||||||
font.pixelSize: 14
|
font.pixelSize: 14
|
||||||
readOnly: true
|
readOnly: true
|
||||||
|
@ -77,5 +79,6 @@ Rectangle {
|
||||||
font.pixelSize: 10
|
font.pixelSize: 10
|
||||||
readOnly: true
|
readOnly: true
|
||||||
selectByMouse: true
|
selectByMouse: true
|
||||||
|
visible: repeatMessageInfo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue