From 0178569f14cb30e9fde4967fa51cee16a4b8d132 Mon Sep 17 00:00:00 2001 From: Balazs Toldi Date: Thu, 3 Aug 2023 07:21:41 +0200 Subject: [PATCH] Mark as read for replies --- .../activities/MainActivity.java | 12 ++++----- .../ViewPrivateMessagesActivity.java | 8 +++--- .../ViewSubredditDetailActivity.java | 12 ++++----- .../activities/ViewUserDetailActivity.java | 14 +++++----- .../adapters/MessageRecyclerViewAdapter.java | 12 ++++++--- .../toldi/infinityforlemmy/apis/LemmyAPI.java | 10 +++++++ .../infinityforlemmy/dto/ReadCommentDTO.java | 26 +++++++++++++++++++ .../infinityforlemmy/dto/ReadMessageDTO.java | 26 +++++++++++++++++++ .../fragments/ViewPostDetailFragment.java | 8 +++--- .../infinityforlemmy/message/ReadMessage.java | 13 +++------- 10 files changed, 102 insertions(+), 39 deletions(-) create mode 100644 app/src/main/java/eu/toldi/infinityforlemmy/dto/ReadCommentDTO.java create mode 100644 app/src/main/java/eu/toldi/infinityforlemmy/dto/ReadMessageDTO.java diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/activities/MainActivity.java b/app/src/main/java/eu/toldi/infinityforlemmy/activities/MainActivity.java index 8067c2eb..e2900a45 100644 --- a/app/src/main/java/eu/toldi/infinityforlemmy/activities/MainActivity.java +++ b/app/src/main/java/eu/toldi/infinityforlemmy/activities/MainActivity.java @@ -231,7 +231,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb private boolean mFetchUserInfoSuccess = false; private boolean mFetchSubscriptionsSuccess = false; private boolean mDrawerOnAccountSwitch = false; - private String mMessageFullname; + private int mMessageFullname; private String mNewAccountName; private boolean hideFab; @@ -348,11 +348,11 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb mFetchUserInfoSuccess = savedInstanceState.getBoolean(FETCH_USER_INFO_STATE); mFetchSubscriptionsSuccess = savedInstanceState.getBoolean(FETCH_SUBSCRIPTIONS_STATE); mDrawerOnAccountSwitch = savedInstanceState.getBoolean(DRAWER_ON_ACCOUNT_SWITCH_STATE); - mMessageFullname = savedInstanceState.getString(MESSAGE_FULLNAME_STATE); + mMessageFullname = savedInstanceState.getInt(MESSAGE_FULLNAME_STATE); mNewAccountName = savedInstanceState.getString(NEW_ACCOUNT_NAME_STATE); inboxCount = savedInstanceState.getInt(INBOX_COUNT_STATE); } else { - mMessageFullname = getIntent().getStringExtra(EXTRA_MESSSAGE_FULLNAME); + mMessageFullname = getIntent().getIntExtra(EXTRA_MESSSAGE_FULLNAME, 0); mNewAccountName = getIntent().getStringExtra(EXTRA_NEW_ACCOUNT_NAME); } @@ -1029,11 +1029,11 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb loadUserData(); if (mAccessToken != null) { - if (mMessageFullname != null) { + if (mMessageFullname != 0) { ReadMessage.readMessage(mOauthRetrofit, mAccessToken, mMessageFullname, new ReadMessage.ReadMessageListener() { @Override public void readSuccess() { - mMessageFullname = null; + mMessageFullname = 0; } @Override @@ -1190,7 +1190,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb outState.putBoolean(FETCH_USER_INFO_STATE, mFetchUserInfoSuccess); outState.putBoolean(FETCH_SUBSCRIPTIONS_STATE, mFetchSubscriptionsSuccess); outState.putBoolean(DRAWER_ON_ACCOUNT_SWITCH_STATE, mDrawerOnAccountSwitch); - outState.putString(MESSAGE_FULLNAME_STATE, mMessageFullname); + outState.putInt(MESSAGE_FULLNAME_STATE, mMessageFullname); outState.putString(NEW_ACCOUNT_NAME_STATE, mNewAccountName); outState.putInt(INBOX_COUNT_STATE, inboxCount); } diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/activities/ViewPrivateMessagesActivity.java b/app/src/main/java/eu/toldi/infinityforlemmy/activities/ViewPrivateMessagesActivity.java index 1598346e..3ca525ad 100644 --- a/app/src/main/java/eu/toldi/infinityforlemmy/activities/ViewPrivateMessagesActivity.java +++ b/app/src/main/java/eu/toldi/infinityforlemmy/activities/ViewPrivateMessagesActivity.java @@ -229,13 +229,15 @@ public class ViewPrivateMessagesActivity extends BaseActivity implements Activit } if (fullnames.length() > 0) { fullnames.deleteCharAt(fullnames.length() - 1); - ReadMessage.readMessage(mOauthRetrofit, mAccessToken, fullnames.toString(), + ReadMessage.readMessage(mOauthRetrofit, mAccessToken, 0, new ReadMessage.ReadMessageListener() { @Override - public void readSuccess() {} + public void readSuccess() { + } @Override - public void readFailed() {} + public void readFailed() { + } }); } } diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/activities/ViewSubredditDetailActivity.java b/app/src/main/java/eu/toldi/infinityforlemmy/activities/ViewSubredditDetailActivity.java index 0a9e2372..745ef679 100644 --- a/app/src/main/java/eu/toldi/infinityforlemmy/activities/ViewSubredditDetailActivity.java +++ b/app/src/main/java/eu/toldi/infinityforlemmy/activities/ViewSubredditDetailActivity.java @@ -221,7 +221,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp private boolean hideFab; private boolean showBottomAppBar; private boolean lockBottomAppBar; - private String mMessageFullname; + private int mMessageFullname; private String mNewAccountName; private RequestManager glide; private int expandedTabTextColor; @@ -352,12 +352,12 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp mAccountQualifiedName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_QUALIFIED_NAME, null); if (savedInstanceState == null) { - mMessageFullname = getIntent().getStringExtra(EXTRA_MESSAGE_FULLNAME); + mMessageFullname = getIntent().getIntExtra(EXTRA_MESSAGE_FULLNAME, 0); mNewAccountName = getIntent().getStringExtra(EXTRA_NEW_ACCOUNT_NAME); } else { mFetchSubredditInfoSuccess = savedInstanceState.getBoolean(FETCH_SUBREDDIT_INFO_STATE); mNCurrentOnlineSubscribers = savedInstanceState.getInt(CURRENT_ONLINE_SUBSCRIBERS_STATE); - mMessageFullname = savedInstanceState.getString(MESSAGE_FULLNAME_STATE); + mMessageFullname = savedInstanceState.getInt(MESSAGE_FULLNAME_STATE); mNewAccountName = savedInstanceState.getString(NEW_ACCOUNT_NAME_STATE); if (mFetchSubredditInfoSuccess) { @@ -872,11 +872,11 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp } private void bindView() { - if (mMessageFullname != null) { + if (mMessageFullname != 0) { ReadMessage.readMessage(mRetrofit.getRetrofit(), mAccessToken, mMessageFullname, new ReadMessage.ReadMessageListener() { @Override public void readSuccess() { - mMessageFullname = null; + mMessageFullname = 0; } @Override @@ -1234,7 +1234,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp super.onSaveInstanceState(outState); outState.putBoolean(FETCH_SUBREDDIT_INFO_STATE, mFetchSubredditInfoSuccess); outState.putInt(CURRENT_ONLINE_SUBSCRIBERS_STATE, mNCurrentOnlineSubscribers); - outState.putString(MESSAGE_FULLNAME_STATE, mMessageFullname); + outState.putInt(MESSAGE_FULLNAME_STATE, mMessageFullname); outState.putString(NEW_ACCOUNT_NAME_STATE, mNewAccountName); } diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/activities/ViewUserDetailActivity.java b/app/src/main/java/eu/toldi/infinityforlemmy/activities/ViewUserDetailActivity.java index 7b7c0c77..b90713f4 100644 --- a/app/src/main/java/eu/toldi/infinityforlemmy/activities/ViewUserDetailActivity.java +++ b/app/src/main/java/eu/toldi/infinityforlemmy/activities/ViewUserDetailActivity.java @@ -233,7 +233,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele private boolean hideFab; private boolean showBottomAppBar; private boolean lockBottomAppBar; - private String mMessageFullname; + private int mMessageId; private String mNewAccountName; private UserData mUserData; @@ -282,11 +282,11 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele if (savedInstanceState == null) { - mMessageFullname = getIntent().getStringExtra(EXTRA_MESSAGE_FULLNAME); + mMessageId = getIntent().getIntExtra(EXTRA_MESSAGE_FULLNAME, 0); mNewAccountName = getIntent().getStringExtra(EXTRA_NEW_ACCOUNT_NAME); } else { mFetchUserInfoSuccess = savedInstanceState.getBoolean(FETCH_USER_INFO_STATE); - mMessageFullname = savedInstanceState.getString(MESSAGE_FULLNAME_STATE); + mMessageId = savedInstanceState.getInt(MESSAGE_FULLNAME_STATE); mNewAccountName = savedInstanceState.getString(NEW_ACCOUNT_NAME_STATE); } @@ -706,11 +706,11 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele fixViewPager2Sensitivity(viewPager2); - if (mMessageFullname != null) { - ReadMessage.readMessage(mOauthRetrofit, mAccessToken, mMessageFullname, new ReadMessage.ReadMessageListener() { + if (mMessageId != 0) { + ReadMessage.readMessage(mOauthRetrofit, mAccessToken, mMessageId, new ReadMessage.ReadMessageListener() { @Override public void readSuccess() { - mMessageFullname = null; + mMessageId = 0; } @Override @@ -1268,7 +1268,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele protected void onSaveInstanceState(@NonNull Bundle outState) { super.onSaveInstanceState(outState); outState.putBoolean(FETCH_USER_INFO_STATE, mFetchUserInfoSuccess); - outState.putString(MESSAGE_FULLNAME_STATE, mMessageFullname); + outState.putInt(MESSAGE_FULLNAME_STATE, mMessageId); outState.putString(NEW_ACCOUNT_NAME_STATE, mNewAccountName); } diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/adapters/MessageRecyclerViewAdapter.java b/app/src/main/java/eu/toldi/infinityforlemmy/adapters/MessageRecyclerViewAdapter.java index 6fd6885e..3210ab7b 100644 --- a/app/src/main/java/eu/toldi/infinityforlemmy/adapters/MessageRecyclerViewAdapter.java +++ b/app/src/main/java/eu/toldi/infinityforlemmy/adapters/MessageRecyclerViewAdapter.java @@ -17,6 +17,8 @@ import androidx.paging.PagedListAdapter; import androidx.recyclerview.widget.DiffUtil; import androidx.recyclerview.widget.RecyclerView; +import org.greenrobot.eventbus.EventBus; + import butterknife.BindView; import butterknife.ButterKnife; import eu.toldi.infinityforlemmy.NetworkState; @@ -27,12 +29,14 @@ import eu.toldi.infinityforlemmy.activities.ViewPostDetailActivity; import eu.toldi.infinityforlemmy.activities.ViewPrivateMessagesActivity; import eu.toldi.infinityforlemmy.activities.ViewUserDetailActivity; import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper; +import eu.toldi.infinityforlemmy.events.ChangeInboxCountEvent; import eu.toldi.infinityforlemmy.markdown.RedditHeadingPlugin; import eu.toldi.infinityforlemmy.markdown.SpoilerAwareMovementMethod; import eu.toldi.infinityforlemmy.markdown.SpoilerParserPlugin; import eu.toldi.infinityforlemmy.markdown.SuperscriptPlugin; import eu.toldi.infinityforlemmy.message.CommentInteraction; import eu.toldi.infinityforlemmy.message.FetchMessage; +import eu.toldi.infinityforlemmy.message.ReadMessage; import io.noties.markwon.AbstractMarkwonPlugin; import io.noties.markwon.Markwon; import io.noties.markwon.MarkwonConfiguration; @@ -61,7 +65,7 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter userUnreadCount(@NonNull @Query("auth") String access_token); + @Headers("Content-Type: application/json") + @POST("api/v3/user/mention/mark_as_read") + Call userMentionMarkAsRead(@Body ReadMessageDTO params); + + @Headers("Content-Type: application/json") + @POST("api/v3/comment/mark_as_read") + Call commentMarkAsRead(@Body ReadCommentDTO params); + @GET("api/v3/community") Call communityInfo(@Query("name") String name, @Query("auth") String access_token); diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/dto/ReadCommentDTO.java b/app/src/main/java/eu/toldi/infinityforlemmy/dto/ReadCommentDTO.java new file mode 100644 index 00000000..b86837e2 --- /dev/null +++ b/app/src/main/java/eu/toldi/infinityforlemmy/dto/ReadCommentDTO.java @@ -0,0 +1,26 @@ +package eu.toldi.infinityforlemmy.dto; + +public class ReadCommentDTO { + + private int comment_reply_id; + private boolean read; + private String auth; + + public ReadCommentDTO(int comment_reply_id, boolean read, String auth) { + this.comment_reply_id = comment_reply_id; + this.read = read; + this.auth = auth; + } + + public int getComment_reply_id() { + return comment_reply_id; + } + + public boolean isRead() { + return read; + } + + public String getAuth() { + return auth; + } +} diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/dto/ReadMessageDTO.java b/app/src/main/java/eu/toldi/infinityforlemmy/dto/ReadMessageDTO.java new file mode 100644 index 00000000..b1bab216 --- /dev/null +++ b/app/src/main/java/eu/toldi/infinityforlemmy/dto/ReadMessageDTO.java @@ -0,0 +1,26 @@ +package eu.toldi.infinityforlemmy.dto; + +public class ReadMessageDTO { + + private int person_mention_id; + private boolean read; + private String auth; + + public ReadMessageDTO(int person_mention_id, boolean read, String auth) { + this.person_mention_id = person_mention_id; + this.read = read; + this.auth = auth; + } + + public int getPerson_mention_id() { + return person_mention_id; + } + + public boolean isRead() { + return read; + } + + public String getAuth() { + return auth; + } +} diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/fragments/ViewPostDetailFragment.java b/app/src/main/java/eu/toldi/infinityforlemmy/fragments/ViewPostDetailFragment.java index f8b22bbf..07ed0ea1 100644 --- a/app/src/main/java/eu/toldi/infinityforlemmy/fragments/ViewPostDetailFragment.java +++ b/app/src/main/java/eu/toldi/infinityforlemmy/fragments/ViewPostDetailFragment.java @@ -213,7 +213,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic @State boolean isFetchingComments = false; @State - String mMessageFullname; + int mMessageFullname; @State SortType.Type sortType; @State @@ -553,7 +553,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic if (mSingleCommentId != 0) { isSingleCommentThreadMode = true; } - mMessageFullname = getArguments().getString(EXTRA_MESSAGE_FULLNAME); + mMessageFullname = getArguments().getInt(EXTRA_MESSAGE_FULLNAME); if (!mRespectSubredditRecommendedSortType || isSingleCommentThreadMode) { sortType = loadSortType(); @@ -575,11 +575,11 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic } private void bindView() { - if (mAccessToken != null && mMessageFullname != null) { + if (mAccessToken != null && mMessageFullname != 0) { ReadMessage.readMessage(mRetrofit.getRetrofit(), mAccessToken, mMessageFullname, new ReadMessage.ReadMessageListener() { @Override public void readSuccess() { - mMessageFullname = null; + mMessageFullname = 0; } @Override diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/message/ReadMessage.java b/app/src/main/java/eu/toldi/infinityforlemmy/message/ReadMessage.java index 13832a95..9cb60734 100644 --- a/app/src/main/java/eu/toldi/infinityforlemmy/message/ReadMessage.java +++ b/app/src/main/java/eu/toldi/infinityforlemmy/message/ReadMessage.java @@ -2,22 +2,17 @@ package eu.toldi.infinityforlemmy.message; import androidx.annotation.NonNull; -import java.util.HashMap; -import java.util.Map; - -import eu.toldi.infinityforlemmy.apis.RedditAPI; -import eu.toldi.infinityforlemmy.utils.APIUtils; +import eu.toldi.infinityforlemmy.apis.LemmyAPI; +import eu.toldi.infinityforlemmy.dto.ReadCommentDTO; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; import retrofit2.Retrofit; public class ReadMessage { - public static void readMessage(Retrofit oauthRetrofit, String accessToken, String commaSeparatedFullnames, + public static void readMessage(Retrofit oauthRetrofit, String accessToken, int messageId, ReadMessageListener readMessageListener) { - Map params = new HashMap<>(); - params.put(APIUtils.ID_KEY, commaSeparatedFullnames); - oauthRetrofit.create(RedditAPI.class).readMessage(APIUtils.getOAuthHeader(accessToken), params) + oauthRetrofit.create(LemmyAPI.class).commentMarkAsRead(new ReadCommentDTO(messageId, true, accessToken)) .enqueue(new Callback() { @Override public void onResponse(@NonNull Call call, @NonNull Response response) {