* Fix id-loaded on Android * Fix id-loaded on iOS * Remove constant for PUSH_TYPE_ID_LOADED
This commit is contained in:
parent
8838fd92c2
commit
591d65e57b
4 changed files with 25 additions and 18 deletions
|
|
@ -50,7 +50,6 @@ public class CustomPushNotification extends PushNotification {
|
|||
|
||||
private static final String PUSH_TYPE_MESSAGE = "message";
|
||||
private static final String PUSH_TYPE_CLEAR = "clear";
|
||||
private static final String PUSH_TYPE_ID_LOADED = "id_loaded";
|
||||
private static final String PUSH_TYPE_UPDATE_BADGE = "update_badge";
|
||||
|
||||
private NotificationChannel mHighImportanceChannel;
|
||||
|
|
@ -107,13 +106,14 @@ public class CustomPushNotification extends PushNotification {
|
|||
final String ackId = initialData.getString("ack_id");
|
||||
final String postId = initialData.getString("post_id");
|
||||
final String channelId = initialData.getString("channel_id");
|
||||
final boolean isIdLoaded = initialData.getString("id_loaded") != null ? initialData.getString("id_loaded").equals("true") : false;
|
||||
int notificationId = MESSAGE_NOTIFICATION_ID;
|
||||
|
||||
if (ackId != null) {
|
||||
notificationReceiptDelivery(ackId, postId, type, new ResolvePromise() {
|
||||
notificationReceiptDelivery(ackId, postId, type, isIdLoaded, new ResolvePromise() {
|
||||
@Override
|
||||
public void resolve(@Nullable Object value) {
|
||||
if (PUSH_TYPE_ID_LOADED.equals(type)) {
|
||||
if (isIdLoaded) {
|
||||
Bundle response = (Bundle) value;
|
||||
mNotificationProps = createProps(response);
|
||||
}
|
||||
|
|
@ -330,7 +330,7 @@ public class CustomPushNotification extends PushNotification {
|
|||
}
|
||||
|
||||
private void setMessagingStyleConversationTitle(Notification.MessagingStyle messagingStyle, String conversationTitle, Bundle bundle) {
|
||||
String channelName = bundle.getString("channel_name");
|
||||
String channelName = getConversationTitle(bundle);
|
||||
String senderName = bundle.getString("sender_name");
|
||||
if (android.text.TextUtils.isEmpty(senderName)) {
|
||||
senderName = getSenderName(bundle);
|
||||
|
|
@ -358,6 +358,9 @@ public class CustomPushNotification extends PushNotification {
|
|||
Bundle data = bundleList.get(i);
|
||||
String message = data.getString("message");
|
||||
String senderId = data.getString("sender_id");
|
||||
if (senderId == null) {
|
||||
senderId = "sender_id";
|
||||
}
|
||||
Bundle userInfoBundle = data.getBundle("userInfo");
|
||||
String senderName = getSenderName(data);
|
||||
if (userInfoBundle != null) {
|
||||
|
|
@ -518,15 +521,15 @@ public class CustomPushNotification extends PushNotification {
|
|||
}
|
||||
}
|
||||
|
||||
return " ";
|
||||
return getConversationTitle(bundle);
|
||||
}
|
||||
|
||||
private String removeSenderNameFromMessage(String message, String senderName) {
|
||||
return message.replaceFirst(senderName, "").replaceFirst(": ", "").trim();
|
||||
}
|
||||
|
||||
private void notificationReceiptDelivery(String ackId, String postId, String type, ResolvePromise promise) {
|
||||
ReceiptDelivery.send(context, ackId, postId, type, promise);
|
||||
private void notificationReceiptDelivery(String ackId, String postId, String type, boolean isIdLoaded, ResolvePromise promise) {
|
||||
ReceiptDelivery.send(context, ackId, postId, type, isIdLoaded, promise);
|
||||
}
|
||||
|
||||
private void createNotificationChannels() {
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ import com.mattermost.react_native_interface.ResolvePromise;
|
|||
public class ReceiptDelivery {
|
||||
static final String CURRENT_SERVER_URL = "@currentServerUrl";
|
||||
|
||||
public static void send(Context context, final String ackId, final String postId, final String type, ResolvePromise promise) {
|
||||
public static void send(Context context, final String ackId, final String postId, final String type, final boolean isIdLoaded, ResolvePromise promise) {
|
||||
final ReactApplicationContext reactApplicationContext = new ReactApplicationContext(context);
|
||||
|
||||
MattermostCredentialsHelper.getCredentialsForCurrentServer(reactApplicationContext, new ResolvePromise() {
|
||||
|
|
@ -48,14 +48,14 @@ public class ReceiptDelivery {
|
|||
}
|
||||
}
|
||||
|
||||
Log.i("ReactNative", String.format("Send receipt delivery ACK=%s TYPE=%s to URL=%s with TOKEN=%s", ackId, type, serverUrl, token));
|
||||
execute(serverUrl, postId, token, ackId, type, promise);
|
||||
Log.i("ReactNative", String.format("Send receipt delivery ACK=%s TYPE=%s to URL=%s with TOKEN=%s ID-LOADED=%s", ackId, type, serverUrl, token, isIdLoaded));
|
||||
execute(serverUrl, postId, token, ackId, type, isIdLoaded, promise);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected static void execute(String serverUrl, String postId, String token, String ackId, String type, ResolvePromise promise) {
|
||||
protected static void execute(String serverUrl, String postId, String token, String ackId, String type, boolean isIdLoaded, ResolvePromise promise) {
|
||||
if (token == null) {
|
||||
promise.reject("Receipt delivery failure", "Invalid token");
|
||||
return;
|
||||
|
|
@ -75,6 +75,7 @@ public class ReceiptDelivery {
|
|||
json.put("platform", "android");
|
||||
json.put("type", type);
|
||||
json.put("post_id", postId);
|
||||
json.put("is_id_loaded", isIdLoaded);
|
||||
} catch (JSONException e) {
|
||||
Log.e("ReactNative", "Receipt delivery failed to build json payload");
|
||||
promise.reject("Receipt delivery failure", e.toString());
|
||||
|
|
@ -96,8 +97,8 @@ public class ReceiptDelivery {
|
|||
|
||||
try {
|
||||
Response response = client.newCall(request).execute();
|
||||
String responseBody = response.body().toString();
|
||||
if (response.code() != 200) {
|
||||
String responseBody = response.body().string();
|
||||
if (response.code() != 200 || !isIdLoaded) {
|
||||
throw new Exception(responseBody);
|
||||
}
|
||||
JSONObject jsonResponse = new JSONObject(responseBody);
|
||||
|
|
|
|||
|
|
@ -13,13 +13,15 @@ class NotificationService: UNNotificationServiceExtension {
|
|||
let ackId = bestAttemptContent.userInfo["ack_id"]
|
||||
let type = bestAttemptContent.userInfo["type"]
|
||||
let postId = bestAttemptContent.userInfo["post_id"]
|
||||
let idLoaded = bestAttemptContent.userInfo["id_loaded"] ?? false
|
||||
UploadSession.shared.notificationReceipt(
|
||||
notificationId: ackId,
|
||||
receivedAt: Date().millisencondsSince1970,
|
||||
type: type,
|
||||
postId: postId
|
||||
postId: postId,
|
||||
idLoaded: idLoaded as! Bool
|
||||
) { data, error in
|
||||
if (type as? String == "id_loaded") {
|
||||
if (idLoaded as! Bool) {
|
||||
guard let data = data, error == nil else {
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -128,10 +128,10 @@ import os.log
|
|||
}
|
||||
|
||||
public func notificationReceipt(notificationId: Any?, receivedAt: Int, type: Any?) {
|
||||
notificationReceipt(notificationId:notificationId, receivedAt:receivedAt, type:type, postId:nil, completion:{_, _ in})
|
||||
notificationReceipt(notificationId:notificationId, receivedAt:receivedAt, type:type, postId:nil, idLoaded: false, completion:{_, _ in})
|
||||
}
|
||||
|
||||
public func notificationReceipt(notificationId: Any?, receivedAt: Int, type: Any?, postId: Any? = nil, completion: @escaping (Data?, Error?) -> Void) {
|
||||
public func notificationReceipt(notificationId: Any?, receivedAt: Int, type: Any?, postId: Any? = nil, idLoaded: Bool, completion: @escaping (Data?, Error?) -> Void) {
|
||||
if (notificationId != nil) {
|
||||
let store = StoreManager.shared() as StoreManager
|
||||
let entities = store.getEntities(true)
|
||||
|
|
@ -147,7 +147,8 @@ import os.log
|
|||
"received_at": receivedAt,
|
||||
"platform": "ios",
|
||||
"type": type as Any,
|
||||
"post_id": postId as Any
|
||||
"post_id": postId as Any,
|
||||
"is_id_loaded": idLoaded as Bool
|
||||
]
|
||||
|
||||
if !JSONSerialization.isValidJSONObject(jsonObject) {return}
|
||||
|
|
|
|||
Loading…
Reference in a new issue