From fb4b46074a8e60554ee39fd3df638bbb793cf00a Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Thu, 2 Aug 2018 09:41:34 +0200 Subject: [PATCH] Support group membership notifications. --- .../client/data/arrays/NotifsList.java | 4 ++++ .../client/data/enums/NotifElemType.java | 5 +++++ .../client/data/enums/NotificationTypes.java | 14 +++++++++++++ .../data/helpers/NotificationsHelper.java | 21 +++++++++++++++++++ .../client/data/utils/NotifsUtils.java | 19 +++++++++++++++++ app/src/main/res/values/strings.xml | 6 ++++++ 6 files changed, 69 insertions(+) diff --git a/app/src/main/java/org/communiquons/android/comunic/client/data/arrays/NotifsList.java b/app/src/main/java/org/communiquons/android/comunic/client/data/arrays/NotifsList.java index 43c5e0c..8745df3 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/data/arrays/NotifsList.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/data/arrays/NotifsList.java @@ -86,6 +86,10 @@ public class NotifsList extends ArrayList { && !IDs.contains(notif.getFrom_container_id())) IDs.add(notif.getFrom_container_id()); + if(notif.getOn_elem_type() == NotifElemType.GROUPS_MEMBERSHIP + && !IDs.contains(notif.getOn_elem_id())) + IDs.add(notif.getOn_elem_id()); + } return IDs; diff --git a/app/src/main/java/org/communiquons/android/comunic/client/data/enums/NotifElemType.java b/app/src/main/java/org/communiquons/android/comunic/client/data/enums/NotifElemType.java index 70531d4..e6448c3 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/data/enums/NotifElemType.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/data/enums/NotifElemType.java @@ -44,6 +44,11 @@ public enum NotifElemType { */ FRIEND_REQUEST, + /** + * Notifications related to group memberships + */ + GROUPS_MEMBERSHIP, + /** * Unknown type */ diff --git a/app/src/main/java/org/communiquons/android/comunic/client/data/enums/NotificationTypes.java b/app/src/main/java/org/communiquons/android/comunic/client/data/enums/NotificationTypes.java index b0715e8..5ba2c5c 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/data/enums/NotificationTypes.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/data/enums/NotificationTypes.java @@ -39,6 +39,20 @@ public enum NotificationTypes { */ ELEM_UPDATED, + /** + * Group membership invitations + */ + SENT_GROUP_MEMBERSHIP_INVITATION, + ACCEPTED_GROUP_MEMBERSHIP_INVITATION, + REJECTED_GROUP_MEMBERSHIP_INVITATION, + + /** + * Group membership requests + */ + SENT_GROUP_MEMBERSHIP_REQUEST, + ACCEPTED_GROUP_MEMBERSHIP_REQUEST, + REJECTED_GROUP_MEMBERSHIP_REQUEST, + /** * Unknown notification type */ diff --git a/app/src/main/java/org/communiquons/android/comunic/client/data/helpers/NotificationsHelper.java b/app/src/main/java/org/communiquons/android/comunic/client/data/helpers/NotificationsHelper.java index b90091a..36d891e 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/data/helpers/NotificationsHelper.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/data/helpers/NotificationsHelper.java @@ -213,6 +213,9 @@ public class NotificationsHelper { case "friend_request": return NotifElemType.FRIEND_REQUEST; + case "group_membership": + return NotifElemType.GROUPS_MEMBERSHIP; + //Default : unknown type of elem default: return NotifElemType.UNKNOWN; @@ -248,6 +251,24 @@ public class NotificationsHelper { case "elem_updated": return NotificationTypes.ELEM_UPDATED; + case "sent_group_membership_invitation": + return NotificationTypes.SENT_GROUP_MEMBERSHIP_INVITATION; + + case "accepted_group_membership_invitation": + return NotificationTypes.ACCEPTED_GROUP_MEMBERSHIP_INVITATION; + + case "rejected_group_membership_invitation": + return NotificationTypes.REJECTED_GROUP_MEMBERSHIP_INVITATION; + + case "sent_group_membership_request": + return NotificationTypes.SENT_GROUP_MEMBERSHIP_REQUEST; + + case "accepted_group_membership_request": + return NotificationTypes.ACCEPTED_GROUP_MEMBERSHIP_REQUEST; + + case "rejected_group_membership_request": + return NotificationTypes.REJECTED_GROUP_MEMBERSHIP_REQUEST; + //Default : Unknown notification type default: return NotificationTypes.UNKNOWN; diff --git a/app/src/main/java/org/communiquons/android/comunic/client/data/utils/NotifsUtils.java b/app/src/main/java/org/communiquons/android/comunic/client/data/utils/NotifsUtils.java index 3a0e9e1..b87a4cb 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/data/utils/NotifsUtils.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/data/utils/NotifsUtils.java @@ -47,6 +47,20 @@ public class NotifsUtils { if(notif.getType() == NotificationTypes.REJECTED_FRIEND_REQUEST) message += UiUtils.getString(context, R.string.notif_rejected_friend_request); + //For group membership + if(notif.getType() == NotificationTypes.SENT_GROUP_MEMBERSHIP_INVITATION) + message += UiUtils.getString(context, R.string.notif_sent_group_membership_invitation); + if(notif.getType() == NotificationTypes.ACCEPTED_GROUP_MEMBERSHIP_INVITATION) + message += UiUtils.getString(context, R.string.notif_accepted_group_membership_invitation); + if(notif.getType() == NotificationTypes.REJECTED_GROUP_MEMBERSHIP_INVITATION) + message += UiUtils.getString(context, R.string.notif_rejected_group_membership_invitation); + if(notif.getType() == NotificationTypes.SENT_GROUP_MEMBERSHIP_REQUEST) + message += UiUtils.getString(context, R.string.notif_sent_group_membership_request); + if(notif.getType() == NotificationTypes.ACCEPTED_GROUP_MEMBERSHIP_REQUEST) + message += UiUtils.getString(context, R.string.notif_accepted_group_membership_request); + if(notif.getType() == NotificationTypes.REJECTED_GROUP_MEMBERSHIP_REQUEST) + message += UiUtils.getString(context, R.string.notif_rejected_group_membership_request); + //In case of creation of an element if(notif.getType() == NotificationTypes.ELEM_CREATED){ @@ -83,6 +97,11 @@ public class NotifsUtils { groupsInfo.get(notif.getFrom_container_id()).getName()); } + //Group membership + else if(notif.getOn_elem_type() == NotifElemType.GROUPS_MEMBERSHIP){ + message += groupsInfo.get(notif.getOn_elem_id()).getName(); + } + //Return the message return message; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6e00ae9..2ac8d33 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -203,4 +203,10 @@ on the page of the group %1$s Could not get information about groups! members + invited you to join the group + accepted his invitation to join the group + rejected his invitation to join the group + sent a request to join the group + accepted your request to join the group + rejected your request to join the group