show identifier as the first message of chat view

This commit is contained in:
Richard Ramos 2020-06-08 13:29:28 -04:00 committed by RichΛrd
parent 9d75f6f552
commit b5b02cfd57
8 changed files with 107 additions and 13 deletions

View File

@ -70,7 +70,7 @@ proc init*(self: ChatController) =
proc handleMessage(self: ChatController, data: MessageSignal) =
for c in data.chats:
self.view.updateChat(c.toChatItem())
self.view.updateChat(c.toChatItem())
self.view.pushMessages(data.messages)
proc handleDiscoverySummary(self: ChatController, data: DiscoverySummarySignal) =

View File

@ -76,7 +76,7 @@ QtObject:
proc upsertChannel(self: ChatsView, channel: string) =
if not self.messageList.hasKey(channel):
self.messageList[channel] = newChatMessageList()
self.messageList[channel] = newChatMessageList(channel)
proc pushMessage*(self:ChatsView, message: ChatMessage) =
self.upsertChannel(message.chatId)

View File

@ -12,6 +12,7 @@ type
Sticker = UserRole + 7
FromAuthor = UserRole + 8
Clock = UserRole + 9
ChatId = UserRole + 10
QtObject:
type
ChatMessageList* = ref object of QAbstractListModel
@ -26,9 +27,15 @@ QtObject:
proc setup(self: ChatMessageList) =
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)
result.messages = @[]
result.messages = @[result.chatIdentifier(chatId)]
result.setup
method rowCount(self: ChatMessageList, index: QModelIndex = nil): int =
@ -51,6 +58,7 @@ QtObject:
of ChatMessageRoles.ContentType: result = newQVariant(message.contentType)
of ChatMessageRoles.Sticker: result = newQVariant(message.sticker)
of ChatMessageRoles.FromAuthor: result = newQVariant(message.fromAuthor)
of ChatMessageRoles.ChatId: result = newQVariant(message.chatId)
method roleNames(self: ChatMessageList): Table[int, string] =
{
@ -62,7 +70,8 @@ QtObject:
ChatMessageRoles.IsCurrentUser.int:"isCurrentUser",
ChatMessageRoles.ContentType.int:"contentType",
ChatMessageRoles.Sticker.int:"sticker",
ChatMessageRoles.FromAuthor.int:"fromAuthor"
ChatMessageRoles.FromAuthor.int:"fromAuthor",
ChatMessageRoles.ChatId.int:"chatId"
}.toTable
proc add*(self: ChatMessageList, message: ChatMessage) =

View File

@ -36,7 +36,7 @@ proc toChat*(jsonChat: JsonNode): Chat =
proc toMessage*(jsonMsg: JsonNode): Message =
result = Message(
alias: jsonMsg{"alias"}.getStr,
chatId: jsonMsg{"chatId"}.getStr,
chatId: jsonMsg{"localChatId"}.getStr,
clock: jsonMsg{"clock"}.getInt,
contentType: jsonMsg{"contentType"}.getInt,
ensName: jsonMsg{"ensName"}.getStr,

View File

@ -32,13 +32,14 @@ proc newChatMessage*(): ChatMessage =
proc toChatMessage*(payload: JsonNode): ChatMessage =
result = ChatMessage(
chatId: payload["chatId"].str,
chatId: payload["localChatId"].str,
fromAuthor: payload["from"].getStr,
userName: payload["alias"].str,
message: payload["text"].str,
timestamp: $payload["timestamp"],
clock: payload["clock"].getInt,
identicon: payload["identicon"].str,
isCurrentUser: false,
isCurrentUser: false, # TODO: compare the "from" to the current user
contentType: payload["contentType"].getInt,
sticker: "" # TODO: implement when implementing stickers from user
)

View File

@ -37,7 +37,7 @@ ScrollView {
Qt.callLater( chatLogView.positionViewAtEnd )
}
model: messageListDelegate
section.property: "userName"
section.property: "fromAuthor"
section.criteria: ViewSection.FullString
}
@ -88,8 +88,10 @@ ScrollView {
}
}
model: messageList
delegate: Message {
Message {
id: msgDelegate
chatId: model.chatId
userName: model.userName
message: model.message
identicon: model.identicon

View File

@ -15,16 +15,96 @@ Item {
property int timestamp: 1234567
property string sticker: "Qme8vJtyrEHxABcSVGPF95PtozDgUyfr1xGjePmFdZgk9v"
property int contentType: 1 // constants don't work in default props
property string chatId: "chatId"
property string authorCurrentMsg: "authorCurrentMsg"
property string authorPrevMsg: "authorPrevMsg"
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 {
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 {
id: chatImage
width: 36
@ -35,7 +115,7 @@ Item {
anchors.top: parent.top
fillMode: Image.PreserveAspectFit
source: identicon
visible: authorCurrentMsg != authorPrevMsg && !isCurrentUser
visible: contentType > -1 && authorCurrentMsg != authorPrevMsg && !isCurrentUser
MouseArea {
cursorShape: Qt.PointingHandCursor
@ -58,7 +138,7 @@ Item {
readOnly: true
wrapMode: Text.WordWrap
selectByMouse: true
visible: authorCurrentMsg != authorPrevMsg && !isCurrentUser
visible: contentType > -1 && authorCurrentMsg != authorPrevMsg && !isCurrentUser
}
Rectangle {
@ -77,6 +157,7 @@ Item {
anchors.rightMargin: !isCurrentUser ? 0 : Theme.padding
anchors.top: authorCurrentMsg != authorPrevMsg && !isCurrentUser ? chatImage.top : parent.top
anchors.topMargin: 0
visible: contentType > -1
// Thi`s rectangle's only job is to mask the corner to make it less rounded... yep
Rectangle {

View File

@ -7,6 +7,7 @@ QtObject {
readonly property int chatTypePublic: 2
readonly property int chatTypePrivateGroupChat: 3
readonly property int chatIdentifier: -1
readonly property int messageType: 1
readonly property int stickerType: 2