2021-11-10 08:09:31 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
import QtQuick.Controls 2.13
|
|
|
|
|
2023-01-12 22:39:46 +00:00
|
|
|
import StatusQ.Core 0.1
|
2024-07-12 09:46:43 +00:00
|
|
|
import StatusQ.Core.Backpressure 0.1
|
2023-01-12 22:39:46 +00:00
|
|
|
import StatusQ.Popups 0.1
|
|
|
|
|
2022-04-01 10:30:55 +00:00
|
|
|
import shared.stores 1.0
|
2021-11-10 08:09:31 +00:00
|
|
|
import utils 1.0
|
|
|
|
|
|
|
|
Item {
|
|
|
|
id: appSearch
|
|
|
|
|
|
|
|
property var store
|
|
|
|
readonly property var searchMessages: Backpressure.debounce(searchPopup, 400, function (value) {
|
2022-01-27 11:28:27 +00:00
|
|
|
appSearch.store.searchMessages(value)
|
2021-11-10 08:09:31 +00:00
|
|
|
})
|
2022-02-16 16:13:45 +00:00
|
|
|
property alias opened: searchPopup.opened
|
2021-11-10 08:09:31 +00:00
|
|
|
|
2022-11-07 14:56:59 +00:00
|
|
|
signal closed()
|
|
|
|
|
2021-11-10 08:09:31 +00:00
|
|
|
function openSearchPopup(){
|
|
|
|
searchPopup.open()
|
|
|
|
}
|
|
|
|
|
2022-02-16 16:13:45 +00:00
|
|
|
function closeSearchPopup(){
|
|
|
|
searchPopup.close()
|
|
|
|
}
|
|
|
|
|
2021-11-10 08:09:31 +00:00
|
|
|
Connections {
|
2022-01-27 11:28:27 +00:00
|
|
|
target: appSearch.store.locationMenuModel
|
2023-01-18 09:25:36 +00:00
|
|
|
function onModelAboutToBeReset() {
|
2022-02-16 16:13:45 +00:00
|
|
|
while (searchPopupMenu.takeItem(searchPopupMenu.numDefaultItems)) {
|
|
|
|
// Delete the item right after the default items
|
|
|
|
// If takeItem returns null, it means there was nothing to remove
|
2021-11-10 08:09:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-27 11:28:27 +00:00
|
|
|
Connections {
|
|
|
|
target: appSearch.store.appSearchModule
|
2023-01-18 09:25:36 +00:00
|
|
|
function onAppSearchCompleted() {
|
|
|
|
searchPopup.loading = false
|
|
|
|
}
|
2022-01-27 11:28:27 +00:00
|
|
|
}
|
|
|
|
|
2021-11-10 08:09:31 +00:00
|
|
|
StatusSearchLocationMenu {
|
|
|
|
id: searchPopupMenu
|
2022-12-01 16:58:37 +00:00
|
|
|
|
2022-01-27 11:28:27 +00:00
|
|
|
locationModel: appSearch.store.locationMenuModel
|
2021-11-10 08:09:31 +00:00
|
|
|
|
|
|
|
onItemClicked: {
|
2022-01-27 11:28:27 +00:00
|
|
|
appSearch.store.setSearchLocation(firstLevelItemValue, secondLevelItemValue)
|
2022-09-27 21:26:26 +00:00
|
|
|
searchPopup.forceActiveFocus()
|
2021-11-10 08:09:31 +00:00
|
|
|
if(searchPopup.searchText !== "")
|
|
|
|
searchMessages(searchPopup.searchText)
|
|
|
|
}
|
2022-12-01 16:58:37 +00:00
|
|
|
|
|
|
|
onResetSearchSelection: {
|
|
|
|
searchPopup.resetSearchSelection()
|
|
|
|
}
|
|
|
|
|
|
|
|
onSetSearchSelection: {
|
|
|
|
searchPopup.setSearchSelection(text,
|
|
|
|
secondaryText,
|
|
|
|
imageSource,
|
|
|
|
isIdenticon,
|
|
|
|
iconName,
|
|
|
|
iconColor,
|
|
|
|
isUserIcon,
|
|
|
|
colorId,
|
|
|
|
colorHash)
|
|
|
|
}
|
2021-11-10 08:09:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
StatusSearchPopup {
|
|
|
|
id: searchPopup
|
|
|
|
noResultsLabel: qsTr("No results")
|
|
|
|
defaultSearchLocationText: qsTr("Anywhere")
|
|
|
|
searchOptionsPopupMenu: searchPopupMenu
|
2022-01-27 11:28:27 +00:00
|
|
|
searchResults: appSearch.store.resultModel
|
2021-11-10 08:09:31 +00:00
|
|
|
formatTimestampFn: function (ts) {
|
2023-01-12 22:39:46 +00:00
|
|
|
return LocaleUtils.formatDateTime(parseInt(ts, 10))
|
2021-11-10 08:09:31 +00:00
|
|
|
}
|
|
|
|
onSearchTextChanged: {
|
2022-03-28 11:54:32 +00:00
|
|
|
if (searchPopup.searchText !== "") {
|
|
|
|
searchPopup.loading = true
|
|
|
|
searchMessages(searchPopup.searchText);
|
|
|
|
}
|
2021-11-10 08:09:31 +00:00
|
|
|
}
|
|
|
|
onAboutToHide: {
|
|
|
|
if (searchPopupMenu.visible) {
|
|
|
|
searchPopupMenu.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
onClosed: {
|
|
|
|
searchPopupMenu.dismiss();
|
2022-11-07 14:56:59 +00:00
|
|
|
appSearch.closed();
|
2021-11-10 08:09:31 +00:00
|
|
|
}
|
2022-07-25 11:18:10 +00:00
|
|
|
onResetSearchLocationClicked: {
|
|
|
|
searchPopup.resetSearchSelection();
|
|
|
|
appSearch.store.setSearchLocation("", "")
|
|
|
|
searchMessages(searchPopup.searchText)
|
|
|
|
}
|
2021-11-10 08:09:31 +00:00
|
|
|
onOpened: {
|
|
|
|
searchPopup.resetSearchSelection();
|
2022-01-27 11:28:27 +00:00
|
|
|
appSearch.store.prepareLocationMenuModel()
|
2021-11-10 08:09:31 +00:00
|
|
|
|
2022-01-27 11:28:27 +00:00
|
|
|
const jsonObj = appSearch.store.getSearchLocationObject()
|
2021-11-10 08:09:31 +00:00
|
|
|
|
|
|
|
if (!jsonObj) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
let obj = JSON.parse(jsonObj)
|
2022-07-13 15:06:07 +00:00
|
|
|
if (obj.location === "" || (obj.location !== "" && !obj.subLocation)) {
|
2021-11-10 08:09:31 +00:00
|
|
|
if(obj.subLocation === "") {
|
2022-01-27 11:28:27 +00:00
|
|
|
appSearch.store.setSearchLocation("", "")
|
2022-07-13 15:06:07 +00:00
|
|
|
} else {
|
2021-11-10 08:09:31 +00:00
|
|
|
searchPopup.setSearchSelection(obj.subLocation.text,
|
|
|
|
"",
|
|
|
|
obj.subLocation.imageSource,
|
2022-03-30 15:30:28 +00:00
|
|
|
false,
|
2021-11-10 08:09:31 +00:00
|
|
|
obj.subLocation.iconName,
|
|
|
|
obj.subLocation.identiconColor)
|
|
|
|
|
2022-01-27 11:28:27 +00:00
|
|
|
appSearch.store.setSearchLocation("", obj.subLocation.value)
|
2021-11-10 08:09:31 +00:00
|
|
|
}
|
2022-07-13 15:06:07 +00:00
|
|
|
} else {
|
|
|
|
if (obj.location.title === "Chat" && !!obj.subLocation) {
|
2021-11-10 08:09:31 +00:00
|
|
|
searchPopup.setSearchSelection(obj.subLocation.text,
|
|
|
|
"",
|
|
|
|
obj.subLocation.imageSource,
|
2022-03-30 15:30:28 +00:00
|
|
|
false,
|
2021-11-10 08:09:31 +00:00
|
|
|
obj.subLocation.iconName,
|
2022-05-31 08:37:46 +00:00
|
|
|
obj.subLocation.identiconColor,
|
|
|
|
obj.subLocation.isUserIcon,
|
|
|
|
obj.subLocation.colorId,
|
|
|
|
obj.subLocation.colorHash)
|
2021-11-10 08:09:31 +00:00
|
|
|
|
2022-01-27 11:28:27 +00:00
|
|
|
appSearch.store.setSearchLocation(obj.location.value, obj.subLocation.value)
|
2022-07-13 15:06:07 +00:00
|
|
|
} else {
|
2021-11-10 08:09:31 +00:00
|
|
|
searchPopup.setSearchSelection(obj.location.title,
|
|
|
|
obj.subLocation.text,
|
|
|
|
obj.location.imageSource,
|
2022-03-30 15:30:28 +00:00
|
|
|
false,
|
2021-11-10 08:09:31 +00:00
|
|
|
obj.location.iconName,
|
|
|
|
obj.location.identiconColor)
|
|
|
|
|
2022-01-27 11:28:27 +00:00
|
|
|
appSearch.store.setSearchLocation(obj.location.value, obj.subLocation.value)
|
2021-11-10 08:09:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
onResultItemClicked: {
|
|
|
|
searchPopup.close()
|
2022-01-27 11:28:27 +00:00
|
|
|
appSearch.store.resultItemClicked(itemId)
|
2021-11-10 08:09:31 +00:00
|
|
|
}
|
2022-02-16 16:13:45 +00:00
|
|
|
acceptsTitleClick: function (titleId) {
|
|
|
|
return Utils.isChatKey(titleId)
|
2021-11-10 08:09:31 +00:00
|
|
|
}
|
2023-01-02 14:50:46 +00:00
|
|
|
onResultItemTitleClicked: Global.openProfilePopup(titleId, searchPopup)
|
2021-11-10 08:09:31 +00:00
|
|
|
}
|
|
|
|
}
|