Show warning bar if any account is not set to MAM always

This commit is contained in:
Stephen Paul Weber 2024-11-27 23:28:05 +01:00 committed by Arne
parent d55df65131
commit 7b2d5b4210
5 changed files with 77 additions and 4 deletions

View file

@ -46,6 +46,7 @@ import eu.siacs.conversations.services.AvatarService;
import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.utils.UIHelper;
import eu.siacs.conversations.utils.XmppUri;
import eu.siacs.conversations.xml.Element;
import eu.siacs.conversations.xmpp.Jid;
import eu.siacs.conversations.xmpp.XmppConnection;
import eu.siacs.conversations.xmpp.jingle.RtpCapability;
@ -123,6 +124,7 @@ public class Account extends AbstractEntity implements AvatarService.Avatarable
private final HashMultimap<String, Contact> gateways = HashMultimap.create();
private String otrFingerprint;
private OtrService mOtrService = null;
private Element mamPrefs = null;
public Account(final Jid jid, final String password) {
this(
@ -222,6 +224,14 @@ public class Account extends AbstractEntity implements AvatarService.Avatarable
cursor.getString(cursor.getColumnIndexOrThrow(FAST_TOKEN)));
}
public void setMamPrefs(Element prefs) {
mamPrefs = prefs;
}
public Element mamPrefs() {
return mamPrefs;
}
public boolean httpUploadAvailable(long size) {
return xmppConnection != null && xmppConnection.getFeatures().httpUpload(size);
}

View file

@ -451,6 +451,7 @@ public class XmppConnectionService extends Service {
for (Conversation conversation : pendingJoins) {
joinMuc(conversation);
}
fetchMamPreferences(account, null);
scheduleWakeUpCall(Config.PING_MAX_INTERVAL, account.getUuid().hashCode());
} else if (account.getStatus() == Account.State.OFFLINE || account.getStatus() == Account.State.DISABLED || account.getStatus() == Account.State.LOGGED_OUT) {
resetSendingToWaiting(account);
@ -5985,9 +5986,10 @@ public class XmppConnectionService extends Service {
sendIqPacket(account, request, (packet) -> {
final Element prefs = packet.findChild("prefs", version.namespace);
if (packet.getType() == Iq.Type.RESULT && prefs != null) {
callback.onPreferencesFetched(prefs);
account.setMamPrefs(prefs);
if (callback != null) callback.onPreferencesFetched(prefs);
} else {
callback.onPreferencesFetchFailed();
if (callback != null) callback.onPreferencesFetchFailed();
}
});
}
@ -6095,6 +6097,7 @@ public class XmppConnectionService extends Service {
public void pushMamPreferences(Account account, Element prefs) {
final Iq set = new Iq(Iq.Type.SET);
set.addChild(prefs);
account.setMamPrefs(prefs);
sendIqPacket(account, set, null);
}

View file

@ -540,6 +540,22 @@ public class ConversationsOverviewFragment extends XmppFragment {
}
}
setupSwipe();
binding.snackbar.setVisibility(View.GONE);
if (activity.xmppConnectionService == null) return;
for (final var account : activity.xmppConnectionService.getAccounts()) {
if (account.mamPrefs() != null && !"always".equals(account.mamPrefs().getAttribute("default"))) {
binding.snackbar.setVisibility(View.VISIBLE);
binding.snackbarMessage.setText("Your account " + account.getJid().asBareJid().toEscapedString() + " does not have archiving fully enabled. This may result in missed messages if you use multiple devices or apps.");
binding.snackbarAction.setOnClickListener((v) -> {
final var prefs = account.mamPrefs();
prefs.setAttribute("default", "always");
activity.xmppConnectionService.pushMamPreferences(account, prefs);
refresh();
});
break;
}
}
}
private void setScrollPosition(ScrollState scrollPosition) {

View file

@ -5,6 +5,49 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/snackbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/context_preview"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="4dp"
android:background="@drawable/snackbar"
android:minHeight="48dp"
android:visibility="gone">
<TextView
android:id="@+id/snackbar_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginStart="24dp"
android:layout_toStartOf="@+id/snackbar_action"
android:textColor="?colorOnSurfaceInverse"
android:text="Warning" />
<TextView
android:id="@+id/snackbar_action"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:paddingLeft="24dp"
android:paddingTop="16dp"
android:paddingRight="24dp"
android:paddingBottom="16dp"
android:textAllCaps="true"
android:textColor="?colorOnSurfaceInverse"
android:textStyle="bold"
android:text="@string/action_fix" />
</RelativeLayout>
<de.monocles.chat.ContextMenuRecyclerView
android:id="@+id/list"
@ -12,6 +55,8 @@
android:layout_height="match_parent"
android:scrollbars="vertical" />
</LinearLayout>
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"

View file

@ -1345,7 +1345,6 @@
<string name="pref_create_backup_warning">Full backups are meant for restore after a device loss, or for migrating to a new device. You cannot restore a backup to another app while still being connected with this one!</string>
<string name="pref_ring_from_strangers">Ring calls from strangers</string>
<string name="pref_ring_from_strangers_summary">A stranger is someone not in your contacts to whom you have never sent a message</string>
<string name="enter_a_new_password_txt">Enter a New Password</string>
<string name="confirm_password_txt">Confirm Password</string>
<string name="password_changed_txt">Password Changed</string>
@ -1362,5 +1361,5 @@
<string name="pref_app_lock_enable_summary">Enable the app lock. Be aware you can\'t open the app anymore when you forgot the PIN.</string>
<string name="app_lock_forgot_password">Reinstall app and load chat backup</string>
<string name="new_message">New message</string>
<string name="action_fix">Fix</string>
</resources>