diff options
author | Christian Schneppe <christian@pix-art.de> | 2018-01-26 21:54:10 +0100 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2018-01-26 21:54:10 +0100 |
commit | f84f77316c10328198b52fbdd8a0dce9f03604ff (patch) | |
tree | 6821a7a08a6a4aeeba03fe2a978c56a6cb9a9d85 /src/main/java/de | |
parent | 563fd9f6a6c206e960ed6b5471869f9c1ed4d0ec (diff) |
add possibility to destroy group chat
Diffstat (limited to '')
5 files changed, 96 insertions, 14 deletions
diff --git a/src/main/java/de/pixart/messenger/generator/IqGenerator.java b/src/main/java/de/pixart/messenger/generator/IqGenerator.java index 8275d7762..8e3584598 100644 --- a/src/main/java/de/pixart/messenger/generator/IqGenerator.java +++ b/src/main/java/de/pixart/messenger/generator/IqGenerator.java @@ -339,6 +339,17 @@ public class IqGenerator extends AbstractGenerator { return packet; } + public IqPacket destroyConference(Conversation conference) { + IqPacket packet = new IqPacket(IqPacket.TYPE.SET); + packet.setTo(conference.getJid().toBareJid()); + packet.setFrom(conference.getAccount().getJid()); + final Element query = packet.addChild("query", "http://jabber.org/protocol/muc#owner"); + final Element destroy = query.addChild("destroy"); + destroy.setAttribute("jid", conference.getJid().toBareJid().toString()); + Log.d(Config.LOGTAG, "Destroy: " + packet.toString()); + return packet; + } + public IqPacket requestHttpUploadSlot(Jid host, DownloadableFile file, String mime) { IqPacket packet = new IqPacket(IqPacket.TYPE.GET); packet.setTo(host); diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index eee8a30ac..6c2a3cfcd 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -3,7 +3,6 @@ package de.pixart.messenger.services; import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.app.AlarmManager; -import android.app.NotificationManager; import android.app.PendingIntent; import android.app.Service; import android.content.Context; @@ -105,6 +104,7 @@ import de.pixart.messenger.parser.MessageParser; import de.pixart.messenger.parser.PresenceParser; import de.pixart.messenger.persistance.DatabaseBackend; import de.pixart.messenger.persistance.FileBackend; +import de.pixart.messenger.ui.ConversationActivity; import de.pixart.messenger.ui.SettingsActivity; import de.pixart.messenger.ui.UiCallback; import de.pixart.messenger.utils.ConversationsFileObserver; @@ -174,8 +174,8 @@ public class XmppConnectionService extends Service { private ReplacingSerialSingleThreadExecutor mContactMergerExecutor = new ReplacingSerialSingleThreadExecutor(true); private WakeLock wakeLock; private long mLastActivity = 0; - private NotificationManager mNotifyManager; - AbstractConnectionManager mAbstractConnectionManager; + ConversationActivity mConversationActivity; + private ContentObserver contactObserver = new ContentObserver(null) { @Override @@ -2414,9 +2414,9 @@ public class XmppConnectionService extends Service { account.pendingConferenceLeaves.remove(conversation); if (account.getStatus() == Account.State.ONLINE) { - // disabled for testing strange MUC leaves - // sendPresencePacket(account, mPresenceGenerator.leave(conversation.getMucOptions())); - // + //disabled for testing strange MUC leaves + sendPresencePacket(account, mPresenceGenerator.leave(conversation.getMucOptions())); + conversation.resetMucOptions(); if (onConferenceJoined != null) { conversation.getMucOptions().flagNoAutoPushConfiguration(); @@ -2892,6 +2892,32 @@ public class XmppConnectionService extends Service { }); } + public void destroyMuc(Conversation mSelectedConversation) { + destroyConference(mSelectedConversation, new XmppConnectionService.OnDestroyMuc() { + @Override + public void OnDestroyMucSuccessful() { + Log.d(Config.LOGTAG, "Destroy succeed"); + } + + @Override + public void OnDestroyMucFailed(int resId) { + Log.d(Config.LOGTAG, "Destroy failed"); + showErrorToastInUi(resId); + } + }); + } + + public void destroyConference(final Conversation conference, final OnDestroyMuc callback) { + IqPacket request = this.mIqGenerator.destroyConference(conference); + sendIqPacket(conference.getAccount(), request, (account, packet) -> { + if (packet.getType() == IqPacket.TYPE.RESULT) { + callback.OnDestroyMucSuccessful(); + } else { + callback.OnDestroyMucFailed(R.string.failed); + } + }); + } + private void disconnect(Account account, boolean force) { if ((account.getStatus() == Account.State.ONLINE) || (account.getStatus() == Account.State.DISABLED)) { @@ -4259,6 +4285,12 @@ public class XmppConnectionService extends Service { void onRoleChangeFailed(String nick, int resid); } + public interface OnDestroyMuc { + void OnDestroyMucSuccessful(); + + void OnDestroyMucFailed(int resId); + } + public interface OnConversationUpdate { void onConversationUpdate(); } diff --git a/src/main/java/de/pixart/messenger/ui/ConferenceDetailsActivity.java b/src/main/java/de/pixart/messenger/ui/ConferenceDetailsActivity.java index 55a7ad85e..f17380843 100644 --- a/src/main/java/de/pixart/messenger/ui/ConferenceDetailsActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ConferenceDetailsActivity.java @@ -5,8 +5,10 @@ import android.app.AlertDialog; import android.app.PendingIntent; import android.content.Context; import android.content.DialogInterface; +import android.content.Intent; import android.content.IntentSender.SendIntentException; import android.os.Bundle; +import android.util.Log; import android.view.ContextMenu; import android.view.LayoutInflater; import android.view.Menu; @@ -52,6 +54,27 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers inviteToConversation(mConversation); } }; + private OnClickListener destroyListener = new OnClickListener() { + + @Override + public void onClick(View v) { + final AlertDialog.Builder DestroyMucDialog = new AlertDialog.Builder(ConferenceDetailsActivity.this); + DestroyMucDialog.setNegativeButton(getString(R.string.cancel), null); + DestroyMucDialog.setTitle(getString(R.string.action_destroy_muc)); + DestroyMucDialog.setMessage(getString(R.string.destroy_muc_text, mConversation.getName())); + DestroyMucDialog.setPositiveButton(getString(R.string.delete), (dialogInterface, i) -> { + Intent intent = new Intent(xmppConnectionService, ConversationActivity.class); + intent.setAction(ConversationActivity.ACTION_DESTROY_MUC); + intent.putExtra("MUC_UUID", mConversation.getUuid()); + Log.d(Config.LOGTAG, "Sending DESTROY intent for " + mConversation.getName()); + startActivity(intent); + deleteBookmark(); + finish(); + }); + DestroyMucDialog.create().show(); + } + }; + private TextView ConferenceName; private TextView mYourNick; private ImageView mYourPhoto; @@ -68,6 +91,7 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers private ImageButton mChangeConferenceSettingsButton; private ImageButton mNotifyStatusButton; private Button mInviteButton; + private Button mDestroyButton; private String uuid = null; private User mSelectedUser = null; @@ -264,6 +288,9 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers mInviteButton = findViewById(R.id.invite); mInviteButton.setVisibility(View.GONE); mInviteButton.setOnClickListener(inviteListener); + mDestroyButton = findViewById(R.id.destroy); + mDestroyButton.setVisibility(View.GONE); + mDestroyButton.setOnClickListener(destroyListener); mConferenceType = findViewById(R.id.muc_conference_type); if (getActionBar() != null) { getActionBar().setHomeButtonEnabled(true); @@ -604,8 +631,10 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers mConferenceInfoMam.setText(R.string.server_info_unavailable); } if (self.getAffiliation().ranks(MucOptions.Affiliation.OWNER)) { + mDestroyButton.setVisibility(View.VISIBLE); mChangeConferenceSettingsButton.setVisibility(View.VISIBLE); } else { + mDestroyButton.setVisibility(View.GONE); mChangeConferenceSettingsButton.setVisibility(View.GONE); } } else { diff --git a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java index 81611343a..005bc2b74 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java @@ -96,6 +96,7 @@ public class ConversationActivity extends XmppActivity implements OnAccountUpdate, OnConversationUpdate, OnRosterUpdate, OnUpdateBlocklist, XmppConnectionService.OnShowErrorToast, View.OnClickListener { public static final String ACTION_VIEW_CONVERSATION = "de.pixart.messenger.VIEW"; + public static final String ACTION_DESTROY_MUC = "de.pixart.messenger.DESTROY_MUC"; public static final String CONVERSATION = "conversationUuid"; public static final String EXTRA_DOWNLOAD_UUID = "de.pixart.messenger.download_uuid"; public static final String TEXT = "text"; @@ -1204,6 +1205,15 @@ public class ConversationActivity extends XmppActivity } else { setIntent(intent); } + } else if (intent != null && ACTION_DESTROY_MUC.equals(intent.getAction())) { + final Bundle extras = intent.getExtras(); + if (extras != null && extras.containsKey("MUC_UUID")) { + Log.d(Config.LOGTAG, "Get " + intent.getAction() + " intent for " + extras.getString("MUC_UUID")); + Conversation conversation = xmppConnectionService.findConversationByUuid(extras.getString("MUC_UUID")); + ConversationActivity.this.xmppConnectionService.clearConversationHistory(conversation); + xmppConnectionService.destroyMuc(conversation); + endConversation(conversation); + } } } @@ -1292,8 +1302,9 @@ public class ConversationActivity extends XmppActivity void onBackendConnected() { this.xmppConnectionService.getNotificationService().setIsInForeground(true); updateConversationList(); + final Intent intent = getIntent(); + final Bundle extras = intent.getExtras(); - Bundle extras = getIntent().getExtras(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (extras != null && extras.containsKey(PREF_FIRST_START)) { FirstStartTime = extras.getLong(PREF_FIRST_START); @@ -1321,13 +1332,13 @@ public class ConversationActivity extends XmppActivity editor.putLong(PREF_FIRST_START, FirstStartTime); editor.commit(); // restart - Intent intent = getBaseContext().getPackageManager().getLaunchIntentForPackage(getBaseContext().getPackageName()); - intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - startActivity(intent); + Intent restartintent = getBaseContext().getPackageManager().getLaunchIntentForPackage(getBaseContext().getPackageName()); + restartintent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + restartintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + startActivity(restartintent); System.exit(0); } - final Intent intent = getIntent(); + if (xmppConnectionService.getAccounts().size() == 0) { if (mRedirected.compareAndSet(false, true)) { if (Config.X509_VERIFICATION) { diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java index 509d4d17d..edd88d58a 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java @@ -1145,8 +1145,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa showSnackbar(R.string.conference_kicked, R.string.join, joinMuc); break; case UNKNOWN: - activity.xmppConnectionService.joinMuc(conversation); - //showSnackbar(R.string.conference_unknown_error, R.string.try_again, joinMuc); + showSnackbar(R.string.conference_unknown_error, R.string.leave, leaveMuc); break; case INVALID_NICK: showSnackbar(R.string.invalid_muc_nick, R.string.edit, clickToMuc); |