Fix async actions with cached notifications

This commit is contained in:
Thomas 2025-03-14 10:50:46 +01:00
parent ef6319b735
commit 9001676971
11 changed files with 31 additions and 12 deletions

View file

@ -22,7 +22,6 @@ import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_ID;
import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_INSTANCE;
import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_SOFTWARE;
import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_TOKEN;
import static app.fedilab.android.mastodon.helper.Helper.TAG;
import static app.fedilab.android.mastodon.helper.Helper.displayReleaseNotesIfNeeded;
import static app.fedilab.android.mastodon.helper.ThemeHelper.fetchAccentColor;
import static app.fedilab.android.mastodon.ui.drawer.StatusAdapter.sendAction;

View file

@ -17,7 +17,6 @@ package app.fedilab.android.mastodon.activities;
import static app.fedilab.android.BaseMainActivity.currentInstance;
import static app.fedilab.android.BaseMainActivity.emojis;
import static app.fedilab.android.mastodon.helper.Helper.TAG;
import android.Manifest;
import android.annotation.SuppressLint;
@ -35,7 +34,6 @@ import android.os.Looper;
import android.text.Editable;
import android.text.InputFilter;
import android.text.TextWatcher;
import android.util.Log;
import android.util.TypedValue;
import android.view.Menu;
import android.view.MenuItem;

View file

@ -112,6 +112,7 @@ public class Status implements Serializable, Cloneable {
@SerializedName("reactions")
public List<Reaction> reactions;
public String attachedNotification = null;
public transient boolean isFetchMore = false;
public transient boolean isFetching = false;

View file

@ -14,6 +14,8 @@ package app.fedilab.android.mastodon.client.entities.app;
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
* see <http://www.gnu.org/licenses>. */
import static app.fedilab.android.mastodon.helper.Helper.TAG;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
@ -289,7 +291,6 @@ public class StatusCache {
if (statusCache.type != null) {
query += " AND " + Sqlite.COL_TYPE + " = '" + statusCache.type.getValue() + "'";
}
Cursor mCount = db.rawQuery(query, null);
mCount.moveToFirst();
int count = mCount.getInt(0);
@ -352,7 +353,11 @@ public class StatusCache {
values.put(Sqlite.COL_STATUS, mastodonStatusToStringStorage(statusCache.status));
}
if (statusCache.notification != null) {
values.put(Sqlite.COL_STATUS, mastodonNotificationToStringStorage(statusCache.notification));
Notification currentNotification = getCachedNotification(statusCache);
if(currentNotification != null && currentNotification.status != null) {
currentNotification.status = statusCache.notification.status;
values.put(Sqlite.COL_STATUS, mastodonNotificationToStringStorage(currentNotification));
}
}
if (statusCache.conversation != null) {
values.put(Sqlite.COL_STATUS, mastodonConversationToStringStorage(statusCache.conversation));
@ -594,6 +599,15 @@ public class StatusCache {
}
}
public Notification getCachedNotification(StatusCache statusCache) throws DBException {
if (db == null) {
throw new DBException("db is null. Wrong initialization.");
}
Cursor c = db.query(Sqlite.TABLE_STATUS_CACHE, null, Sqlite.COL_STATUS_ID + " = ? AND " + Sqlite.COL_USER_ID + " = ? AND " + Sqlite.COL_INSTANCE + " =?",
new String[]{statusCache.status_id, statusCache.user_id, statusCache.instance}, null, null, null, "1");
c.moveToFirst();
return convertCursorToNotification(c);
}
/**
* Get paginated conversations from db

View file

@ -15,7 +15,6 @@ package app.fedilab.android.mastodon.helper;
* see <http://www.gnu.org/licenses>. */
import static app.fedilab.android.mastodon.helper.Helper.TAG;
import android.content.Context;
import android.content.SharedPreferences;

View file

@ -379,6 +379,7 @@ public class NotificationAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
SearchVM searchVM = new ViewModelProvider((ViewModelStoreOwner) context).get(SearchVM.class);
if (notification.status != null) {
notification.status.cached = notification.cached;
notification.status.attachedNotification = notification.id;
}
statusManagement(context, statusesVM, searchVM, holderStatus, mRecyclerView, this, null, notification.status, Timeline.TimeLineEnum.NOTIFICATION, false, true, false, null);
holderStatus.bindingNotification.status.dateShort.setText(Helper.dateDiff(context, notification.created_at));

View file

@ -34,6 +34,7 @@ import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_ID;
import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_INSTANCE;
import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_SOFTWARE;
import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_TOKEN;
import static app.fedilab.android.mastodon.helper.Helper.TAG;
import static app.fedilab.android.mastodon.helper.Helper.getCurrentAccount;
import android.annotation.SuppressLint;
@ -58,6 +59,7 @@ import android.os.Looper;
import android.text.Html;
import android.text.SpannableString;
import android.text.TextUtils;
import android.util.Log;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.MotionEvent;
@ -151,6 +153,7 @@ import app.fedilab.android.mastodon.activities.TimelineActivity;
import app.fedilab.android.mastodon.activities.admin.AdminAccountActivity;
import app.fedilab.android.mastodon.client.entities.api.Attachment;
import app.fedilab.android.mastodon.client.entities.api.Field;
import app.fedilab.android.mastodon.client.entities.api.Notification;
import app.fedilab.android.mastodon.client.entities.api.Poll;
import app.fedilab.android.mastodon.client.entities.api.Reaction;
import app.fedilab.android.mastodon.client.entities.api.Status;
@ -410,8 +413,16 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
StatusCache statusCache = new StatusCache();
statusCache.instance = BaseMainActivity.currentInstance;
statusCache.user_id = BaseMainActivity.currentUserID;
statusCache.status = statusToDeal;
statusCache.status_id = statusToDeal.id;
if(statusToDeal.attachedNotification != null) {
statusCache.notification = new Notification();
statusCache.notification.status = statusToDeal;
statusCache.status_id = statusToDeal.attachedNotification;
statusCache.type = Timeline.TimeLineEnum.NOTIFICATION;
} else {
statusCache.status_id = statusToDeal.id;
statusCache.status = statusToDeal;
}
try {
new StatusCache(context).updateIfExists(statusCache);
} catch (DBException e) {

View file

@ -17,7 +17,6 @@ package app.fedilab.android.mastodon.ui.drawer;
import static androidx.core.text.HtmlCompat.FROM_HTML_MODE_LEGACY;
import static app.fedilab.android.mastodon.helper.Helper.TAG;
import android.content.Context;
import android.content.Intent;

View file

@ -17,7 +17,6 @@ package app.fedilab.android.mastodon.ui.fragment.timeline;
import static app.fedilab.android.BaseMainActivity.currentInstance;
import static app.fedilab.android.BaseMainActivity.networkAvailable;
import static app.fedilab.android.mastodon.helper.Helper.TAG;
import android.content.BroadcastReceiver;
import android.content.Context;

View file

@ -14,7 +14,6 @@ package app.fedilab.android.mastodon.viewmodel.mastodon;
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
* see <http://www.gnu.org/licenses>. */
import static app.fedilab.android.mastodon.helper.Helper.TAG;
import android.app.Application;
import android.os.Handler;

View file

@ -15,7 +15,6 @@ package app.fedilab.android.peertube.activities;
* see <http://www.gnu.org/licenses>. */
import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_INSTANCE_PEERTUBE_BROWSING;
import static app.fedilab.android.mastodon.helper.Helper.TAG;
import static app.fedilab.android.mastodon.helper.Helper.addFragment;
import static app.fedilab.android.peertube.helper.Helper.recreatePeertubeActivity;