refactor(timeline): Removed all timeline related code (#122)
This feature is deprecated and shall be removed Relates to #4064
This commit is contained in:
parent
6d0e5ccf62
commit
c858eed50f
|
@ -156,7 +156,7 @@ proc removeChatFilters(self: ChatModel, chatId: string) =
|
||||||
for filter in filters:
|
for filter in filters:
|
||||||
if filter["chatId"].getStr == chatId:
|
if filter["chatId"].getStr == chatId:
|
||||||
status_chat.removeFilters(chatId, filter["filterId"].getStr)
|
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
|
# Check if user does not belong to any active chat group
|
||||||
var inGroup = false
|
var inGroup = false
|
||||||
for channel in self.channels.values:
|
for channel in self.channels.values:
|
||||||
|
@ -256,6 +256,19 @@ proc sortChats(x, y: chat_type.Chat): int =
|
||||||
elif t1 == t2: 0
|
elif t1 == t2: 0
|
||||||
else: -1
|
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) =
|
proc init*(self: ChatModel, pubKey: string) =
|
||||||
self.publicKey = pubKey
|
self.publicKey = pubKey
|
||||||
|
|
||||||
|
@ -264,31 +277,6 @@ proc init*(self: ChatModel, pubKey: string) =
|
||||||
var chatList = status_chat.loadChats()
|
var chatList = status_chat.loadChats()
|
||||||
chatList.sort(sortChats)
|
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] = @[]
|
var filters:seq[JsonNode] = @[]
|
||||||
for chat in chatList:
|
for chat in chatList:
|
||||||
if self.hasChannel(chat.id):
|
if self.hasChannel(chat.id):
|
||||||
|
@ -307,23 +295,14 @@ proc init*(self: ChatModel, pubKey: string) =
|
||||||
self.mailserverReady = true
|
self.mailserverReady = true
|
||||||
self.requestMissingCommunityInfos()
|
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) =
|
proc statusUpdates*(self: ChatModel) =
|
||||||
let statusUpdates = status_chat.statusUpdates()
|
let statusUpdates = status_chat.statusUpdates()
|
||||||
self.events.emit("messagesLoaded", MsgsLoadedArgs(statusUpdates: 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) =
|
proc clearHistory*(self: ChatModel, chatId: string) =
|
||||||
discard status_chat.clearChatHistory(chatId)
|
discard status_chat.clearChatHistory(chatId)
|
||||||
let chat = self.channels[chatId]
|
let chat = self.channels[chatId]
|
||||||
|
@ -807,4 +786,4 @@ proc getCurrentPinnedMessageCursor*(self: ChatModel, channelId: string): string
|
||||||
if(not self.pinnedMsgCursor.hasKey(channelId)):
|
if(not self.pinnedMsgCursor.hasKey(channelId)):
|
||||||
self.pinnedMsgCursor[channelId] = ""
|
self.pinnedMsgCursor[channelId] = ""
|
||||||
|
|
||||||
return self.pinnedMsgCursor[channelId]
|
return self.pinnedMsgCursor[channelId]
|
||||||
|
|
|
@ -90,7 +90,6 @@ proc addContact*(self: ContactModel, id: string, accountKeyUID: string) =
|
||||||
|
|
||||||
if not updating:
|
if not updating:
|
||||||
contact.added = true
|
contact.added = true
|
||||||
discard status_chat.createProfileChat(contact.id)
|
|
||||||
else:
|
else:
|
||||||
contact.blocked = false
|
contact.blocked = false
|
||||||
|
|
||||||
|
|
|
@ -41,9 +41,6 @@ proc deactivateChat*(chat: Chat):string =
|
||||||
chat.isActive = false
|
chat.isActive = false
|
||||||
callPrivateRPC("deactivateChat".prefix, %* [{ "ID": chat.id }])
|
callPrivateRPC("deactivateChat".prefix, %* [{ "ID": chat.id }])
|
||||||
|
|
||||||
proc createProfileChat*(pubKey: string):string =
|
|
||||||
callPrivateRPC("createProfileChat".prefix, %* [{ "ID": pubKey }])
|
|
||||||
|
|
||||||
proc loadChats*(): seq[Chat] =
|
proc loadChats*(): seq[Chat] =
|
||||||
result = @[]
|
result = @[]
|
||||||
let jsonResponse = parseJson($callPrivateRPC("chats".prefix))
|
let jsonResponse = parseJson($callPrivateRPC("chats".prefix))
|
||||||
|
|
|
@ -14,11 +14,10 @@ type ChatType* {.pure.}= enum
|
||||||
Public = 2,
|
Public = 2,
|
||||||
PrivateGroupChat = 3,
|
PrivateGroupChat = 3,
|
||||||
Profile = 4,
|
Profile = 4,
|
||||||
Timeline = 5
|
Timeline = 5,
|
||||||
CommunityChat = 6
|
CommunityChat = 6
|
||||||
|
|
||||||
proc isOneToOne*(self: ChatType): bool = self == ChatType.OneToOne
|
proc isOneToOne*(self: ChatType): bool = self == ChatType.OneToOne
|
||||||
proc isTimeline*(self: ChatType): bool = self == ChatType.Timeline
|
|
||||||
|
|
||||||
type Chat* = ref object
|
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
|
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.identicon = generateIdenticon(id)
|
||||||
result.name = generateAlias(id)
|
result.name = generateAlias(id)
|
||||||
else:
|
else:
|
||||||
result.name = id
|
result.name = id
|
||||||
|
|
|
@ -59,12 +59,6 @@ proc decodeContentHash*(value: string): string =
|
||||||
error "Error decoding sticker", hash=value, exception=e.msg
|
error "Error decoding sticker", hash=value, exception=e.msg
|
||||||
raise
|
raise
|
||||||
|
|
||||||
proc getTimelineChatId*(pubKey: string = ""): string =
|
|
||||||
if pubKey == "":
|
|
||||||
return "@timeline70bd746ddcc12beb96b2c9d572d0784ab137ffc774f5383e50585a932080b57cca0484b259e61cecbaa33a4c98a300a"
|
|
||||||
else:
|
|
||||||
return "@" & pubKey
|
|
||||||
|
|
||||||
proc isWakuEnabled(): bool =
|
proc isWakuEnabled(): bool =
|
||||||
true # TODO:
|
true # TODO:
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue