Skip to content

Commit

Permalink
Only auto-mark notifications as read on click if we can handle the URL
Browse files Browse the repository at this point in the history
Fixes #1208
  • Loading branch information
maniac103 committed Jul 14, 2022
1 parent 5e68216 commit 74e0112
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions app/src/main/java/com/gh4a/fragment/NotificationListFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.gh4a.activities.RepositoryActivity;
import com.gh4a.adapter.NotificationAdapter;
import com.gh4a.adapter.RootAdapter;
import com.gh4a.resolver.LinkParser;
import com.gh4a.worker.NotificationsWorker;
import com.gh4a.model.NotificationHolder;
import com.gh4a.resolver.BrowseFilter;
Expand Down Expand Up @@ -133,14 +134,24 @@ public void onItemClick(NotificationHolder item) {
if (item.notification == null) {
intent = RepositoryActivity.makeIntent(getActivity(), item.repository);
} else {
markAsRead(null, item.notification);

NotificationSubject subject = item.notification.subject();
String url = subject.url();
if (url != null) {
Uri uri = ApiHelpers.normalizeUri(Uri.parse(url));
intent = BrowseFilter.makeRedirectionIntent(getActivity(), uri,
new IntentUtils.InitialCommentMarker(item.notification.lastReadAt()));
IntentUtils.InitialCommentMarker initialComment =
new IntentUtils.InitialCommentMarker(item.notification.lastReadAt());
LinkParser.ParseResult result = LinkParser.parseUri(getActivity(), uri, initialComment);
if (result != null && result.intent != null) {
intent = result.intent;
} else {
// We either can't handle the URL ourselves or need to resolve it
// asynchronously. Pass it to the BrowseFilter for resolving or redirection
intent = BrowseFilter.makeRedirectionIntent(getActivity(), uri, initialComment);
// Only auto-mark the notification as read if we can handle the URL ourselves
if (result != null) {
markAsRead(null, item.notification);
}
}
} else {
intent = null;
}
Expand Down

0 comments on commit 74e0112

Please sign in to comment.