From 52e1a0c708d1f4ac8f65a3f23782f3089773401c Mon Sep 17 00:00:00 2001 From: Christoph Scholz Date: Sun, 30 Dec 2018 16:57:37 +0100 Subject: [PATCH] implement room destruction --- .../services/XmppConnectionService.java | 26 +++++++++++++++++ .../ui/ConferenceDetailsActivity.java | 29 ++++++++++++++++++- src/main/res/menu/muc_details.xml | 5 ++++ src/main/res/values/strings.xml | 3 ++ 4 files changed, 62 insertions(+), 1 deletion(-) diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 48044766a..af0b81585 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -2822,6 +2822,26 @@ public class XmppConnectionService extends Service { }); } + public void destroyRoom(final Conversation conversation, final OnRoomDestroy callback) { + IqPacket request = new IqPacket(IqPacket.TYPE.SET); + request.setTo(conversation.getJid().asBareJid()); + request.query("http://jabber.org/protocol/muc#owner").addChild("destroy"); + sendIqPacket(conversation.getAccount(), request, new OnIqPacketReceived() { + @Override + public void onIqPacketReceived(Account account, IqPacket packet) { + if (packet.getType() == IqPacket.TYPE.RESULT) { + if (callback != null) { + callback.onRoomDestroySucceeded(); + } + } else if (packet.getType() == IqPacket.TYPE.ERROR) { + if (callback != null) { + callback.onRoomDestroyFailed(); + } + } + } + }); + } + private void disconnect(Account account, boolean force) { if ((account.getStatus() == Account.State.ONLINE) || (account.getStatus() == Account.State.DISABLED)) { @@ -4140,6 +4160,12 @@ public class XmppConnectionService extends Service { void onPasswordChangeFailed(); } + public interface OnRoomDestroy { + void onRoomDestroySucceeded(); + + void onRoomDestroyFailed(); + } + public interface OnAffiliationChanged { void onAffiliationChangedSuccessful(Jid jid); diff --git a/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java b/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java index 8d2efff0b..882b8f364 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java @@ -72,7 +72,7 @@ import rocks.xmpp.addr.Jid; import static eu.siacs.conversations.entities.Bookmark.printableValue; import static eu.siacs.conversations.utils.StringUtils.changed; -public class ConferenceDetailsActivity extends XmppActivity implements OnConversationUpdate, OnMucRosterUpdate, XmppConnectionService.OnAffiliationChanged, XmppConnectionService.OnRoleChanged, XmppConnectionService.OnConfigurationPushed, TextWatcher, OnMediaLoaded { +public class ConferenceDetailsActivity extends XmppActivity implements OnConversationUpdate, OnMucRosterUpdate, XmppConnectionService.OnAffiliationChanged, XmppConnectionService.OnRoleChanged, XmppConnectionService.OnConfigurationPushed, XmppConnectionService.OnRoomDestroy, TextWatcher, OnMediaLoaded { public static final String ACTION_VIEW_MUC = "view_muc"; private static final float INACTIVE_ALPHA = 0.4684f; //compromise between dark and light theme @@ -319,6 +319,9 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers case R.id.action_delete_bookmark: deleteBookmark(); break; + case R.id.action_destroy_room: + destroyRoom(); + break; case R.id.action_advanced_mode: this.mAdvancedMode = !menuItem.isChecked(); menuItem.setChecked(this.mAdvancedMode); @@ -406,6 +409,7 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers MenuItem menuItemSaveBookmark = menu.findItem(R.id.action_save_as_bookmark); MenuItem menuItemDeleteBookmark = menu.findItem(R.id.action_delete_bookmark); MenuItem menuItemAdvancedMode = menu.findItem(R.id.action_advanced_mode); + MenuItem menuItemDestroyRoom = menu.findItem(R.id.action_destroy_room); menuItemAdvancedMode.setChecked(mAdvancedMode); if (mConversation == null) { return true; @@ -417,6 +421,7 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers menuItemDeleteBookmark.setVisible(false); menuItemSaveBookmark.setVisible(true); } + menuItemDestroyRoom.setVisible(mConversation.getMucOptions().getSelf().getAffiliation().ranks(MucOptions.Affiliation.OWNER)); return true; } @@ -481,6 +486,19 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers updateView(); } + protected void destroyRoom() { + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle(R.string.destroy_room); + builder.setMessage(R.string.destroy_room_dialog); + builder.setPositiveButton(R.string.ok, (dialog, which) -> { + xmppConnectionService.destroyRoom(mConversation, ConferenceDetailsActivity.this); + }); + builder.setNegativeButton(R.string.cancel, null); + final AlertDialog dialog = builder.create(); + dialog.setCanceledOnTouchOutside(false); + dialog.show(); + } + @Override void onBackendConnected() { if (mPendingConferenceInvite != null) { @@ -687,6 +705,15 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers displayToast(getString(resId, nick)); } + @Override + public void onRoomDestroySucceeded() { + finish(); + } + @Override + public void onRoomDestroyFailed() { + displayToast(getString(R.string.could_not_destroy_room)); + } + @Override public void onPushSucceeded() { displayToast(getString(R.string.modified_conference_options)); diff --git a/src/main/res/menu/muc_details.xml b/src/main/res/menu/muc_details.xml index 5fc3ac600..16063b2b1 100644 --- a/src/main/res/menu/muc_details.xml +++ b/src/main/res/menu/muc_details.xml @@ -31,6 +31,11 @@ android:orderInCategory="80" app:showAsAction="never" android:title="@string/delete_bookmark"/> + room@conference.example.com/nick Save as bookmark Delete bookmark + Destroy group chat + Are you sure you want to destroy this group chat?\n\nWarning: The group chat will be completely removed on the server. + Could not destroy room This bookmark already exists Edit group chat subject Topic