feat: add api to delete a community channel

This commit is contained in:
Jonathan Rainville 2021-07-30 12:14:10 -04:00 committed by Iuri Matias
parent b5aa8d876e
commit 9f21740bae
6 changed files with 56 additions and 25 deletions

View File

@ -498,6 +498,15 @@ QtObject:
chat.muted = true chat.muted = true
return chat return chat
proc deleteCommunityChat*(self: CommunitiesView, communityId: string, channelId: string): string {.slot.} =
try:
self.status.chat.deleteCommunityChat(communityId, channelId)
self.joinedCommunityList.removeChannelInCommunity(communityId, channelId)
except RpcException as e:
error "Error deleting channel", msg=e.msg, channelId
result = StatusGoError(error: e.msg).toJson
proc setCommunityMuted*(self: CommunitiesView, communityId: string, muted: bool) {.slot.} = proc setCommunityMuted*(self: CommunitiesView, communityId: string, muted: bool) {.slot.} =
self.status.chat.setCommunityMuted(communityId, muted) self.status.chat.setCommunityMuted(communityId, muted)
if (communityId == self.activeCommunity.communityItem.id): if (communityId == self.activeCommunity.communityItem.id):

View File

@ -195,6 +195,14 @@ QtObject:
if channelIdx > -1: if channelIdx > -1:
community.chats[channelIdx] = channel community.chats[channelIdx] = channel
proc removeChannelInCommunity*(self: CommunityList, communityId: string, channelId: string) =
var community = self.getCommunityById(communityId)
let idx = community.chats.findIndexById(channelId)
if idx == -1: return
community.chats.delete(idx)
let index = self.communities.findIndexById(communityId)
self.communities[index] = community
proc addCategoryToCommunity*(self: CommunityList, communityId: string, category: CommunityCategory) = proc addCategoryToCommunity*(self: CommunityList, communityId: string, category: CommunityCategory) =
var community = self.getCommunityById(communityId) var community = self.getCommunityById(communityId)
community.categories.add(category) community.categories.add(category)

View File

