Browse Source

Fix #275

Signed-off-by: Mario Danic <mario@lovelyhq.com>
Mario Danic 6 years ago
parent
commit
08710d5f1c

+ 3 - 3
app/src/main/java/com/nextcloud/talk/adapters/messages/MagicIncomingTextMessageViewHolder.java

@@ -44,7 +44,7 @@ import com.nextcloud.talk.utils.database.user.UserUtils;
 import com.stfalcon.chatkit.messages.MessageHolders;
 import com.stfalcon.chatkit.utils.ShapeImageView;
 
-import java.util.HashMap;
+import java.util.Map;
 
 import javax.inject.Inject;
 
@@ -120,7 +120,7 @@ public class MagicIncomingTextMessageViewHolder
             messageAuthor.setVisibility(View.VISIBLE);
         }
 
-        HashMap<String, HashMap<String, String>> messageParameters = message.getMessageParameters();
+        Map<String, Map<String, String>> messageParameters = message.getMessageParameters();
 
         Context context = NextcloudTalkApplication.getSharedApplication().getApplicationContext();
         itemView.setSelected(false);
@@ -133,7 +133,7 @@ public class MagicIncomingTextMessageViewHolder
 
         if (messageParameters != null && message.getMessageParameters().size() > 0) {
             for (String key : message.getMessageParameters().keySet()) {
-                HashMap<String, String> individualHashMap = message.getMessageParameters().get(key);
+                Map<String, String> individualHashMap = message.getMessageParameters().get(key);
                 if (individualHashMap.get("type").equals("user")) {
                     int color;
 

+ 3 - 3
app/src/main/java/com/nextcloud/talk/adapters/messages/MagicOutcomingTextMessageViewHolder.java

@@ -41,7 +41,7 @@ import com.nextcloud.talk.utils.EmojiDetection;
 import com.nextcloud.talk.utils.database.user.UserUtils;
 import com.stfalcon.chatkit.messages.MessageHolders;
 
-import java.util.HashMap;
+import java.util.Map;
 
 import javax.inject.Inject;
 
@@ -77,7 +77,7 @@ public class MagicOutcomingTextMessageViewHolder extends MessageHolders.Outcomin
     public void onBind(ChatMessage message) {
         super.onBind(message);
 
-        HashMap<String, HashMap<String, String>> messageParameters = message.getMessageParameters();
+        Map<String, Map<String, String>> messageParameters = message.getMessageParameters();
 
         Spannable messageString = new SpannableString(message.getText());
 
@@ -90,7 +90,7 @@ public class MagicOutcomingTextMessageViewHolder extends MessageHolders.Outcomin
 
         if (messageParameters != null && message.getMessageParameters().size() > 0) {
             for (String key : message.getMessageParameters().keySet()) {
-                HashMap<String, String> individualHashMap = message.getMessageParameters().get(key);
+                Map<String, String> individualHashMap = message.getMessageParameters().get(key);
                 if (individualHashMap.get("type").equals("user")) {
                     if (!individualHashMap.get("id").equals(currentUser.getUserId())) {
                         messageString = DisplayUtils.searchAndColor(messageText.getText().toString(),

+ 34 - 19
app/src/main/java/com/nextcloud/talk/jobs/NotificationJob.java

@@ -50,6 +50,7 @@ import com.nextcloud.talk.application.NextcloudTalkApplication;
 import com.nextcloud.talk.models.RingtoneSettings;
 import com.nextcloud.talk.models.SignatureVerification;
 import com.nextcloud.talk.models.database.UserEntity;
+import com.nextcloud.talk.models.json.chat.ChatUtils;
 import com.nextcloud.talk.models.json.notifications.NotificationOverall;
 import com.nextcloud.talk.models.json.push.DecryptedPushMessage;
 import com.nextcloud.talk.models.json.rooms.Conversation;
@@ -186,8 +187,7 @@ public class NotificationJob extends Job {
                                     // do absolutely nothing, we won't even come to this point
                                     break;
                                 case "chat":
-                                    if (signatureVerification.getUserEntity().hasSpreedCapabilityWithName("object-data") &&
-                                            signatureVerification.getUserEntity().hasNotificationsCapability("rich-strings")) {
+                                    if (decryptedPushMessage.getNotificationId() != Long.MIN_VALUE) {
                                         showMessageNotificationWithObjectData(intent);
                                     } else {
                                         showNotification(intent);
@@ -252,28 +252,39 @@ public class NotificationJob extends Job {
         UserEntity userEntity = signatureVerification.getUserEntity();
         ncApi.getNotification(ApiUtils.getCredentials(userEntity.getUserId(),
                 userEntity.getToken()), ApiUtils.getUrlForNotificationWithId(userEntity.getBaseUrl(),
-                        Long.toString(decryptedPushMessage.getNotificationId())))
-                        .subscribeOn(Schedulers.newThread())
-                        .subscribe(new Observer<NotificationOverall>() {
-                            @Override
-                            public void onSubscribe(Disposable d) {
+                Long.toString(decryptedPushMessage.getNotificationId())))
+                .subscribeOn(Schedulers.newThread())
+                .subscribe(new Observer<NotificationOverall>() {
+                    @Override
+                    public void onSubscribe(Disposable d) {
 
-                            }
+                    }
 
-                            @Override
-                            public void onNext(NotificationOverall notificationOverall) {
+                    @Override
+                    public void onNext(NotificationOverall notificationOverall) {
+                        com.nextcloud.talk.models.json.notifications.Notification notification =
+                                notificationOverall.getOcs().getNotification();
+
+                        if (notification.getMessageRichParameters() != null &&
+                                notification.getMessageRichParameters().size() > 0) {
+                            decryptedPushMessage.setText(ChatUtils.getParsedMessage(notification.getMessageRich(),
+                                    notification.getMessageRichParameters()));
+                        } else {
+                            decryptedPushMessage.setText(notification.getMessage());
+                        }
 
-                            }
+                        showNotification(intent);
+                    }
 
-                            @Override
-                            public void onError(Throwable e) {
-                            }
+                    @Override
+                    public void onError(Throwable e) {
+                        showNotification(intent);
+                    }
 
-                            @Override
-                            public void onComplete() {
-                                showNotification(intent);
-                            }
-                        });
+                    @Override
+                    public void onComplete() {
+                    }
+                });
     }
 
     private void showNotification(Intent intent) {
@@ -312,6 +323,10 @@ public class NotificationJob extends Job {
                 .setContentIntent(pendingIntent)
                 .setAutoCancel(true);
 
+        if (!TextUtils.isEmpty(decryptedPushMessage.getText())) {
+            notificationBuilder.setContentText(decryptedPushMessage.getText());
+        }
+
         if (Build.VERSION.SDK_INT >= 23) {
             // This method should exist since API 21, but some phones don't have it
             // So as a safeguard, we don't use it until 23

+ 3 - 19
app/src/main/java/com/nextcloud/talk/models/json/chat/ChatMessage.java

@@ -30,7 +30,7 @@ import com.stfalcon.chatkit.commons.models.IUser;
 import org.parceler.Parcel;
 
 import java.util.Date;
-import java.util.HashMap;
+import java.util.Map;
 
 import lombok.Data;
 
@@ -75,7 +75,7 @@ public class ChatMessage implements IMessage {
     @JsonField(name = "message")
     String message;
     @JsonField(name = "messageParameters")
-    HashMap<String, HashMap<String, String>> messageParameters;
+    Map<String, Map<String, String>> messageParameters;
 
     @JsonField(name = "systemMessage", typeConverter = EnumSystemMessageTypeConverter.class)
     SystemMessageType systemMessageType;
@@ -98,7 +98,7 @@ public class ChatMessage implements IMessage {
 
     @Override
     public String getText() {
-        return getParsedMessage();
+        return ChatUtils.getParsedMessage(getMessage(), getMessageParameters());
     }
 
     @Override
@@ -129,20 +129,4 @@ public class ChatMessage implements IMessage {
     public Date getCreatedAt() {
         return new Date(timestamp * 1000L);
     }
-
-    private String getParsedMessage() {
-        String message = getMessage();
-        if (messageParameters != null && messageParameters.size() > 0) {
-            for (String key : messageParameters.keySet()) {
-                HashMap<String, String> individualHashMap = messageParameters.get(key);
-                if (individualHashMap.get("type").equals("user")) {
-                    message = message.replaceAll("\\{" + key + "\\}", "@" +
-                            messageParameters.get(key).get("name"));
-                }
-            }
-        }
-
-
-        return message;
-    }
 }

+ 41 - 0
app/src/main/java/com/nextcloud/talk/models/json/chat/ChatUtils.java

@@ -0,0 +1,41 @@
+/*
+ * Nextcloud Talk application
+ *
+ * @author Mario Danic
+ * Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package com.nextcloud.talk.models.json.chat;
+
+import java.util.Map;
+
+public class ChatUtils {
+
+    public static String getParsedMessage(String message, Map<String, Map<String, String>> messageParameters) {
+        if (messageParameters != null && messageParameters.size() > 0) {
+            for (String key : messageParameters.keySet()) {
+                Map<String, String> individualHashMap = messageParameters.get(key);
+                if (individualHashMap.get("type").equals("user")) {
+                    message = message.replaceAll("\\{" + key + "\\}", "@" +
+                            messageParameters.get(key).get("name"));
+                }
+            }
+        }
+
+
+        return message;
+    }
+}

+ 2 - 2
app/src/main/java/com/nextcloud/talk/models/json/notifications/Notification.java

@@ -60,7 +60,7 @@ public class Notification {
     String subjectRich;
 
     @JsonField(name = "subjectRichParameters")
-    Map<String, NotificationRichObject> subjectRichParameters;
+    Map<String, Map<String, String>> subjectRichParameters;
 
     @JsonField(name = "message")
     String message;
@@ -69,7 +69,7 @@ public class Notification {
     String messageRich;
 
     @JsonField(name = "messageRichParameters")
-    Map<String, NotificationRichObject> messageRichParameters;
+    Map<String, Map<String, String>> messageRichParameters;
 
     @JsonField(name = "link")
     String link;

+ 4 - 0
app/src/main/java/com/nextcloud/talk/models/json/push/DecryptedPushMessage.java

@@ -21,6 +21,7 @@
 package com.nextcloud.talk.models.json.push;
 
 import com.bluelinelabs.logansquare.annotation.JsonField;
+import com.bluelinelabs.logansquare.annotation.JsonIgnore;
 import com.bluelinelabs.logansquare.annotation.JsonObject;
 
 import org.parceler.Parcel;
@@ -45,4 +46,7 @@ public class DecryptedPushMessage {
 
     @JsonField(name = "nid")
     long notificationId;
+
+    @JsonIgnore
+    String text;
 }

+ 3 - 1
app/src/main/java/com/nextcloud/talk/utils/preferences/AppPreferences.java

@@ -20,6 +20,8 @@
 
 package com.nextcloud.talk.utils.preferences;
 
+import com.nextcloud.talk.R;
+
 import net.orange_box.storebox.annotations.method.ClearMethod;
 import net.orange_box.storebox.annotations.method.DefaultValue;
 import net.orange_box.storebox.annotations.method.KeyByString;
@@ -180,7 +182,7 @@ public interface AppPreferences {
     void removeMessagesNotificationChannelUpgradeToV3();
 
     @KeyByString("notifications_vibrate")
-    @DefaultValue(1)
+    @DefaultValue(R.bool.value_true)
     boolean getShouldVibrateSetting();
 
     @KeyByString("notifications_vibrate")

+ 24 - 0
app/src/main/res/values/bool.xml

@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Nextcloud Talk application
+  ~
+  ~ @author Mario Danic
+  ~ Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
+  ~
+  ~ This program is free software: you can redistribute it and/or modify
+  ~ it under the terms of the GNU General Public License as published by
+  ~ the Free Software Foundation, either version 3 of the License, or
+  ~ at your option) any later version.
+  ~
+  ~ This program is distributed in the hope that it will be useful,
+  ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
+  ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  ~ GNU General Public License for more details.
+  ~
+  ~ You should have received a copy of the GNU General Public License
+  ~ along with this program.  If not, see <http://www.gnu.org/licenses/>.
+  -->
+
+<resources>
+    <bool name="value_true">true</bool>
+</resources>