diff --git a/app/src/main/java/com/nextcloud/talk/api/NcApi.java b/app/src/main/java/com/nextcloud/talk/api/NcApi.java index 1088d81f9..f4c6c095a 100644 --- a/app/src/main/java/com/nextcloud/talk/api/NcApi.java +++ b/app/src/main/java/com/nextcloud/talk/api/NcApi.java @@ -28,6 +28,7 @@ import com.nextcloud.talk.models.json.chat.ChatOverall; import com.nextcloud.talk.models.json.generic.GenericOverall; import com.nextcloud.talk.models.json.generic.Status; import com.nextcloud.talk.models.json.mention.MentionOverall; +import com.nextcloud.talk.models.json.notifications.NotificationOverall; import com.nextcloud.talk.models.json.participants.AddParticipantOverall; import com.nextcloud.talk.models.json.participants.ParticipantsOverall; import com.nextcloud.talk.models.json.push.PushRegistrationOverall; @@ -298,4 +299,8 @@ public interface NcApi { @DELETE Observable unpinConversation(@Header("Authorization") String authorization, @Url String url); + + @GET + Observable getNotification(@Header("Authorization") String authorization, + @Url String url); } diff --git a/app/src/main/java/com/nextcloud/talk/jobs/NotificationJob.java b/app/src/main/java/com/nextcloud/talk/jobs/NotificationJob.java index 2ce965836..f2729cd22 100644 --- a/app/src/main/java/com/nextcloud/talk/jobs/NotificationJob.java +++ b/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.notifications.NotificationOverall; import com.nextcloud.talk.models.json.push.DecryptedPushMessage; import com.nextcloud.talk.models.json.rooms.Conversation; import com.nextcloud.talk.models.json.rooms.RoomOverall; @@ -185,7 +186,12 @@ public class NotificationJob extends Job { // do absolutely nothing, we won't even come to this point break; case "chat": - showNotification(intent); + if (signatureVerification.getUserEntity().hasSpreedCapabilityWithName("object-data") && + signatureVerification.getUserEntity().hasNotificationsCapability("rich-strings")) { + showMessageNotificationWithObjectData(intent); + } else { + showNotification(intent); + } break; default: break; @@ -242,6 +248,34 @@ public class NotificationJob extends Job { }); } + private void showMessageNotificationWithObjectData(Intent intent) { + 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() { + @Override + public void onSubscribe(Disposable d) { + + } + + @Override + public void onNext(NotificationOverall notificationOverall) { + + } + + @Override + public void onError(Throwable e) { + } + + @Override + public void onComplete() { + showNotification(intent); + } + }); + } + private void showNotification(Intent intent) { int smallIcon; Bitmap largeIcon; diff --git a/app/src/main/java/com/nextcloud/talk/models/database/User.java b/app/src/main/java/com/nextcloud/talk/models/database/User.java index ff009bb42..db419f664 100644 --- a/app/src/main/java/com/nextcloud/talk/models/database/User.java +++ b/app/src/main/java/com/nextcloud/talk/models/database/User.java @@ -61,6 +61,20 @@ public interface User extends Parcelable, Persistable, Serializable { boolean getScheduledForDeletion(); + default boolean hasNotificationsCapability(String capabilityName) { + if (getCapabilities() != null) { + try { + Capabilities capabilities = LoganSquare.parse(getCapabilities(), Capabilities.class); + if (capabilities.getNotificationsCapability() != null && capabilities.getNotificationsCapability().getFeatures() != null) { + return capabilities.getSpreedCapability().getFeatures().contains(capabilityName); + } + } catch (IOException e) { + Log.e(TAG, "Failed to get capabilities for the user"); + } + } + return false; + } + default boolean hasSpreedCapabilityWithName(String capabilityName) { if (getCapabilities() != null) { try { @@ -73,6 +87,5 @@ public interface User extends Parcelable, Persistable, Serializable { } } return false; - } } diff --git a/app/src/main/java/com/nextcloud/talk/models/json/capabilities/Capabilities.java b/app/src/main/java/com/nextcloud/talk/models/json/capabilities/Capabilities.java index f17c35bb1..8db91189f 100644 --- a/app/src/main/java/com/nextcloud/talk/models/json/capabilities/Capabilities.java +++ b/app/src/main/java/com/nextcloud/talk/models/json/capabilities/Capabilities.java @@ -33,4 +33,7 @@ import lombok.Data; public class Capabilities { @JsonField(name = "spreed") SpreedCapability spreedCapability; + + @JsonField(name = "notifications") + NotificationsCapability notificationsCapability; } diff --git a/app/src/main/java/com/nextcloud/talk/models/json/capabilities/NotificationsCapability.java b/app/src/main/java/com/nextcloud/talk/models/json/capabilities/NotificationsCapability.java new file mode 100644 index 000000000..bb22d988c --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/models/json/capabilities/NotificationsCapability.java @@ -0,0 +1,38 @@ +/* + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017-2018 Mario Danic + * + * 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 . + */ + +package com.nextcloud.talk.models.json.capabilities; + +import com.bluelinelabs.logansquare.annotation.JsonField; +import com.bluelinelabs.logansquare.annotation.JsonObject; + +import org.parceler.Parcel; + +import java.util.List; + +import lombok.Data; + +@Parcel +@Data +@JsonObject +public class NotificationsCapability { + @JsonField(name = "ocs-endpoints") + List features; +} diff --git a/app/src/main/java/com/nextcloud/talk/models/json/notifications/Notification.java b/app/src/main/java/com/nextcloud/talk/models/json/notifications/Notification.java new file mode 100644 index 000000000..8eaeec97d --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/models/json/notifications/Notification.java @@ -0,0 +1,82 @@ +/* + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017-2018 Mario Danic + * + * 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 . + */ + +package com.nextcloud.talk.models.json.notifications; + +import com.bluelinelabs.logansquare.annotation.JsonField; +import com.bluelinelabs.logansquare.annotation.JsonObject; + +import org.parceler.Parcel; + +import java.util.Date; +import java.util.List; +import java.util.Map; + +import lombok.Data; + +@Data +@Parcel +@JsonObject +public class Notification { + @JsonField(name = "notification_id") + int notificationId; + + @JsonField(name = "app") + String app; + + @JsonField(name = "user") + String user; + + @JsonField(name = "datetime") + Date datetime; + + @JsonField(name = "object_type") + String objectType; + + @JsonField(name = "object_id") + String objectId; + + @JsonField(name = "subject") + String subject; + + @JsonField(name = "subjectRich") + String subjectRich; + + @JsonField(name = "subjectRichParameters") + Map subjectRichParameters; + + @JsonField(name = "message") + String message; + + @JsonField(name = "messageRich") + String messageRich; + + @JsonField(name = "messageRichParameters") + Map messageRichParameters; + + @JsonField(name = "link") + String link; + + @JsonField(name = "icon") + public String icon; + + @JsonField(name = "actions") + List actions; +} diff --git a/app/src/main/java/com/nextcloud/talk/models/json/notifications/NotificationAction.java b/app/src/main/java/com/nextcloud/talk/models/json/notifications/NotificationAction.java new file mode 100644 index 000000000..0bad1cfb3 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/models/json/notifications/NotificationAction.java @@ -0,0 +1,45 @@ +/* + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017-2018 Mario Danic + * + * 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 . + */ + +package com.nextcloud.talk.models.json.notifications; + +import com.bluelinelabs.logansquare.annotation.JsonField; +import com.bluelinelabs.logansquare.annotation.JsonObject; + +import org.parceler.Parcel; + +import lombok.Data; + +@Data +@Parcel +@JsonObject +public class NotificationAction { + @JsonField(name = "label") + String label; + + @JsonField(name = "link") + String link; + + @JsonField(name = "type") + String type; + + @JsonField(name = "primary") + boolean primary; +} diff --git a/app/src/main/java/com/nextcloud/talk/models/json/notifications/NotificationOCS.java b/app/src/main/java/com/nextcloud/talk/models/json/notifications/NotificationOCS.java new file mode 100644 index 000000000..261021a50 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/models/json/notifications/NotificationOCS.java @@ -0,0 +1,37 @@ +/* + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017-2018 Mario Danic + * + * 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 . + */ + +package com.nextcloud.talk.models.json.notifications; + +import com.bluelinelabs.logansquare.annotation.JsonField; +import com.bluelinelabs.logansquare.annotation.JsonObject; +import com.nextcloud.talk.models.json.generic.GenericOCS; + +import org.parceler.Parcel; + +import lombok.Data; + +@Data +@Parcel +@JsonObject +public class NotificationOCS extends GenericOCS { + @JsonField(name = "data") + Notification notification; +} diff --git a/app/src/main/java/com/nextcloud/talk/models/json/notifications/NotificationOverall.java b/app/src/main/java/com/nextcloud/talk/models/json/notifications/NotificationOverall.java new file mode 100644 index 000000000..b96961aa0 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/models/json/notifications/NotificationOverall.java @@ -0,0 +1,32 @@ +/* + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017-2018 Mario Danic + * + * 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 . + */ +package com.nextcloud.talk.models.json.notifications; + +import com.bluelinelabs.logansquare.annotation.JsonField; +import com.bluelinelabs.logansquare.annotation.JsonObject; + +import lombok.Data; + +@Data +@JsonObject +public class NotificationOverall { + @JsonField(name = "ocs") + NotificationOCS ocs; +} diff --git a/app/src/main/java/com/nextcloud/talk/models/json/notifications/NotificationRichObject.java b/app/src/main/java/com/nextcloud/talk/models/json/notifications/NotificationRichObject.java new file mode 100644 index 000000000..b341ee79b --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/models/json/notifications/NotificationRichObject.java @@ -0,0 +1,42 @@ +/* + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017-2018 Mario Danic + * + * 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 . + */ + +package com.nextcloud.talk.models.json.notifications; + +import com.bluelinelabs.logansquare.annotation.JsonField; +import com.bluelinelabs.logansquare.annotation.JsonObject; + +import org.parceler.Parcel; + +import lombok.Data; + +@Data +@Parcel +@JsonObject +public class NotificationRichObject { + @JsonField(name = "id") + String label; + + @JsonField(name = "type") + String type; + + @JsonField(name = "name") + String name; +} diff --git a/app/src/main/java/com/nextcloud/talk/models/json/notifications/NotificationsOCS.java b/app/src/main/java/com/nextcloud/talk/models/json/notifications/NotificationsOCS.java new file mode 100644 index 000000000..b400ca5a6 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/models/json/notifications/NotificationsOCS.java @@ -0,0 +1,39 @@ +/* + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017-2018 Mario Danic + * + * 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 . + */ + +package com.nextcloud.talk.models.json.notifications; + +import com.bluelinelabs.logansquare.annotation.JsonField; +import com.bluelinelabs.logansquare.annotation.JsonObject; +import com.nextcloud.talk.models.json.generic.GenericOCS; + +import org.parceler.Parcel; + +import java.util.List; + +import lombok.Data; + +@Data +@Parcel +@JsonObject +public class NotificationsOCS extends GenericOCS { + @JsonField(name = "data") + List notificationsList; +} diff --git a/app/src/main/java/com/nextcloud/talk/models/json/notifications/NotificationsOverall.java b/app/src/main/java/com/nextcloud/talk/models/json/notifications/NotificationsOverall.java new file mode 100644 index 000000000..934ee1ed9 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/models/json/notifications/NotificationsOverall.java @@ -0,0 +1,32 @@ +/* + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017-2018 Mario Danic + * + * 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 . + */ +package com.nextcloud.talk.models.json.notifications; + +import com.bluelinelabs.logansquare.annotation.JsonField; +import com.bluelinelabs.logansquare.annotation.JsonObject; + +import lombok.Data; + +@Data +@JsonObject +public class NotificationsOverall { + @JsonField(name = "ocs") + NotificationsOCS ocs; +} diff --git a/app/src/main/java/com/nextcloud/talk/models/json/push/DecryptedPushMessage.java b/app/src/main/java/com/nextcloud/talk/models/json/push/DecryptedPushMessage.java index 65f676e6c..70bca0891 100644 --- a/app/src/main/java/com/nextcloud/talk/models/json/push/DecryptedPushMessage.java +++ b/app/src/main/java/com/nextcloud/talk/models/json/push/DecryptedPushMessage.java @@ -42,4 +42,7 @@ public class DecryptedPushMessage { @JsonField(name = "id") String id; + + @JsonField(name = "nid") + long notificationId; } diff --git a/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java b/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java index 65b7f3667..46f72a11d 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java +++ b/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java @@ -191,4 +191,8 @@ public class ApiUtils { public static String getUrlForConversationPin(String baseUrl, String roomToken) { return baseUrl + ocsApiVersion + "/room/" + roomToken + "/pin"; } + + public static String getUrlForNotificationWithId(String baseUrl, String notificationId) { + return baseUrl + ocsApiVersion + "/apps/notifications/api/v2/notifications/" + notificationId; + } }