show identifier as the first message of chat view
This commit is contained in:
parent
9d75f6f552
commit
b5b02cfd57
|
@ -70,7 +70,7 @@ proc init*(self: ChatController) =
|
||||||
|
|
||||||
proc handleMessage(self: ChatController, data: MessageSignal) =
|
proc handleMessage(self: ChatController, data: MessageSignal) =
|
||||||
for c in data.chats:
|
for c in data.chats:
|
||||||
self.view.updateChat(c.toChatItem())
|
self.view.updateChat(c.toChatItem())
|
||||||
self.view.pushMessages(data.messages)
|
self.view.pushMessages(data.messages)
|
||||||
|
|
||||||
proc handleDiscoverySummary(self: ChatController, data: DiscoverySummarySignal) =
|
proc handleDiscoverySummary(self: ChatController, data: DiscoverySummarySignal) =
|
||||||
|
|
|
@ -76,7 +76,7 @@ QtObject:
|
||||||
|
|
||||||
proc upsertChannel(self: ChatsView, channel: string) =
|
proc upsertChannel(self: ChatsView, channel: string) =
|
||||||
if not self.messageList.hasKey(channel):
|
if not self.messageList.hasKey(channel):
|
||||||
self.messageList[channel] = newChatMessageList()
|
self.messageList[channel] = newChatMessageList(channel)
|
||||||
|
|
||||||
proc pushMessage*(self:ChatsView, message: ChatMessage) =
|
proc pushMessage*(self:ChatsView, message: ChatMessage) =
|
||||||
self.upsertChannel(message.chatId)
|
self.upsertChannel(message.chatId)
|
||||||
|
|
|
@ -12,6 +12,7 @@ type
|
||||||
Sticker = UserRole + 7
|
Sticker = UserRole + 7
|
||||||
FromAuthor = UserRole + 8
|
FromAuthor = UserRole + 8
|
||||||
Clock = UserRole + 9
|
Clock = UserRole + 9
|
||||||
|
ChatId = UserRole + 10
|
||||||
QtObject:
|
QtObject:
|
||||||
type
|
type
|
||||||
ChatMessageList* = ref object of QAbstractListModel
|
ChatMessageList* = ref object of QAbstractListModel
|
||||||
|
@ -26,9 +27,15 @@ QtObject:
|
||||||
proc setup(self: ChatMessageList) =
|
proc setup(self: ChatMessageList) =
|
||||||
self.QAbstractListModel.setup
|
self.QAbstractListModel.setup
|
||||||
|
|
||||||
proc newChatMessageList*(): ChatMessageList =
|
proc chatIdentifier(self: ChatMessageList, chatId:string): ChatMessage =
|
||||||
|
result = newChatMessage();
|
||||||
|
result.contentType = -1;
|
||||||
|
result.chatId = chatId
|
||||||
|
|
||||||
|
|
||||||
|
proc newChatMessageList*(chatId: string): ChatMessageList =
|
||||||
new(result, delete)
|
new(result, delete)
|
||||||
result.messages = @[]
|
result.messages = @[result.chatIdentifier(chatId)]
|
||||||
result.setup
|
result.setup
|
||||||
|
|
||||||
method rowCount(self: ChatMessageList, index: QModelIndex = nil): int =
|
method rowCount(self: ChatMessageList, index: QModelIndex = nil): int =
|
||||||
|
@ -51,6 +58,7 @@ QtObject:
|
||||||
of ChatMessageRoles.ContentType: result = newQVariant(message.contentType)
|
of ChatMessageRoles.ContentType: result = newQVariant(message.contentType)
|
||||||
of ChatMessageRoles.Sticker: result = newQVariant(message.sticker)
|
of ChatMessageRoles.Sticker: result = newQVariant(message.sticker)
|
||||||
of ChatMessageRoles.FromAuthor: result = newQVariant(message.fromAuthor)
|
of ChatMessageRoles.FromAuthor: result = newQVariant(message.fromAuthor)
|
||||||
|
of ChatMessageRoles.ChatId: result = newQVariant(message.chatId)
|
||||||
|
|
||||||
method roleNames(self: ChatMessageList): Table[int, string] =
|
method roleNames(self: ChatMessageList): Table[int, string] =
|
||||||
{
|
{
|
||||||
|
@ -62,7 +70,8 @@ QtObject:
|
||||||
ChatMessageRoles.IsCurrentUser.int:"isCurrentUser",
|
ChatMessageRoles.IsCurrentUser.int:"isCurrentUser",
|
||||||
ChatMessageRoles.ContentType.int:"contentType",
|
ChatMessageRoles.ContentType.int:"contentType",
|
||||||
ChatMessageRoles.Sticker.int:"sticker",
|
ChatMessageRoles.Sticker.int:"sticker",
|
||||||
ChatMessageRoles.FromAuthor.int:"fromAuthor"
|
ChatMessageRoles.FromAuthor.int:"fromAuthor",
|
||||||
|
ChatMessageRoles.ChatId.int:"chatId"
|
||||||
}.toTable
|
}.toTable
|
||||||
|
|
||||||
proc add*(self: ChatMessageList, message: ChatMessage) =
|
proc add*(self: ChatMessageList, message: ChatMessage) =
|
||||||
|
|
|
@ -36,7 +36,7 @@ proc toChat*(jsonChat: JsonNode): Chat =
|
||||||
proc toMessage*(jsonMsg: JsonNode): Message =
|
proc toMessage*(jsonMsg: JsonNode): Message =
|
||||||
result = Message(
|
result = Message(
|
||||||
alias: jsonMsg{"alias"}.getStr,
|
alias: jsonMsg{"alias"}.getStr,
|
||||||
chatId: jsonMsg{"chatId"}.getStr,
|
chatId: jsonMsg{"localChatId"}.getStr,
|
||||||
clock: jsonMsg{"clock"}.getInt,
|
clock: jsonMsg{"clock"}.getInt,
|
||||||
contentType: jsonMsg{"contentType"}.getInt,
|
contentType: jsonMsg{"contentType"}.getInt,
|
||||||
ensName: jsonMsg{"ensName"}.getStr,
|
ensName: jsonMsg{"ensName"}.getStr,
|
||||||
|
|
|
@ -32,13 +32,14 @@ proc newChatMessage*(): ChatMessage =
|
||||||
|
|
||||||
proc toChatMessage*(payload: JsonNode): ChatMessage =
|
proc toChatMessage*(payload: JsonNode): ChatMessage =
|
||||||
result = ChatMessage(
|
result = ChatMessage(
|
||||||
chatId: payload["chatId"].str,
|
chatId: payload["localChatId"].str,
|
||||||
|
fromAuthor: payload["from"].getStr,
|
||||||
userName: payload["alias"].str,
|
userName: payload["alias"].str,
|
||||||
message: payload["text"].str,
|
message: payload["text"].str,
|
||||||
timestamp: $payload["timestamp"],
|
timestamp: $payload["timestamp"],
|
||||||
clock: payload["clock"].getInt,
|
clock: payload["clock"].getInt,
|
||||||
identicon: payload["identicon"].str,
|
identicon: payload["identicon"].str,
|
||||||
isCurrentUser: false,
|
isCurrentUser: false, # TODO: compare the "from" to the current user
|
||||||
contentType: payload["contentType"].getInt,
|
contentType: payload["contentType"].getInt,
|
||||||
sticker: "" # TODO: implement when implementing stickers from user
|
sticker: "" # TODO: implement when implementing stickers from user
|
||||||
)
|
)
|
||||||
|
|
|
@ -37,7 +37,7 @@ ScrollView {
|
||||||
Qt.callLater( chatLogView.positionViewAtEnd )
|
Qt.callLater( chatLogView.positionViewAtEnd )
|
||||||
}
|
}
|
||||||
model: messageListDelegate
|
model: messageListDelegate
|
||||||
section.property: "userName"
|
section.property: "fromAuthor"
|
||||||
section.criteria: ViewSection.FullString
|
section.criteria: ViewSection.FullString
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,8 +88,10 @@ ScrollView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
model: messageList
|
model: messageList
|
||||||
delegate: Message {
|
|
||||||
|
Message {
|
||||||
id: msgDelegate
|
id: msgDelegate
|
||||||
|
chatId: model.chatId
|
||||||
userName: model.userName
|
userName: model.userName
|
||||||
message: model.message
|
message: model.message
|
||||||
identicon: model.identicon
|
identicon: model.identicon
|
||||||
|
|
|
@ -15,16 +15,96 @@ Item {
|
||||||
property int timestamp: 1234567
|
property int timestamp: 1234567
|
||||||
property string sticker: "Qme8vJtyrEHxABcSVGPF95PtozDgUyfr1xGjePmFdZgk9v"
|
property string sticker: "Qme8vJtyrEHxABcSVGPF95PtozDgUyfr1xGjePmFdZgk9v"
|
||||||
property int contentType: 1 // constants don't work in default props
|
property int contentType: 1 // constants don't work in default props
|
||||||
|
property string chatId: "chatId"
|
||||||
|
|
||||||
property string authorCurrentMsg: "authorCurrentMsg"
|
property string authorCurrentMsg: "authorCurrentMsg"
|
||||||
property string authorPrevMsg: "authorPrevMsg"
|
property string authorPrevMsg: "authorPrevMsg"
|
||||||
|
|
||||||
width: parent.width
|
width: parent.width
|
||||||
height: contentType == Constants.stickerType ? stickerId.height + 50 : (isCurrentUser || (!isCurrentUser && authorCurrentMsg == authorPrevMsg) ? chatBox.height : 24 + chatBox.height)
|
height: {
|
||||||
|
switch(contentType){
|
||||||
|
case Constants.chatIdentifier:
|
||||||
|
return 196;
|
||||||
|
case Constants.stickerType:
|
||||||
|
return stickerId.height + 50
|
||||||
|
default:
|
||||||
|
return (isCurrentUser || (!isCurrentUser && authorCurrentMsg == authorPrevMsg) ? chatBox.height : 24 + chatBox.height)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ProfilePopup {
|
ProfilePopup {
|
||||||
id: profilePopup
|
id: profilePopup
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Item {
|
||||||
|
id: channelIdentifier
|
||||||
|
visible: authorCurrentMsg == ""
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
anchors.topMargin: 20
|
||||||
|
anchors.top: parent.top
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
id: circleId
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
width: 120
|
||||||
|
height: 120
|
||||||
|
radius: 120
|
||||||
|
border.width: chatsModel.activeChannel.chatType == Constants.chatTypeOneToOne ? 2 : 0
|
||||||
|
border.color: Theme.grey
|
||||||
|
color: {
|
||||||
|
const color = chatsModel.getChannelColor(chatId)
|
||||||
|
if (chatsModel.activeChannel.chatType == Constants.chatTypeOneToOne || !color) {
|
||||||
|
return Theme.transparent
|
||||||
|
}
|
||||||
|
return color
|
||||||
|
}
|
||||||
|
|
||||||
|
Image {
|
||||||
|
visible: chatsModel.activeChannel.chatType == Constants.chatTypeOneToOne
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
width: 120
|
||||||
|
height: 120
|
||||||
|
fillMode: Image.PreserveAspectFit
|
||||||
|
source: chatsModel.activeChannel.identicon
|
||||||
|
}
|
||||||
|
|
||||||
|
Text {
|
||||||
|
visible: chatsModel.activeChannel.chatType != Constants.chatTypeOneToOne
|
||||||
|
text: {
|
||||||
|
if (chatsModel.activeChannel.chatType == Constants.chatTypeOneToOne) {
|
||||||
|
return chatsModel.activeChannel.name;
|
||||||
|
} else {
|
||||||
|
return (chatId.charAt(0) == "#" ? chatId.charAt(1) : chatId.charAt(0)).toUpperCase();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
opacity: 0.7
|
||||||
|
font.weight: Font.Bold
|
||||||
|
font.pixelSize: 51
|
||||||
|
color: "white"
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Text {
|
||||||
|
wrapMode: Text.Wrap
|
||||||
|
text: {
|
||||||
|
if (chatsModel.activeChannel.chatType == Constants.chatTypeOneToOne) {
|
||||||
|
return chatsModel.activeChannel.name;
|
||||||
|
} else {
|
||||||
|
return "#" + chatId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
font.weight: Font.Bold
|
||||||
|
font.pixelSize: 22
|
||||||
|
color: Theme.black
|
||||||
|
anchors.top: circleId.bottom
|
||||||
|
anchors.topMargin: 16
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Image {
|
Image {
|
||||||
id: chatImage
|
id: chatImage
|
||||||
width: 36
|
width: 36
|
||||||
|
@ -35,7 +115,7 @@ Item {
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
fillMode: Image.PreserveAspectFit
|
fillMode: Image.PreserveAspectFit
|
||||||
source: identicon
|
source: identicon
|
||||||
visible: authorCurrentMsg != authorPrevMsg && !isCurrentUser
|
visible: contentType > -1 && authorCurrentMsg != authorPrevMsg && !isCurrentUser
|
||||||
|
|
||||||
MouseArea {
|
MouseArea {
|
||||||
cursorShape: Qt.PointingHandCursor
|
cursorShape: Qt.PointingHandCursor
|
||||||
|
@ -58,7 +138,7 @@ Item {
|
||||||
readOnly: true
|
readOnly: true
|
||||||
wrapMode: Text.WordWrap
|
wrapMode: Text.WordWrap
|
||||||
selectByMouse: true
|
selectByMouse: true
|
||||||
visible: authorCurrentMsg != authorPrevMsg && !isCurrentUser
|
visible: contentType > -1 && authorCurrentMsg != authorPrevMsg && !isCurrentUser
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
|
@ -77,6 +157,7 @@ Item {
|
||||||
anchors.rightMargin: !isCurrentUser ? 0 : Theme.padding
|
anchors.rightMargin: !isCurrentUser ? 0 : Theme.padding
|
||||||
anchors.top: authorCurrentMsg != authorPrevMsg && !isCurrentUser ? chatImage.top : parent.top
|
anchors.top: authorCurrentMsg != authorPrevMsg && !isCurrentUser ? chatImage.top : parent.top
|
||||||
anchors.topMargin: 0
|
anchors.topMargin: 0
|
||||||
|
visible: contentType > -1
|
||||||
|
|
||||||
// Thi`s rectangle's only job is to mask the corner to make it less rounded... yep
|
// Thi`s rectangle's only job is to mask the corner to make it less rounded... yep
|
||||||
Rectangle {
|
Rectangle {
|
||||||
|
|
|
@ -7,6 +7,7 @@ QtObject {
|
||||||
readonly property int chatTypePublic: 2
|
readonly property int chatTypePublic: 2
|
||||||
readonly property int chatTypePrivateGroupChat: 3
|
readonly property int chatTypePrivateGroupChat: 3
|
||||||
|
|
||||||
|
readonly property int chatIdentifier: -1
|
||||||
readonly property int messageType: 1
|
readonly property int messageType: 1
|
||||||
readonly property int stickerType: 2
|
readonly property int stickerType: 2
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue