2021-01-21 14:39:27 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
import QtQuick.Controls 2.13
|
|
|
|
import QtQuick.Layouts 1.13
|
|
|
|
import "./"
|
|
|
|
import "../../../../shared"
|
|
|
|
import "../../../../imports"
|
|
|
|
|
|
|
|
PopupMenu {
|
|
|
|
property int channelIndex
|
2021-02-17 21:06:16 +00:00
|
|
|
property var contextChannel: ({})
|
2021-01-21 14:39:27 +00:00
|
|
|
|
|
|
|
id: channelContextMenu
|
|
|
|
width: 175
|
|
|
|
subMenuIcons: [
|
|
|
|
/* { */
|
|
|
|
/* source: Qt.resolvedUrl("../../../img/bell.svg"), */
|
|
|
|
/* width: 16, */
|
|
|
|
/* height: 16 */
|
|
|
|
/* }, */
|
|
|
|
{
|
|
|
|
source: Qt.resolvedUrl("../../../img/fetch.svg"),
|
|
|
|
width: 16,
|
|
|
|
height: 16
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2021-02-12 18:38:25 +00:00
|
|
|
function openMenu(channel, index, x, y) {
|
refactor(ChannelContextMenu): remove dependency on active channel
This commit does a bunch of things:
- First and foremost, it removes the active channel dependency.
This is needed to have it operate on the correct channel object,
without forcing us to change the active channel (e.g. right-clicking
on a channel item that's not active, will make it active eventually)
- To make that work, this commit changes the `ChannelContextMenu`
to receive a `ChatItemView`, so it can be used for things like determining
what menu options are shown, what members are in a group, whether
someone is admin of a group etc.
- This also required a new `QtProperty` called `contextChannel`.
The reason this is required, is because in some cases, like receiving
members count of groups, we need a complete `ChatItemView` object
as we don't have access to certain APIs otherwise.
- Unfortunately, we can't pass down `activeChannel` every where for that
because sometimes the context menu should not actually operate on
the active channel.
Fixes: #1755
2021-01-25 15:58:33 +00:00
|
|
|
channelContextMenu.contextChannel = channel
|
2021-01-21 14:39:27 +00:00
|
|
|
if (index !== undefined) {
|
|
|
|
channelContextMenu.channelIndex = index
|
|
|
|
}
|
2021-02-12 18:38:25 +00:00
|
|
|
channelContextMenu.popup(x, y)
|
2021-01-21 14:39:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Action {
|
2021-02-12 18:38:25 +00:00
|
|
|
id: viewProfileButton
|
refactor(ChannelContextMenu): remove dependency on active channel
This commit does a bunch of things:
- First and foremost, it removes the active channel dependency.
This is needed to have it operate on the correct channel object,
without forcing us to change the active channel (e.g. right-clicking
on a channel item that's not active, will make it active eventually)
- To make that work, this commit changes the `ChannelContextMenu`
to receive a `ChatItemView`, so it can be used for things like determining
what menu options are shown, what members are in a group, whether
someone is admin of a group etc.
- This also required a new `QtProperty` called `contextChannel`.
The reason this is required, is because in some cases, like receiving
members count of groups, we need a complete `ChatItemView` object
as we don't have access to certain APIs otherwise.
- Unfortunately, we can't pass down `activeChannel` every where for that
because sometimes the context menu should not actually operate on
the active channel.
Fixes: #1755
2021-01-25 15:58:33 +00:00
|
|
|
enabled: channelContextMenu.contextChannel.chatType !== Constants.chatTypePublic
|
2021-01-21 14:39:27 +00:00
|
|
|
text: {
|
refactor(ChannelContextMenu): remove dependency on active channel
This commit does a bunch of things:
- First and foremost, it removes the active channel dependency.
This is needed to have it operate on the correct channel object,
without forcing us to change the active channel (e.g. right-clicking
on a channel item that's not active, will make it active eventually)
- To make that work, this commit changes the `ChannelContextMenu`
to receive a `ChatItemView`, so it can be used for things like determining
what menu options are shown, what members are in a group, whether
someone is admin of a group etc.
- This also required a new `QtProperty` called `contextChannel`.
The reason this is required, is because in some cases, like receiving
members count of groups, we need a complete `ChatItemView` object
as we don't have access to certain APIs otherwise.
- Unfortunately, we can't pass down `activeChannel` every where for that
because sometimes the context menu should not actually operate on
the active channel.
Fixes: #1755
2021-01-25 15:58:33 +00:00
|
|
|
if (channelContextMenu.contextChannel.chatType === Constants.chatTypeOneToOne) {
|
2021-01-21 14:39:27 +00:00
|
|
|
//% "View Profile"
|
|
|
|
return qsTrId("view-profile")
|
|
|
|
}
|
refactor(ChannelContextMenu): remove dependency on active channel
This commit does a bunch of things:
- First and foremost, it removes the active channel dependency.
This is needed to have it operate on the correct channel object,
without forcing us to change the active channel (e.g. right-clicking
on a channel item that's not active, will make it active eventually)
- To make that work, this commit changes the `ChannelContextMenu`
to receive a `ChatItemView`, so it can be used for things like determining
what menu options are shown, what members are in a group, whether
someone is admin of a group etc.
- This also required a new `QtProperty` called `contextChannel`.
The reason this is required, is because in some cases, like receiving
members count of groups, we need a complete `ChatItemView` object
as we don't have access to certain APIs otherwise.
- Unfortunately, we can't pass down `activeChannel` every where for that
because sometimes the context menu should not actually operate on
the active channel.
Fixes: #1755
2021-01-25 15:58:33 +00:00
|
|
|
if (channelContextMenu.contextChannel.chatType === Constants.chatTypePrivateGroupChat) {
|
2021-01-21 14:39:27 +00:00
|
|
|
//% "View Group"
|
|
|
|
return qsTrId("view-group")
|
|
|
|
}
|
|
|
|
//% "Share Chat"
|
|
|
|
return qsTrId("share-chat")
|
|
|
|
}
|
|
|
|
icon.source: "../../../img/group.svg"
|
|
|
|
icon.width: 16
|
|
|
|
icon.height: 16
|
|
|
|
onTriggered: {
|
refactor(ChannelContextMenu): remove dependency on active channel
This commit does a bunch of things:
- First and foremost, it removes the active channel dependency.
This is needed to have it operate on the correct channel object,
without forcing us to change the active channel (e.g. right-clicking
on a channel item that's not active, will make it active eventually)
- To make that work, this commit changes the `ChannelContextMenu`
to receive a `ChatItemView`, so it can be used for things like determining
what menu options are shown, what members are in a group, whether
someone is admin of a group etc.
- This also required a new `QtProperty` called `contextChannel`.
The reason this is required, is because in some cases, like receiving
members count of groups, we need a complete `ChatItemView` object
as we don't have access to certain APIs otherwise.
- Unfortunately, we can't pass down `activeChannel` every where for that
because sometimes the context menu should not actually operate on
the active channel.
Fixes: #1755
2021-01-25 15:58:33 +00:00
|
|
|
if (channelContextMenu.contextChannel.chatType === Constants.chatTypeOneToOne) {
|
|
|
|
const userProfileImage = appMain.getProfileImage(channelContextMenu.contextChannel.id)
|
|
|
|
return openProfilePopup(
|
|
|
|
channelContextMenu.contextChannel.name,
|
|
|
|
channelContextMenu.contextChannel.id,
|
|
|
|
userProfileImage || channelContextMenu.contextChannel.identicon
|
|
|
|
)
|
2021-01-21 14:39:27 +00:00
|
|
|
}
|
refactor(ChannelContextMenu): remove dependency on active channel
This commit does a bunch of things:
- First and foremost, it removes the active channel dependency.
This is needed to have it operate on the correct channel object,
without forcing us to change the active channel (e.g. right-clicking
on a channel item that's not active, will make it active eventually)
- To make that work, this commit changes the `ChannelContextMenu`
to receive a `ChatItemView`, so it can be used for things like determining
what menu options are shown, what members are in a group, whether
someone is admin of a group etc.
- This also required a new `QtProperty` called `contextChannel`.
The reason this is required, is because in some cases, like receiving
members count of groups, we need a complete `ChatItemView` object
as we don't have access to certain APIs otherwise.
- Unfortunately, we can't pass down `activeChannel` every where for that
because sometimes the context menu should not actually operate on
the active channel.
Fixes: #1755
2021-01-25 15:58:33 +00:00
|
|
|
if (channelContextMenu.contextChannel.chatType === Constants.chatTypePrivateGroupChat) {
|
2021-02-17 20:36:10 +00:00
|
|
|
return openPopup(groupInfoPopupComponent, {channel: channelContextMenu.contextChannel})
|
2021-01-21 14:39:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-12 18:38:25 +00:00
|
|
|
Separator {
|
|
|
|
visible: viewProfileButton.enabled
|
|
|
|
}
|
2021-01-21 14:39:27 +00:00
|
|
|
|
|
|
|
Action {
|
refactor(ChannelContextMenu): remove dependency on active channel
This commit does a bunch of things:
- First and foremost, it removes the active channel dependency.
This is needed to have it operate on the correct channel object,
without forcing us to change the active channel (e.g. right-clicking
on a channel item that's not active, will make it active eventually)
- To make that work, this commit changes the `ChannelContextMenu`
to receive a `ChatItemView`, so it can be used for things like determining
what menu options are shown, what members are in a group, whether
someone is admin of a group etc.
- This also required a new `QtProperty` called `contextChannel`.
The reason this is required, is because in some cases, like receiving
members count of groups, we need a complete `ChatItemView` object
as we don't have access to certain APIs otherwise.
- Unfortunately, we can't pass down `activeChannel` every where for that
because sometimes the context menu should not actually operate on
the active channel.
Fixes: #1755
2021-01-25 15:58:33 +00:00
|
|
|
text: channelContextMenu.contextChannel.muted ?
|
2021-01-21 14:39:27 +00:00
|
|
|
//% "Unmute chat"
|
|
|
|
qsTrId("unmute-chat") :
|
|
|
|
//% "Mute chat"
|
|
|
|
qsTrId("mute-chat")
|
|
|
|
icon.source: "../../../img/bell.svg"
|
|
|
|
icon.width: 16
|
|
|
|
icon.height: 16
|
|
|
|
onTriggered: {
|
|
|
|
if (chatsModel.channelIsMuted(channelContextMenu.channelIndex)) {
|
|
|
|
chatsModel.unmuteChannel(channelContextMenu.channelIndex)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
chatsModel.muteChannel(channelContextMenu.channelIndex)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Action {
|
|
|
|
//% "Mark as Read"
|
|
|
|
text: qsTrId("mark-as-read")
|
|
|
|
icon.source: "../../../img/check-circle.svg"
|
|
|
|
icon.width: 16
|
|
|
|
icon.height: 16
|
|
|
|
onTriggered: {
|
|
|
|
chatsModel.markAllChannelMessagesReadByIndex(channelContextMenu.channelIndex)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
FetchMoreMessages {}
|
|
|
|
Action {
|
|
|
|
//% "Clear History"
|
|
|
|
text: qsTrId("clear-history")
|
|
|
|
icon.source: "../../../img/close.svg"
|
|
|
|
icon.width: 16
|
|
|
|
icon.height: 16
|
|
|
|
onTriggered: chatsModel.clearChatHistoryByIndex(channelContextMenu.channelIndex)
|
|
|
|
}
|
|
|
|
|
|
|
|
Separator {}
|
|
|
|
|
|
|
|
Action {
|
|
|
|
text: {
|
refactor(ChannelContextMenu): remove dependency on active channel
This commit does a bunch of things:
- First and foremost, it removes the active channel dependency.
This is needed to have it operate on the correct channel object,
without forcing us to change the active channel (e.g. right-clicking
on a channel item that's not active, will make it active eventually)
- To make that work, this commit changes the `ChannelContextMenu`
to receive a `ChatItemView`, so it can be used for things like determining
what menu options are shown, what members are in a group, whether
someone is admin of a group etc.
- This also required a new `QtProperty` called `contextChannel`.
The reason this is required, is because in some cases, like receiving
members count of groups, we need a complete `ChatItemView` object
as we don't have access to certain APIs otherwise.
- Unfortunately, we can't pass down `activeChannel` every where for that
because sometimes the context menu should not actually operate on
the active channel.
Fixes: #1755
2021-01-25 15:58:33 +00:00
|
|
|
if (channelContextMenu.contextChannel.chatType === Constants.chatTypeOneToOne) {
|
2021-01-21 14:39:27 +00:00
|
|
|
//% "Delete chat"
|
|
|
|
return qsTrId("delete-chat")
|
|
|
|
}
|
refactor(ChannelContextMenu): remove dependency on active channel
This commit does a bunch of things:
- First and foremost, it removes the active channel dependency.
This is needed to have it operate on the correct channel object,
without forcing us to change the active channel (e.g. right-clicking
on a channel item that's not active, will make it active eventually)
- To make that work, this commit changes the `ChannelContextMenu`
to receive a `ChatItemView`, so it can be used for things like determining
what menu options are shown, what members are in a group, whether
someone is admin of a group etc.
- This also required a new `QtProperty` called `contextChannel`.
The reason this is required, is because in some cases, like receiving
members count of groups, we need a complete `ChatItemView` object
as we don't have access to certain APIs otherwise.
- Unfortunately, we can't pass down `activeChannel` every where for that
because sometimes the context menu should not actually operate on
the active channel.
Fixes: #1755
2021-01-25 15:58:33 +00:00
|
|
|
if (channelContextMenu.contextChannel.chatType === Constants.chatTypePrivateGroupChat) {
|
2021-01-21 14:39:27 +00:00
|
|
|
//% "Leave group"
|
|
|
|
return qsTrId("leave-group")
|
|
|
|
}
|
|
|
|
//% "Leave chat"
|
|
|
|
return qsTrId("leave-chat")
|
|
|
|
}
|
|
|
|
icon.source: {
|
refactor(ChannelContextMenu): remove dependency on active channel
This commit does a bunch of things:
- First and foremost, it removes the active channel dependency.
This is needed to have it operate on the correct channel object,
without forcing us to change the active channel (e.g. right-clicking
on a channel item that's not active, will make it active eventually)
- To make that work, this commit changes the `ChannelContextMenu`
to receive a `ChatItemView`, so it can be used for things like determining
what menu options are shown, what members are in a group, whether
someone is admin of a group etc.
- This also required a new `QtProperty` called `contextChannel`.
The reason this is required, is because in some cases, like receiving
members count of groups, we need a complete `ChatItemView` object
as we don't have access to certain APIs otherwise.
- Unfortunately, we can't pass down `activeChannel` every where for that
because sometimes the context menu should not actually operate on
the active channel.
Fixes: #1755
2021-01-25 15:58:33 +00:00
|
|
|
if (channelContextMenu.contextChannel.chatType === Constants.chatTypeOneToOne) {
|
2021-01-21 14:39:27 +00:00
|
|
|
return "../../../img/delete.svg"
|
|
|
|
}
|
|
|
|
return "../../../img/leave_chat.svg"
|
|
|
|
}
|
|
|
|
icon.width: 16
|
|
|
|
icon.height: 16
|
|
|
|
onTriggered: chatsModel.leaveChatByIndex(channelContextMenu.channelIndex)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|