feat: display connected/disconnected status in the chat module
This commit is contained in:
parent
f4601eb9bf
commit
fd88fd19d0
|
@ -43,6 +43,12 @@ proc handleChatEvents(self: ChatController) =
|
||||||
var msg = MessageSentArgs(e)
|
var msg = MessageSentArgs(e)
|
||||||
self.view.markMessageAsSent(msg.chatId, msg.id)
|
self.view.markMessageAsSent(msg.chatId, msg.id)
|
||||||
|
|
||||||
|
self.status.events.on("chat:disconnected") do(e: Args):
|
||||||
|
self.view.setConnected(false)
|
||||||
|
|
||||||
|
self.status.events.on("chat:connected") do(e: Args):
|
||||||
|
self.view.setConnected(true)
|
||||||
|
|
||||||
proc handleMailserverEvents(self: ChatController) =
|
proc handleMailserverEvents(self: ChatController) =
|
||||||
self.status.events.on("mailserverTopics") do(e: Args):
|
self.status.events.on("mailserverTopics") do(e: Args):
|
||||||
self.status.mailservers.addTopics(TopicArgs(e).topics)
|
self.status.mailservers.addTopics(TopicArgs(e).topics)
|
||||||
|
|
|
@ -28,6 +28,7 @@ QtObject:
|
||||||
recentStickers*: StickerList
|
recentStickers*: StickerList
|
||||||
replyTo: string
|
replyTo: string
|
||||||
channelOpenTime*: Table[string, int64]
|
channelOpenTime*: Table[string, int64]
|
||||||
|
connected: bool
|
||||||
|
|
||||||
proc setup(self: ChatsView) = self.QAbstractListModel.setup
|
proc setup(self: ChatsView) = self.QAbstractListModel.setup
|
||||||
|
|
||||||
|
@ -43,6 +44,7 @@ QtObject:
|
||||||
proc newChatsView*(status: Status): ChatsView =
|
proc newChatsView*(status: Status): ChatsView =
|
||||||
new(result, delete)
|
new(result, delete)
|
||||||
result.status = status
|
result.status = status
|
||||||
|
result.connected = false
|
||||||
result.chats = newChannelsList(status)
|
result.chats = newChannelsList(status)
|
||||||
result.activeChannel = newChatItemView(status)
|
result.activeChannel = newChatItemView(status)
|
||||||
result.messageList = initTable[string, ChatMessageList]()
|
result.messageList = initTable[string, ChatMessageList]()
|
||||||
|
@ -270,3 +272,16 @@ QtObject:
|
||||||
|
|
||||||
proc ensResolved(self: ChatsView, pubKey: string) {.slot.} =
|
proc ensResolved(self: ChatsView, pubKey: string) {.slot.} =
|
||||||
self.ensWasResolved(pubKey)
|
self.ensWasResolved(pubKey)
|
||||||
|
|
||||||
|
proc isConnected*(self: ChatsView): bool {.slot.} =
|
||||||
|
result = self.connected
|
||||||
|
|
||||||
|
proc onlineStatusChanged(self: ChatsView, connected: bool) {.signal.}
|
||||||
|
|
||||||
|
proc setConnected*(self: ChatsView, connected: bool) =
|
||||||
|
self.connected = connected
|
||||||
|
self.onlineStatusChanged(connected)
|
||||||
|
|
||||||
|
QtProperty[bool] isOnline:
|
||||||
|
read = isConnected
|
||||||
|
notify = onlineStatusChanged
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import NimQml, chronicles
|
import NimQml, chronicles
|
||||||
import ../../signals/types
|
import ../../signals/types
|
||||||
import ../../status/[status, node]
|
import ../../status/[status, node, network]
|
||||||
|
import ../../status/libstatus/types as status_types
|
||||||
import view
|
import view
|
||||||
|
|
||||||
logScope:
|
logScope:
|
||||||
|
@ -24,7 +25,16 @@ proc delete*(self: NodeController) =
|
||||||
proc init*(self: NodeController) =
|
proc init*(self: NodeController) =
|
||||||
discard
|
discard
|
||||||
|
|
||||||
|
proc handleWalletSignal(self: NodeController, data: WalletSignal) =
|
||||||
|
self.view.setLastMessage(data.content)
|
||||||
|
|
||||||
|
proc handleDiscoverySummary(self: NodeController, data: DiscoverySummarySignal) =
|
||||||
|
self.status.network.peerSummaryChange(data.enodes)
|
||||||
|
|
||||||
method onSignal(self: NodeController, data: Signal) =
|
method onSignal(self: NodeController, data: Signal) =
|
||||||
debug "New signal received"
|
case data.signalType:
|
||||||
var msg = cast[WalletSignal](data)
|
of SignalType.Wallet: handleWalletSignal(self, WalletSignal(data))
|
||||||
self.view.setLastMessage(msg.content)
|
of SignalType.DiscoverySummary: handleDiscoverySummary(self, DiscoverySummarySignal(data))
|
||||||
|
else:
|
||||||
|
warn "Unhandled signal received", signalType = data.signalType
|
||||||
|
|
||||||
|
|
|
@ -107,6 +107,7 @@ proc mainProc() =
|
||||||
signalController.init()
|
signalController.init()
|
||||||
signalController.addSubscriber(SignalType.Wallet, wallet)
|
signalController.addSubscriber(SignalType.Wallet, wallet)
|
||||||
signalController.addSubscriber(SignalType.Wallet, node)
|
signalController.addSubscriber(SignalType.Wallet, node)
|
||||||
|
signalController.addSubscriber(SignalType.DiscoverySummary, node)
|
||||||
signalController.addSubscriber(SignalType.Message, chat)
|
signalController.addSubscriber(SignalType.Message, chat)
|
||||||
signalController.addSubscriber(SignalType.Message, profile)
|
signalController.addSubscriber(SignalType.Message, profile)
|
||||||
signalController.addSubscriber(SignalType.DiscoverySummary, chat)
|
signalController.addSubscriber(SignalType.DiscoverySummary, chat)
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
import chronicles, eventemitter
|
||||||
|
|
||||||
|
logScope:
|
||||||
|
topics = "network-model"
|
||||||
|
|
||||||
|
type
|
||||||
|
NetworkModel* = ref object
|
||||||
|
peers*: seq[string]
|
||||||
|
events*: EventEmitter
|
||||||
|
|
||||||
|
proc newNetworkModel*(events: EventEmitter): NetworkModel =
|
||||||
|
result = NetworkModel()
|
||||||
|
result.events = events
|
||||||
|
result.peers = @[]
|
||||||
|
|
||||||
|
proc peerSummaryChange*(self: NetworkModel, peers: seq[string]) =
|
||||||
|
if peers.len == 0:
|
||||||
|
self.events.emit("chat:disconnected", Args())
|
||||||
|
|
||||||
|
if peers.len > 0 and self.peers.len == 0:
|
||||||
|
self.events.emit("chat:connected", Args())
|
||||||
|
|
||||||
|
self.peers = peers
|
||||||
|
|
||||||
|
proc peerCount*(self: NetworkModel): int = self.peers.len
|
|
@ -13,6 +13,7 @@ import mailservers as mailservers
|
||||||
import messages as messages
|
import messages as messages
|
||||||
import contacts as contacts
|
import contacts as contacts
|
||||||
import profile
|
import profile
|
||||||
|
import network as network
|
||||||
|
|
||||||
type Status* = ref object
|
type Status* = ref object
|
||||||
events*: EventEmitter
|
events*: EventEmitter
|
||||||
|
@ -24,6 +25,7 @@ type Status* = ref object
|
||||||
node*: NodeModel
|
node*: NodeModel
|
||||||
profile*: ProfileModel
|
profile*: ProfileModel
|
||||||
contacts*: ContactModel
|
contacts*: ContactModel
|
||||||
|
network*: NetworkModel
|
||||||
|
|
||||||
proc newStatusInstance*(): Status =
|
proc newStatusInstance*(): Status =
|
||||||
result = Status()
|
result = Status()
|
||||||
|
@ -37,6 +39,7 @@ proc newStatusInstance*(): Status =
|
||||||
result.messages = messages.newMessagesModel(result.events)
|
result.messages = messages.newMessagesModel(result.events)
|
||||||
result.profile = profile.newProfileModel()
|
result.profile = profile.newProfileModel()
|
||||||
result.contacts = contacts.newContactModel(result.events)
|
result.contacts = contacts.newContactModel(result.events)
|
||||||
|
result.network = network.newNetworkModel(result.events)
|
||||||
|
|
||||||
proc initNode*(self: Status) =
|
proc initNode*(self: Status) =
|
||||||
libstatus_accounts.initNode()
|
libstatus_accounts.initNode()
|
||||||
|
|
|
@ -11,6 +11,7 @@ StackLayout {
|
||||||
property int chatGroupsListViewCount: 0
|
property int chatGroupsListViewCount: 0
|
||||||
property bool isReply: false
|
property bool isReply: false
|
||||||
property var appSettings
|
property var appSettings
|
||||||
|
property bool isConnected: false
|
||||||
Layout.fillHeight: true
|
Layout.fillHeight: true
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.minimumWidth: 300
|
Layout.minimumWidth: 300
|
||||||
|
@ -26,7 +27,49 @@ StackLayout {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
z: 60
|
z: 60
|
||||||
spacing: 0
|
spacing: 0
|
||||||
TopBar {}
|
TopBar {
|
||||||
|
id: topBar
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RowLayout {
|
||||||
|
Layout.alignment: Qt.AlignHCenter
|
||||||
|
Layout.fillWidth: true
|
||||||
|
z: 60
|
||||||
|
Rectangle {
|
||||||
|
id: connectedStatusRect
|
||||||
|
Layout.fillWidth: true
|
||||||
|
height: 40;
|
||||||
|
color: isConnected ? Style.current.green : Style.current.darkGrey
|
||||||
|
visible: false
|
||||||
|
Text {
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
color: Style.current.white
|
||||||
|
id: connectedStatusLbl
|
||||||
|
text: isConnected ?
|
||||||
|
qsTr("Connected") :
|
||||||
|
qsTr("Disconnected")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Timer {
|
||||||
|
id: timer
|
||||||
|
}
|
||||||
|
|
||||||
|
Connections {
|
||||||
|
target: chatsModel
|
||||||
|
onOnlineStatusChanged: {
|
||||||
|
isConnected = connected
|
||||||
|
if(connected){
|
||||||
|
timer.setTimeout(function(){
|
||||||
|
connectedStatusRect.visible = false;
|
||||||
|
}, 5000);
|
||||||
|
} else {
|
||||||
|
connectedStatusRect.visible = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RowLayout {
|
RowLayout {
|
||||||
|
|
|
@ -11,6 +11,7 @@ Theme {
|
||||||
property color transparent: "#00000000"
|
property color transparent: "#00000000"
|
||||||
property color darkGrey: "#939BA1"
|
property color darkGrey: "#939BA1"
|
||||||
property color lightBlueText: "#8f9fec"
|
property color lightBlueText: "#8f9fec"
|
||||||
|
property color green: "#41cd52"
|
||||||
|
|
||||||
property color darkBlue: "#3c55c9"
|
property color darkBlue: "#3c55c9"
|
||||||
property color darkBlueBtn: "#5a70dd"
|
property color darkBlueBtn: "#5a70dd"
|
||||||
|
|
|
@ -16,7 +16,7 @@ Theme {
|
||||||
property color red: "#FF2D55"
|
property color red: "#FF2D55"
|
||||||
property color lightRed: "#FFEAEE"
|
property color lightRed: "#FFEAEE"
|
||||||
property color green: "#4EBC60"
|
property color green: "#4EBC60"
|
||||||
|
|
||||||
property color background: white
|
property color background: white
|
||||||
property color border: grey
|
property color border: grey
|
||||||
property color textColor: black
|
property color textColor: black
|
||||||
|
|
Loading…
Reference in New Issue