ConversationsActivity.java

  1/*
  2 * Copyright (c) 2018, Daniel Gultsch All rights reserved.
  3 *
  4 * Redistribution and use in source and binary forms, with or without modification,
  5 * are permitted provided that the following conditions are met:
  6 *
  7 * 1. Redistributions of source code must retain the above copyright notice, this
  8 * list of conditions and the following disclaimer.
  9 *
 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
 11 * this list of conditions and the following disclaimer in the documentation and/or
 12 * other materials provided with the distribution.
 13 *
 14 * 3. Neither the name of the copyright holder nor the names of its contributors
 15 * may be used to endorse or promote products derived from this software without
 16 * specific prior written permission.
 17 *
 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 21 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
 22 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 25 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 28 */
 29
 30package eu.siacs.conversations.ui;
 31
 32
 33import android.annotation.SuppressLint;
 34import android.app.Activity;
 35import android.app.Fragment;
 36import android.app.FragmentManager;
 37import android.app.FragmentTransaction;
 38import android.content.ActivityNotFoundException;
 39import android.content.Context;
 40import android.content.Intent;
 41import android.content.pm.PackageManager;
 42import android.databinding.DataBindingUtil;
 43import android.net.Uri;
 44import android.os.Bundle;
 45import android.provider.Settings;
 46import android.support.annotation.IdRes;
 47import android.support.annotation.NonNull;
 48import android.support.v7.app.ActionBar;
 49import android.support.v7.app.AlertDialog;
 50import android.support.v7.widget.Toolbar;
 51import android.util.Log;
 52import android.view.Menu;
 53import android.view.MenuItem;
 54import android.widget.Toast;
 55
 56import org.openintents.openpgp.util.OpenPgpApi;
 57
 58import java.util.concurrent.atomic.AtomicBoolean;
 59
 60import eu.siacs.conversations.Config;
 61import eu.siacs.conversations.R;
 62import eu.siacs.conversations.crypto.OmemoSetting;
 63import eu.siacs.conversations.databinding.ActivityConversationsBinding;
 64import eu.siacs.conversations.entities.Account;
 65import eu.siacs.conversations.entities.Conversation;
 66import eu.siacs.conversations.services.XmppConnectionService;
 67import eu.siacs.conversations.ui.interfaces.OnBackendConnected;
 68import eu.siacs.conversations.ui.interfaces.OnConversationArchived;
 69import eu.siacs.conversations.ui.interfaces.OnConversationRead;
 70import eu.siacs.conversations.ui.interfaces.OnConversationSelected;
 71import eu.siacs.conversations.ui.interfaces.OnConversationsListItemUpdated;
 72import eu.siacs.conversations.ui.service.EmojiService;
 73import eu.siacs.conversations.ui.util.ActivityResult;
 74import eu.siacs.conversations.ui.util.ConversationMenuConfigurator;
 75import eu.siacs.conversations.ui.util.MenuDoubleTabUtil;
 76import eu.siacs.conversations.ui.util.PendingItem;
 77import eu.siacs.conversations.utils.ExceptionHelper;
 78import eu.siacs.conversations.utils.XmppUri;
 79import eu.siacs.conversations.xmpp.OnUpdateBlocklist;
 80
 81import static eu.siacs.conversations.ui.ConversationFragment.REQUEST_DECRYPT_PGP;
 82
 83public class ConversationsActivity extends XmppActivity implements OnConversationSelected, OnConversationArchived, OnConversationsListItemUpdated, OnConversationRead, XmppConnectionService.OnAccountUpdate, XmppConnectionService.OnConversationUpdate, XmppConnectionService.OnRosterUpdate, OnUpdateBlocklist, XmppConnectionService.OnShowErrorToast {
 84
 85	public static final String ACTION_VIEW_CONVERSATION = "eu.siacs.conversations.action.VIEW";
 86	public static final String EXTRA_CONVERSATION = "conversationUuid";
 87	public static final String EXTRA_DOWNLOAD_UUID = "eu.siacs.conversations.download_uuid";
 88	public static final String EXTRA_TEXT = "text";
 89	public static final String EXTRA_AS_QUOTE = "as_quote";
 90	public static final String EXTRA_NICK = "nick";
 91	public static final String EXTRA_IS_PRIVATE_MESSAGE = "pm";
 92
 93	public static final int REQUEST_OPEN_MESSAGE = 0x9876;
 94	public static final int REQUEST_PLAY_PAUSE = 0x5432;
 95
 96
 97	//secondary fragment (when holding the conversation, must be initialized before refreshing the overview fragment
 98	private static final @IdRes
 99	int[] FRAGMENT_ID_NOTIFICATION_ORDER = {R.id.secondary_fragment, R.id.main_fragment};
100	private final PendingItem<Intent> pendingViewIntent = new PendingItem<>();
101	private final PendingItem<ActivityResult> postponedActivityResult = new PendingItem<>();
102	private ActivityConversationsBinding binding;
103	private boolean mActivityPaused = true;
104	private AtomicBoolean mRedirectInProcess = new AtomicBoolean(false);
105
106	private static boolean isViewIntent(Intent i) {
107		return i != null && ACTION_VIEW_CONVERSATION.equals(i.getAction()) && i.hasExtra(EXTRA_CONVERSATION);
108	}
109
110	private static Intent createLauncherIntent(Context context) {
111		final Intent intent = new Intent(context, ConversationsActivity.class);
112		intent.setAction(Intent.ACTION_MAIN);
113		intent.addCategory(Intent.CATEGORY_LAUNCHER);
114		return intent;
115	}
116
117	@Override
118	protected void refreshUiReal() {
119		for (@IdRes int id : FRAGMENT_ID_NOTIFICATION_ORDER) {
120			refreshFragment(id);
121		}
122	}
123
124	@Override
125	void onBackendConnected() {
126		if (performRedirectIfNecessary(true)) {
127			return;
128		}
129		xmppConnectionService.getNotificationService().setIsInForeground(true);
130		Intent intent = pendingViewIntent.pop();
131		if (intent != null) {
132			if (processViewIntent(intent)) {
133				if (binding.secondaryFragment != null) {
134					notifyFragmentOfBackendConnected(R.id.main_fragment);
135				}
136				invalidateActionBarTitle();
137				return;
138			}
139		}
140		for (@IdRes int id : FRAGMENT_ID_NOTIFICATION_ORDER) {
141			notifyFragmentOfBackendConnected(id);
142		}
143
144		ActivityResult activityResult = postponedActivityResult.pop();
145		if (activityResult != null) {
146			handleActivityResult(activityResult);
147		}
148
149		invalidateActionBarTitle();
150		if (binding.secondaryFragment != null && ConversationFragment.getConversation(this) == null) {
151			Conversation conversation = ConversationsOverviewFragment.getSuggestion(this);
152			if (conversation != null) {
153				openConversation(conversation, null);
154			}
155		}
156		showDialogsIfMainIsOverview();
157	}
158
159	private boolean performRedirectIfNecessary(boolean noAnimation) {
160		return performRedirectIfNecessary(null, noAnimation);
161	}
162
163	private boolean performRedirectIfNecessary(final Conversation ignore, final boolean noAnimation) {
164		if (xmppConnectionService == null) {
165			return false;
166		}
167		boolean isConversationsListEmpty = xmppConnectionService.isConversationsListEmpty(ignore);
168		if (isConversationsListEmpty && mRedirectInProcess.compareAndSet(false, true)) {
169			final Intent intent = getRedirectionIntent(noAnimation);
170			runOnUiThread(() -> {
171				startActivity(intent);
172				if (noAnimation) {
173					overridePendingTransition(0, 0);
174				}
175			});
176		}
177		return mRedirectInProcess.get();
178	}
179
180	private Intent getRedirectionIntent(boolean noAnimation) {
181		Account pendingAccount = xmppConnectionService.getPendingAccount();
182		Intent intent;
183		if (pendingAccount != null) {
184			intent = new Intent(this, EditAccountActivity.class);
185			intent.putExtra("jid", pendingAccount.getJid().asBareJid().toString());
186		} else {
187			if (xmppConnectionService.getAccounts().size() == 0) {
188				if (Config.X509_VERIFICATION) {
189					intent = new Intent(this, ManageAccountActivity.class);
190				} else if (Config.MAGIC_CREATE_DOMAIN != null) {
191					intent = new Intent(this, WelcomeActivity.class);
192					WelcomeActivity.addInviteUri(intent, getIntent());
193				} else {
194					intent = new Intent(this, EditAccountActivity.class);
195				}
196			} else {
197				intent = new Intent(this, StartConversationActivity.class);
198			}
199		}
200		intent.putExtra("init", true);
201		intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
202		if (noAnimation) {
203			intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
204		}
205		return intent;
206	}
207
208	private void showDialogsIfMainIsOverview() {
209		if (xmppConnectionService == null) {
210			return;
211		}
212		final Fragment fragment = getFragmentManager().findFragmentById(R.id.main_fragment);
213		if (fragment != null && fragment instanceof ConversationsOverviewFragment) {
214			if (ExceptionHelper.checkForCrash(this)) {
215				return;
216			}
217			openBatteryOptimizationDialogIfNeeded();
218		}
219	}
220
221	private String getBatteryOptimizationPreferenceKey() {
222		@SuppressLint("HardwareIds") String device = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID);
223		return "show_battery_optimization" + (device == null ? "" : device);
224	}
225
226	private void setNeverAskForBatteryOptimizationsAgain() {
227		getPreferences().edit().putBoolean(getBatteryOptimizationPreferenceKey(), false).apply();
228	}
229
230	private void openBatteryOptimizationDialogIfNeeded() {
231		if (hasAccountWithoutPush()
232				&& isOptimizingBattery()
233				&& getPreferences().getBoolean(getBatteryOptimizationPreferenceKey(), true)) {
234			AlertDialog.Builder builder = new AlertDialog.Builder(this);
235			builder.setTitle(R.string.battery_optimizations_enabled);
236			builder.setMessage(R.string.battery_optimizations_enabled_dialog);
237			builder.setPositiveButton(R.string.next, (dialog, which) -> {
238				Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
239				Uri uri = Uri.parse("package:" + getPackageName());
240				intent.setData(uri);
241				try {
242					startActivityForResult(intent, REQUEST_BATTERY_OP);
243				} catch (ActivityNotFoundException e) {
244					Toast.makeText(this, R.string.device_does_not_support_battery_op, Toast.LENGTH_SHORT).show();
245				}
246			});
247			builder.setOnDismissListener(dialog -> setNeverAskForBatteryOptimizationsAgain());
248			final AlertDialog dialog = builder.create();
249			dialog.setCanceledOnTouchOutside(false);
250			dialog.show();
251		}
252	}
253
254	private boolean hasAccountWithoutPush() {
255		for (Account account : xmppConnectionService.getAccounts()) {
256			if (account.getStatus() == Account.State.ONLINE && !xmppConnectionService.getPushManagementService().available(account)) {
257				return true;
258			}
259		}
260		return false;
261	}
262
263	private void notifyFragmentOfBackendConnected(@IdRes int id) {
264		final Fragment fragment = getFragmentManager().findFragmentById(id);
265		if (fragment != null && fragment instanceof OnBackendConnected) {
266			((OnBackendConnected) fragment).onBackendConnected();
267		}
268	}
269
270	private void refreshFragment(@IdRes int id) {
271		final Fragment fragment = getFragmentManager().findFragmentById(id);
272		if (fragment != null && fragment instanceof XmppFragment) {
273			((XmppFragment) fragment).refresh();
274		}
275	}
276
277	private boolean processViewIntent(Intent intent) {
278		String uuid = intent.getStringExtra(EXTRA_CONVERSATION);
279		Conversation conversation = uuid != null ? xmppConnectionService.findConversationByUuid(uuid) : null;
280		if (conversation == null) {
281			Log.d(Config.LOGTAG, "unable to view conversation with uuid:" + uuid);
282			return false;
283		}
284		openConversation(conversation, intent.getExtras());
285		return true;
286	}
287
288	@Override
289	public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
290		UriHandlerActivity.onRequestPermissionResult(this, requestCode, grantResults);
291		if (grantResults.length > 0) {
292			if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
293				switch (requestCode) {
294					case REQUEST_OPEN_MESSAGE:
295						refreshUiReal();
296						ConversationFragment.openPendingMessage(this);
297						break;
298					case REQUEST_PLAY_PAUSE:
299						ConversationFragment.startStopPending(this);
300						break;
301				}
302			}
303		}
304	}
305
306	@Override
307	public void onActivityResult(int requestCode, int resultCode, final Intent data) {
308		super.onActivityResult(requestCode, resultCode, data);
309		ActivityResult activityResult = ActivityResult.of(requestCode, resultCode, data);
310		if (xmppConnectionService != null) {
311			handleActivityResult(activityResult);
312		} else {
313			this.postponedActivityResult.push(activityResult);
314		}
315	}
316
317	private void handleActivityResult(ActivityResult activityResult) {
318		if (activityResult.resultCode == Activity.RESULT_OK) {
319			handlePositiveActivityResult(activityResult.requestCode, activityResult.data);
320		} else {
321			handleNegativeActivityResult(activityResult.requestCode);
322		}
323	}
324
325	private void handleNegativeActivityResult(int requestCode) {
326		Conversation conversation = ConversationFragment.getConversationReliable(this);
327		switch (requestCode) {
328			case REQUEST_DECRYPT_PGP:
329				if (conversation == null) {
330					break;
331				}
332				conversation.getAccount().getPgpDecryptionService().giveUpCurrentDecryption();
333				break;
334			case REQUEST_BATTERY_OP:
335				setNeverAskForBatteryOptimizationsAgain();
336				break;
337		}
338	}
339
340	private void handlePositiveActivityResult(int requestCode, final Intent data) {
341		Conversation conversation = ConversationFragment.getConversationReliable(this);
342		if (conversation == null) {
343			Log.d(Config.LOGTAG, "conversation not found");
344			return;
345		}
346		switch (requestCode) {
347			case REQUEST_DECRYPT_PGP:
348				conversation.getAccount().getPgpDecryptionService().continueDecryption(data);
349				break;
350			case REQUEST_CHOOSE_PGP_ID:
351				long id = data.getLongExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, 0);
352				if (id != 0) {
353					conversation.getAccount().setPgpSignId(id);
354					announcePgp(conversation.getAccount(), null, null, onOpenPGPKeyPublished);
355				} else {
356					choosePgpSignId(conversation.getAccount());
357				}
358				break;
359			case REQUEST_ANNOUNCE_PGP:
360				announcePgp(conversation.getAccount(), conversation, data, onOpenPGPKeyPublished);
361				break;
362		}
363	}
364
365	@Override
366	protected void onCreate(final Bundle savedInstanceState) {
367		super.onCreate(savedInstanceState);
368		ConversationMenuConfigurator.reloadFeatures(this);
369		OmemoSetting.load(this);
370		new EmojiService(this).init();
371		this.binding = DataBindingUtil.setContentView(this, R.layout.activity_conversations);
372		setSupportActionBar((Toolbar) binding.toolbar);
373		configureActionBar(getSupportActionBar());
374		this.getFragmentManager().addOnBackStackChangedListener(this::invalidateActionBarTitle);
375		this.getFragmentManager().addOnBackStackChangedListener(this::showDialogsIfMainIsOverview);
376		this.initializeFragments();
377		this.invalidateActionBarTitle();
378		final Intent intent;
379		if (savedInstanceState == null) {
380			intent = getIntent();
381		} else {
382			intent = savedInstanceState.getParcelable("intent");
383		}
384		if (isViewIntent(intent)) {
385			pendingViewIntent.push(intent);
386			setIntent(createLauncherIntent(this));
387		}
388	}
389
390	@Override
391	public boolean onCreateOptionsMenu(Menu menu) {
392		getMenuInflater().inflate(R.menu.activity_conversations, menu);
393		MenuItem qrCodeScanMenuItem = menu.findItem(R.id.action_scan_qr_code);
394		if (qrCodeScanMenuItem != null) {
395			if (isCameraFeatureAvailable()) {
396				Fragment fragment = getFragmentManager().findFragmentById(R.id.main_fragment);
397				boolean visible = getResources().getBoolean(R.bool.show_qr_code_scan)
398						&& fragment != null
399						&& fragment instanceof ConversationsOverviewFragment;
400				qrCodeScanMenuItem.setVisible(visible);
401			} else {
402				qrCodeScanMenuItem.setVisible(false);
403			}
404		}
405		return super.onCreateOptionsMenu(menu);
406	}
407
408	@Override
409	public void onConversationSelected(Conversation conversation) {
410		if (ConversationFragment.getConversation(this) == conversation) {
411			Log.d(Config.LOGTAG, "ignore onConversationSelected() because conversation is already open");
412			return;
413		}
414		openConversation(conversation, null);
415	}
416
417	private void openConversation(Conversation conversation, Bundle extras) {
418		ConversationFragment conversationFragment = (ConversationFragment) getFragmentManager().findFragmentById(R.id.secondary_fragment);
419		final boolean mainNeedsRefresh;
420		if (conversationFragment == null) {
421			mainNeedsRefresh = false;
422			Fragment mainFragment = getFragmentManager().findFragmentById(R.id.main_fragment);
423			if (mainFragment != null && mainFragment instanceof ConversationFragment) {
424				conversationFragment = (ConversationFragment) mainFragment;
425			} else {
426				conversationFragment = new ConversationFragment();
427				FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
428				fragmentTransaction.replace(R.id.main_fragment, conversationFragment);
429				fragmentTransaction.addToBackStack(null);
430				try {
431					fragmentTransaction.commit();
432				} catch (IllegalStateException e) {
433					Log.w(Config.LOGTAG,"sate loss while opening conversation",e);
434					//allowing state loss is probably fine since view intents et all are already stored and a click can probably be 'ignored'
435					return;
436				}
437			}
438		} else {
439			mainNeedsRefresh = true;
440		}
441		conversationFragment.reInit(conversation, extras == null ? new Bundle() : extras);
442		if (mainNeedsRefresh) {
443			refreshFragment(R.id.main_fragment);
444		} else {
445			invalidateActionBarTitle();
446		}
447	}
448
449	public boolean onXmppUriClicked(Uri uri) {
450		XmppUri xmppUri = new XmppUri(uri);
451		if (xmppUri.isJidValid() && !xmppUri.hasFingerprints()) {
452			final Conversation conversation = xmppConnectionService.findUniqueConversationByJid(xmppUri);
453			if (conversation != null) {
454				openConversation(conversation, null);
455				return true;
456			}
457		}
458		return false;
459	}
460
461	@Override
462	public boolean onOptionsItemSelected(MenuItem item) {
463		if (MenuDoubleTabUtil.shouldIgnoreTap()) {
464			return false;
465		}
466		switch (item.getItemId()) {
467			case android.R.id.home:
468				FragmentManager fm = getFragmentManager();
469				if (fm.getBackStackEntryCount() > 0) {
470					fm.popBackStack();
471					return true;
472				}
473				break;
474			case R.id.action_scan_qr_code:
475				UriHandlerActivity.scan(this);
476				return true;
477		}
478		return super.onOptionsItemSelected(item);
479	}
480
481	@Override
482	public void onSaveInstanceState(Bundle savedInstanceState) {
483		Intent pendingIntent = pendingViewIntent.peek();
484		savedInstanceState.putParcelable("intent", pendingIntent != null ? pendingIntent : getIntent());
485		super.onSaveInstanceState(savedInstanceState);
486	}
487
488	@Override
489	protected void onStart() {
490		final int theme = findTheme();
491		if (this.mTheme != theme) {
492			this.mSkipBackgroundBinding = true;
493			recreate();
494		} else {
495			this.mSkipBackgroundBinding = false;
496		}
497		mRedirectInProcess.set(false);
498		super.onStart();
499	}
500
501	@Override
502	protected void onNewIntent(final Intent intent) {
503		if (isViewIntent(intent)) {
504			if (xmppConnectionService != null) {
505				processViewIntent(intent);
506			} else {
507				pendingViewIntent.push(intent);
508			}
509		}
510		setIntent(createLauncherIntent(this));
511	}
512
513	@Override
514	public void onPause() {
515		this.mActivityPaused = true;
516		super.onPause();
517	}
518
519	@Override
520	public void onResume() {
521		super.onResume();
522		this.mActivityPaused = false;
523	}
524
525	private void initializeFragments() {
526		FragmentTransaction transaction = getFragmentManager().beginTransaction();
527		Fragment mainFragment = getFragmentManager().findFragmentById(R.id.main_fragment);
528		Fragment secondaryFragment = getFragmentManager().findFragmentById(R.id.secondary_fragment);
529		if (mainFragment != null) {
530			if (binding.secondaryFragment != null) {
531				if (mainFragment instanceof ConversationFragment) {
532					getFragmentManager().popBackStack();
533					transaction.remove(mainFragment);
534					transaction.commit();
535					getFragmentManager().executePendingTransactions();
536					transaction = getFragmentManager().beginTransaction();
537					transaction.replace(R.id.secondary_fragment, mainFragment);
538					transaction.replace(R.id.main_fragment, new ConversationsOverviewFragment());
539					transaction.commit();
540					return;
541				}
542			} else {
543				if (secondaryFragment != null && secondaryFragment instanceof ConversationFragment) {
544					transaction.remove(secondaryFragment);
545					transaction.commit();
546					getFragmentManager().executePendingTransactions();
547					transaction = getFragmentManager().beginTransaction();
548					transaction.replace(R.id.main_fragment, secondaryFragment);
549					transaction.addToBackStack(null);
550					transaction.commit();
551					return;
552				}
553			}
554		} else {
555			transaction.replace(R.id.main_fragment, new ConversationsOverviewFragment());
556		}
557		if (binding.secondaryFragment != null && secondaryFragment == null) {
558			transaction.replace(R.id.secondary_fragment, new ConversationFragment());
559		}
560		transaction.commit();
561	}
562
563	private void invalidateActionBarTitle() {
564		final ActionBar actionBar = getSupportActionBar();
565		if (actionBar != null) {
566			Fragment mainFragment = getFragmentManager().findFragmentById(R.id.main_fragment);
567			if (mainFragment != null && mainFragment instanceof ConversationFragment) {
568				final Conversation conversation = ((ConversationFragment) mainFragment).getConversation();
569				if (conversation != null) {
570					actionBar.setTitle(conversation.getName());
571					actionBar.setDisplayHomeAsUpEnabled(true);
572					return;
573				}
574			}
575			actionBar.setTitle(R.string.app_name);
576			actionBar.setDisplayHomeAsUpEnabled(false);
577		}
578	}
579
580	@Override
581	public void onConversationArchived(Conversation conversation) {
582		if (performRedirectIfNecessary(conversation, false)) {
583			return;
584		}
585		Fragment mainFragment = getFragmentManager().findFragmentById(R.id.main_fragment);
586		if (mainFragment != null && mainFragment instanceof ConversationFragment) {
587			try {
588				getFragmentManager().popBackStack();
589			} catch (IllegalStateException e) {
590				Log.w(Config.LOGTAG,"state loss while popping back state after archiving conversation",e);
591				//this usually means activity is no longer active; meaning on the next open we will run through this again
592			}
593			return;
594		}
595		Fragment secondaryFragment = getFragmentManager().findFragmentById(R.id.secondary_fragment);
596		if (secondaryFragment != null && secondaryFragment instanceof ConversationFragment) {
597			if (((ConversationFragment) secondaryFragment).getConversation() == conversation) {
598				Conversation suggestion = ConversationsOverviewFragment.getSuggestion(this, conversation);
599				if (suggestion != null) {
600					openConversation(suggestion, null);
601				}
602			}
603		}
604	}
605
606	@Override
607	public void onConversationsListItemUpdated() {
608		Fragment fragment = getFragmentManager().findFragmentById(R.id.main_fragment);
609		if (fragment != null && fragment instanceof ConversationsOverviewFragment) {
610			((ConversationsOverviewFragment) fragment).refresh();
611		}
612	}
613
614	@Override
615	public void switchToConversation(Conversation conversation) {
616		Log.d(Config.LOGTAG, "override");
617		openConversation(conversation, null);
618	}
619
620	@Override
621	public void onConversationRead(Conversation conversation, String upToUuid) {
622		if (!mActivityPaused && pendingViewIntent.peek() == null) {
623			xmppConnectionService.sendReadMarker(conversation, upToUuid);
624		} else {
625			Log.d(Config.LOGTAG, "ignoring read callback. mActivityPaused=" + Boolean.toString(mActivityPaused));
626		}
627	}
628
629	@Override
630	public void onAccountUpdate() {
631		this.refreshUi();
632	}
633
634	@Override
635	public void onConversationUpdate() {
636		if (performRedirectIfNecessary(false)) {
637			return;
638		}
639		this.refreshUi();
640	}
641
642	@Override
643	public void onRosterUpdate() {
644		this.refreshUi();
645	}
646
647	@Override
648	public void OnUpdateBlocklist(OnUpdateBlocklist.Status status) {
649		this.refreshUi();
650	}
651
652	@Override
653	public void onShowErrorToast(int resId) {
654		runOnUiThread(() -> Toast.makeText(this, resId, Toast.LENGTH_SHORT).show());
655	}
656}