Register signals for chat messages
This commit is contained in:
parent
390322dc6a
commit
110bd25c06
|
@ -1,12 +1,13 @@
|
|||
import NimQml
|
||||
import "../../status/chat" as status_chat
|
||||
import ../../status/chat as status_chat
|
||||
import chatView
|
||||
import ../signals/signalSubscriber
|
||||
|
||||
var sendMessage = proc (msg: string): string =
|
||||
echo "sending public message"
|
||||
status_chat.sendPublicChatMessage("test", msg)
|
||||
|
||||
type ChatController* = ref object
|
||||
type ChatController* = ref object of SignalSubscriber
|
||||
view*: ChatsView
|
||||
variant*: QVariant
|
||||
|
||||
|
@ -37,3 +38,7 @@ proc load*(self: ChatController): seq[string] =
|
|||
# TODO: retrieve chats from DB
|
||||
self.join("test")
|
||||
result = @["test"]
|
||||
|
||||
method onSignal(self: ChatController, data: Signal) =
|
||||
echo "Received a signal in the chat module"
|
||||
# result.view.pushMessage(signal)
|
|
@ -1,8 +1,9 @@
|
|||
import NimQml
|
||||
import ../../status/types as types
|
||||
import ../../status/types as status_types
|
||||
import tables
|
||||
import json
|
||||
import signalSubscriber
|
||||
import messages
|
||||
|
||||
QtObject:
|
||||
type SignalsController* = ref object of QObject
|
||||
|
@ -36,15 +37,15 @@ QtObject:
|
|||
proc processSignal(self: SignalsController) =
|
||||
let jsonSignal = (self.statusSignal).parseJson
|
||||
let signalType = $jsonSignal["type"].getStr
|
||||
|
||||
# TODO: ideally the signal would receive an object
|
||||
# formatted for easier usage so the controllers dont
|
||||
# have to parse the signal themselves
|
||||
case signalType:
|
||||
of "messages.new":
|
||||
self.signalSubscribers[SignalType.Message].onSignal($jsonSignal)
|
||||
self.signalSubscribers[SignalType.Message].onSignal(messages.fromEvent(jsonSignal))
|
||||
of "wallet":
|
||||
self.signalSubscribers[SignalType.Wallet].onSignal($jsonSignal)
|
||||
var wMsg = WalletMessage(content: $jsonSignal)
|
||||
self.signalSubscribers[SignalType.Wallet].onSignal(wMsg)
|
||||
else:
|
||||
# TODO: log error?
|
||||
discard
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
import json
|
||||
import signalSubscriber
|
||||
|
||||
proc fromEvent*(event: JsonNode): Signal =
|
||||
result = Message()
|
|
@ -1,5 +1,35 @@
|
|||
type SignalSubscriber* = ref object of RootObj
|
||||
|
||||
type Signal* = ref object of RootObj
|
||||
|
||||
type WalletMessage* = ref object of Signal
|
||||
content*: string
|
||||
|
||||
type Message* = ref object of Signal
|
||||
alias: string
|
||||
chatId: string
|
||||
clock: uint
|
||||
# commandParameters: # ???
|
||||
contentType: uint # ???
|
||||
ensName: string # ???
|
||||
fromAuthor: string
|
||||
id: string
|
||||
identicon: string
|
||||
lineCount: uint
|
||||
localChatId: string
|
||||
messageType: string # ???
|
||||
# parsedText: # ???
|
||||
# quotedMessage: # ???
|
||||
replace: string # ???
|
||||
responseTo: string # ???
|
||||
rtl: bool # ???
|
||||
seen: bool
|
||||
# sticker: # ???
|
||||
text: string
|
||||
timestamp: uint
|
||||
whisperTimestamp: uint
|
||||
|
||||
|
||||
# Override this method
|
||||
method onSignal*(self: SignalSubscriber, signal: string) {.base.} =
|
||||
echo "Received a signal: ", signal # TODO: log signal received
|
||||
method onSignal*(self: SignalSubscriber, data: Signal) {.base.} =
|
||||
echo "Received a signal" # TODO: log signal received
|
|
@ -40,6 +40,6 @@ proc init*(self: WalletController) =
|
|||
let symbol = "ETH"
|
||||
self.view.addAssetToList("Ethereum", symbol, fmt"{eth_value:.6}", "$" & fmt"{usd_balance:.6}", fmt"../../img/token-icons/{toLowerAscii(symbol)}.svg")
|
||||
|
||||
method onSignal(self: WalletController, signal: string) =
|
||||
echo "Received a signal in the wallet module: ", signal
|
||||
self.view.setLastMessage(signal)
|
||||
method onSignal(self: WalletController, data: Signal) =
|
||||
var msg = cast[WalletMessage](data)
|
||||
self.view.setLastMessage(msg.content)
|
|
@ -44,6 +44,8 @@ proc mainProc() =
|
|||
|
||||
status_test.setupNewAccount()
|
||||
|
||||
status_chat.startMessenger()
|
||||
|
||||
var wallet = wallet.newController()
|
||||
wallet.init()
|
||||
engine.setRootContextProperty("assetsModel", wallet.variant)
|
||||
|
@ -58,6 +60,8 @@ proc mainProc() =
|
|||
|
||||
signalController.init()
|
||||
signalController.addSubscriber(SignalType.Wallet, wallet)
|
||||
signalController.addSubscriber(SignalType.Message, chat)
|
||||
|
||||
engine.setRootContextProperty("signals", signalController.variant)
|
||||
|
||||
appState.subscribe(proc () =
|
||||
|
|
Loading…
Reference in New Issue