feat: Join chats on demand

This commit is contained in:
Richard Ramos 2020-05-13 13:46:12 -04:00 committed by RichΛrd
parent ae7ee0b363
commit 79638f6214
7 changed files with 37 additions and 11 deletions

15
src/chat/core.nim Normal file
View File

@ -0,0 +1,15 @@
import "../status/chat" as status_chat
proc join*(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)
status_chat.chatMessages(chatId)
proc load*(): seq[string] =
# TODO: retrieve chats from DB
join("test")
result = @["test"]

View File

@ -1,5 +1,6 @@
import NimQml import NimQml
import Tables import Tables
import chat/core as chat
type type
RoleNames {.pure.} = enum RoleNames {.pure.} = enum
@ -18,11 +19,15 @@ QtObject:
proc newChatsModel*(): ChatsModel = proc newChatsModel*(): ChatsModel =
new(result, delete) new(result, delete)
result.names = @["test", "test2"] result.names = @[]
result.setup result.setup
proc addNameTolist*(self: ChatsModel, name: string) = proc addNameTolist*(self: ChatsModel, chatId: string) {.slot.} =
self.names.add(name) chat.join(chatId)
self.beginInsertRows(newQModelIndex(), self.names.len, self.names.len)
self.names.add(chatId)
self.endInsertRows()
method rowCount(self: ChatsModel, index: QModelIndex = nil): int = method rowCount(self: ChatsModel, index: QModelIndex = nil): int =
return self.names.len return self.names.len

View File

@ -28,7 +28,6 @@ proc mainProc() =
echo status.callPrivateRPC("{\"jsonrpc\":\"2.0\", \"method\":\"wakuext_requestMessages\", \"params\":[{\"topics\": [\"0x7998f3c8\"]}], \"id\": 1}") echo status.callPrivateRPC("{\"jsonrpc\":\"2.0\", \"method\":\"wakuext_requestMessages\", \"params\":[{\"topics\": [\"0x7998f3c8\"]}], \"id\": 1}")
# result.accountResult = status.queryAccounts() # result.accountResult = status.queryAccounts()
status_test.subscribeToTest()
let logic = newApplicationView(app, status.callPrivateRPC) let logic = newApplicationView(app, status.callPrivateRPC)
defer: logic.delete defer: logic.delete
@ -49,11 +48,13 @@ proc mainProc() =
chatsModel.addNameTolist(channel.name) chatsModel.addNameTolist(channel.name)
) )
status.startMessenger()
appState.addChannel("test") appState.addChannel("test")
appState.addChannel("test2") appState.addChannel("test2")
engine.setRootContextProperty("logic", logicVariant) engine.setRootContextProperty("logic", logicVariant)
engine.setRootContextProperty("chatsModel", chatsVariant) engine.setRootContextProperty("chatsModel", chatsVariant)
engine.load("../ui/main.qml") engine.load("../ui/main.qml")
# Qt main event loop is entered here # Qt main event loop is entered here

View File

@ -1,6 +1,7 @@
import libstatus import libstatus
import signals import signals
import types import types
import chat
proc setSignalHandler(signalHandler: SignalCallback) = proc setSignalHandler(signalHandler: SignalCallback) =
libstatus.setSignalEventCallback(signalHandler) libstatus.setSignalEventCallback(signalHandler)
@ -8,6 +9,9 @@ proc setSignalHandler(signalHandler: SignalCallback) =
proc init*() = proc init*() =
setSignalHandler(onSignal) setSignalHandler(onSignal)
proc startMessenger*() =
chat.startMessenger()
proc callRPC*(inputJSON: string): string = proc callRPC*(inputJSON: string): string =
return $libstatus.callRPC(inputJSON) return $libstatus.callRPC(inputJSON)

View File

@ -14,6 +14,6 @@ var onSignal*: SignalCallback = proc(p0: cstring): void =
of "messages.new": of "messages.new":
echo $p0 echo $p0
else: else:
echo messageType #TODO: do something discard messageType #TODO: do something
tearDownForeignThreadGc() tearDownForeignThreadGc()

View File

@ -29,12 +29,6 @@ proc queryAccounts*(): string =
echo response echo response
result = parseJson(response)["result"][0].getStr() result = parseJson(response)["result"][0].getStr()
proc subscribeToTest*() =
loadFilters("test")
saveChat("test")
chatMessages("test")
proc setupNewAccount*() = proc setupNewAccount*() =
# Deleting directories # Deleting directories
recreateDir(datadir) recreateDir(datadir)

View File

@ -108,6 +108,13 @@ SplitView {
font.bold: true font.bold: true
font.pixelSize: 28 font.pixelSize: 28
} }
MouseArea {
anchors.fill: parent
onClicked : {
chatsModel.addNameTolist(searchText.text)
}
}
} }
} }