Skip to content

Commit

Permalink
feature: add remove from group option to group chats
Browse files Browse the repository at this point in the history
feature: add remove from group option to group chats

add isAdmin property

move removeMemberFromGroupChat to root store
  • Loading branch information
iurimatias committed Sep 20, 2024
1 parent 9d06b36 commit e74aa19
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 6 deletions.
44 changes: 43 additions & 1 deletion storybook/pages/ProfileContextMenuPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ SplitView {
ensVerified: ensVerifiedCheckBox.checked
onlineStatus: onlineStatusSelector.currentValue
hasLocalNickname: hasLocalNicknameCheckBox.checked
chatType: chatTypeSelector.currentValue
isAdmin: isAdminCheckBox.checked
publicKey: publicKeyInput.text

onOpenProfileClicked: () => {
Expand Down Expand Up @@ -97,6 +99,9 @@ SplitView {
onBlockContact: () => {
logs.logEvent("Block contact:", profileContextMenu.publicKey)
}
onRemoveFromGroup: (publicKey) => {
logs.logEvent("Remove from group:", publicKey)
}
onClosed: {
destroy()
}
Expand All @@ -115,6 +120,8 @@ SplitView {
ensVerified: ensVerifiedCheckBox.checked
onlineStatus: onlineStatusSelector.currentValue
hasLocalNickname: hasLocalNicknameCheckBox.checked
chatType: chatTypeSelector.currentValue
isAdmin: isAdminCheckBox.checked
publicKey: publicKeyInput.text

onOpenProfileClicked: () => {
Expand Down Expand Up @@ -150,7 +157,9 @@ SplitView {
onBlockContact: () => {
logs.logEvent("Block contact:", profileContextMenu.publicKey)
}

onRemoveFromGroup: (publicKey) => {
logs.logEvent("Remove from group:", publicKey)
}
onClosed: {
destroy()
}
Expand Down Expand Up @@ -273,6 +282,39 @@ SplitView {
Layout.fillWidth: true
text: "Has Local Nickname: " + (hasLocalNicknameCheckBox.checked ? "Yes" : "No")
}

ComboBox {
id: chatTypeSelector
textRole: "text"
valueRole: "value"
model: [
{ text: "Unknown", value: Constants.chatType.unknown },
{ text: "Category", value: Constants.chatType.category },
{ text: "One-to-One", value: Constants.chatType.oneToOne },
{ text: "Public Chat", value: Constants.chatType.publicChat },
{ text: "Private Group Chat", value: Constants.chatType.privateGroupChat },
{ text: "Profile", value: Constants.chatType.profile },
{ text: "Community Chat", value: Constants.chatType.communityChat }
]
currentIndex: 0
}

CheckBox {
id: isAdminCheckBox
text: "Is Admin"
checked: false
}

Label {
Layout.fillWidth: true
text: "Is Admin: " + (isAdminCheckBox.checked ? "Yes" : "No")
}

Label {
Layout.fillWidth: true
text: "Chat type: " + chatTypeSelector.currentText
}

}
}
}
Expand Down
7 changes: 6 additions & 1 deletion ui/app/AppLayouts/Chat/panels/UserListPanel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,11 @@ Item {
onClicked: {
if (mouse.button === Qt.RightButton) {
const { profileType, trustStatus, contactType, ensVerified, onlineStatus, hasLocalNickname } = root.store.contactsStore.getProfileContext(model.pubKey, userProfile.pubKey)
const chatType = chatContentModule.chatDetails.type
const isAdmin = chatContentModule.amIChatAdmin()

Global.openMenu(profileContextMenuComponent, this, {
profileType, trustStatus, contactType, ensVerified, onlineStatus, hasLocalNickname,
profileType, trustStatus, contactType, ensVerified, onlineStatus, hasLocalNickname, chatType, isAdmin,
publicKey: model.pubKey,
displayName: nickName || userName,
userIcon: model.icon,
Expand Down Expand Up @@ -209,6 +211,9 @@ Item {
const contactDetails = profileContextMenu.publicKey === "" ? {} : Utils.getContactDetailsAsJson(profileContextMenu.publicKey, true, true)
Global.blockContactRequested(profileContextMenu.publicKey, contactDetails)
}
onRemoveFromGroup: {
root.store.removeMemberFromGroupChat(profileContextMenu.publicKey)
}
}
}
}
5 changes: 5 additions & 0 deletions ui/app/AppLayouts/Chat/stores/RootStore.qml
Original file line number Diff line number Diff line change
Expand Up @@ -761,4 +761,9 @@ QtObject {
function updatePermissionsModel(communityId, sharedAddresses) {
communitiesModuleInst.checkPermissions(communityId, JSON.stringify(sharedAddresses))
}

function removeMemberFromGroupChat(publicKey) {
const chatId = chatCommunitySectionModule.activeItem.id
chatCommunitySectionModule.removeMemberFromGroupChat("", chatId, publicKey)
}
}
6 changes: 3 additions & 3 deletions ui/app/AppLayouts/Profile/views/ContactsView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ SettingsContentBase {

Global.openMenu(contactContextMenuComponent, this, {
profileType, trustStatus, contactType, ensVerified, onlineStatus, hasLocalNickname,
selectedUserPublicKey: publicKey,
selectedUserDisplayName: name,
selectedUserIcon: icon,
publicKey: publicKey,
displayName: name,
userIcon: icon,
})
}

Expand Down
7 changes: 6 additions & 1 deletion ui/imports/shared/views/chat/MessageView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,10 @@ Loader {
const publicKey = isReply ? quotedMessageFrom : root.senderId
const isBridgedAccount = isReply ? (quotedMessageContentType === Constants.messageContentType.bridgeMessageType) : root.isBridgeMessage
const { profileType, trustStatus, contactType, ensVerified, onlineStatus, hasLocalNickname } = root.contactsStore.getProfileContext(publicKey, root.rootStore.contactsStore.myPublicKey, isBridgedAccount)
const chatType = chatContentModule.chatDetails.type
const isAdmin = chatContentModule.amIChatAdmin()

const params = { profileType, trustStatus, contactType, ensVerified, onlineStatus, hasLocalNickname,
const params = { profileType, trustStatus, contactType, ensVerified, onlineStatus, hasLocalNickname, chatType, isAdmin,
publicKey: isReply ? quotedMessageFrom : root.senderId,
displayName: isReply ? quotedMessageAuthorDetailsDisplayName : root.senderDisplayName,
userIcon: isReply ? quotedMessageAuthorDetailsThumbnailImage : root.senderIcon,
Expand Down Expand Up @@ -1211,6 +1213,9 @@ Loader {
const contactDetails = profileContextMenu.publicKey === "" ? {} : Utils.getContactDetailsAsJson(profileContextMenu.publicKey, true, true)
Global.blockContactRequested(profileContextMenu.publicKey, contactDetails)
}
onRemoveFromGroup: () => {
root.store.removeMemberFromGroupChat(profileContextMenu.publicKey)
}
onOpened: root.setMessageActive(root.messageId, true)
}
}
Expand Down
13 changes: 13 additions & 0 deletions ui/imports/shared/views/chat/ProfileContextMenu.qml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ StatusMenu {
property int profileType: Constants.profileType.regular
property bool ensVerified: false
property bool hasLocalNickname: false
property int chatType: Constants.chatType.unknown
property bool isAdmin: false

signal openProfileClicked
signal createOneToOneChat
Expand All @@ -33,6 +35,7 @@ StatusMenu {
signal removeTrustStatus
signal removeContact
signal blockContact
signal removeFromGroup

ProfileHeader {
width: parent.width
Expand Down Expand Up @@ -128,6 +131,16 @@ StatusMenu {
onTriggered: root.sendContactRequest()
}

// Remove from Group
StatusAction {
text: qsTr("Remove from group")
objectName: "removeFromGroup_StatusItem"
icon.name: "remove-contact"
type: StatusAction.Type.Danger
enabled: root.isAdmin && root.profileType !== Constants.profileType.self && root.chatType === Constants.chatType.privateGroupChat
onTriggered: root.removeFromGroup()
}

// Mark as Untrusted
StatusAction {
id: markUntrustworthyMenuItem
Expand Down

0 comments on commit e74aa19

Please sign in to comment.