From c858eed50fd7dd86ddf9a58b7edbf492bdef9a7c Mon Sep 17 00:00:00 2001 From: Alexandra Betouni <31625338+alexandraB99@users.noreply.github.com> Date: Fri, 3 Dec 2021 19:55:34 +0200 Subject: [PATCH] refactor(timeline): Removed all timeline related code (#122) This feature is deprecated and shall be removed Relates to #4064 --- status/chat.nim | 59 ++++++++++---------------------- status/contacts.nim | 1 - status/statusgo_backend/chat.nim | 3 -- status/types/chat.nim | 5 ++- status/utils.nim | 6 ---- 5 files changed, 21 insertions(+), 53 deletions(-) diff --git a/status/chat.nim b/status/chat.nim index a782be2..2e2483c 100644 --- a/status/chat.nim +++ b/status/chat.nim @@ -156,7 +156,7 @@ proc removeChatFilters(self: ChatModel, chatId: string) = for filter in filters: if filter["chatId"].getStr == chatId: status_chat.removeFilters(chatId, filter["filterId"].getStr) - of ChatType.OneToOne, ChatType.Profile: + of ChatType.OneToOne: # Check if user does not belong to any active chat group var inGroup = false for channel in self.channels.values: @@ -256,6 +256,19 @@ proc sortChats(x, y: chat_type.Chat): int = elif t1 == t2: 0 else: -1 +proc leave*(self: ChatModel, chatId: string) = + self.removeChatFilters(chatId) + + if self.channels[chatId].chatType == ChatType.PrivateGroupChat: + let leaveGroupResponse = status_chat.leaveGroupChat(chatId) + self.emitUpdate(leaveGroupResponse) + + discard status_chat.deactivateChat(self.channels[chatId]) + + self.channels.del(chatId) + discard status_chat.clearChatHistory(chatId) + self.events.emit("channelLeft", ChatIdArg(chatId: chatId)) + proc init*(self: ChatModel, pubKey: string) = self.publicKey = pubKey @@ -264,31 +277,6 @@ proc init*(self: ChatModel, pubKey: string) = var chatList = status_chat.loadChats() chatList.sort(sortChats) - let profileUpdatesChatIds = chatList.filter(c => c.chatType == ChatType.Profile).map(c => c.id) - - if chatList.filter(c => c.chatType == ChatType.Timeline).len == 0: - var timelineChannel = newChat(status_utils.getTimelineChatId(), ChatType.Timeline) - self.join(timelineChannel.id, timelineChannel.chatType) - chatList.add(timelineChannel) - - let timelineChatId = status_utils.getTimelineChatId(pubKey) - - if not profileUpdatesChatIds.contains(timelineChatId): - var profileUpdateChannel = newChat(timelineChatId, ChatType.Profile) - status_chat.saveChat(profileUpdateChannel.id, profileUpdateChannel.chatType, profile=pubKey) - chatList.add(profileUpdateChannel) - - # For profile updates and timeline, we have to make sure that for - # each added contact, a chat has been saved for the currently logged-in - # user. Users that will use a version of Status with timeline support for the - # first time, won't have any of those otherwise. - if profileUpdatesChatIds.filter(id => id != timelineChatId).len != contacts.len: - for contact in contacts: - if not profileUpdatesChatIds.contains(status_utils.getTimelineChatId(contact.address)): - let profileUpdatesChannel = newChat(status_utils.getTimelineChatId(contact.address), ChatType.Profile) - status_chat.saveChat(profileUpdatesChannel.id, profileUpdatesChannel.chatType, ensName=contact.ensName, profile=contact.address) - chatList.add(profileUpdatesChannel) - var filters:seq[JsonNode] = @[] for chat in chatList: if self.hasChannel(chat.id): @@ -307,23 +295,14 @@ proc init*(self: ChatModel, pubKey: string) = self.mailserverReady = true self.requestMissingCommunityInfos() + let timelineAndProfileChatIds = chatList.filter(c => c.chatType == ChatType.Profile or c.chatType == ChatType.Timeline).map(c => c.id) + for chatId in timelineAndProfileChatIds: + self.leave(chatId) + proc statusUpdates*(self: ChatModel) = let statusUpdates = status_chat.statusUpdates() self.events.emit("messagesLoaded", MsgsLoadedArgs(statusUpdates: statusUpdates)) -proc leave*(self: ChatModel, chatId: string) = - self.removeChatFilters(chatId) - - if self.channels[chatId].chatType == ChatType.PrivateGroupChat: - let leaveGroupResponse = status_chat.leaveGroupChat(chatId) - self.emitUpdate(leaveGroupResponse) - - discard status_chat.deactivateChat(self.channels[chatId]) - - self.channels.del(chatId) - discard status_chat.clearChatHistory(chatId) - self.events.emit("channelLeft", ChatIdArg(chatId: chatId)) - proc clearHistory*(self: ChatModel, chatId: string) = discard status_chat.clearChatHistory(chatId) let chat = self.channels[chatId] @@ -807,4 +786,4 @@ proc getCurrentPinnedMessageCursor*(self: ChatModel, channelId: string): string if(not self.pinnedMsgCursor.hasKey(channelId)): self.pinnedMsgCursor[channelId] = "" - return self.pinnedMsgCursor[channelId] \ No newline at end of file + return self.pinnedMsgCursor[channelId] diff --git a/status/contacts.nim b/status/contacts.nim index 124b82d..e0213b9 100644 --- a/status/contacts.nim +++ b/status/contacts.nim @@ -90,7 +90,6 @@ proc addContact*(self: ContactModel, id: string, accountKeyUID: string) = if not updating: contact.added = true - discard status_chat.createProfileChat(contact.id) else: contact.blocked = false diff --git a/status/statusgo_backend/chat.nim b/status/statusgo_backend/chat.nim index a73c6b9..2309c34 100644 --- a/status/statusgo_backend/chat.nim +++ b/status/statusgo_backend/chat.nim @@ -41,9 +41,6 @@ proc deactivateChat*(chat: Chat):string = chat.isActive = false callPrivateRPC("deactivateChat".prefix, %* [{ "ID": chat.id }]) -proc createProfileChat*(pubKey: string):string = - callPrivateRPC("createProfileChat".prefix, %* [{ "ID": pubKey }]) - proc loadChats*(): seq[Chat] = result = @[] let jsonResponse = parseJson($callPrivateRPC("chats".prefix)) diff --git a/status/types/chat.nim b/status/types/chat.nim index a909817..459dcdd 100644 --- a/status/types/chat.nim +++ b/status/types/chat.nim @@ -14,11 +14,10 @@ type ChatType* {.pure.}= enum Public = 2, PrivateGroupChat = 3, Profile = 4, - Timeline = 5 + Timeline = 5, CommunityChat = 6 proc isOneToOne*(self: ChatType): bool = self == ChatType.OneToOne -proc isTimeline*(self: ChatType): bool = self == ChatType.Timeline type Chat* = ref object id*: string # ID is the id of the chat, for public chats it is the name e.g. status, for one-to-one is the hex encoded public key and for group chats is a random uuid appended with the hex encoded pk of the creator of the chat @@ -168,4 +167,4 @@ proc newChat*(id: string, chatType: ChatType): Chat = result.identicon = generateIdenticon(id) result.name = generateAlias(id) else: - result.name = id \ No newline at end of file + result.name = id diff --git a/status/utils.nim b/status/utils.nim index ef19dd0..4a93b93 100644 --- a/status/utils.nim +++ b/status/utils.nim @@ -59,12 +59,6 @@ proc decodeContentHash*(value: string): string = error "Error decoding sticker", hash=value, exception=e.msg raise -proc getTimelineChatId*(pubKey: string = ""): string = - if pubKey == "": - return "@timeline70bd746ddcc12beb96b2c9d572d0784ab137ffc774f5383e50585a932080b57cca0484b259e61cecbaa33a4c98a300a" - else: - return "@" & pubKey - proc isWakuEnabled(): bool = true # TODO: