implement room destruction

This commit is contained in:
Christoph Scholz 2018-12-30 16:57:37 +01:00
parent 835c89328d
commit 52e1a0c708
4 changed files with 62 additions and 1 deletions

View File

@ -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);

View File

@ -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));

View File

@ -31,6 +31,11 @@
android:orderInCategory="80"
app:showAsAction="never"
android:title="@string/delete_bookmark"/>
<item
android:id="@+id/action_destroy_room"
android:orderInCategory="82"
app:showAsAction="never"
android:title="@string/destroy_room"/>
<item
android:id="@+id/action_advanced_mode"
android:checkable="true"

View File

@ -228,6 +228,9 @@
<string name="conference_address_example">room@conference.example.com/nick</string>
<string name="save_as_bookmark">Save as bookmark</string>
<string name="delete_bookmark">Delete bookmark</string>
<string name="destroy_room">Destroy group chat</string>
<string name="destroy_room_dialog">Are you sure you want to destroy this group chat?\n\n<b>Warning:</b> The group chat will be completely removed on the server.</string>
<string name="could_not_destroy_room">Could not destroy room</string>
<string name="bookmark_already_exists">This bookmark already exists</string>
<string name="action_edit_subject">Edit group chat subject</string>
<string name="topic">Topic</string>