display users own message

This commit is contained in:
Iuri Matias 2020-05-19 14:30:53 -04:00
parent 3916fb739b
commit 1883a4bc1f
6 changed files with 35 additions and 9 deletions

View File

@ -1,11 +1,25 @@
import NimQml import NimQml
import ../../status/chat as status_chat import ../../status/chat as status_chat
import view import view
import messages
import ../signals/types import ../signals/types
import ../../status/utils import ../../status/utils
var sendMessage = proc (chatId: string, msg: string): string = var sendMessage = proc (view: ChatsView, chatId: string, msg: string): string =
echo "sending message" echo "sending message!"
var message = Message(
fromAuthor: "myself",
text: msg,
timestamp: "0",
isCurrentUser: true
)
# var message = newChatMessage()
# message.userName = "myself"
# message.message = msg
# message.timestamp = "0"
# message.isCurrentUser = true
view.pushMessage(message)
status_chat.sendChatMessage(chatId, msg) status_chat.sendChatMessage(chatId, msg)
type ChatController* = ref object of SignalSubscriber type ChatController* = ref object of SignalSubscriber

View File

@ -56,8 +56,8 @@ QtObject:
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.isCurrentUser = false #TODO: Determine who originated the message chatMessage.isCurrentUser = message.isCurrentUser #TODO: Determine who originated the message
self.beginInsertRows(newQModelIndex(), self.messages.len, self.messages.len) self.beginInsertRows(newQModelIndex(), self.messages.len, self.messages.len)
self.messages.add(chatMessage) self.messages.add(chatMessage)
self.endInsertRows() self.endInsertRows()

10
src/app/chat/model.nim Normal file
View File

@ -0,0 +1,10 @@
import "../../status/chat" as status_chat
type ChatModel* = ref object
proc newChatModel*(): ChatModel =
result = ChatModel()
proc sendMessage*(self: ChatModel, msg: string): string =
echo "sending public message"
status_chat.sendPublicChatMessage("test", msg)

View File

@ -14,7 +14,7 @@ QtObject:
names*: seq[string] names*: seq[string]
callResult: string callResult: string
messageList: ChatMessageList messageList: ChatMessageList
sendMessage: proc (chatId: string, msg: string): string sendMessage: proc (view: ChatsView, chatId: string, msg: string): string
proc delete(self: ChatsView) = proc delete(self: ChatsView) =
self.QAbstractListModel.delete self.QAbstractListModel.delete
@ -68,7 +68,7 @@ QtObject:
proc onSend*(self: ChatsView, inputJSON: string) {.slot.} = proc onSend*(self: ChatsView, inputJSON: string) {.slot.} =
# TODO unhardcode chatId # TODO unhardcode chatId
self.setCallResult(self.sendMessage("test", inputJSON)) self.setCallResult(self.sendMessage(self, "test", inputJSON))
echo "Done!: ", self.callResult echo "Done!: ", self.callResult
proc onMessage*(self: ChatsView, message: string) {.slot.} = proc onMessage*(self: ChatsView, message: string) {.slot.} =
@ -82,4 +82,4 @@ QtObject:
return newQVariant(self.messageList) return newQVariant(self.messageList)
QtProperty[QVariant] messageList: QtProperty[QVariant] messageList:
read = getMessageList read = getMessageList

View File

@ -23,9 +23,10 @@ proc fromEvent*(event: JsonNode): Signal =
seen: jsonMsg["seen"].getBool, seen: jsonMsg["seen"].getBool,
text: jsonMsg["text"].getStr, text: jsonMsg["text"].getStr,
timestamp: $jsonMsg["timestamp"].getInt, timestamp: $jsonMsg["timestamp"].getInt,
whisperTimestamp: $jsonMsg["whisperTimestamp"].getInt whisperTimestamp: $jsonMsg["whisperTimestamp"].getInt,
isCurrentUser: false
) )
signal.messages.add(msg) signal.messages.add(msg)
result = signal result = signal

View File

@ -28,6 +28,7 @@ type Message* = object
text*: string text*: string
timestamp*: string timestamp*: string
whisperTimestamp*: string whisperTimestamp*: string
isCurrentUser*: bool
type ChatSignal* = ref object of Signal type ChatSignal* = ref object of Signal