-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat: Implement 'Mark as Read' action for push notifications … #6867
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
DSingh0304
wants to merge
5
commits into
RocketChat:develop
Choose a base branch
from
DSingh0304:feature/mark-as-read
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b2fd8db
feat: Implement 'Mark as Read' action for push notifications and upda…
DSingh0304 6ff4ed4
Merge branch 'develop' into feature/mark-as-read
DSingh0304 e487fe4
feat: Introduce development commands, local Docker setup, Firebase cr…
DSingh0304 8c3bc38
feat: Add local development setup files, update Firebase configuratio…
DSingh0304 66707b7
Merge branch 'develop' into feature/mark-as-read
DSingh0304 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
236 changes: 147 additions & 89 deletions
236
android/app/src/main/java/chat/rocket/reactnative/notification/CustomPushNotification.java
Large diffs are not rendered by default.
Oops, something went wrong.
86 changes: 86 additions & 0 deletions
86
android/app/src/main/java/chat/rocket/reactnative/notification/MarkAsReadBroadcast.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| package chat.rocket.reactnative.notification; | ||
|
|
||
| import android.app.NotificationManager; | ||
| import android.content.BroadcastReceiver; | ||
| import android.content.Context; | ||
| import android.content.Intent; | ||
| import android.os.Bundle; | ||
| import android.util.Log; | ||
|
|
||
| import com.google.gson.Gson; | ||
| import com.wix.reactnativenotifications.core.NotificationIntentAdapter; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| import okhttp3.Call; | ||
| import okhttp3.MediaType; | ||
| import okhttp3.OkHttpClient; | ||
| import okhttp3.Request; | ||
| import okhttp3.RequestBody; | ||
| import okhttp3.Response; | ||
|
|
||
| public class MarkAsReadBroadcast extends BroadcastReceiver { | ||
| private static final String TAG = "RocketChat.MarkAsRead"; | ||
| public static final String KEY_MARK_AS_READ = "KEY_MARK_AS_READ"; | ||
|
|
||
| @Override | ||
| public void onReceive(Context context, Intent intent) { | ||
| Bundle bundle = NotificationIntentAdapter.extractPendingNotificationDataFromIntent(intent); | ||
| NotificationManager notificationManager = (NotificationManager) context | ||
| .getSystemService(Context.NOTIFICATION_SERVICE); | ||
|
|
||
| String notId = bundle.getString("notId"); | ||
|
|
||
| Gson gson = new Gson(); | ||
| Ejson ejson = gson.fromJson(bundle.getString("ejson", "{}"), Ejson.class); | ||
|
|
||
| try { | ||
| int id = Integer.parseInt(notId); | ||
| markAsRead(ejson, id, notificationManager); | ||
| } catch (NumberFormatException e) { | ||
| Log.e(TAG, "Invalid notification ID: " + notId, e); | ||
| } | ||
| } | ||
|
|
||
| protected void markAsRead(final Ejson ejson, final int notId, final NotificationManager notificationManager) { | ||
| String serverURL = ejson.serverURL(); | ||
| String rid = ejson.rid; | ||
|
|
||
| if (serverURL == null || rid == null) { | ||
| Log.e(TAG, "Missing serverURL or rid"); | ||
| return; | ||
| } | ||
|
|
||
| final OkHttpClient client = new OkHttpClient(); | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| final MediaType JSON = MediaType.parse("application/json; charset=utf-8"); | ||
|
|
||
| String json = String.format("{\"rid\":\"%s\"}", rid); | ||
|
|
||
| CustomPushNotification.clearMessages(notId); | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| RequestBody body = RequestBody.create(JSON, json); | ||
| Request request = new Request.Builder() | ||
| .header("x-auth-token", ejson.token()) | ||
| .header("x-user-id", ejson.userId()) | ||
| .url(String.format("%s/api/v1/subscriptions.read", serverURL)) | ||
| .post(body) | ||
| .build(); | ||
|
|
||
| client.newCall(request).enqueue(new okhttp3.Callback() { | ||
| @Override | ||
| public void onFailure(Call call, IOException e) { | ||
| Log.e(TAG, "Mark as read FAILED: " + e.getMessage()); | ||
| } | ||
|
|
||
| @Override | ||
| public void onResponse(Call call, final Response response) throws IOException { | ||
| if (response.isSuccessful()) { | ||
| Log.d(TAG, "Mark as read SUCCESS"); | ||
| notificationManager.cancel(notId); | ||
| } else { | ||
| Log.e(TAG, String.format("Mark as read FAILED status %s", response.code())); | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| }); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| // | ||
| // MarkAsRead.swift | ||
| // RocketChatRN | ||
| // | ||
| // Created for Mark as Read notification action | ||
| // Copyright © 2025 Rocket.Chat. All rights reserved. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| struct MarkAsReadBody: Codable { | ||
| let rid: String | ||
| } | ||
|
|
||
| struct MarkAsReadResponse: Response { | ||
| var success: Bool | ||
| } | ||
|
|
||
| final class MarkAsReadRequest: Request { | ||
| typealias ResponseType = MarkAsReadResponse | ||
|
|
||
| let method: HTTPMethod = .post | ||
| let path = "/api/v1/subscriptions.read" | ||
|
|
||
| let rid: String | ||
|
|
||
| init(rid: String) { | ||
| self.rid = rid | ||
| } | ||
|
|
||
| func body() -> Data? { | ||
| return try? JSONEncoder().encode(MarkAsReadBody(rid: rid)) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.