feature(@desktop/chat): implement search results for communities, channels

Added a part for fetching messages from multiple chats/channels/communities.

Fixes: #2934
This commit is contained in:
Sale Djenic 2021-08-06 17:31:42 +02:00 committed by Iuri Matias
parent e2628338de
commit 06c10df134
2 changed files with 42 additions and 30 deletions

View File

@ -16,6 +16,7 @@ import ../../status/tasks/[qt, task_runner_impl]
import ../../status/tasks/marathon/mailserver/worker import ../../status/tasks/marathon/mailserver/worker
import ../../status/signals/types as signal_types import ../../status/signals/types as signal_types
import ../../status/types import ../../status/types
import views/message_search/[view_controller]
# TODO: remove me # TODO: remove me
import ../../status/libstatus/chat as libstatus_chat import ../../status/libstatus/chat as libstatus_chat
@ -76,6 +77,7 @@ QtObject:
ensView: EnsView ensView: EnsView
channelView*: ChannelView channelView*: ChannelView
messageView*: MessageView messageView*: MessageView
messageSearchViewController: MessageSearchViewController
currentSuggestions*: SuggestionsList currentSuggestions*: SuggestionsList
activityNotificationList*: ActivityNotificationList activityNotificationList*: ActivityNotificationList
callResult: string callResult: string
@ -103,6 +105,7 @@ QtObject:
self.groups.delete self.groups.delete
self.transactions.delete self.transactions.delete
self.communities.delete self.communities.delete
self.messageSearchViewController.delete
self.QAbstractListModel.delete self.QAbstractListModel.delete
proc newChatsView*(status: Status): ChatsView = proc newChatsView*(status: Status): ChatsView =
@ -113,6 +116,8 @@ QtObject:
result.communities = newCommunitiesView(status) result.communities = newCommunitiesView(status)
result.channelView = newChannelView(status, result.communities) result.channelView = newChannelView(status, result.communities)
result.messageView = newMessageView(status, result.channelView, result.communities) result.messageView = newMessageView(status, result.channelView, result.communities)
result.messageSearchViewController = newMessageSearchViewController(status,
result.channelView, result.communities)
result.connected = false result.connected = false
result.currentSuggestions = newSuggestionsList() result.currentSuggestions = newSuggestionsList()
result.activityNotificationList = newActivityNotificationList(status) result.activityNotificationList = newActivityNotificationList(status)
@ -160,6 +165,12 @@ QtObject:
QtProperty[QVariant] messageView: QtProperty[QVariant] messageView:
read = getMessageView read = getMessageView
proc getMessageSearchViewController*(self: ChatsView): QVariant {.slot.} =
newQVariant(self.messageSearchViewController)
QtProperty[QVariant] messageSearchViewController:
read = getMessageSearchViewController
proc plainText(self: ChatsView, input: string): string {.slot.} = proc plainText(self: ChatsView, input: string): string {.slot.} =
result = plain_text(input) result = plain_text(input)
@ -443,7 +454,7 @@ QtObject:
self.messageView.onMessagesLoaded(chatId, messages) self.messageView.onMessagesLoaded(chatId, messages)
proc onSearchMessagesLoaded*(self: ChatsView, messages: seq[Message]) = proc onSearchMessagesLoaded*(self: ChatsView, messages: seq[Message]) =
self.messageView.onSearchMessagesLoaded(messages) self.messageSearchViewController.onSearchMessagesLoaded(messages)
proc pushMessages*(self: ChatsView, messages: var seq[Message]) = proc pushMessages*(self: ChatsView, messages: var seq[Message]) =
self.messageView.pushMessages(messages) self.messageView.pushMessages(messages)
@ -496,3 +507,23 @@ QtObject:
# in the meantime I'm hardcoding a specific mailserver # in the meantime I'm hardcoding a specific mailserver
echo self.status.mailservers.setMailserver("16Uiu2HAm4v86W3bmT1BiH6oSPzcsSr24iDQpSN5Qa992BCjjwgrD") echo self.status.mailservers.setMailserver("16Uiu2HAm4v86W3bmT1BiH6oSPzcsSr24iDQpSN5Qa992BCjjwgrD")
echo self.status.mailservers.requestAllHistoricMessages() echo self.status.mailservers.requestAllHistoricMessages()
proc switchToSearchedItem*(self: ChatsView, itemId: string) {.slot.} =
let info = self.messageSearchViewController.getItemInfo(itemId)
if(info.isEmpty()):
return
if (info.communityId.len > 0):
self.communities.setActiveCommunity(info.communityId)
if (info.channelId.len > 0):
self.channelView.setActiveChannel(info.channelId)
if (info.messageId.len > 0):
self.messageView.switchToMessage(info.messageId)
else:
self.communities.activeCommunity.setActive(false)
if (info.channelId.len > 0):
self.channelView.setActiveChannel(info.channelId)
if (info.messageId.len > 0):
self.messageView.switchToMessage(info.messageId)

View File

