parent
97cd5043eb
commit
33011385af
|
@ -2,10 +2,11 @@ import NimQml
|
||||||
import ../../status/chat as status_chat
|
import ../../status/chat as status_chat
|
||||||
import view
|
import view
|
||||||
import ../signals/types
|
import ../signals/types
|
||||||
|
import ../../status/utils
|
||||||
|
|
||||||
var sendMessage = proc (msg: string): string =
|
var sendMessage = proc (chatId: string, msg: string): string =
|
||||||
echo "sending public message"
|
echo "sending message"
|
||||||
status_chat.sendPublicChatMessage("test", msg)
|
status_chat.sendChatMessage(chatId, msg)
|
||||||
|
|
||||||
type ChatController* = ref object of SignalSubscriber
|
type ChatController* = ref object of SignalSubscriber
|
||||||
view*: ChatsView
|
view*: ChatsView
|
||||||
|
@ -28,8 +29,10 @@ proc join*(self: ChatController, chatId: string) =
|
||||||
# TODO: check whether we have joined a chat already or not
|
# TODO: check whether we have joined a chat already or not
|
||||||
# TODO: save chat list in the db
|
# TODO: save chat list in the db
|
||||||
echo "Joining chat: ", chatId
|
echo "Joining chat: ", chatId
|
||||||
status_chat.loadFilters(chatId)
|
let oneToOne = isOneToOneChat(chatId)
|
||||||
status_chat.saveChat(chatId)
|
echo "Is one to one? ", oneToOne
|
||||||
|
status_chat.loadFilters(chatId, oneToOne)
|
||||||
|
status_chat.saveChat(chatId, oneToOne)
|
||||||
status_chat.chatMessages(chatId)
|
status_chat.chatMessages(chatId)
|
||||||
# self.chatsModel.addNameTolist(channel.name)
|
# self.chatsModel.addNameTolist(channel.name)
|
||||||
self.view.addNameTolist(chatId)
|
self.view.addNameTolist(chatId)
|
||||||
|
|
|
@ -14,7 +14,7 @@ QtObject:
|
||||||
names*: seq[string]
|
names*: seq[string]
|
||||||
callResult: string
|
callResult: string
|
||||||
messageList: ChatMessageList
|
messageList: ChatMessageList
|
||||||
sendMessage: proc (msg: string): string
|
sendMessage: proc (chatId: string, msg: string): string
|
||||||
|
|
||||||
proc delete(self: ChatsView) =
|
proc delete(self: ChatsView) =
|
||||||
self.QAbstractListModel.delete
|
self.QAbstractListModel.delete
|
||||||
|
@ -67,7 +67,8 @@ QtObject:
|
||||||
notify = callResultChanged
|
notify = callResultChanged
|
||||||
|
|
||||||
proc onSend*(self: ChatsView, inputJSON: string) {.slot.} =
|
proc onSend*(self: ChatsView, inputJSON: string) {.slot.} =
|
||||||
self.setCallResult(self.sendMessage(inputJSON))
|
# TODO unhardcode chatId
|
||||||
|
self.setCallResult(self.sendMessage("test", inputJSON))
|
||||||
echo "Done!: ", self.callResult
|
echo "Done!: ", self.callResult
|
||||||
|
|
||||||
proc onMessage*(self: ChatsView, message: string) {.slot.} =
|
proc onMessage*(self: ChatsView, message: string) {.slot.} =
|
||||||
|
|
|
@ -12,7 +12,7 @@ proc startMessenger*() =
|
||||||
discard $libstatus.callPrivateRPC($payload)
|
discard $libstatus.callPrivateRPC($payload)
|
||||||
# TODO: create template for error handling
|
# TODO: create template for error handling
|
||||||
|
|
||||||
proc loadFilters*(chatId: string) =
|
proc loadFilters*(chatId: string, oneToOne = false) =
|
||||||
let payload = %* {
|
let payload = %* {
|
||||||
"jsonrpc": "2.0",
|
"jsonrpc": "2.0",
|
||||||
"id": 3, #TODO:
|
"id": 3, #TODO:
|
||||||
|
@ -20,13 +20,13 @@ proc loadFilters*(chatId: string) =
|
||||||
"params": [
|
"params": [
|
||||||
[{
|
[{
|
||||||
"ChatID": chatId,
|
"ChatID": chatId,
|
||||||
"OneToOne": false
|
"OneToOne": oneToOne
|
||||||
}]
|
}]
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
discard $libstatus.callPrivateRPC($payload)
|
discard $libstatus.callPrivateRPC($payload)
|
||||||
|
|
||||||
proc saveChat*(chatId: string) =
|
proc saveChat*(chatId: string, oneToOne = false) =
|
||||||
let payload = %* {
|
let payload = %* {
|
||||||
"jsonrpc": "2.0",
|
"jsonrpc": "2.0",
|
||||||
"id": 4,
|
"id": 4,
|
||||||
|
@ -40,7 +40,7 @@ proc saveChat*(chatId: string) =
|
||||||
"active": true,
|
"active": true,
|
||||||
"id": chatId,
|
"id": chatId,
|
||||||
"unviewedMessagesCount": 0,
|
"unviewedMessagesCount": 0,
|
||||||
"chatType": 2,
|
"chatType": if oneToOne: 1 else: 2,
|
||||||
"timestamp": 1588940692659
|
"timestamp": 1588940692659
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -59,7 +59,8 @@ proc chatMessages*(chatId: string) =
|
||||||
discard $libstatus.callPrivateRPC($payload)
|
discard $libstatus.callPrivateRPC($payload)
|
||||||
# TODO: create template for error handling
|
# TODO: create template for error handling
|
||||||
|
|
||||||
proc sendPublicChatMessage*(chatId: string, msg: string): string =
|
|
||||||
|
proc sendChatMessage*(chatId: string, msg: string): string =
|
||||||
let payload = %* {
|
let payload = %* {
|
||||||
"jsonrpc": "2.0",
|
"jsonrpc": "2.0",
|
||||||
"id": 40,
|
"id": 40,
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
|
import strutils
|
||||||
|
|
||||||
proc isWakuEnabled(): bool =
|
proc isWakuEnabled(): bool =
|
||||||
true # TODO:
|
true # TODO:
|
||||||
|
|
||||||
proc prefix*(methodName: string): string =
|
proc prefix*(methodName: string): string =
|
||||||
result = if isWakuEnabled(): "wakuext_" else: "shhext_"
|
result = if isWakuEnabled(): "wakuext_" else: "shhext_"
|
||||||
result = result & methodName
|
result = result & methodName
|
||||||
|
|
||||||
|
proc isOneToOneChat*(chatId: string): bool =
|
||||||
|
result = chatId.startsWith("0x") # There is probably a better way to do this
|
Loading…
Reference in New Issue