@ -467,6 +467,9 @@ proc createCommunityChannel*(self: ChatModel, communityId: string, name: string,
proc editCommunityChannel*(self: ChatModel, communityId: string, channelId: string, name: string, description: string, categoryId: string): Chat = proc editCommunityChannel*(self: ChatModel, communityId: string, channelId: string, name: string, description: string, categoryId: string): Chat =
result = status_chat.editCommunityChannel(communityId, channelId, name, description, categoryId) result = status_chat.editCommunityChannel(communityId, channelId, name, description, categoryId)
proc deleteCommunityChat*(self: ChatModel, communityId: string, channelId: string) =
status_chat.deleteCommunityChat(communityId, channelId)
proc createCommunityCategory*(self: ChatModel, communityId: string, name: string, channels: seq[string]): CommunityCategory = proc createCommunityCategory*(self: ChatModel, communityId: string, name: string, channels: seq[string]): CommunityCategory =
result = status_chat.createCommunityCategory(communityId, name, channels) result = status_chat.createCommunityCategory(communityId, name, channels)

View File

@ -424,6 +424,9 @@ proc editCommunityChannel*(communityId: string, channelId: string, name: string,
if rpcResult{"result"} != nil and rpcResult{"result"}.kind != JNull: if rpcResult{"result"} != nil and rpcResult{"result"}.kind != JNull:
result = rpcResult["result"]["chats"][0].toChat() result = rpcResult["result"]["chats"][0].toChat()
proc deleteCommunityChat*(communityId: string, chatId: string) =
discard callPrivateRPC("deleteCommunityChat".prefix, %*[communityId, chatId])
proc createCommunityCategory*(communityId: string, name: string, channels: seq[string]): CommunityCategory = proc createCommunityCategory*(communityId: string, name: string, channels: seq[string]): CommunityCategory =
let rpcResult = callPrivateRPC("createCommunityCategory".prefix, %*[ let rpcResult = callPrivateRPC("createCommunityCategory".prefix, %*[
{ {

View File

@ -10,6 +10,7 @@ import StatusQ.Popups 0.1
StatusPopupMenu { StatusPopupMenu {
property var chatItem property var chatItem
property bool communityActive: chatsModel.communities.activeCommunity.active
StatusMenuItem { StatusMenuItem {
id: viewProfileMenuItem id: viewProfileMenuItem
@ -19,11 +20,9 @@ StatusPopupMenu {
case Constants.chatTypeOneToOne: case Constants.chatTypeOneToOne:
//% "View Profile" //% "View Profile"
return qsTrId("view-profile") return qsTrId("view-profile")
break;
case Constants.chatTypePrivateGroupChat: case Constants.chatTypePrivateGroupChat:
//% "View Group" //% "View Group"
return qsTrId("view-group") return qsTrId("view-group")
break;
} }
} }
return "" return ""
@ -58,7 +57,7 @@ StatusPopupMenu {
Action { Action {
enabled: profileModel.fleets.fleet == Constants.waku_prod || profileModel.fleets.fleet == Constants.waku_test enabled: profileModel.fleets.fleet == Constants.waku_prod || profileModel.fleets.fleet === Constants.waku_test
//% "Test WakuV2 - requestAllHistoricMessages" //% "Test WakuV2 - requestAllHistoricMessages"
text: qsTrId("test-wakuv2---requestallhistoricmessages") text: qsTrId("test-wakuv2---requestallhistoricmessages")
onTriggered: chatsModel.requestAllHistoricMessages() onTriggered: chatsModel.requestAllHistoricMessages()
@ -99,7 +98,7 @@ StatusPopupMenu {
//% "Edit Channel" //% "Edit Channel"
text: qsTrId("edit-channel") text: qsTrId("edit-channel")
icon.name: "edit" icon.name: "edit"
enabled: chatsModel.communities.activeCommunity.active && enabled: communityActive &&
chatsModel.communities.activeCommunity.admin chatsModel.communities.activeCommunity.admin
onTriggered: openPopup(editChannelPopup, { onTriggered: openPopup(editChannelPopup, {
communityId: chatsModel.communities.activeCommunity.id, communityId: chatsModel.communities.activeCommunity.id,
@ -113,12 +112,17 @@ StatusPopupMenu {
StatusMenuItem { StatusMenuItem {
id: deleteOrLeaveMenuItem id: deleteOrLeaveMenuItem
text: chatItem && chatItem.chatType === Constants.chatTypeOneToOne ? text: {
if (communityActive) {
return qsTr("Delete Channel")
}
return chatItem && chatItem.chatType === Constants.chatTypeOneToOne ?
//% "Delete chat" //% "Delete chat"
qsTrId("delete-chat") : qsTrId("delete-chat") :
//% "Leave chat" //% "Leave chat"
qsTrId("leave-chat") qsTrId("leave-chat")
icon.name: chatItem && chatItem.chatType === Constants.chatTypeOneToOne ? "delete" : "arrow-right" }
icon.name: chatItem && chatItem.chatType === Constants.chatTypeOneToOne || communityActive ? "delete" : "arrow-right"
icon.width: chatItem && chatItem.chatType === Constants.chatTypeOneToOne ? 18 : 14 icon.width: chatItem && chatItem.chatType === Constants.chatTypeOneToOne ? 18 : 14
iconRotation: chatItem && chatItem.chatType === Constants.chatTypeOneToOne ? 0 : 180 iconRotation: chatItem && chatItem.chatType === Constants.chatTypeOneToOne ? 0 : 180
@ -136,7 +140,7 @@ StatusPopupMenu {
}) })
} }
enabled: !chatsModel.communities.activeCommunity.active enabled: !communityActive || chatsModel.communities.activeCommunity.admin
} }
Component { Component {
@ -144,13 +148,17 @@ StatusPopupMenu {
ConfirmationDialog { ConfirmationDialog {
property string chatId property string chatId
btnType: "warn" btnType: "warn"
//% "Are you sure you want to leave this chat?" confirmationText: communityActive ? qsTr("Are you sure you want to delete this channel?") :
confirmationText: qsTrId("are-you-sure-you-want-to-leave-this-chat-") qsTr("Are you sure you want to leave this chat?")
onClosed: { onClosed: {
destroy() destroy()
} }
onConfirmButtonClicked: { onConfirmButtonClicked: {
if (communityActive) {
chatsModel.communities.deleteCommunityChat(chatsModel.communities.activeCommunity.id, chatId)
} else {
chatsModel.channelView.leaveChat(chatId) chatsModel.channelView.leaveChat(chatId)
}
close(); close();
} }
} }

2
vendor/status-go vendored

@ -1 +1 @@
Subproject commit cdc7c5503001e2c987cf657dc707a3da81ea397e Subproject commit 151edb36077cdbb9f1f2b89f32cd939ee873ed98