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:
MMXMessage message = … ;
MMXChannel channel = … ;
Map<String, String> extra = new HashMap<>();
extra.put("messageId", message.getId());
MMXBookmark.create(name,
BookmarkObjectType.CHANNEL, channel().getIdentifier(),
message.getPublishDate(),
extra,
new MaxCoreActionCallback<MMXBookmark>() {
@Override
public void onResult(boolean isSuccess, Throwable error, MMXBookmark result) {
if (isSuccess) {
// success
} else {
// failed to create bookmark
}
}
});
Update Bookmark
We now have successfully bookmarked the message. Here's how to update it:
MMXBookmark bookmark = … ;
MMXBookmark.update(bookmark, new MaxCoreActionCallback<MMXBookmark>() {
@Override
public void onResult(boolean isSuccess, Throwable error, MMXBookmark result) {
if (isSuccess) {
// success
} else {
// failed to update bookmark
}
}
});
Retrieve Bookmarks
There are a few ways to retrieve bookmarks.
To retrieve a list of bookmarks:
MMXBookmark.get(BookmarkObjectType.CHANNEL, new MaxCoreActionCallback<List<MMXBookmark>>() {
@Override
public void onResult(boolean isSuccess, Throwable error, List<MMXBookmark> result) {
if (isSuccess) {
// success
} else {
// failed to retrieve bookmark
}
}
});
To retrieve bookmarks by object ID (in this case, channel ID):
MMXBookmark.get(BookmarkObjectType.CHANNEL, "ChannelID", new MaxCoreActionCallback<List<MMXBookmark>>() {
@Override
public void onResult(boolean isSuccess, Throwable error, List<MMXBookmark> result){
if (isSuccess) {
// success
} else {
// failed to retrieve bookmark
}
}
});
Delete Bookmark
This final example shows how to delete a bookmark:
MMXBookmark bookmark = … ;
MMXBookmark.delete(bookmark, new MaxCoreActionCallback<MMXBookmark>() {
@Override
public void onResult(boolean isSuccess, Throwable throwable, MMXBookmark mmxBookmark) {
if (isSuccess) {
// success
} else {
// failed to remove the bookmark
}
}
});