浏览代码

Update push messages

Signed-off-by: Mario Danic <mario@lovelyhq.com>
Mario Danic 7 年之前
父节点
当前提交
08580dc815

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

@@ -34,6 +34,9 @@ public class DecryptedPushMessage {
     @JsonField(name = "app")
     String app;
 
+    @JsonField(name = "type")
+    String type;
+
     @JsonField(name = "subject")
     String subject;
 }

+ 52 - 6
app/src/main/java/com/nextcloud/talk/services/firebase/MagicFirebaseMessagingService.java

@@ -21,12 +21,19 @@
 package com.nextcloud.talk.services.firebase;
 
 import android.annotation.SuppressLint;
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.media.RingtoneManager;
 import android.util.Base64;
 import android.util.Log;
 
 import com.bluelinelabs.logansquare.LoganSquare;
 import com.google.firebase.messaging.FirebaseMessagingService;
 import com.google.firebase.messaging.RemoteMessage;
+import com.nextcloud.talk.R;
 import com.nextcloud.talk.api.models.json.push.DecryptedPushMessage;
 import com.nextcloud.talk.api.models.json.push.PushMessage;
 import com.nextcloud.talk.models.SignatureVerification;
@@ -35,6 +42,7 @@ import com.nextcloud.talk.utils.PushUtils;
 import java.security.InvalidKeyException;
 import java.security.NoSuchAlgorithmException;
 import java.security.PrivateKey;
+import java.util.zip.CRC32;
 
 import javax.crypto.Cipher;
 import javax.crypto.NoSuchPaddingException;
@@ -67,17 +75,55 @@ public class MagicFirebaseMessagingService extends FirebaseMessagingService {
                         DecryptedPushMessage decryptedPushMessage = LoganSquare.parse(new String(decryptedSubject),
                                 DecryptedPushMessage.class);
 
-                        if (decryptedPushMessage.getApp().equals("spreed") || decryptedPushMessage.getApp().equals
-                                ("talk")) {
-                            // process message
+                        if (decryptedPushMessage.getApp().equals("spreed")) {
+                            int smallIcon;
+                            Bitmap largeIcon;
+                            switch (decryptedPushMessage.getType()) {
+                                case "call":
+                                    smallIcon = R.drawable.ic_call_black_24dp;
+                                    break;
+                                case "room":
+                                    smallIcon = R.drawable.ic_notifications_black_24dp;
+                                    break;
+                                case "chat":
+                                    smallIcon = R.drawable.ic_chat_black_24dp;
+                                    break;
+                                default:
+                                    smallIcon = R.drawable.ic_logo;
+                            }
+
+                            largeIcon = BitmapFactory.decodeResource(getResources(), smallIcon);
+
+                            Notification.Builder notificationBuilder = new Notification.Builder(this)
+                                    .setSmallIcon(smallIcon)
+                                    .setLargeIcon(largeIcon)
+                                    .setColor(getColor(R.color.colorPrimary))
+                                    .setContentTitle(decryptedPushMessage.getSubject())
+                                    .setContentText(signatureVerification.getUserEntity().getDisplayName())
+                                    .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
+                                    .setAutoCancel(true);
+
+                            NotificationManager notificationManager =
+                                    (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
+
+                            if (notificationManager != null) {
+                                String stringForCrc = decryptedPushMessage.getSubject() + " " + signatureVerification
+                                        .getUserEntity().getDisplayName() + " " + signatureVerification.getUserEntity
+                                        ().getBaseUrl();
+
+                                CRC32 crc32 = new CRC32();
+                                crc32.update(stringForCrc.getBytes());
+
+                                notificationManager.notify((int) crc32.getValue(), notificationBuilder.build());
+                            }
                         }
                     }
                 } catch (NoSuchAlgorithmException e1) {
-                    Log.d(TAG, "No proper algorithm to decrypt the message");
+                    Log.d(TAG, "No proper algorithm to decrypt the message " + e1.getLocalizedMessage());
                 } catch (NoSuchPaddingException e1) {
-                    Log.d(TAG, "No proper padding to decrypt the message");
+                    Log.d(TAG, "No proper padding to decrypt the message " + e1.getLocalizedMessage());
                 } catch (InvalidKeyException e1) {
-                    Log.d(TAG, "Invalid private key");
+                    Log.d(TAG, "Invalid private key " + e1.getLocalizedMessage());
                 }
             } catch (Exception exception) {
                 Log.d(TAG, "Something went very wrong" + exception.getLocalizedMessage());

+ 25 - 0
app/src/main/res/drawable/ic_chat_black_24dp.xml

@@ -0,0 +1,25 @@
+<!--
+  ~ Nextcloud Talk application
+  ~
+  ~ @author Mario Danic
+  ~ Copyright (C) 2017 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/>.
+  -->
+
+<vector android:autoMirrored="true" android:height="24dp"
+    android:viewportHeight="24.0" android:viewportWidth="24.0"
+    android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
+    <path android:fillColor="#FF000000" android:pathData="M20,2L4,2c-1.1,0 -1.99,0.9 -1.99,2L2,22l4,-4h14c1.1,0 2,-0.9 2,-2L22,4c0,-1.1 -0.9,-2 -2,-2zM6,9h12v2L6,11L6,9zM14,14L6,14v-2h8v2zM18,8L6,8L6,6h12v2z"/>
+</vector>

+ 25 - 0
app/src/main/res/drawable/ic_notifications_black_24dp.xml

@@ -0,0 +1,25 @@
+<!--
+  ~ Nextcloud Talk application
+  ~
+  ~ @author Mario Danic
+  ~ Copyright (C) 2017 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/>.
+  -->
+
+<vector android:autoMirrored="true" android:height="24dp"
+    android:viewportHeight="24.0" android:viewportWidth="24.0"
+    android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
+    <path android:fillColor="#FF000000" android:pathData="M12,22c1.1,0 2,-0.9 2,-2h-4c0,1.1 0.89,2 2,2zM18,16v-5c0,-3.07 -1.64,-5.64 -4.5,-6.32L13.5,4c0,-0.83 -0.67,-1.5 -1.5,-1.5s-1.5,0.67 -1.5,1.5v0.68C7.63,5.36 6,7.92 6,11v5l-2,2v1h16v-1l-2,-2z"/>
+</vector>