@ -10,7 +10,7 @@ import ../../../status/profile/profile
import ../../../status/tasks/[qt, task_runner_impl] import ../../../status/tasks/[qt, task_runner_impl]
import ../../../status/tasks/marathon/mailserver/worker import ../../../status/tasks/marathon/mailserver/worker
import communities, chat_item, channels_list, communities, community_list, message_list, channel, message_item, message_list_proxy import communities, chat_item, channels_list, communities, community_list, message_list, channel, message_item
logScope: logScope:
topics = "messages-view" topics = "messages-view"
@ -24,7 +24,6 @@ QtObject:
type MessageView* = ref object of QAbstractListModel type MessageView* = ref object of QAbstractListModel
status: Status status: Status
messageList*: OrderedTable[string, ChatMessageList] messageList*: OrderedTable[string, ChatMessageList]
searchResultMessageModel*: MessageListProxyModel
pinnedMessagesList*: OrderedTable[string, ChatMessageList] pinnedMessagesList*: OrderedTable[string, ChatMessageList]
channelView*: ChannelView channelView*: ChannelView
communities*: CommunitiesView communities*: CommunitiesView
@ -44,8 +43,7 @@ QtObject:
self.messageList = initOrderedTable[string, ChatMessageList]() self.messageList = initOrderedTable[string, ChatMessageList]()
self.pinnedMessagesList = initOrderedTable[string, ChatMessageList]() self.pinnedMessagesList = initOrderedTable[string, ChatMessageList]()
self.channelOpenTime = initTable[string, int64]() self.channelOpenTime = initTable[string, int64]()
self.QAbstractListModel.delete self.QAbstractListModel.delete
self.searchResultMessageModel.delete
proc newMessageView*(status: Status, channelView: ChannelView, communitiesView: CommunitiesView): MessageView = proc newMessageView*(status: Status, channelView: ChannelView, communitiesView: CommunitiesView): MessageView =
new(result, delete) new(result, delete)
@ -57,7 +55,6 @@ QtObject:
result.messageList[status_utils.getTimelineChatId()] = newChatMessageList(status_utils.getTimelineChatId(), result.status, false) result.messageList[status_utils.getTimelineChatId()] = newChatMessageList(status_utils.getTimelineChatId(), result.status, false)
result.loadingMessages = false result.loadingMessages = false
result.unreadMessageCnt = 0 result.unreadMessageCnt = 0
result.searchResultMessageModel = newMessageListProxyModel(status)
result.unreadDirectMessagesAndMentionsCount = 0 result.unreadDirectMessagesAndMentionsCount = 0
result.setup result.setup
@ -448,34 +445,13 @@ QtObject:
self.messageList.del(chatId) self.messageList.del(chatId)
self.endRemoveRows() self.endRemoveRows()
proc getSearchResultMessageModel*(self: MessageView): QVariant {.slot.} = proc isMessageDisplayed(self: MessageView, messageId: string): bool =
newQVariant(self.searchResultMessageModel)
# we just need to expose model to qml, there is no need for exposing notifying signal
QtProperty[QVariant] searchResultMessageModel:
read = getSearchResultMessageModel
proc searchMessages*(self: MessageView, searchTerm: string) {.slot.} =
if (searchTerm.len == 0):
self.searchResultMessageModel.clear(false)
return
# chatId is used here only to support message search in currently selected channel
# later when we decide to apply message search over multiple channels MessageListProxyModel
# will be updated to support setting list of sourcer messages.
let chatId = self.channelView.activeChannel.id
self.status.chat.asyncSearchMessages(chatId, searchTerm, false)
proc onSearchMessagesLoaded*(self: MessageView, messages: seq[Message]) =
self.searchResultMessageModel.setFilteredMessages(messages)
proc isMessageDisplayed*(self: MessageView, messageId: string): bool {.slot.} =
let chatId = self.channelView.activeChannel.id let chatId = self.channelView.activeChannel.id
var message = self.messageList[chatId].getMessageById(messageId) var message = self.messageList[chatId].getMessageById(messageId)
return message.id != "" return message.id != ""
proc loadMessagesUntillMessageWithIdIsLoaded*(self: MessageView, messageId: string) {.slot.} = proc loadMessagesUntillMessageWithIdIsLoaded*(self: MessageView, messageId: string) =
self.searchedMessageId = messageId self.searchedMessageId = messageId
let chatId = self.channelView.activeChannel.id let chatId = self.channelView.activeChannel.id
@ -500,4 +476,9 @@ QtObject:
proc setInitialMessagesLoaded*(self: MessageView, chatId: string, value: bool) = proc setInitialMessagesLoaded*(self: MessageView, chatId: string, value: bool) =
if self.messageList.hasKey(chatId): if self.messageList.hasKey(chatId):
self.messageList[chatId].setInitialMessagesLoaded(value) self.messageList[chatId].setInitialMessagesLoaded(value)
proc switchToMessage*(self: MessageView, messageId: string) =
if (self.isMessageDisplayed(messageId)):
self.searchedMessageLoaded(messageId)
else:
self.loadMessagesUntillMessageWithIdIsLoaded(messageId)