Merge pull request #12 from status-im/chats

initial chats/contacts layout; state & messages
This commit is contained in:
Iuri Matias 2020-05-11 07:32:13 -04:00 committed by GitHub
commit 18161ae693
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 189 additions and 80 deletions

View File

@ -7,7 +7,7 @@ ApplicationWindow {
id: applicationWindow
width: 1024
height: 768
title: "JSON RPC Caller"
title: "Nim Status Client"
visible: true
RowLayout {
@ -160,6 +160,15 @@ ApplicationWindow {
height: parent.height
Layout.minimumWidth: 200
ColumnLayout {
anchors.rightMargin: 0
anchors.fill: parent
Item {
Layout.preferredHeight: 100
Layout.fillHeight: false
Layout.fillWidth: true
Text {
id: element
x: 772
@ -239,6 +248,25 @@ ApplicationWindow {
}
}
Item {
Layout.fillHeight: true
Layout.fillWidth: true
Component {
id: chatViewDelegate
Label { text: "Name:" + name }
}
ListView {
id: listView
anchors.fill: parent
model: chatsModel
delegate: chatViewDelegate
}
}
}
}
Item {
width: parent.width/2
height: parent.height
@ -292,6 +320,6 @@ ApplicationWindow {
/*##^##
Designer {
D{i:9;anchors_height:40;anchors_width:40}D{i:19;anchors_y:0}D{i:23;anchors_height:100;anchors_width:100}
D{i:9;anchors_height:40;anchors_width:40}
}
##^##*/

View File

@ -3,7 +3,6 @@ import status
import libstatus
import json
var signalHandler: SignalCallback = proc(p0: cstring): void =
setupForeignThreadGc()
@ -20,6 +19,7 @@ QtObject:
app: QApplication
callResult: string
accountResult: string
# chats: seq[ChatView]
# Constructor
proc newApplicationLogic*(app: QApplication): ApplicationLogic =
@ -37,8 +37,6 @@ QtObject:
result.accountResult = status.queryAccounts()
status.subscribeToTest()
# ¯\_(ツ)_/¯ dunno what is this
proc setup(self: ApplicationLogic) =
# discard status.onMessage(self.onMessage)

38
src/chats.nim Normal file
View File

@ -0,0 +1,38 @@
import NimQml
import Tables
type
RoleNames {.pure.} = enum
Name = UserRole + 1,
QtObject:
type
ChatsModel* = ref object of QAbstractListModel
names*: seq[string]
proc delete(self: ChatsModel) =
self.QAbstractListModel.delete
proc setup(self: ChatsModel) =
self.QAbstractListModel.setup
proc newChatsModel*(): ChatsModel =
new(result, delete)
result.names = @["test", "test2"]
result.setup
proc addNameTolist*(self: ChatsModel, name: string) =
self.names.add(name)
method rowCount(self: ChatsModel, index: QModelIndex = nil): int =
return self.names.len
method data(self: ChatsModel, index: QModelIndex, role: int): QVariant =
if not index.isValid:
return
if index.row < 0 or index.row >= self.names.len:
return
return newQVariant(self.names[index.row])
method roleNames(self: ChatsModel): Table[int, string] =
{ RoleNames.Name.int:"name"}.toTable

View File

@ -1,5 +1,7 @@
import NimQml
import applicationLogic
import chats
import state
proc mainProc() =
@ -11,6 +13,8 @@ proc mainProc() =
var app = newQApplication()
defer: app.delete() # Defer will run this just before mainProc() function ends
var chatsModel = newChatsModel();
defer: chatsModel.delete
var engine = newQQmlApplicationEngine()
defer: engine.delete()
@ -22,7 +26,24 @@ proc mainProc() =
let logicVariant = newQVariant(logic)
defer: logicVariant.delete
let chatsVariant = newQVariant(chatsModel)
defer: chatsVariant.delete
var appState = state.newAppState()
echo appState.title
appState.subscribe(proc () =
chatsModel.names = @[]
for channel in appState.channels:
echo channel.name
chatsModel.addNameTolist(channel.name)
)
appState.addChannel("test")
appState.addChannel("test2")
engine.setRootContextProperty("logic", logicVariant)
engine.setRootContextProperty("chatsModel", chatsVariant)
engine.load("main.qml")
# Qt main event loop is entered here

24
src/state.nim Normal file
View File

@ -0,0 +1,24 @@
type Channel = object
name*: string
type
Subscriber* = proc ()
type AppState* = ref object
title*: string
channels*: seq[Channel]
subscribers*: seq[Subscriber]
proc newAppState*(): AppState =
result = AppState(title: "hello")
proc subscribe*(self: AppState, subscriber: Subscriber) =
self.subscribers.add(subscriber)
proc dispatch*(self: AppState) =
for subscriber in self.subscribers:
subscriber()
proc addChannel*(self: AppState, name: string) =
self.channels.add(Channel(name: name))
self.dispatch()