From afe6d34735238d765882305b2b9080b7bf0d58cc Mon Sep 17 00:00:00 2001 From: Sale Djenic Date: Fri, 3 Dec 2021 20:57:25 +0100 Subject: [PATCH] refactor: issues after rebase onto `master` fixed --- src/app/chat/view.nim | 20 +++++--- src/app/chat/views/chat_item.nim | 25 ++++------ src/app/chat/views/messages.nim | 25 +++++++--- src/app/chat/views/reactions.nim | 11 +++- .../profile_section/contacts/controller.nim | 3 -- .../main/profile_section/contacts/model.nim | 6 --- .../main/profile_section/controller.nim | 5 +- src/app_service/service/contacts/service.nim | 41 +++++++++++---- .../service/settings/dto/settings.nim | 5 +- src/app_service/service/settings/service.nim | 50 +++++-------------- .../service/settings/service_interface.nim | 16 +++--- ui/app/AppLayouts/Chat/ChatLayout.qml | 4 -- 12 files changed, 104 insertions(+), 107 deletions(-) diff --git a/src/app/chat/view.nim b/src/app/chat/view.nim index 01b96b04b5..a135095975 100644 --- a/src/app/chat/view.nim +++ b/src/app/chat/view.nim @@ -1,6 +1,6 @@ import NimQml, Tables, json, sequtils, chronicles, strutils, os, strformat import status/[status] -import status/utils as status_utils +#import status/utils as status_utils import status/chat as status_chat import status/messages as status_messages import status/mailservers @@ -308,15 +308,19 @@ QtObject: self.messageView.removeChat(chatId) proc toggleReaction*(self: ChatsView, messageId: string, emojiId: int) {.slot.} = - if self.channelView.activeChannel.id == status_utils.getTimelineChatId(): - let message = self.messageView.messageList[status_utils.getTimelineChatId()].getMessageById(messageId) - self.reactions.toggle(messageId, message.chatId, emojiId) - else: - self.reactions.toggle(messageId, self.channelView.activeChannel.id, emojiId) + discard + # Not Refactored Yet + # if self.channelView.activeChannel.id == status_utils.getTimelineChatId(): + # let message = self.messageView.messageList[status_utils.getTimelineChatId()].getMessageById(messageId) + # self.reactions.toggle(messageId, message.chatId, emojiId) + # else: + # self.reactions.toggle(messageId, self.channelView.activeChannel.id, emojiId) proc removeMessagesFromTimeline*(self: ChatsView, chatId: string) = - self.messageView.messageList[status_utils.getTimelineChatId()].deleteMessagesByChatId(chatId) - self.channelView.activeChannelChanged() + discard + # Not Refactored Yet + # self.messageView.messageList[status_utils.getTimelineChatId()].deleteMessagesByChatId(chatId) + # self.channelView.activeChannelChanged() proc updateChats*(self: ChatsView, chats: seq[Chat]) = for chat in chats: diff --git a/src/app/chat/views/chat_item.nim b/src/app/chat/views/chat_item.nim index 4e3c6d87d0..3e29972327 100644 --- a/src/app/chat/views/chat_item.nim +++ b/src/app/chat/views/chat_item.nim @@ -1,6 +1,6 @@ import NimQml, Tables, std/wrapnils import status/[chat/chat, status, ens, accounts, settings] -import status/utils as status_utils +#import status/utils as status_utils import status/types/[setting] import chat_members @@ -26,8 +26,6 @@ QtObject: result.chatMembers = newChatMembersView(status) result.setup - proc chatItemChanged*(self: ChatItemView) {.signal.} - proc membershipChanged*(self: ChatItemView) {.signal.} proc setChatItem*(self: ChatItemView, chatItem: Chat) = @@ -37,7 +35,6 @@ QtObject: self.chatItem = chatItem self.chatMembers.setMembers(chatItem.members) self.membershipChanged() - self.chatItemChanged() proc id*(self: ChatItemView): string {.slot.} = result = ?.self.chatItem.id @@ -146,6 +143,14 @@ QtObject: read = getMembers notify = membershipChanged + proc isTimelineChat*(self: ChatItemView): bool {.slot.} = + # Not Refactored Yet + #result = ?.self.chatItem.id == status_utils.getTimelineChatId() + return false + + QtProperty[bool] isTimelineChat: + read = isTimelineChat + proc mentionsCount*(self: ChatItemView): int {.slot.} = result = ?.self.chatItem.mentionsCount @@ -208,15 +213,3 @@ QtObject: self.chatItem.muted = false self.status.chat.unmuteChat(self.chatItem) self.mutedChanged() - - proc syncedFrom*(self: ChatItemView): string {.slot.} = result = $(?.self.chatItem.syncedFrom) - - proc syncedTo*(self: ChatItemView): string {.slot.} = result = $(?.self.chatItem.syncedTo) - - QtProperty[string] syncedFrom: - read = syncedFrom - notify = chatItemChanged - - QtProperty[string] syncedTo: - read = syncedTo - notify = chatItemChanged \ No newline at end of file diff --git a/src/app/chat/views/messages.nim b/src/app/chat/views/messages.nim index 88b99d0f21..9b95656f53 100644 --- a/src/app/chat/views/messages.nim +++ b/src/app/chat/views/messages.nim @@ -2,7 +2,7 @@ import NimQml, Tables, json, sequtils, chronicles, times, re, strutils, sugar import status/[status, contacts] import status/messages as status_messages -import status/utils as status_utils +#import status/utils as status_utils import status/chat/[chat] import status/types/[message, profile] @@ -54,6 +54,8 @@ QtObject: result.communities = communitiesView result.messageList = initOrderedTable[string, ChatMessageList]() result.pinnedMessagesList = initOrderedTable[string, ChatMessageList]() + # Not Rrefactored Yet + # result.messageList[status_utils.getTimelineChatId()] = newChatMessageList(status_utils.getTimelineChatId(), result.status, false) result.loadingMessages = false result.unreadMessageCnt = 0 result.unreadDirectMessagesAndMentionsCount = 0 @@ -167,7 +169,7 @@ QtObject: let channel = self.channelView.getChannelById(id) if (channel == nil): return - self.messageList[id].clear(not channel.isNil) + self.messageList[id].clear(not channel.isNil and channel.chatType != ChatType.Profile) self.messagesCleared() proc getBlockedContacts*(self: MessageView): seq[string] = @@ -188,7 +190,7 @@ QtObject: if not self.messageList.hasKey(channel): self.beginInsertRows(newQModelIndex(), self.messageList.len, self.messageList.len) - self.messageList[channel] = newChatMessageList(channel, self.status, not chat.isNil, blockedContacts) + self.messageList[channel] = newChatMessageList(channel, self.status, not chat.isNil and chat.chatType != ChatType.Profile, blockedContacts) self.channelOpenTime[channel] = now().toTime.toUnix * 1000 self.endInsertRows(); if not self.pinnedMessagesList.hasKey(channel): @@ -225,11 +227,20 @@ QtObject: msg.userName = self.status.chat.getUserName(msg.fromAuthor, msg.alias) var msgIndex:int; if self.status.chat.channels.hasKey(msg.chatId): - self.messageList[msg.chatId].add(msg) - if self.pinnedMessagesList[msg.chatId].contains(msg): - self.pinnedMessagesList[msg.chatId].add(msg) + let chat = self.status.chat.channels[msg.chatId] + if (chat.chatType == ChatType.Profile): + # Not Rrefactored Yet + let timelineChatId = "" #status_utils.getTimelineChatId() + self.messageList[timelineChatId].add(msg) - msgIndex = self.messageList[msg.chatId].count - 1 + if self.channelView.activeChannel.id == timelineChatId: self.channelView.activeChannelChanged() + msgIndex = self.messageList[timelineChatId].count - 1 + else: + self.messageList[msg.chatId].add(msg) + if self.pinnedMessagesList[msg.chatId].contains(msg): + self.pinnedMessagesList[msg.chatId].add(msg) + + msgIndex = self.messageList[msg.chatId].count - 1 self.messagePushed(msgIndex) if self.channelOpenTime.getOrDefault(msg.chatId, high(int64)) < msg.timestamp.parseFloat.fromUnixFloat.toUnix: diff --git a/src/app/chat/views/reactions.nim b/src/app/chat/views/reactions.nim index ec700774a9..c45bdaf79a 100644 --- a/src/app/chat/views/reactions.nim +++ b/src/app/chat/views/reactions.nim @@ -1,7 +1,7 @@ import NimQml, tables, json, chronicles -import status/[status, chat/chat, settings] +import status/[status, settings] import message_list, chat_item -import status/utils as status_utils +#import status/utils as status_utils import status/types/[message, setting] logScope: @@ -36,6 +36,9 @@ QtObject: proc messageEmojiReactionId(self: ReactionView, chatId: string, messageId: string, emojiId: int): string = let chat = self.status.chat.channels[chatId] var chatId = chatId + # Not Rrefactored Yet + # if chat.chatType == ChatType.Profile: + # chatId = status_utils.getTimelineChatId() if (self.messageList[][chatId].getReactions(messageId) == "") : return "" @@ -67,6 +70,10 @@ QtObject: let chat = self.status.chat.channels[chatId] var messageList = self.messageList[][chatId] + # Not Rrefactored Yet + # if chat.chatType == ChatType.Profile: + # messageList = self.messageList[][status_utils.getTimelineChatId()] + var emojiReactions = messageList.getReactions(reaction.messageId) var oldReactions: JsonNode if (emojiReactions == "") : diff --git a/src/app/modules/main/profile_section/contacts/controller.nim b/src/app/modules/main/profile_section/contacts/controller.nim index dcbd124c3c..114167c96e 100644 --- a/src/app/modules/main/profile_section/contacts/controller.nim +++ b/src/app/modules/main/profile_section/contacts/controller.nim @@ -6,9 +6,6 @@ import ../../../../../app_service/service/contacts/service as contacts_service import ../../../../../app_service/service/contacts/dto/contacts import ../../../../../app_service/service/accounts/service as accounts_service -import status/signals - -# import ./item as item import eventemitter export controller_interface diff --git a/src/app/modules/main/profile_section/contacts/model.nim b/src/app/modules/main/profile_section/contacts/model.nim index 6f7ef218e9..59d4c6fe01 100644 --- a/src/app/modules/main/profile_section/contacts/model.nim +++ b/src/app/modules/main/profile_section/contacts/model.nim @@ -67,12 +67,6 @@ QtObject: self.blockedContacts.changeNicknameForContactWithId(id, nickname) self.contactRequests.changeNicknameForContactWithId(id, nickname) - proc changeNicknameForContactWithId*(self: Model, id: string, nickname: string) = - self.contactList.changeNicknameForContactWithId(id, nickname) - self.addedContacts.changeNicknameForContactWithId(id, nickname) - self.blockedContacts.changeNicknameForContactWithId(id, nickname) - self.contactRequests.changeNicknameForContactWithId(id, nickname) - proc updateContactList*(self: Model, contacts: seq[ContactsDto]) = for contact in contacts: var requestAlreadyAdded = false diff --git a/src/app/modules/main/profile_section/controller.nim b/src/app/modules/main/profile_section/controller.nim index cc3aad15b7..9fec1d8897 100644 --- a/src/app/modules/main/profile_section/controller.nim +++ b/src/app/modules/main/profile_section/controller.nim @@ -55,10 +55,11 @@ method isTelemetryEnabled*[T](self: Controller[T]): bool = return self.settingsService.getTelemetryServerUrl().len > 0 method toggleAutoMessage*[T](self: Controller[T]) = - self.settingsService.toggleAutoMessage() + let enabled = self.settingsService.autoMessageEnabled() + discard self.settingsService.saveAutoMessageEnabled(not enabled) method isAutoMessageEnabled*[T](self: Controller[T]): bool = - return self.settingsService.isAutoMessageEnabled() + return self.settingsService.autoMessageEnabled() method toggleDebug*[T](self: Controller[T]) = discard diff --git a/src/app_service/service/contacts/service.nim b/src/app_service/service/contacts/service.nim index 029da96e18..c56e98f6d1 100644 --- a/src/app_service/service/contacts/service.nim +++ b/src/app_service/service/contacts/service.nim @@ -132,29 +132,36 @@ QtObject: else: contact.blocked = false + let response = status_contacts.addContact(contact.id, contact.name) + if(not response.error.isNil): + let msg = response.error.message + error "error adding contact ", msg + return self.saveContact(contact) - - var ensName = "" - if contact.name.endsWith(".eth"): - ensName = contact.name - - status_contacts.addContact(contact.id, ensName) self.events.emit(SIGNAL_CONTACT_ADDED, ContactAddedArgs(contact: contact)) proc rejectContactRequest*(self: Service, publicKey: string) = var contact = self.getContactById(publicKey) contact.hasAddedUs = false + let response = status_contacts.rejectContactRequest(contact.id) + if(not response.error.isNil): + let msg = response.error.message + error "error rejecting contact ", msg + return self.saveContact(contact) - status_contacts.rejectContactRequest(contact.id) self.events.emit(SIGNAL_CONTACT_REMOVED, ContactArgs(contactId: contact.id)) proc changeContactNickname*(self: Service, publicKey: string, nickname: string) = var contact = self.getContactById(publicKey) contact.localNickname = nickname + let response = status_contacts.setContactLocalNickname(contact.id, contact.localNickname) + if(not response.error.isNil): + let msg = response.error.message + error "error setting local name ", msg + return self.saveContact(contact) - status_contacts.setContactLocalNickname(contact.id, contact.localNickname) let data = ContactNicknameUpdatedArgs(contactId: contact.id, nickname: nickname) self.events.emit(SIGNAL_CONTACT_NICKNAME_CHANGED, data) @@ -162,16 +169,24 @@ QtObject: var contact = self.getContactById(publicKey) contact.blocked = false + let response = status_contacts.unblockContact(contact.id) + if(not response.error.isNil): + let msg = response.error.message + error "error unblocking contact ", msg + return self.saveContact(contact) - status_contacts.unblockContact(contact.id) self.events.emit(SIGNAL_CONTACT_UNBLOCKED, ContactArgs(contactId: contact.id)) proc blockContact*(self: Service, publicKey: string) = var contact = self.getContactById(publicKey) contact.blocked = true + let response = status_contacts.blockContact(contact.id) + if(not response.error.isNil): + let msg = response.error.message + error "error blocking contact ", msg + return self.saveContact(contact) - status_contacts.blockContact(contact.id) self.events.emit(SIGNAL_CONTACT_BLOCKED, ContactArgs(contactId: contact.id)) proc removeContact*(self: Service, publicKey: string) = @@ -179,8 +194,12 @@ QtObject: contact.added = false contact.hasAddedUs = false + let response = status_contacts.removeContact(contact.id) + if(not response.error.isNil): + let msg = response.error.message + error "error removing contact ", msg + return self.saveContact(contact) - status_contacts.removeContact(contact.id) self.events.emit(SIGNAL_CONTACT_REMOVED, ContactArgs(contactId: contact.id)) proc ensResolved*(self: Service, id: string) {.slot.} = diff --git a/src/app_service/service/settings/dto/settings.nim b/src/app_service/service/settings/dto/settings.nim index a79f9e0d9c..29d7cce837 100644 --- a/src/app_service/service/settings/dto/settings.nim +++ b/src/app_service/service/settings/dto/settings.nim @@ -1,4 +1,4 @@ -import json, options, tables, strutils, sequtils +import json, options, tables, strutils import ../../stickers/dto/stickers include ../../../common/json_utils @@ -38,6 +38,7 @@ const KEY_INSTALLED_STICKER_PACKS* = "stickers/packs-installed" const KEY_FLEET* = "fleet" const KEY_NODE_CONFIG* = "node-config" const KEY_WAKU_BLOOM_FILTER_MODE* = "waku-bloom-filter-mode" +const KEY_AUTO_MESSAGE_ENABLED* = "auto-message-enabled?" type UpstreamConfig* = object enabled*: bool @@ -101,6 +102,7 @@ type wakuBloomFilterMode*: bool recentStickerHashes*: seq[string] installedStickerPacks*: Table[int, StickerPackDto] + autoMessageEnabled*: bool proc toUpstreamConfig*(jsonObj: JsonNode): UpstreamConfig = discard jsonObj.getProp("Enabled", result.enabled) @@ -189,6 +191,7 @@ proc toSettingsDto*(jsonObj: JsonNode): SettingsDto = discard jsonObj.getProp(KEY_SEND_STATUS_UPDATES, result.sendStatusUpdates) discard jsonObj.getProp(KEY_TELEMETRY_SERVER_URL, result.telemetryServerUrl) discard jsonObj.getProp(KEY_FLEET, result.fleet) + discard jsonObj.getProp(KEY_AUTO_MESSAGE_ENABLED, result.autoMessageEnabled) var pinnedMailserversObj: JsonNode if(jsonObj.getProp(KEY_PINNED_MAILSERVERS, pinnedMailserversObj)): diff --git a/src/app_service/service/settings/service.nim b/src/app_service/service/settings/service.nim index 1b1eb5e055..08186ee039 100644 --- a/src/app_service/service/settings/service.nim +++ b/src/app_service/service/settings/service.nim @@ -1,7 +1,7 @@ import chronicles, json, sequtils, tables, sugar import service_interface, ./dto/settings -import status/statusgo_backend_new/settings as status_go +import status/statusgo_backend_new/settings as status_settings export service_interface @@ -22,7 +22,7 @@ proc newService*(): Service = method init*(self: Service) = try: - let response = status_go.getSettings() + let response = status_settings.getSettings() self.settings = response.result.toSettingsDto() except Exception as e: let errDesription = e.msg @@ -30,7 +30,7 @@ method init*(self: Service) = return proc saveSetting(self: Service, attribute: string, value: string | JsonNode | bool | int): bool = - let response = status_go.saveSettings(attribute, value) + let response = status_settings.saveSettings(attribute, value) if(not response.error.isNil): error "error saving settings: ", errDescription = response.error.message return false @@ -300,38 +300,6 @@ method getPinnedMailservers*(self: Service): PinnedMailservers = method getWalletVisibleTokens*(self: Service): seq[string] = self.settings.walletVisibleTokens.tokens -method toggleTelemetry*(self: Service) = - let telemetryServerUrl = status_go_settings.getSetting[string](Setting.TelemetryServerUrl) - var newValue = "" - if telemetryServerUrl == "": - newValue = "https://telemetry.status.im" - - discard status_go_settings.saveSetting(Setting.TelemetryServerUrl, newValue) - -method isTelemetryEnabled*(self: Service): bool = - let telemetryServerUrl = status_go_settings.getSetting[string](Setting.TelemetryServerUrl) - return telemetryServerUrl != "" - -method toggleAutoMessage*(self: Service) = - let enabled = status_go_settings.getSetting[bool](Setting.AutoMessageEnabled) - discard status_go_settings.saveSetting(Setting.AutoMessageEnabled, not enabled) - -method isAutoMessageEnabled*(self: Service): bool = - return status_go_settings.getSetting[bool](Setting.AutoMessageEnabled) - -method toggleDebug*(self: Service) = - var nodeConfig = status_go_settings.getNodeConfig() - if nodeConfig["LogLevel"].getStr() == $LogLevel.INFO: - nodeConfig["LogLevel"] = newJString($LogLevel.DEBUG) - else: - nodeConfig["LogLevel"] = newJString($LogLevel.INFO) - discard status_go_settings.saveSetting(Setting.NodeConfig, nodeConfig) - quit(QuitSuccess) # quits the app TODO: change this to logout instead when supported - -method isDebugEnabled*(self: Service): bool = - let nodeConfig = status_go_settings.getNodeConfig() - return nodeConfig["LogLevel"].getStr() != $LogLevel.INFO - method saveWalletVisibleTokens*(self: Service, tokens: seq[string]): bool = var obj = newJObject() obj[self.getCurrentNetwork()] = %* tokens @@ -379,7 +347,6 @@ method saveRecentStickers*(self: Service, installedStickerPacks: Table[int, Stic return true return false - method saveNodeConfiguration*(self: Service, value: JsonNode): bool = if(self.saveSetting(KEY_NODE_CONFIG, value)): self.settings.nodeConfig = value @@ -390,4 +357,13 @@ method saveWakuBloomFilterMode*(self: Service, value: bool): bool = if(self.saveSetting(KEY_WAKU_BLOOM_FILTER_MODE, value)): self.settings.wakuBloomFilterMode = value return true - return false \ No newline at end of file + return false + +method saveAutoMessageEnabled*(self: Service, value: bool): bool = + if(self.saveSetting(KEY_AUTO_MESSAGE_ENABLED, value)): + self.settings.autoMessageEnabled = value + return true + return false + +method autoMessageEnabled*(self: Service): bool = + return self.settings.autoMessageEnabled \ No newline at end of file diff --git a/src/app_service/service/settings/service_interface.nim b/src/app_service/service/settings/service_interface.nim index 03a3bec4ad..fda925854a 100644 --- a/src/app_service/service/settings/service_interface.nim +++ b/src/app_service/service/settings/service_interface.nim @@ -123,15 +123,6 @@ method saveDefaultSyncPeriod*(self: ServiceInterface, value: int): bool {.base.} method getDefaultSyncPeriod*(self: ServiceInterface): int {.base.} = raise newException(ValueError, "No implementation available") -method toggleAutoMessage*(self: ServiceInterface) {.base.} = - raise newException(ValueError, "No implementation available") - -method isAutoMessageEnabled*(self: ServiceInterface): bool {.base.} = - raise newException(ValueError, "No implementation available") - -method toggleDebug*(self: ServiceInterface) {.base.} = - raise newException(ValueError, "No implementation available") - method saveSendPushNotifications*(self: ServiceInterface, value: bool): bool {.base.} = raise newException(ValueError, "No implementation available") @@ -225,9 +216,14 @@ method getInstalledStickerPacks*(self: ServiceInterface): Table[int, StickerPack method saveRecentStickers*(self: ServiceInterface, installedStickerPacks: Table[int, StickerPackDto]): bool {.base.} = raise newException(ValueError, "No implementation available") - method saveNodeConfiguration*(self: ServiceInterface, value: JsonNode): bool {.base.} = raise newException(ValueError, "No implementation available") method saveWakuBloomFilterMode*(self: ServiceInterface, value: bool): bool {.base.} = + raise newException(ValueError, "No implementation available") + +method saveAutoMessageEnabled*(self: ServiceInterface, value: bool): bool {.base.} = + raise newException(ValueError, "No implementation available") + +method autoMessageEnabled*(self: ServiceInterface): bool {.base.} = raise newException(ValueError, "No implementation available") \ No newline at end of file diff --git a/ui/app/AppLayouts/Chat/ChatLayout.qml b/ui/app/AppLayouts/Chat/ChatLayout.qml index f776b6418e..c79e38f2f3 100644 --- a/ui/app/AppLayouts/Chat/ChatLayout.qml +++ b/ui/app/AppLayouts/Chat/ChatLayout.qml @@ -55,10 +55,6 @@ StatusAppThreePanelLayout { // root.rootStore.chatsModelInst.channelView.restorePreviousActiveChannel(); // chatColumn.onActivated(); // } - // Not Refactored - property RootStore rootStore: RootStore { - messageStore: root.messageStore - } leftPanel: Loader { id: contactColumnLoader