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

344 lines
13 KiB
QML
Raw Normal View History

2020-12-11 20:29:46 +00:00
import QtQuick 2.13
import QtQuick.Controls 2.13
import QtQuick.Dialogs 1.2
import QtGraphicalEffects 1.13
2020-12-11 20:29:46 +00:00
import QtQuick.Layouts 1.13
import StatusQ.Components 0.1
import StatusQ.Popups 0.1
2020-12-11 20:29:46 +00:00
import "../../../imports"
import "../../../shared"
import "../../../shared/status"
import "./components"
2020-12-11 20:38:10 +00:00
import "./CommunityComponents"
2020-12-11 20:29:46 +00:00
Item {
id: root
width: 304
height: parent.height
2020-12-11 20:29:46 +00:00
// TODO unhardcode
property int chatGroupsListViewCount: communityChatListAndCategories.chatList.count
2021-06-02 19:43:33 +00:00
property Component pinnedMessagesPopupComponent
2020-12-11 20:29:46 +00:00
StatusChatInfoToolBar {
2020-12-11 20:29:46 +00:00
id: communityHeader
anchors.top: parent.top
anchors.horizontalCenter: parent.horizontalCenter
chatInfoButton.title: chatsModel.communities.activeCommunity.name
chatInfoButton.subTitle: chatsModel.communities.activeCommunity.nbMembers === 1 ?
//% "1 Member"
qsTrId("1-member") :
//% "%1 Members"
qsTrId("-1-members").arg(chatsModel.communities.activeCommunity.nbMembers)
chatInfoButton.image.source: chatsModel.communities.activeCommunity.thumbnailImage
chatInfoButton.icon.color: chatsModel.communities.activeCommunity.communityColor
menuButton.visible: chatsModel.communities.activeCommunity.admin && chatsModel.communities.activeCommunity.canManageUsers
chatInfoButton.onClicked: openPopup(communityProfilePopup, {
community: chatsModel.communities.activeCommunity
})
popupMenu: StatusPopupMenu {
StatusMenuItem {
//% "Create channel"
text: qsTrId("create-channel")
icon.name: "channel"
enabled: chatsModel.communities.activeCommunity.admin
onTriggered: openPopup(createChannelPopup, {communityId: chatsModel.communities.activeCommunity.id})
2020-12-11 20:29:46 +00:00
}
StatusMenuItem {
//% "Create category"
text: qsTrId("create-category")
icon.name: "channel-category"
enabled: chatsModel.communities.activeCommunity.admin
onTriggered: openPopup(createCategoryPopup, {communityId: chatsModel.communities.activeCommunity.id})
}
StatusMenuSeparator {}
StatusMenuItem {
//% "Invite people"
text: qsTrId("invite-people")
icon.name: "share-ios"
enabled: chatsModel.communities.activeCommunity.canManageUsers
onTriggered: openPopup(inviteFriendsToCommunityPopup, {
community: chatsModel.communities.activeCommunity
})
}
}
}
Loader {
id: membershipRequests
property int nbRequests: chatsModel.communities.activeCommunity.communityMembershipRequests.nbRequests
anchors.top: communityHeader.bottom
anchors.topMargin: active ? 8 : 0
anchors.horizontalCenter: parent.horizontalCenter
active: chatsModel.communities.activeCommunity.admin && nbRequests > 0
height: nbRequests > 0 ? 64 : 0
sourceComponent: Component {
StatusContactRequestsIndicatorListItem {
//% "Membership requests"
title: qsTrId("membership-requests")
requestsCount: membershipRequests.nbRequests
sensor.onClicked: openPopup(membershipRequestPopup)
}
}
}
2020-12-11 20:29:46 +00:00
ScrollView {
id: chatGroupsContainer
anchors.top: membershipRequests.bottom
2020-12-11 20:29:46 +00:00
anchors.topMargin: Style.current.padding
anchors.bottom: parent.bottom
anchors.horizontalCenter: parent.horizontalCenter
width: parent.width
2020-12-11 20:29:46 +00:00
leftPadding: Style.current.halfPadding
rightPadding: Style.current.halfPadding
2020-12-11 20:29:46 +00:00
ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
clip: true
contentHeight: communityChatListAndCategories.height
+ emptyViewAndSuggestionsLoader.height
+ backUpBannerLoader.height
+ 16
StatusChatListAndCategories {
id: communityChatListAndCategories
anchors.horizontalCenter: parent.horizontalCenter
width: root.width
height: {
if (!emptyViewAndSuggestionsLoader.active &&
!backUpBannerLoader.active) {
return implicitHeight > (root.height - 82) ? implicitHeight + 8 : root.height - 82
}
return implicitHeight
}
draggableItems: chatsModel.communities.activeCommunity.admin
draggableCategories: chatsModel.communities.activeCommunity.admin
chatList.model: chatsModel.communities.activeCommunity.chats
categoryList.model: chatsModel.communities.activeCommunity.categories
showCategoryActionButtons: chatsModel.communities.activeCommunity.admin
showPopupMenu: chatsModel.communities.activeCommunity.admin && chatsModel.communities.activeCommunity.canManageUsers
selectedChatId: chatsModel.channelView.activeChannel.id
onChatItemSelected: chatsModel.channelView.setActiveChannel(id)
onChatItemUnmuted: chatsModel.channelView.unmuteChatItem(id)
onChatItemReordered: function (categoryId, id, from, to) {
chatsModel.communities.reorderCommunityChannel(chatsModel.communities.activeCommunity.id, categoryId, id, to);
}
onChatListCategoryReordered: function (categoryId, from, to) {
chatsModel.communities.reorderCommunityCategories(chatsModel.communities.activeCommunity.id, categoryId, to);
}
onCategoryAddButtonClicked: openPopup(createChannelPopup, {
communityId: chatsModel.communities.activeCommunity.id,
categoryId: id
})
popupMenu: StatusPopupMenu {
StatusMenuItem {
//% "Create channel"
text: qsTrId("create-channel")
icon.name: "channel"
enabled: chatsModel.communities.activeCommunity.admin
onTriggered: openPopup(createChannelPopup, {communityId: chatsModel.communities.activeCommunity.id})
}
StatusMenuItem {
//% "Create category"
text: qsTrId("create-category")
icon.name: "channel-category"
enabled: chatsModel.communities.activeCommunity.admin
onTriggered: openPopup(createCategoryPopup, {communityId: chatsModel.communities.activeCommunity.id})
}
2020-12-11 20:29:46 +00:00
StatusMenuSeparator {}
StatusMenuItem {
//% "Invite people"
text: qsTrId("invite-people")
icon.name: "share-ios"
enabled: chatsModel.communities.activeCommunity.canManageUsers
onTriggered: openPopup(inviteFriendsToCommunityPopup, {
community: chatsModel.communities.activeCommunity
})
}
}
categoryPopupMenu: StatusPopupMenu {
property var categoryItem
openHandler: function (id) {
categoryItem = chatsModel.communities.activeCommunity.getCommunityCategoryItemById(id)
}
StatusMenuItem {
enabled: chatsModel.communities.activeCommunity.admin
//% "Edit Category"
text: qsTrId("edit-category")
icon.name: "edit"
onTriggered: {
openPopup(createCategoryPopup, {
communityId: chatsModel.communities.activeCommunity.id,
isEdit: true,
categoryId: categoryItem.id,
categoryName: categoryItem.name
})
}
}
StatusMenuSeparator {
visible: chatsModel.communities.activeCommunity.admin
}
StatusMenuItem {
enabled: chatsModel.communities.activeCommunity.admin
//% "Delete Category"
text: qsTrId("delete-category")
icon.name: "delete"
type: StatusMenuItem.Type.Danger
onTriggered: {
openPopup(deleteCategoryConfirmationDialogComponent, {
//% "Delete %1 category"
title: qsTrId("delete--1-category").arg(categoryItem.name),
//% "Are you sure you want to delete %1 category? Channels inside the category wont be deleted."
confirmationText: qsTrId("are-you-sure-you-want-to-delete--1-category--channels-inside-the-category-won-t-be-deleted-")
.arg(categoryItem.name),
categoryId: categoryItem.id
})
}
}
}
chatListPopupMenu: ChatContextMenu {
openHandler: function (id) {
chatItem = chatsModel.channelView.getChatItemById(id)
}
}
2021-05-16 15:16:42 +00:00
}
Loader {
id: emptyViewAndSuggestionsLoader
active: chatsModel.communities.activeCommunity.admin && !appSettings.hiddenCommunityWelcomeBanners.includes(chatsModel.communities.activeCommunity.id)
2020-12-11 20:29:46 +00:00
width: parent.width
height: active ? item.height : 0
anchors.top: communityChatListAndCategories.bottom
anchors.topMargin: active ? Style.current.padding : 0
sourceComponent: Component {
CommunityWelcomeBanner {}
}
}
Loader {
id: backUpBannerLoader
active: chatsModel.communities.activeCommunity.admin && !appSettings.hiddenCommunityBackUpBanners.includes(chatsModel.communities.activeCommunity.id)
width: parent.width
height: active ? item.height : 0
anchors.top: emptyViewAndSuggestionsLoader.bottom
anchors.topMargin: active ? Style.current.padding : 0
sourceComponent: Component {
Item {
width: parent.width
height: backupBanner.height
BackUpCommuntyBanner {
id: backupBanner
}
MouseArea {
anchors.fill: backupBanner
acceptedButtons: Qt.RightButton
onClicked: {
/* Prevents sending events to the component beneath
if Right Mouse Button is clicked. */
mouse.accepted = false;
}
}
}
}
2020-12-11 20:29:46 +00:00
}
}
Component {
id: createChannelPopup
CreateChannelPopup {
anchors.centerIn: parent
pinnedMessagesPopupComponent: root.pinnedMessagesPopupComponent
onClosed: {
destroy()
}
}
}
Component {
id: createCategoryPopup
CreateCategoryPopup {
anchors.centerIn: parent
onClosed: {
destroy()
}
}
}
Component {
id: deleteCategoryConfirmationDialogComponent
ConfirmationDialog {
property string categoryId
btnType: "warn"
showCancelButton: true
onClosed: {
destroy()
}
onCancelButtonClicked: {
close();
}
onConfirmButtonClicked: function(){
const error = chatsModel.communities.deleteCommunityCategory(chatsModel.communities.activeCommunity.id, categoryId)
if (error) {
creatingError.text = error
return creatingError.open()
}
close();
}
}
}
MessageDialog {
id: deleteError
//% "Error deleting the category"
title: qsTrId("error-deleting-the-category")
icon: StandardIcon.Critical
standardButtons: StandardButton.Ok
}
Component {
id: membershipRequestPopup
MembershipRequestsPopup {
anchors.centerIn: parent
onClosed: {
destroy()
}
}
}
2020-12-11 20:29:46 +00:00
}
/*##^##
Designer {
D{i:0;autoSize:true;formeditorColor:"#ffffff";height:480;width:640}
}
##^##*/