diff --git a/src/app/chat/core.nim b/src/app/chat/core.nim index c5351ed3aa..d8718955bf 100644 --- a/src/app/chat/core.nim +++ b/src/app/chat/core.nim @@ -2,10 +2,11 @@ import NimQml import ../../status/chat as status_chat import view import ../signals/types +import ../../status/utils -var sendMessage = proc (msg: string): string = - echo "sending public message" - status_chat.sendPublicChatMessage("test", msg) +var sendMessage = proc (chatId: string, msg: string): string = + echo "sending message" + status_chat.sendChatMessage(chatId, msg) type ChatController* = ref object of SignalSubscriber view*: ChatsView @@ -28,8 +29,10 @@ proc join*(self: ChatController, chatId: string) = # TODO: check whether we have joined a chat already or not # TODO: save chat list in the db echo "Joining chat: ", chatId - status_chat.loadFilters(chatId) - status_chat.saveChat(chatId) + let oneToOne = isOneToOneChat(chatId) + echo "Is one to one? ", oneToOne + status_chat.loadFilters(chatId, oneToOne) + status_chat.saveChat(chatId, oneToOne) status_chat.chatMessages(chatId) # self.chatsModel.addNameTolist(channel.name) self.view.addNameTolist(chatId) diff --git a/src/app/chat/view.nim b/src/app/chat/view.nim index 389eb5a40a..c1487421e5 100644 --- a/src/app/chat/view.nim +++ b/src/app/chat/view.nim @@ -14,7 +14,7 @@ QtObject: names*: seq[string] callResult: string messageList: ChatMessageList - sendMessage: proc (msg: string): string + sendMessage: proc (chatId: string, msg: string): string proc delete(self: ChatsView) = self.QAbstractListModel.delete @@ -67,7 +67,8 @@ QtObject: notify = callResultChanged 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 proc onMessage*(self: ChatsView, message: string) {.slot.} = diff --git a/src/status/chat.nim b/src/status/chat.nim index ba038058ae..50054dc876 100644 --- a/src/status/chat.nim +++ b/src/status/chat.nim @@ -12,7 +12,7 @@ proc startMessenger*() = discard $libstatus.callPrivateRPC($payload) # TODO: create template for error handling -proc loadFilters*(chatId: string) = +proc loadFilters*(chatId: string, oneToOne = false) = let payload = %* { "jsonrpc": "2.0", "id": 3, #TODO: @@ -20,13 +20,13 @@ proc loadFilters*(chatId: string) = "params": [ [{ "ChatID": chatId, - "OneToOne": false + "OneToOne": oneToOne }] ] } discard $libstatus.callPrivateRPC($payload) -proc saveChat*(chatId: string) = +proc saveChat*(chatId: string, oneToOne = false) = let payload = %* { "jsonrpc": "2.0", "id": 4, @@ -40,7 +40,7 @@ proc saveChat*(chatId: string) = "active": true, "id": chatId, "unviewedMessagesCount": 0, - "chatType": 2, + "chatType": if oneToOne: 1 else: 2, "timestamp": 1588940692659 } ] @@ -59,7 +59,8 @@ proc chatMessages*(chatId: string) = discard $libstatus.callPrivateRPC($payload) # TODO: create template for error handling -proc sendPublicChatMessage*(chatId: string, msg: string): string = + +proc sendChatMessage*(chatId: string, msg: string): string = let payload = %* { "jsonrpc": "2.0", "id": 40, diff --git a/src/status/utils.nim b/src/status/utils.nim index e61a3e95f0..b6a4782d49 100644 --- a/src/status/utils.nim +++ b/src/status/utils.nim @@ -1,6 +1,11 @@ +import strutils + proc isWakuEnabled(): bool = true # TODO: proc prefix*(methodName: string): string = result = if isWakuEnabled(): "wakuext_" else: "shhext_" - result = result & methodName \ No newline at end of file + result = result & methodName + +proc isOneToOneChat*(chatId: string): bool = + result = chatId.startsWith("0x") # There is probably a better way to do this \ No newline at end of file