Skip to content

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:

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")
})
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)")
})
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);
    });
const query = NotificationsQuery.withStatus(['unread']);
Notifications.getCount(query).then((numberOfNotifications) => {
console.log('Unread notifications count: ' + numberOfNotifications);
}, (error) => {
console.log('Failed to get notifications count: ' + error);
});
var query = NotificationsQuery.withStatuses([NotificationStatus.unread]);
Notifications.getCount(query)
    .then((numberOfNotifications) => print('Unread notifications count: $numberOfNotifications'))
    .catchError((error) =>  print('Failed to get notifications count, error: $error'));
const query = GetSocialSDK.NotificationsQuery.withStatus(['unread']);
GetSocialSDK.Notifications.getCount(new GetSocialSDK.PagingQuery(query))
    .then((numberOfNotifications) => {
        console.log('Unread notifications count: ' + numberOfNotifications);
    }, (error) => {
        console.log('Failed to get notifications count: ', error);
    });

Notifications List

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

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")
})
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)")
})
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);
    );
const query = NotificationsQuery.withStatus(['read']);
Notifications.get(new PagingQuery(query)).then((result) => {
    this.showNotifications(result.entries);
}, (error) => {
    console.log('Failed to get notifications: ' + error);
});
var query = NotificationsQuery.withStatuses([NotificationStatus.read]);
Notifications.get(PagingQuery(query)).then((result) {
    this.showNotifications(result.entries);
}).catchError((error) => { print('Failed to get list of notifications, error: $error') });
const query = GetSocialSDK.NotificationsQuery.withStatus(['read']);
GetSocialSDK.Notifications.get(new GetSocialSDK.PagingQuery(query))
    .then((result) => {
        console.log('Notifications: ', result.entries);
    }, (error) => {
        console.log('Failed to get notifications: ', 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:

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")
})
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)")
}
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);
    });
const notificationsToBeRead: Array<Notification> = ...;
const notificationIds = notificationsToBeRead.map((notification) => {
return notification.id});
const newStatus = 'read';
Notifications.setStatus(newStatus, notificationIds).then(() => {
console.log('Successfully changed notifications status');
}, (error) => {
console.log('Failed to change notifications status: ' + error);
});
var notificationIds = ... // notification ids
Notifications.setStatus(NotificationStatus.read, notificationIds)
    .then((result) => print('Successfully changed notifications status'))
    .catchError((error) => { print('Failed to change notifications status, error: $error') });
const notificationsToBeRead: Array<Notification> = ...;
const notificationIds = notificationsToBeRead
    .map((notification) => notification.id);
const newStatus = 'read';
GetSocialSDK.Notifications.setStatus(newStatus, notificationIds)
    .then(() => {
        console.log('Successfully changed notifications status');
    }, (error) => {
        console.log('Failed to change notifications status: ', 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?

😀 🙁