display users own message
This commit is contained in:
parent
3916fb739b
commit
1883a4bc1f
|
@ -1,11 +1,25 @@
|
|||
import NimQml
|
||||
import ../../status/chat as status_chat
|
||||
import view
|
||||
import messages
|
||||
import ../signals/types
|
||||
import ../../status/utils
|
||||
|
||||
var sendMessage = proc (chatId: string, msg: string): string =
|
||||
echo "sending message"
|
||||
var sendMessage = proc (view: ChatsView, chatId: string, msg: string): string =
|
||||
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)
|
||||
|
||||
type ChatController* = ref object of SignalSubscriber
|
||||
|
|
|
@ -56,7 +56,7 @@ QtObject:
|
|||
chatMessage.userName = message.alias
|
||||
chatMessage.message = message.text
|
||||
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.messages.add(chatMessage)
|
||||
|
|
|
@ -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)
|
|
@ -14,7 +14,7 @@ QtObject:
|
|||
names*: seq[string]
|
||||
callResult: string
|
||||
messageList: ChatMessageList
|
||||
sendMessage: proc (chatId: string, msg: string): string
|
||||
sendMessage: proc (view: ChatsView, chatId: string, msg: string): string
|
||||
|
||||
proc delete(self: ChatsView) =
|
||||
self.QAbstractListModel.delete
|
||||
|
@ -68,7 +68,7 @@ QtObject:
|
|||
|
||||
proc onSend*(self: ChatsView, inputJSON: string) {.slot.} =
|
||||
# TODO unhardcode chatId
|
||||
self.setCallResult(self.sendMessage("test", inputJSON))
|
||||
self.setCallResult(self.sendMessage(self, "test", inputJSON))
|
||||
echo "Done!: ", self.callResult
|
||||
|
||||
proc onMessage*(self: ChatsView, message: string) {.slot.} =
|
||||
|
|
|
@ -23,7 +23,8 @@ proc fromEvent*(event: JsonNode): Signal =
|
|||
seen: jsonMsg["seen"].getBool,
|
||||
text: jsonMsg["text"].getStr,
|
||||
timestamp: $jsonMsg["timestamp"].getInt,
|
||||
whisperTimestamp: $jsonMsg["whisperTimestamp"].getInt
|
||||
whisperTimestamp: $jsonMsg["whisperTimestamp"].getInt,
|
||||
isCurrentUser: false
|
||||
)
|
||||
|
||||
signal.messages.add(msg)
|
||||
|
|
|
@ -28,6 +28,7 @@ type Message* = object
|
|||
text*: string
|
||||
timestamp*: string
|
||||
whisperTimestamp*: string
|
||||
isCurrentUser*: bool
|
||||
|
||||
|
||||
type ChatSignal* = ref object of Signal
|
||||
|
|
Loading…
Reference in New Issue