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