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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
}
}
});
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Update Bookmark

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

1
2
3
4
5
6
7
8
9
10
11
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
}
}
});
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Retrieve Bookmarks

There are a few ways to retrieve bookmarks.

To retrieve a list of bookmarks:

1
2
3
4
5
6
7
8
9
10
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
}
}
});
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

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

1
2
3
4
5
6
7
8
9
10
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
}
}
});
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Delete Bookmark

This final example shows how to delete a bookmark:

1
2
3
4
5
6
7
8
9
10
11
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
}
}
});
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX