diff options
Diffstat (limited to 'src/main')
7 files changed, 109 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); diff --git a/src/main/res/layout/activity_muc_details.xml b/src/main/res/layout/activity_muc_details.xml index fe4dd30f8..ac49a28c3 100644 --- a/src/main/res/layout/activity_muc_details.xml +++ b/src/main/res/layout/activity_muc_details.xml @@ -204,6 +204,15 @@ android:layout_marginTop="24dp" android:text="@string/invite_contact" /> + <Button + android:id="@+id/destroy" + style="?android:attr/buttonStyleSmall" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center_horizontal" + android:layout_marginTop="24dp" + android:text="@string/destroy_muc" /> + </LinearLayout> <LinearLayout diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 274ca46ad..a554da3c2 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -752,4 +752,8 @@ <string name="invalid_muc_nick">Invalid nickname</string> <string name="title_activity_share_via_account">Share via account</string> <string name="private_messages_are_disabled">Private messages are disabled</string> + <string name="destroy_muc">Delete conference</string> + <string name="conference_unknown_error">You are no longer in this group chat</string> + <string name="action_destroy_muc">Destroy group chat</string> + <string name="destroy_muc_text">Would you like to destroy the group chat %s? This will remove this group chat permanently.</string> </resources> |