refactor(timeline): Removed all timeline related code (#122)

This feature is deprecated and shall be removed

Relates to #4064
This commit is contained in:
Alexandra Betouni 2021-12-03 19:55:34 +02:00 committed by GitHub
parent 6d0e5ccf62
commit c858eed50f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 53 deletions

View File

@ -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]

View File

@ -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

View File

@ -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))

View File

@ -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

View File

@ -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: