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:
parent
e2628338de
commit
06c10df134
|
@ -16,6 +16,7 @@ import ../../status/tasks/[qt, task_runner_impl]
|
|||
import ../../status/tasks/marathon/mailserver/worker
|
||||
import ../../status/signals/types as signal_types
|
||||
import ../../status/types
|
||||
import views/message_search/[view_controller]
|
||||
|
||||
# TODO: remove me
|
||||
import ../../status/libstatus/chat as libstatus_chat
|
||||
|
@ -76,6 +77,7 @@ QtObject:
|
|||
ensView: EnsView
|
||||
channelView*: ChannelView
|
||||
messageView*: MessageView
|
||||
messageSearchViewController: MessageSearchViewController
|
||||
currentSuggestions*: SuggestionsList
|
||||
activityNotificationList*: ActivityNotificationList
|
||||
callResult: string
|
||||
|
@ -103,6 +105,7 @@ QtObject:
|
|||
self.groups.delete
|
||||
self.transactions.delete
|
||||
self.communities.delete
|
||||
self.messageSearchViewController.delete
|
||||
self.QAbstractListModel.delete
|
||||
|
||||
proc newChatsView*(status: Status): ChatsView =
|
||||
|
@ -113,6 +116,8 @@ QtObject:
|
|||
result.communities = newCommunitiesView(status)
|
||||
result.channelView = newChannelView(status, result.communities)
|
||||
result.messageView = newMessageView(status, result.channelView, result.communities)
|
||||
result.messageSearchViewController = newMessageSearchViewController(status,
|
||||
result.channelView, result.communities)
|
||||
result.connected = false
|
||||
result.currentSuggestions = newSuggestionsList()
|
||||
result.activityNotificationList = newActivityNotificationList(status)
|
||||
|
@ -160,6 +165,12 @@ QtObject:
|
|||
QtProperty[QVariant] messageView:
|
||||
read = getMessageView
|
||||
|
||||
proc getMessageSearchViewController*(self: ChatsView): QVariant {.slot.} =
|
||||
newQVariant(self.messageSearchViewController)
|
||||
|
||||
QtProperty[QVariant] messageSearchViewController:
|
||||
read = getMessageSearchViewController
|
||||
|
||||
proc plainText(self: ChatsView, input: string): string {.slot.} =
|
||||
result = plain_text(input)
|
||||
|
||||
|
@ -443,7 +454,7 @@ QtObject:
|
|||
self.messageView.onMessagesLoaded(chatId, messages)
|
||||
|
||||
proc onSearchMessagesLoaded*(self: ChatsView, messages: seq[Message]) =
|
||||
self.messageView.onSearchMessagesLoaded(messages)
|
||||
self.messageSearchViewController.onSearchMessagesLoaded(messages)
|
||||
|
||||
proc pushMessages*(self: ChatsView, messages: var seq[Message]) =
|
||||
self.messageView.pushMessages(messages)
|
||||
|
@ -496,3 +507,23 @@ QtObject:
|
|||
# in the meantime I'm hardcoding a specific mailserver
|
||||
echo self.status.mailservers.setMailserver("16Uiu2HAm4v86W3bmT1BiH6oSPzcsSr24iDQpSN5Qa992BCjjwgrD")
|
||||
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)
|
||||
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ import ../../../status/profile/profile
|
|||
import ../../../status/tasks/[qt, task_runner_impl]
|
||||
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:
|
||||
topics = "messages-view"
|
||||
|
@ -24,7 +24,6 @@ QtObject:
|
|||
type MessageView* = ref object of QAbstractListModel
|
||||
status: Status
|
||||
messageList*: OrderedTable[string, ChatMessageList]
|
||||
searchResultMessageModel*: MessageListProxyModel
|
||||
pinnedMessagesList*: OrderedTable[string, ChatMessageList]
|
||||
channelView*: ChannelView
|
||||
communities*: CommunitiesView
|
||||
|
@ -45,7 +44,6 @@ QtObject:
|
|||
self.pinnedMessagesList = initOrderedTable[string, ChatMessageList]()
|
||||
self.channelOpenTime = initTable[string, int64]()
|
||||
self.QAbstractListModel.delete
|
||||
self.searchResultMessageModel.delete
|
||||
|
||||
proc newMessageView*(status: Status, channelView: ChannelView, communitiesView: CommunitiesView): MessageView =
|
||||
new(result, delete)
|
||||
|
@ -57,7 +55,6 @@ QtObject:
|
|||
result.messageList[status_utils.getTimelineChatId()] = newChatMessageList(status_utils.getTimelineChatId(), result.status, false)
|
||||
result.loadingMessages = false
|
||||
result.unreadMessageCnt = 0
|
||||
result.searchResultMessageModel = newMessageListProxyModel(status)
|
||||
result.unreadDirectMessagesAndMentionsCount = 0
|
||||
result.setup
|
||||
|
||||
|
@ -448,34 +445,13 @@ QtObject:
|
|||
self.messageList.del(chatId)
|
||||
self.endRemoveRows()
|
||||
|
||||
proc getSearchResultMessageModel*(self: MessageView): QVariant {.slot.} =
|
||||
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.} =
|
||||
proc isMessageDisplayed(self: MessageView, messageId: string): bool =
|
||||
let chatId = self.channelView.activeChannel.id
|
||||
var message = self.messageList[chatId].getMessageById(messageId)
|
||||
|
||||
return message.id != ""
|
||||
|
||||
proc loadMessagesUntillMessageWithIdIsLoaded*(self: MessageView, messageId: string) {.slot.} =
|
||||
proc loadMessagesUntillMessageWithIdIsLoaded*(self: MessageView, messageId: string) =
|
||||
self.searchedMessageId = messageId
|
||||
let chatId = self.channelView.activeChannel.id
|
||||
|
||||
|
@ -501,3 +477,8 @@ QtObject:
|
|||
if self.messageList.hasKey(chatId):
|
||||
self.messageList[chatId].setInitialMessagesLoaded(value)
|
||||
|
||||
proc switchToMessage*(self: MessageView, messageId: string) =
|
||||
if (self.isMessageDisplayed(messageId)):
|
||||
self.searchedMessageLoaded(messageId)
|
||||
else:
|
||||
self.loadMessagesUntillMessageWithIdIsLoaded(messageId)
|
||||
|
|
Loading…
Reference in New Issue