fix(general): online/offline selector updated

Fixes: #4049
This commit is contained in:
Sale Djenic 2021-11-22 12:08:09 +01:00 committed by Jakub
parent c0450f0580
commit 484748314f
18 changed files with 102 additions and 114 deletions

View File

@ -309,7 +309,8 @@ proc buildAndRegisterUserProfile(self: AppController) =
let pubKey = self.settingsService.getPubKey() let pubKey = self.settingsService.getPubKey()
let sendUserStatus = self.settingsService.getSendUserStatus() let sendUserStatus = self.settingsService.getSendUserStatus()
let currentUserStatus = self.settingsService.getCurrentUserStatus() ## This is still not in use. Read a comment in UserProfile.
## let currentUserStatus = self.settingsService.getCurrentUserStatus()
let obj = self.settingsService.getIdentityImage(loggedInAccount.keyUid) let obj = self.settingsService.getIdentityImage(loggedInAccount.keyUid)
singletonInstance.userProfile.setFixedData(loggedInAccount.name, loggedInAccount.keyUid, loggedInAccount.identicon, singletonInstance.userProfile.setFixedData(loggedInAccount.name, loggedInAccount.keyUid, loggedInAccount.identicon,
@ -317,7 +318,6 @@ proc buildAndRegisterUserProfile(self: AppController) =
singletonInstance.userProfile.setEnsName("") # in this moment we don't know ens name singletonInstance.userProfile.setEnsName("") # in this moment we don't know ens name
singletonInstance.userProfile.setThumbnailImage(obj.thumbnail) singletonInstance.userProfile.setThumbnailImage(obj.thumbnail)
singletonInstance.userProfile.setLargeImage(obj.large) singletonInstance.userProfile.setLargeImage(obj.large)
singletonInstance.userProfile.setSendUserStatus(sendUserStatus) singletonInstance.userProfile.setUserStatus(sendUserStatus)
singletonInstance.userProfile.setCurrentUserStatus(currentUserStatus)
singletonInstance.engine.setRootContextProperty("userProfile", self.userProfileVariant) singletonInstance.engine.setRootContextProperty("userProfile", self.userProfileVariant)

View File

@ -11,7 +11,7 @@ QtObject:
ensName: string ensName: string
thumbnailImage: string thumbnailImage: string
largeImage: string largeImage: string
sendUserStatus: bool userStatus: bool
currentUserStatus: int currentUserStatus: int
proc setup(self: UserProfile) = proc setup(self: UserProfile) =
@ -112,35 +112,49 @@ QtObject:
notify = largeImageChanged notify = largeImageChanged
proc sendUserStatusChanged*(self: UserProfile) {.signal.} proc userStatusChanged*(self: UserProfile) {.signal.}
proc getSendUserStatus*(self: UserProfile): bool {.slot.} = proc getUserStatus*(self: UserProfile): bool {.slot.} =
self.sendUserStatus self.userStatus
# this is not a slot # this is not a slot
proc setSendUserStatus*(self: UserProfile, status: bool) = proc setUserStatus*(self: UserProfile, status: bool) =
if(self.sendUserStatus == status): if(self.userStatus == status):
return return
self.sendUserStatus = status self.userStatus = status
self.sendUserStatusChanged() self.userStatusChanged()
QtProperty[bool] sendUserStatus: QtProperty[bool] userStatus:
read = getSendUserStatus read = getUserStatus
notify = sendUserStatusChanged notify = userStatusChanged
proc currentUserStatusChanged*(self: UserProfile) {.signal.} ## This is still not in use.
## Once we decide to differ more than Online/Offline statuses we shouldn't use this code below,
## but update current `userStatus` which is a bool to something like the code bellow (`currentUserStatus`).
##
## Proposal - some statuses we may have:
## type
## OnlineStatus* {.pure.} = enum
## Online = 0
## Idle
## DoNotDisturb
## Invisible
## Offline
##
##
## proc currentUserStatusChanged*(self: UserProfile) {.signal.}
proc getCurrentUserStatus*(self: UserProfile): int {.slot.} = ## proc getCurrentUserStatus*(self: UserProfile): int {.slot.} =
self.currentUserStatus ## self.currentUserStatus
# this is not a slot ## # this is not a slot
proc setCurrentUserStatus*(self: UserProfile, status: int) = ## proc setCurrentUserStatus*(self: UserProfile, status: int) =
if(self.currentUserStatus == status): ## if(self.currentUserStatus == status):
return ## return
self.currentUserStatus = status ## self.currentUserStatus = status
self.currentUserStatusChanged() ## self.currentUserStatusChanged()
QtProperty[int] currentUserStatus: ## QtProperty[int] currentUserStatus:
read = getCurrentUserStatus ## read = getCurrentUserStatus
notify = currentUserStatusChanged ## notify = currentUserStatusChanged

View File

@ -2,6 +2,7 @@ import controller_interface
import io_interface import io_interface
import ../../core/global_singleton import ../../core/global_singleton
import ../../../app_service/service/settings/service_interface as settings_service
import ../../../app_service/service/keychain/service as keychain_service import ../../../app_service/service/keychain/service as keychain_service
import ../../../app_service/service/accounts/service_interface as accounts_service import ../../../app_service/service/accounts/service_interface as accounts_service
import ../../../app_service/service/community/service as community_service import ../../../app_service/service/community/service as community_service
@ -15,12 +16,14 @@ type
Controller* = ref object of controller_interface.AccessInterface Controller* = ref object of controller_interface.AccessInterface
delegate: io_interface.AccessInterface delegate: io_interface.AccessInterface
events: EventEmitter events: EventEmitter
settingsService: settings_service.ServiceInterface
keychainService: keychain_service.Service keychainService: keychain_service.Service
accountsService: accounts_service.ServiceInterface accountsService: accounts_service.ServiceInterface
communityService: community_service.ServiceInterface communityService: community_service.ServiceInterface
proc newController*(delegate: io_interface.AccessInterface, proc newController*(delegate: io_interface.AccessInterface,
events: EventEmitter, events: EventEmitter,
settingsService: settings_service.ServiceInterface,
keychainService: keychain_service.Service, keychainService: keychain_service.Service,
accountsService: accounts_service.ServiceInterface, accountsService: accounts_service.ServiceInterface,
communityService: community_service.ServiceInterface): communityService: community_service.ServiceInterface):
@ -28,6 +31,7 @@ proc newController*(delegate: io_interface.AccessInterface,
result = Controller() result = Controller()
result.delegate = delegate result.delegate = delegate
result.events = events result.events = events
result.settingsService = settingsService
result.keychainService = keychainService result.keychainService = keychainService
result.accountsService = accountsService result.accountsService = accountsService
result.communityService = communityService result.communityService = communityService
@ -76,3 +80,7 @@ method storePassword*(self: Controller, password: string) =
return return
self.keychainService.storePassword(account.name, password) self.keychainService.storePassword(account.name, password)
method setUserStatus*(self: Controller, status: bool) =
self.settingsService.setSendUserStatus(status)
singletonInstance.userProfile.setUserStatus(status)

View File

@ -19,3 +19,6 @@ method checkForStoringPassword*(self: AccessInterface) {.base.} =
method storePassword*(self: AccessInterface, password: string) {.base.} = method storePassword*(self: AccessInterface, password: string) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method setUserStatus*(self: AccessInterface, status: bool) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -83,8 +83,8 @@ proc newModule*[T](
result.delegate = delegate result.delegate = delegate
result.view = view.newView(result) result.view = view.newView(result)
result.viewVariant = newQVariant(result.view) result.viewVariant = newQVariant(result.view)
result.controller = controller.newController(result, events, keychainService, result.controller = controller.newController(result, events, settingsService, keychainService, accountsService,
accountsService, communityService) communityService)
result.moduleLoaded = false result.moduleLoaded = false
# Submodules # Submodules
@ -208,3 +208,6 @@ method emitStoringPasswordError*[T](self: Module[T], errorDescription: string) =
method emitStoringPasswordSuccess*[T](self: Module[T]) = method emitStoringPasswordSuccess*[T](self: Module[T]) =
self.view.emitStoringPasswordSuccess() self.view.emitStoringPasswordSuccess()
method setUserStatus*[T](self: Module[T], status: bool) =
self.controller.setUserStatus(status)

View File

@ -3,3 +3,6 @@ method viewDidLoad*(self: AccessInterface) {.base.} =
method storePassword*(self: AccessInterface, password: string) {.base.} = method storePassword*(self: AccessInterface, password: string) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method setUserStatus*(self: AccessInterface, status: bool) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -49,8 +49,8 @@ method getProfile*[T](self: Controller[T]): item.Item =
ensVerified: false, ensVerified: false,
localNickname: "", localNickname: "",
messagesFromContactsOnly: messagesFromContactsOnly, messagesFromContactsOnly: messagesFromContactsOnly,
sendUserStatus: singletonInstance.userProfile.getSendUserStatus(), sendUserStatus: singletonInstance.userProfile.getUserStatus(),
currentUserStatus: singletonInstance.userProfile.getCurrentUserStatus(), currentUserStatus: 1, # This is still not in use. Read a comment in UserProfile.
identityImage: identityImage, identityImage: identityImage,
appearance: appearance, appearance: appearance,
added: false, added: false,

View File

@ -140,27 +140,3 @@ QtObject:
QtProperty[bool] hasIdentityImage: QtProperty[bool] hasIdentityImage:
read = hasIdentityImage read = hasIdentityImage
notify = identityImageChanged notify = identityImageChanged
proc sendUserStatus*(self: Model): bool {.slot.} = result = self.sendUserStatus
proc setSendUserStatus*(self: Model, sendUserStatus: bool) {.slot.} =
if self.sendUserStatus == sendUserStatus:
return
self.sendUserStatus = sendUserStatus
self.sendUserStatusChanged()
QtProperty[bool] sendUserStatus:
read = sendUserStatus
write = setSendUserStatus
notify = sendUserStatusChanged
proc currentUserStatus*(self: Model): int {.slot.} = result = self.currentUserStatus
proc setCurrentUserStatus*(self: Model, currentUserStatus: int) {.slot.} =
if self.currentUserStatus == currentUserStatus:
return
self.currentUserStatus = currentUserStatus
self.currentUserStatusChanged()
QtProperty[int] currentUserStatus:
read = currentUserStatus
write = setCurrentUserStatus
notify = currentUserStatusChanged

View File

@ -54,3 +54,6 @@ QtObject:
proc emitStoringPasswordSuccess*(self: View) = proc emitStoringPasswordSuccess*(self: View) =
self.storingPasswordSuccess() self.storingPasswordSuccess()
proc setUserStatus*(self: View, status: bool) {.slot.} =
self.delegate.setUserStatus(status)

View File

@ -185,12 +185,6 @@ QtObject:
QtProperty[QVariant] mutedChats: QtProperty[QVariant] mutedChats:
read = getMutedChats read = getMutedChats
proc setSendUserStatus*(self: ProfileView, sendUserStatus: bool) {.slot.} =
if (sendUserStatus == self.profile.sendUserStatus):
return
self.profile.setSendUserStatus(sendUserStatus)
self.status.saveSetting(Setting.SendUserStatus, sendUserStatus)
proc showOSNotification*(self: ProfileView, title: string, message: string, proc showOSNotification*(self: ProfileView, title: string, message: string,
notificationType: int, useOSNotifications: bool) {.slot.} = notificationType: int, useOSNotifications: bool) {.slot.} =

View File

@ -33,12 +33,9 @@ QtObject:
result.identityImage = IdentityImage() result.identityImage = IdentityImage()
result.ensVerified = false result.ensVerified = false
result.messagesFromContactsOnly = false result.messagesFromContactsOnly = false
result.sendUserStatus = false
result.currentUserStatus = 0
result.setup result.setup
proc identityImageChanged*(self: ProfileInfoView) {.signal.} proc identityImageChanged*(self: ProfileInfoView) {.signal.}
proc sendUserStatusChanged*(self: ProfileInfoView) {.signal.}
proc currentUserStatusChanged*(self: ProfileInfoView) {.signal.} proc currentUserStatusChanged*(self: ProfileInfoView) {.signal.}
proc appearanceChanged*(self: ProfileInfoView) {.signal.} proc appearanceChanged*(self: ProfileInfoView) {.signal.}
proc messagesFromContactsOnlyChanged*(self: ProfileInfoView) {.signal.} proc messagesFromContactsOnlyChanged*(self: ProfileInfoView) {.signal.}
@ -52,8 +49,6 @@ QtObject:
self.ensVerified = profile.ensVerified self.ensVerified = profile.ensVerified
self.identityImage = profile.identityImage self.identityImage = profile.identityImage
self.messagesFromContactsOnly = profile.messagesFromContactsOnly self.messagesFromContactsOnly = profile.messagesFromContactsOnly
self.sendUserStatus = profile.sendUserStatus
self.currentUserStatus = profile.currentUserStatus
proc username*(self: ProfileInfoView): string {.slot.} = result = self.username proc username*(self: ProfileInfoView): string {.slot.} = result = self.username
@ -139,26 +134,3 @@ QtObject:
read = hasIdentityImage read = hasIdentityImage
notify = identityImageChanged notify = identityImageChanged
proc sendUserStatus*(self: ProfileInfoView): bool {.slot.} = result = self.sendUserStatus
proc setSendUserStatus*(self: ProfileInfoView, sendUserStatus: bool) {.slot.} =
if self.sendUserStatus == sendUserStatus:
return
self.sendUserStatus = sendUserStatus
self.sendUserStatusChanged()
QtProperty[bool] sendUserStatus:
read = sendUserStatus
write = setSendUserStatus
notify = sendUserStatusChanged
proc currentUserStatus*(self: ProfileInfoView): int {.slot.} = result = self.currentUserStatus
proc setCurrentUserStatus*(self: ProfileInfoView, currentUserStatus: int) {.slot.} =
if self.currentUserStatus == currentUserStatus:
return
self.currentUserStatus = currentUserStatus
self.currentUserStatusChanged()
QtProperty[int] currentUserStatus:
read = currentUserStatus
write = setCurrentUserStatus
notify = currentUserStatusChanged

View File

@ -54,6 +54,10 @@ method getMessagesFromContactsOnly*(self: Service): bool =
method getSendUserStatus*(self: Service): bool = method getSendUserStatus*(self: Service): bool =
return status_go_settings.getSetting[bool](Setting.SendUserStatus) return status_go_settings.getSetting[bool](Setting.SendUserStatus)
method setSendUserStatus*(self: Service, value: bool) =
# this will be done in a proper way in `base_bc`, so far this is just a fix
discard status_go_settings.saveSetting(Setting.SendUserStatus, value)
method getCurrentUserStatus*(self: Service): int = method getCurrentUserStatus*(self: Service): int =
let userStatus = status_go_settings.getSetting[JsonNode](Setting.CurrentUserStatus) let userStatus = status_go_settings.getSetting[JsonNode](Setting.CurrentUserStatus)
return userStatus{"statusType"}.getInt() return userStatus{"statusType"}.getInt()

View File

@ -33,6 +33,9 @@ method getMessagesFromContactsOnly*(self: ServiceInterface): bool {.base.} =
method getSendUserStatus*(self: ServiceInterface): bool {.base.} = method getSendUserStatus*(self: ServiceInterface): bool {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method setSendUserStatus*(self: ServiceInterface, value: bool) {.base.} =
raise newException(ValueError, "No implementation available")
method getCurrentUserStatus*(self: ServiceInterface): int {.base.} = method getCurrentUserStatus*(self: ServiceInterface): int {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")

View File

@ -185,7 +185,7 @@ StatusAppThreePanelLayout {
community: root.rootStore.chatsModelInst.communities.activeCommunity community: root.rootStore.chatsModelInst.communities.activeCommunity
currentUserName: Utils.removeStatusEns(root.rootStore.profileModelInst.ens.preferredUsername currentUserName: Utils.removeStatusEns(root.rootStore.profileModelInst.ens.preferredUsername
|| root.rootStore.profileModelInst.profile.username) || root.rootStore.profileModelInst.profile.username)
currentUserOnline: root.rootStore.profileModelInst.profile.sendUserStatus currentUserOnline: root.store.userProfileInst.userStatus
} }
} }

View File

@ -13,6 +13,7 @@ QtObject {
property var walletModelInst: walletModel property var walletModelInst: walletModel
property var profileModelInst: profileModel property var profileModelInst: profileModel
property var profileModuleInst: profileModule property var profileModuleInst: profileModule
property var userProfileInst: userProfile
property bool isDebugEnabled: profileSectionModule.isDebugEnabled property bool isDebugEnabled: profileSectionModule.isDebugEnabled

View File

@ -2,12 +2,17 @@ import QtQuick 2.13
QtObject { QtObject {
id: root id: root
property var mainModuleInst: mainModule
property var profileModuleInst: profileModule
property var chatsModelInst: chatsModel property var chatsModelInst: chatsModel
property var walletModelInst: walletModel property var walletModelInst: walletModel
property var userProfileInst: userProfile
property var accounts: walletSectionAccounts.model property var accounts: walletSectionAccounts.model
property var currentAccount: walletSectionCurrent property var currentAccount: walletSectionCurrent
property var profileModelInst: profileModel property var profileModelInst: profileModel
property var assets: walletSectionAccountTokens.model property var assets: walletSectionAccountTokens.model
property MessageStore messageStore: MessageStore { } property MessageStore messageStore: MessageStore { }

View File

@ -361,9 +361,8 @@ Item {
badge.implicitHeight: 15 badge.implicitHeight: 15
badge.implicitWidth: 15 badge.implicitWidth: 15
badge.border.color: hovered ? Theme.palette.statusBadge.hoverBorderColor : Theme.palette.statusAppNavBar.backgroundColor badge.border.color: hovered ? Theme.palette.statusBadge.hoverBorderColor : Theme.palette.statusAppNavBar.backgroundColor
badge.color: {
return userProfile.sendUserStatus ? Style.current.green : Style.current.midGrey
/* /*
//This is still not in use. Read a comment for `currentUserStatus` in UserProfile on the nim side.
// Use this code once support for custom user status is added // Use this code once support for custom user status is added
switch(userProfile.currentUserStatus){ switch(userProfile.currentUserStatus){
case Constants.statusType_Online: case Constants.statusType_Online:
@ -373,7 +372,7 @@ Item {
default: default:
return Style.current.midGrey; return Style.current.midGrey;
}*/ }*/
} badge.color: appMain.rootStore.userProfileInst.userStatus ? Style.current.green : Style.current.midGrey
badge.border.width: 3 badge.border.width: 3
onClicked: { onClicked: {
userStatusContextMenu.opened ? userStatusContextMenu.opened ?

View File

@ -35,7 +35,7 @@ PopupMenu {
} }
StyledText { StyledText {
id: username id: username
text: Utils.removeStatusEns(profileModel.ens.preferredUsername || userProfile.username) text: Utils.removeStatusEns(root.store.profileModelInst.ens.preferredUsername || root.store.userProfileInst.username)
elide: Text.ElideRight elide: Text.ElideRight
maximumLineCount: 3 maximumLineCount: 3
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
@ -71,7 +71,7 @@ PopupMenu {
hoverEnabled: true hoverEnabled: true
cursorShape: Qt.PointingHandCursor cursorShape: Qt.PointingHandCursor
onClicked: { onClicked: {
openProfilePopup(userProfile.username, userProfile.pubKey, userProfile.thumbnailImage); openProfilePopup(root.store.userProfileInst.username, root.store.userProfileInst.pubKey, root.store.userProfileInst.thumbnailImage)
root.close() root.close()
} }
} }
@ -86,10 +86,10 @@ PopupMenu {
Action { Action {
text: qsTr("Online") text: qsTr("Online")
onTriggered: { onTriggered: {
if (userProfile.sendUserStatus != true) { if (!root.store.userProfileInst.sendUserStatus) {
root.store.profileModelInst.profile.setSendUserStatus(true) root.store.mainModuleInst.setUserStatus(true)
} }
root.close() root.close();
} }
icon.color: Style.current.green icon.color: Style.current.green
icon.source: Style.svg("online") icon.source: Style.svg("online")
@ -100,10 +100,10 @@ PopupMenu {
Action { Action {
text: qsTr("Offline") text: qsTr("Offline")
onTriggered: { onTriggered: {
if (userProfile.sendUserStatus != false) { if (root.store.userProfileInst.userStatus) {
root.store.profileModelInst.profile.setSendUserStatus(false) root.store.mainModuleInst.setUserStatus(false)
} }
root.close() root.close();
} }
icon.color: Style.current.midGrey icon.color: Style.current.midGrey