Bookmarks

Magnet Max allows developers to add bookmarks to channels. These bookmarks can be used to reference or tag important items in a channel. A common use case is bookmarking messages. This allows a user to quickly find messages. Bookmarks can be used to bookmark attachments as well. For the examples below we will focus on bookmarking messages.

Add Bookmark

A bookmark simply stores a reference to an object; the reference can be retrieved later on as needed. Let’s say we already have a message. We can add a reference to it:

var myChannel = ...; var message = ...; var bookmark = new Max.Bookmark({ objectType: Max.Bookmark.ObjectType.CHANNEL, objectId: myChannel.getChannelId(), objectTime: message.timestamp, name: "MyBookmark", extras: { messageId: message.messageId, content: (message.messageContent && message.messageContent.message) ? message.messageContent.message : '', sender: message.sender.userId, displayName: message.sender.displayName } }); // create a new bookmark object Max.Bookmark.create(bookmark).success(function(newBookmark) { // do something with newBookmark object });

Update Bookmark

We now have successfully bookmarked the message. Here's how to update it:

var myBookmark=...; Max.Bookmark.create(bookmark).success(function(myBookmark) { // do something with updated bookmark object });

Retrieve Bookmarks

There are a few ways to retrieve bookmarks.

To retrieve a list of bookmarks:

Max.Bookmark.get(Max.Bookmark.ObjectType.CHANNEL, myChannel.getChannelId()).success(function(bookmarks) { // do something with bookmarks list }).error(function(err) { // handle error on failure });

To retrieve bookmarks by object ID (in this case, channel ID):

var myChannel = ...; Max.Bookmark.getByObjectId(Max.Bookmark.ObjectType.CHANNEL, myChannel.getChannelId()).success(function(bookmarks) { // do something with bookmarks list }).error(function(err) { // handle error on failure });
To retrieve a bookmark by bookmark name:

var myChannel = ...; Max.Bookmark.getByName(Max.Bookmark.ObjectType.CHANNEL, myChannel.getChannelId(), "bookmarkName").success(function(bookmarks) { // do something with bookmark object }).error(function(err) { // handle error on failure });

Delete Bookmark

This final example shows how to delete a bookmark:

var bookmarkId = ...; Max.Bookmark.delete(bookmarkId).success(function() { // bookmark deleted }).error(function(err) { // handle error on failure });