status-desktop/ui/app/AppLayouts/Chat/ChatLayout.qml

266 lines
9.3 KiB
QML
Raw Normal View History

2020-06-17 19:18:31 +00:00
import QtQuick 2.13
import QtQuick.Controls 2.13
import Qt.labs.settings 1.0
import utils 1.0
import shared 1.0
import shared.panels 1.0
import shared.popups 1.0
import shared.status 1.0
import shared.views.chat 1.0
import StatusQ.Layout 0.1
import StatusQ.Popups 0.1
import "views"
import "panels"
import "panels/communities"
import "popups"
import "helpers"
import "controls"
import "stores"
StatusAppThreePanelLayout {
id: root
2020-05-27 17:10:50 +00:00
handle: SplitViewHandle { implicitWidth: 5 }
property var messageStore
property RootStore rootStore: RootStore {
messageStore: root.messageStore
}
property alias chatColumn: chatColumn
property bool stickersLoaded: false
signal profileButtonClicked()
Connections {
target: root.rootStore.chatsModelInst.stickers
onStickerPacksLoaded: {
stickersLoaded = true;
}
}
property var onActivated: function () {
root.rootStore.chatsModelInst.channelView.restorePreviousActiveChannel();
chatColumn.onActivated();
}
StatusSearchLocationMenu {
id: searchPopupMenu
searchPopup: searchPopup
locationModel: root.rootStore.chatsModelInst.messageSearchViewController.locationMenuModel
onItemClicked: {
root.rootStore.chatsModelInst.messageSearchViewController.setSearchLocation(firstLevelItemValue, secondLevelItemValue)
if(searchPopup.searchText !== "")
searchMessages(searchPopup.searchText)
}
}
property var searchMessages: Backpressure.debounce(searchPopup, 400, function (value) {
root.rootStore.chatsModelInst.messageSearchViewController.searchMessages(value)
})
Connections {
target: root.rootStore.chatsModelInst.messageSearchViewController.locationMenuModel
onModelAboutToBeReset: {
for (var i = 2; i <= searchPopupMenu.count; i++) {
//clear menu
if (!!searchPopupMenu.takeItem(i)) {
searchPopupMenu.removeItem(searchPopupMenu.takeItem(i));
}
}
}
}
StatusSearchPopup {
id: searchPopup
noResultsLabel: qsTr("No results")
defaultSearchLocationText: qsTr("Anywhere")
searchOptionsPopupMenu: searchPopupMenu
searchResults: root.rootStore.chatsModelInst.messageSearchViewController.resultModel
formatTimestampFn: function (ts) {
return new Date(parseInt(ts, 10)).toLocaleString(Qt.locale(localAppSettings.locale))
}
onSearchTextChanged: {
searchMessages(searchPopup.searchText);
}
onAboutToHide: {
if (searchPopupMenu.visible) {
searchPopupMenu.close();
}
}
onClosed: {
searchPopupMenu.dismiss();
}
onOpened: {
searchPopup.resetSearchSelection();
searchPopup.forceActiveFocus()
root.rootStore.chatsModelInst.messageSearchViewController.prepareLocationMenuModel()
const jsonObj = root.rootStore.chatsModelInst.messageSearchViewController.getSearchLocationObject()
if (!jsonObj) {
return
}
let obj = JSON.parse(jsonObj)
if (obj.location === "") {
if(obj.subLocation === "") {
root.rootStore.chatsModelInst.messageSearchViewController.setSearchLocation("", "")
}
else {
searchPopup.setSearchSelection(obj.subLocation.text,
"",
obj.subLocation.imageSource,
obj.subLocation.isIdenticon,
obj.subLocation.iconName,
obj.subLocation.identiconColor)
root.rootStore.chatsModelInst.messageSearchViewController.setSearchLocation("", obj.subLocation.value)
}
}
else {
if (obj.location.title === "Chat") {
searchPopup.setSearchSelection(obj.subLocation.text,
"",
obj.subLocation.imageSource,
obj.subLocation.isIdenticon,
obj.subLocation.iconName,
obj.subLocation.identiconColor)
root.rootStore.chatsModelInst.messageSearchViewController.setSearchLocation(obj.location.value, obj.subLocation.value)
}
else {
searchPopup.setSearchSelection(obj.location.title,
obj.subLocation.text,
obj.location.imageSource,
obj.location.isIdenticon,
obj.location.iconName,
obj.location.identiconColor)
root.rootStore.chatsModelInst.messageSearchViewController.setSearchLocation(obj.location.value, obj.subLocation.value)
}
}
}
onResultItemClicked: {
searchPopup.close()
root.rootStore.chatsModelInst.switchToSearchedItem(itemId)
}
onResultItemTitleClicked: {
const pk = titleId
const userProfileImage = appMain.getProfileImage(pk)
return openProfilePopup(root.rootStore.chatsModelInst.userNameOrAlias(pk), pk, userProfileImage || root.rootStore.utilsModelInst.generateIdenticon(pk))
}
}
leftPanel: Loader {
2020-12-11 20:29:46 +00:00
id: contactColumnLoader
sourceComponent: localAccountSensitiveSettings.communitiesEnabled && root.rootStore.chatsModelInst.communities.activeCommunity.active ? communtiyColumnComponent : contactsColumnComponent
2020-12-11 20:29:46 +00:00
}
2021-10-28 10:01:10 +00:00
centerPanel: ChatColumnView {
id: chatColumn
2021-10-28 15:41:32 +00:00
rootStore: root.rootStore
2021-10-15 19:47:43 +00:00
chatGroupsListViewCount: contactColumnLoader.item.chatGroupsListViewCount
}
showRightPanel: (localAccountSensitiveSettings.expandUsersList && (localAccountSensitiveSettings.showOnlineUsers || chatsModel.communities.activeCommunity.active)
&& (chatsModel.channelView.activeChannel.chatType !== Constants.chatTypeOneToOne))
rightPanel: localAccountSensitiveSettings.communitiesEnabled && chatsModel.communities.activeCommunity.active ? communityUserListComponent : userListComponent
Component {
id: communityUserListComponent
CommunityUserListPanel {
currentTime: chatColumn.currentTime
messageContextMenu: quickActionMessageOptionsMenu
profilePubKey: userProfile.pubKey
contactsList: root.rootStore.profileModelInst.contacts.list
community: root.rootStore.chatsModelInst.communities.activeCommunity
currentUserName: Utils.removeStatusEns(root.rootStore.profileModelInst.ens.preferredUsername
|| root.rootStore.profileModelInst.profile.username)
currentUserOnline: root.store.userProfileInst.userStatus
}
}
Component {
id: userListComponent
UserListPanel {
currentTime: chatColumn.currentTime
userList: chatColumn.userList
messageContextMenu: quickActionMessageOptionsMenu
profilePubKey: userProfile.pubKey
contactsList: root.rootStore.profileModelInst.contacts.list
isOnline: root.rootStore.chatsModelInst.isOnline
}
}
2020-12-11 20:29:46 +00:00
Component {
id: contactsColumnComponent
ContactsColumnView {
store: root.rootStore
onOpenProfileClicked: {
root.profileButtonClicked();
}
2020-12-11 20:29:46 +00:00
}
}
Component {
id: communtiyColumnComponent
CommunityColumnView {
store: root.rootStore
2021-06-02 19:43:33 +00:00
pinnedMessagesPopupComponent: chatColumn.pinnedMessagesPopupComponent
}
}
Component {
id: groupInfoPopupComponent
2021-05-25 19:38:18 +00:00
GroupInfoPopup {
store: root.rootStore
2021-05-25 19:38:18 +00:00
pinnedMessagesPopupComponent: chatColumn.pinnedMessagesPopupComponent
}
}
Component {
id: statusStickerPackClickPopup
StatusStickerPackClickPopup{
onClosed: {
destroy();
}
}
}
2020-10-02 13:02:56 +00:00
ConfirmationDialog {
id: removeContactConfirmationDialog
// % "Remove contact"
header.title: qsTrId("remove-contact")
2020-10-02 13:02:56 +00:00
//% "Are you sure you want to remove this contact?"
confirmationText: qsTrId("are-you-sure-you-want-to-remove-this-contact-")
onConfirmButtonClicked: {
if (root.rootStore.profileModelInst.contacts.isAdded(chatColumn.contactToRemove)) {
root.rootStore.profileModelInst.contacts.removeContact(chatColumn.contactToRemove)
2020-10-02 13:02:56 +00:00
}
removeContactConfirmationDialog.parentPopup.close();
removeContactConfirmationDialog.close();
}
}
MessageContextMenuView {
id: quickActionMessageOptionsMenu
store: root.rootStore
reactionModel: root.rootStore.emojiReactionsModel
}
}
/*##^##
Designer {
D{i:0;formeditorColor:"#ffffff";formeditorZoom:1.25;height:770;width:1152}
}
##^##*/