refactor: re-hook disconnected and re-connected signals and banner

This commit is contained in:
Jonathan Rainville 2022-02-25 13:15:35 -05:00
parent bfda545646
commit 6fa74b7ba9
10 changed files with 89 additions and 42 deletions

View File

@ -15,6 +15,7 @@ import ../../../app_service/service/message/service as message_service
import ../../../app_service/service/gif/service as gif_service
import ../../../app_service/service/mailservers/service as mailservers_service
import ../../../app_service/service/privacy/service as privacy_service
import ../../../app_service/service/node/service as node_service
export controller_interface
@ -35,6 +36,7 @@ type
gifService: gif_service.Service
privacyService: privacy_service.Service
mailserversService: mailservers_service.Service
nodeService: node_service.Service
activeSectionId: string
proc newController*(delegate: io_interface.AccessInterface,
@ -48,7 +50,8 @@ proc newController*(delegate: io_interface.AccessInterface,
messageService: message_service.Service,
gifService: gif_service.Service,
privacyService: privacy_service.Service,
mailserversService: mailservers_service.Service
mailserversService: mailservers_service.Service,
nodeService: node_service.Service
):
Controller =
result = Controller()
@ -63,7 +66,7 @@ proc newController*(delegate: io_interface.AccessInterface,
result.messageService = messageService
result.gifService = gifService
result.privacyService = privacyService
result.mailserversService = mailserversService
result.nodeService = nodeService
method delete*(self: Controller) =
discard
@ -178,6 +181,15 @@ method init*(self: Controller) =
var args = CommunityRequestArgs(e)
self.delegate.newCommunityMembershipRequestReceived(args.communityRequest)
self.events.on(SIGNAL_NETWORK_CONNECTED) do(e: Args):
self.delegate.onNetworkConnected()
self.events.on(SIGNAL_NETWORK_DISCONNECTED) do(e: Args):
self.delegate.onNetworkDisconnected()
method isConnected*(self: Controller): bool =
return self.nodeService.isConnected()
method getJoinedCommunities*(self: Controller): seq[CommunityDto] =
return self.communityService.getJoinedCommunities()

View File

@ -62,3 +62,6 @@ method switchTo*(self: AccessInterface, sectionId, chatId, messageId: string) {.
method getCommunityById*(self: AccessInterface, communityId: string): CommunityDto {.base.} =
raise newException(ValueError, "No implementation available")
method isConnected*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -125,7 +125,8 @@ proc newModule*[T](
messageService,
gifService,
privacyService,
mailserversService
mailserversService,
nodeService
)
result.moduleLoaded = false
@ -550,6 +551,15 @@ method onNotificationsUpdated[T](self: Module[T], sectionId: string, sectionHasU
sectionNotificationCount: int) =
self.view.model().udpateNotifications(sectionId, sectionHasUnreadMessages, sectionNotificationCount)
method onNetworkConnected[T](self: Module[T]) =
self.view.setConnected(true)
method onNetworkDisconnected[T](self: Module[T]) =
self.view.setConnected(false)
method isConnected[T](self: Module[T]): bool =
self.controller.isConnected()
method getAppSearchModule*[T](self: Module[T]): QVariant =
self.appSearchModule.getModuleAsVariant()

View File

@ -47,3 +47,9 @@ method osNotificationClicked*(self: AccessInterface, details: NotificationDetail
method newCommunityMembershipRequestReceived*(self: AccessInterface, membershipRequest: CommunityMembershipRequestDto)
{.base.} =
raise newException(ValueError, "No implementation available")
method onNetworkConnected*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method onNetworkDisconnected*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -34,3 +34,6 @@ method rebuildChatSearchModel*(self: AccessInterface) {.base.} =
method switchTo*(self: AccessInterface, sectionId, chatId: string) {.base.} =
raise newException(ValueError, "No implementation available")
method isConnected*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -165,3 +165,15 @@ QtObject:
proc openCommunityMembershipRequestsPopup*(self: View, sectionId: string) {.signal.}
proc emitOpenCommunityMembershipRequestsPopupSignal*(self: View, sectionId: string) =
self.openCommunityMembershipRequestsPopup(sectionId)
proc onlineStatusChanged(self: View, connected: bool) {.signal.}
proc isConnected*(self: View): bool {.slot.} =
result = self.delegate.isConnected()
proc setConnected*(self: View, connected: bool) = # Not a slot
self.onlineStatusChanged(connected)
QtProperty[bool] isOnline:
read = isConnected
notify = onlineStatusChanged

View File

@ -96,3 +96,5 @@ QtObject:
self.peers = peers
proc peerCount*(self: Service): int = self.peers.len
proc isConnected*(self: Service): bool = self.connected

View File

@ -268,27 +268,26 @@ ColumnLayout {
qsTrId("disconnected")
}
// Not Refactored Yet
// Connections {
// target: chatContentRoot.rootStore.chatsModelInst
// onOnlineStatusChanged: {
// if (connected == isConnected) return;
// isConnected = connected;
// if(isConnected){
// timer.setTimeout(function(){
// connectedStatusRect.visible = false;
// }, 5000);
// } else {
// connectedStatusRect.visible = true;
// }
// }
// }
// Component.onCompleted: {
// isConnected = chatContentRoot.rootStore.chatsModelInst.isOnline
// if(!isConnected){
// connectedStatusRect.visible = true
// }
// }
Connections {
target: mainModule
onOnlineStatusChanged: {
if (connected == isConnected) return;
isConnected = connected;
if(isConnected){
timer.setTimeout(function(){
connectedStatusRect.visible = false;
}, 5000);
} else {
connectedStatusRect.visible = true;
}
}
}
Component.onCompleted: {
isConnected = mainModule.isOnline
if(!isConnected){
connectedStatusRect.visible = true
}
}
}
StatusBanner {

View File

@ -52,17 +52,17 @@ Rectangle {
}
]
// Connections {
// target: RootStore.chatsModelInst
// onOnlineStatusChanged: {
// if (connected && root.state !== "ready" &&
// root.visible &&
// root.source &&
// root.source.startsWith("http")) {
// root.reload()
// }
// }
// }
Connections {
target: mainModule
onOnlineStatusChanged: {
if (connected && root.state !== "ready" &&
root.visible &&
root.source &&
root.source.startsWith("http")) {
root.reload()
}
}
}
function reload() {
// From the documentation (https://doc.qt.io/qt-5/qml-qtquick-image.html#sourceSize-prop)

View File

@ -41,12 +41,12 @@ Popup {
footerContent.visible = true
stickersContainer.visible = true
}
// Connections {
// target: chatsModel
// onOnlineStatusChanged: {
// root.close()
// }
// }
Connections {
target: mainModule
onOnlineStatusChanged: {
root.close()
}
}
Component.onCompleted: {
if (stickersModule.packsLoaded) {