remove logic message model from view and replace it with view representation
This commit is contained in:
parent
1883a4bc1f
commit
175c3a57f4
|
@ -6,20 +6,14 @@ import ../signals/types
|
||||||
import ../../status/utils
|
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 message!"
|
echo "sending public message!"
|
||||||
var message = Message(
|
let chatMessage = newChatMessage()
|
||||||
fromAuthor: "myself",
|
chatMessage.userName = "myself"
|
||||||
text: msg,
|
chatMessage.message = msg
|
||||||
timestamp: "0",
|
chatMessage.timestamp = "0" #TODO convert to date/time?
|
||||||
isCurrentUser: true
|
chatMessage.isCurrentUser = true #TODO: Determine who originated the message
|
||||||
)
|
|
||||||
# var message = newChatMessage()
|
|
||||||
# message.userName = "myself"
|
|
||||||
# message.message = msg
|
|
||||||
# message.timestamp = "0"
|
|
||||||
# message.isCurrentUser = true
|
|
||||||
|
|
||||||
view.pushMessage(message)
|
view.pushMessage(chatMessage)
|
||||||
status_chat.sendChatMessage(chatId, msg)
|
status_chat.sendChatMessage(chatId, msg)
|
||||||
|
|
||||||
type ChatController* = ref object of SignalSubscriber
|
type ChatController* = ref object of SignalSubscriber
|
||||||
|
@ -59,4 +53,9 @@ proc load*(self: ChatController): seq[string] =
|
||||||
method onSignal(self: ChatController, data: Signal) =
|
method onSignal(self: ChatController, data: Signal) =
|
||||||
var chatSignal = cast[ChatSignal](data)
|
var chatSignal = cast[ChatSignal](data)
|
||||||
for message in chatSignal.messages:
|
for message in chatSignal.messages:
|
||||||
self.view.pushMessage(message)
|
let chatMessage = newChatMessage()
|
||||||
|
chatMessage.userName = message.alias
|
||||||
|
chatMessage.message = message.text
|
||||||
|
chatMessage.timestamp = message.timestamp #TODO convert to date/time?
|
||||||
|
chatMessage.isCurrentUser = message.isCurrentUser #TODO: Determine who originated the message
|
||||||
|
self.view.pushMessage(chatMessage)
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import NimQml, messages, Tables
|
import NimQml, messages, Tables
|
||||||
import ../signals/types
|
|
||||||
|
|
||||||
type
|
type
|
||||||
ChatMessageRoles {.pure.} = enum
|
ChatMessageRoles {.pure.} = enum
|
||||||
|
@ -51,13 +50,7 @@ QtObject:
|
||||||
ChatMessageRoles.IsCurrentUser.int:"isCurrentUser"
|
ChatMessageRoles.IsCurrentUser.int:"isCurrentUser"
|
||||||
}.toTable
|
}.toTable
|
||||||
|
|
||||||
proc add*(self: ChatMessageList, message: Message) =
|
proc add*(self: ChatMessageList, message: ChatMessage) =
|
||||||
let chatMessage = newChatMessage()
|
|
||||||
chatMessage.userName = message.alias
|
|
||||||
chatMessage.message = message.text
|
|
||||||
chatMessage.timestamp = message.timestamp #TODO convert to date/time?
|
|
||||||
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(message)
|
||||||
self.endInsertRows()
|
self.endInsertRows()
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import NimQml
|
import NimQml
|
||||||
import Tables
|
import Tables
|
||||||
|
import messages
|
||||||
import messageList
|
import messageList
|
||||||
import ../signals/types
|
import ../signals/types
|
||||||
# import core as chat
|
# import core as chat
|
||||||
|
@ -75,7 +76,7 @@ QtObject:
|
||||||
self.setCallResult(message)
|
self.setCallResult(message)
|
||||||
echo "Received message: ", message
|
echo "Received message: ", message
|
||||||
|
|
||||||
proc pushMessage*(self:ChatsView, message: Message) =
|
proc pushMessage*(self:ChatsView, message: ChatMessage) =
|
||||||
self.messageList.add(message)
|
self.messageList.add(message)
|
||||||
|
|
||||||
proc getMessageList(self: ChatsView): QVariant {.slot.} =
|
proc getMessageList(self: ChatsView): QVariant {.slot.} =
|
||||||
|
|
Loading…
Reference in New Issue