Receive GetSocial Notifications

Notification Center with GetSocial

GetSocial provides a data API to implement notification center, similar to what Facebook has, inside your application. All notifications received via API will also generate an associated push notification.

GetSocial Notification Center UI

Let your users receive and interact with GetSocial Notifications in minutes, not days with prebuilt Notification Center UI.

Prerequisite

Receive Notifications

To be sure your users didn’t miss any important (or not) notifications, you can query GetSocial notifications and show it to your user inside the app. Or send it once again as local notification. Or handle it in any other convenience method.

Query

You have two types of methods: get and count to get notifications list and notifications count respectively.

GetSocialNotification can differ by a read status - be read or unread. Also each notification has type, it is one of NotificationType constants.

To query notifications by status, use NotificationsQuery.withStatuses() factory method. You can pass one or few statuses from NotificationStatus constants. Use withAllStatuses to query notifications with any status.

By default notifications of all types are queries. Also you can explicitly call ofAllTypes to be sure that all types are queries. To specify a list of types you’re interested in call method appendType and pass one or few types you want to query.

If you want to query notifications by actions, use withActions(List<String> actions) method to query with any action.

Notifications Count

To get the count of notifications use Notifications.count() method. For example, to get a number of all unread notifications for current user:

1
2
3
4
5
6
val query = NotificationsQuery.withStatuses(NotificationStatus.UNREAD)
Notifications.getCount(query, { count: Int ->
    Log.d("Notifications", "Unread notifications count: $count")
}, { error: GetSocialError ->
    Log.d("Notifications", "Failed to get notifications count: $error")
})
1
2
3
4
5
6
let query = NotificationsQuery.withStatuses( [NotificationStatus.unread] )
Notifications.count(query, success: { result in
    print("Notifications count is \(result)")
}, failure: { error in
    print("Failed to get notifications count, error: \(error)")
})
1
2
3
4
5
6
7
8
9
var query = NotificationsQuery.WithStatuses(NotificationStatus.Unread);
Notifications.Count(query, 
    (count) => 
    {
        Debug.Log("Notifications count is: " + count);
    }, 
    (error) => {
        Debug.Log("Failed to get notifications count, error: " + error);
    });

Notifications List

Similar to notifications count you can fetch a list of notifications using Notifications.get()) method:

1
2
3
4
5
6
7
8
val query = NotificationsQuery.withStatuses(NotificationStatus.UNREAD)
val pagingQuery = PagingQuery(query)
Notifications.get(pagingQuery, { result: PagingResult<Notification> ->
    val notifications = result.entries
    Log.d("Notifications", "Unread notifications: $notifications")
}, { error: GetSocialError ->
    Log.d("Notifications", "Failed to get notifications: $error")
})
1
2
3
4
5
6
7
let query = NotificationsQuery.withStatuses( [NotificationStatus.unread] )
let pagingQuery = NotificationsPagingQuery(query)
Notifications.get(pagingQuery, success: { result in
    self.showNotifications(result.notifications)
}, failure: { error in
    print("Failed to get notifications, error: \(error)")
})
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
var query = NotificationsQuery.WithStatuses(NotificationStatus.Unread);
var pagingQuery = new PagingQuery<NotificationsQuery>(query);

Notifications.Get(pagingQuery,
    (result) => {
        ShowNotifications(result.Entries);
    },
    (error) => {
        Debug.Log("Failed to get notifications, error: " + error);
    );

Notifications Status

Read and Unread

All the notifications that are sent to a user are unread. The only exception is notifications that were clicked by a user - such become read automatically.

If you want to set notification read or unread use Notifications.setStatus() method:

1
2
3
4
5
6
7
8
val notifications: List<Notification>
val notificationIds = notifications.map { it.id }

Notifications.setStatus(NotificationStatus.READ, notificationIds, {
    Log.d("Notifications", "Changed notifications statuses")
}, { error: GetSocialError ->
    Log.d("Notifications", "Failed to change notifications statuses: $error")
})
1
2
3
4
5
6
7
8
9
let notifications : [GetSocialNotification] = ...
let notificationIds : [String] = notifications.map {
    return $0.notificationId
}
Notifications.setStatus(NotificationStatus.read, notificationIds: notificationIds, success: {
    print("Successfully changed notifications status")
}) { (error : Error) in
    print("Failed to change notifications status, error: \(error)")
}
1
2
3
4
5
6
7
8
List<string> notificationIds = ... // notification id's
Notifications.SetStatus(NotificationStatus.Read, notificationIds,
    () => {
        Debug.Log("Successfully changed notifications status");
    },
    (error) => {
        Debug.Log("Failed to change notifications status, error: " + error);
    });

Consumed and Ignored

If your notification is kind of “consumable” - e.g. friend request, pending action or whatever it could be(check some possible usecase) - you may want to mark it as “consumed” by user, so it won’t appear in the list of read/unread notifications. For this there is consumed status. If user wants to ignore it, e.g. decline friends request, set it to ignored.

Next Steps

Give us your feedback! Was this article helpful?

😀 🙁