display identicons; display correct details for the user own messages
This commit is contained in:
parent
6a4c50fe9c
commit
5cc31ae28d
|
@ -1,4 +1,5 @@
|
||||||
import NimQml
|
import NimQml
|
||||||
|
import json
|
||||||
import ../../status/chat as status_chat
|
import ../../status/chat as status_chat
|
||||||
import view
|
import view
|
||||||
import messages
|
import messages
|
||||||
|
@ -7,14 +8,17 @@ import ../../status/utils
|
||||||
|
|
||||||
var sendMessage = proc (view: ChatsView, chatId: string, msg: string): string =
|
var sendMessage = proc (view: ChatsView, chatId: string, msg: string): string =
|
||||||
echo "sending public message!"
|
echo "sending public message!"
|
||||||
let chatMessage = newChatMessage()
|
var sentMessage = status_chat.sendChatMessage(chatId, msg)
|
||||||
chatMessage.userName = "me" #TODO get users username
|
var parsedMessage = parseJson(sentMessage)["result"]["chats"][0]["lastMessage"]
|
||||||
chatMessage.message = msg
|
|
||||||
chatMessage.timestamp = "0" #TODO convert to date/time?
|
|
||||||
chatMessage.isCurrentUser = true
|
|
||||||
|
|
||||||
|
let chatMessage = newChatMessage()
|
||||||
|
chatMessage.userName = parsedMessage["alias"].str
|
||||||
|
chatMessage.message = msg
|
||||||
|
chatMessage.timestamp = $parsedMessage["timestamp"]
|
||||||
|
chatMessage.identicon = parsedMessage["identicon"].str
|
||||||
|
chatMessage.isCurrentUser = true
|
||||||
view.pushMessage(chatMessage)
|
view.pushMessage(chatMessage)
|
||||||
status_chat.sendChatMessage(chatId, msg)
|
sentMessage
|
||||||
|
|
||||||
type ChatController* = ref object of SignalSubscriber
|
type ChatController* = ref object of SignalSubscriber
|
||||||
view*: ChatsView
|
view*: ChatsView
|
||||||
|
@ -57,5 +61,6 @@ method onSignal(self: ChatController, data: Signal) =
|
||||||
chatMessage.userName = message.alias
|
chatMessage.userName = message.alias
|
||||||
chatMessage.message = message.text
|
chatMessage.message = message.text
|
||||||
chatMessage.timestamp = message.timestamp #TODO convert to date/time?
|
chatMessage.timestamp = message.timestamp #TODO convert to date/time?
|
||||||
|
chatMessage.identicon = message.identicon
|
||||||
chatMessage.isCurrentUser = message.isCurrentUser #TODO: Determine who originated the message
|
chatMessage.isCurrentUser = message.isCurrentUser #TODO: Determine who originated the message
|
||||||
self.view.pushMessage(chatMessage)
|
self.view.pushMessage(chatMessage)
|
||||||
|
|
|
@ -5,7 +5,8 @@ type
|
||||||
UserName = UserRole + 1,
|
UserName = UserRole + 1,
|
||||||
Message = UserRole + 2,
|
Message = UserRole + 2,
|
||||||
Timestamp = UserRole + 3
|
Timestamp = UserRole + 3
|
||||||
IsCurrentUser = UserRole + 4
|
Identicon = UserRole + 4
|
||||||
|
IsCurrentUser = UserRole + 5
|
||||||
|
|
||||||
QtObject:
|
QtObject:
|
||||||
type
|
type
|
||||||
|
@ -40,6 +41,7 @@ QtObject:
|
||||||
of ChatMessageRoles.UserName: result = newQVariant(message.userName)
|
of ChatMessageRoles.UserName: result = newQVariant(message.userName)
|
||||||
of ChatMessageRoles.Message: result = newQVariant(message.message)
|
of ChatMessageRoles.Message: result = newQVariant(message.message)
|
||||||
of ChatMessageRoles.Timestamp: result = newQVariant(message.timestamp)
|
of ChatMessageRoles.Timestamp: result = newQVariant(message.timestamp)
|
||||||
|
of ChatMessageRoles.Identicon: result = newQVariant(message.identicon)
|
||||||
of ChatMessageRoles.IsCurrentUser: result = newQVariant(message.isCurrentUser)
|
of ChatMessageRoles.IsCurrentUser: result = newQVariant(message.isCurrentUser)
|
||||||
|
|
||||||
method roleNames(self: ChatMessageList): Table[int, string] =
|
method roleNames(self: ChatMessageList): Table[int, string] =
|
||||||
|
@ -47,6 +49,7 @@ QtObject:
|
||||||
ChatMessageRoles.UserName.int:"userName",
|
ChatMessageRoles.UserName.int:"userName",
|
||||||
ChatMessageRoles.Message.int:"message",
|
ChatMessageRoles.Message.int:"message",
|
||||||
ChatMessageRoles.Timestamp.int:"timestamp",
|
ChatMessageRoles.Timestamp.int:"timestamp",
|
||||||
|
ChatMessageRoles.Identicon.int:"identicon",
|
||||||
ChatMessageRoles.IsCurrentUser.int:"isCurrentUser"
|
ChatMessageRoles.IsCurrentUser.int:"isCurrentUser"
|
||||||
}.toTable
|
}.toTable
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ QtObject:
|
||||||
userName: string
|
userName: string
|
||||||
message: string
|
message: string
|
||||||
timestamp: string
|
timestamp: string
|
||||||
|
identicon: string
|
||||||
isCurrentUser: bool
|
isCurrentUser: bool
|
||||||
|
|
||||||
proc delete*(self: ChatMessage) =
|
proc delete*(self: ChatMessage) =
|
||||||
|
@ -18,6 +19,7 @@ QtObject:
|
||||||
result.userName = ""
|
result.userName = ""
|
||||||
result.message = ""
|
result.message = ""
|
||||||
result.timestamp = "0"
|
result.timestamp = "0"
|
||||||
|
result.identicon = ""
|
||||||
result.isCurrentUser = false
|
result.isCurrentUser = false
|
||||||
result.setup
|
result.setup
|
||||||
|
|
||||||
|
@ -72,6 +74,23 @@ QtObject:
|
||||||
write = setTimestamp
|
write = setTimestamp
|
||||||
notify = timestampChanged
|
notify = timestampChanged
|
||||||
|
|
||||||
|
proc identicon*(self: ChatMessage): string {.slot.} =
|
||||||
|
result = self.identicon
|
||||||
|
|
||||||
|
proc identiconChanged*(self: ChatMessage, identicon: string) {.signal.}
|
||||||
|
|
||||||
|
proc setIdenticon(self: ChatMessage, identicon: string) {.slot.} =
|
||||||
|
if self.identicon == identicon: return
|
||||||
|
self.identicon = identicon
|
||||||
|
self.identiconChanged(identicon)
|
||||||
|
|
||||||
|
proc `identicon=`*(self: ChatMessage, identicon: string) = self.setIdenticon(identicon)
|
||||||
|
|
||||||
|
QtProperty[string] identicon:
|
||||||
|
read = identicon
|
||||||
|
write = setIdenticons
|
||||||
|
notify = identiconsChanged
|
||||||
|
|
||||||
proc isCurrentUser*(self: ChatMessage): bool {.slot.} =
|
proc isCurrentUser*(self: ChatMessage): bool {.slot.} =
|
||||||
result = self.isCurrentUser
|
result = self.isCurrentUser
|
||||||
|
|
||||||
|
|
|
@ -270,7 +270,7 @@ SplitView {
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
anchors.topMargin: Theme.padding
|
anchors.topMargin: Theme.padding
|
||||||
fillMode: Image.PreserveAspectFit
|
fillMode: Image.PreserveAspectFit
|
||||||
source: "../img/placeholder-profile.png"
|
source: identicon
|
||||||
}
|
}
|
||||||
|
|
||||||
TextEdit {
|
TextEdit {
|
||||||
|
|
Loading…
Reference in New Issue