Skip to content

Commit

Permalink
fix push notifications on android when using SSO to login
Browse files Browse the repository at this point in the history
  • Loading branch information
enahum committed Feb 11, 2025
1 parent b2b5fe5 commit 6055260
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,25 @@
import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.app.NotificationCompat;
import androidx.core.app.Person;

import com.facebook.react.ReactApplication;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.WritableMap;

import com.mattermost.helpers.*;
import com.mattermost.turbolog.TurboLog;
import com.wix.reactnativenotifications.core.NotificationIntentAdapter;
import com.wix.reactnativenotifications.core.notification.INotificationsApplication;
import com.wix.reactnativenotifications.core.notification.PushNotificationProps;

public class NotificationReplyBroadcastReceiver extends BroadcastReceiver {
private Context mContext;
private Bundle bundle;
private NotificationManager notificationManager;

private ReactApplicationContext getReactContext(Context context) {
if (context instanceof ReactApplication) {
ReactNativeHost host = ((ReactApplication) context).getReactNativeHost();
return (ReactApplicationContext) host.getReactInstanceManager().getCurrentReactContext();
}

return null;
}

@Override
public void onReceive(Context context, Intent intent) {
try {
Expand Down Expand Up @@ -80,7 +69,6 @@ protected void replyToMessage(final String serverUrl, final int notificationId,
WritableMap headers = Arguments.createMap();
headers.putString("Content-Type", "application/json");


WritableMap body = Arguments.createMap();
body.putString("channel_id", channelId);
body.putString("message", message.toString());
Expand All @@ -92,9 +80,19 @@ protected void replyToMessage(final String serverUrl, final int notificationId,

String postsEndpoint = "/api/v4/posts?set_online=false";
Network.post(serverUrl, postsEndpoint, options, new ResolvePromise() {
private boolean isSuccessful(int statusCode) {
return statusCode >= 200 && statusCode < 300;
}
@Override
public void resolve(@Nullable Object value) {
if (value != null) {
ReadableMap response = (ReadableMap)value;
ReadableMap data = response.getMap("data");
if (data != null && data.hasKey("status_code") && !isSuccessful(data.getInt("status_code"))) {
TurboLog.Companion.i("ReactNative", String.format("Reply FAILED exception %s", data.getString("message")));
onReplyFailed(notificationId);
return;
}
onReplySuccess(notificationId, message);
TurboLog.Companion.i("ReactNative", "Reply SUCCESS");
} else {
Expand All @@ -104,13 +102,13 @@ public void resolve(@Nullable Object value) {
}

@Override
public void reject(Throwable reason) {
public void reject(@NonNull Throwable reason) {
TurboLog.Companion.i("ReactNative", String.format("Reply FAILED exception %s", reason.getMessage()));
onReplyFailed(notificationId);
}

@Override
public void reject(String code, String message) {
public void reject(@NonNull String code, String message) {
TurboLog.Companion.i("ReactNative",
String.format("Reply FAILED status %s BODY %s", code, message)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public static Bundle send(final String ackId, final String serverUrl, final Stri
JSONObject jsonResponse = new JSONObject(responseBody);
return parseAckResponse(jsonResponse);
} catch (Exception e) {
TurboLog.Companion.e("ReactNative", "Send receipt delivery failed " + e.getMessage());
e.printStackTrace();
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1454,7 +1454,7 @@ PODS:
- Yoga
- react-native-netinfo (11.4.1):
- React-Core
- react-native-network-client (1.8.1):
- react-native-network-client (1.8.2):
- Alamofire (~> 5.10.2)
- DoubleConversion
- glog
Expand Down Expand Up @@ -2518,7 +2518,7 @@ SPEC CHECKSUMS:
react-native-emm: f6003bebdf4fef4feef7c61f96a5c174f43c6b5f
react-native-image-picker: 130fad649d07e4eec8faaed361d3bba570e1e5ff
react-native-netinfo: cec9c4e86083cb5b6aba0e0711f563e2fbbff187
react-native-network-client: f2996a6440c422e64e787bdf8c8e3f992be1cee6
react-native-network-client: fdbd7f5f4c2818d6b90b4dcf9613d0a54ab41303
react-native-notifications: 3bafa1237ae8a47569a84801f17d80242fe9f6a5
react-native-paste-input: d33daa183942fa57f34dff2088805a60895f14d2
react-native-performance: 125a96c145e29918b55b45ce25cbba54f1e24dcd
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@mattermost/compass-icons": "0.1.48",
"@mattermost/hardware-keyboard": "file:./libraries/@mattermost/hardware-keyboard",
"@mattermost/react-native-emm": "1.5.1",
"@mattermost/react-native-network-client": "1.8.1",
"@mattermost/react-native-network-client": "1.8.2",
"@mattermost/react-native-paste-input": "0.8.1",
"@mattermost/react-native-turbo-log": "0.5.0",
"@mattermost/rnshare": "file:./libraries/@mattermost/rnshare",
Expand Down

0 comments on commit 6055260

Please sign in to comment.