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:
MMXBookmark *bookmark = [[MMXBookmark alloc] initWithName:@"MyBookmark" objectID:message.channel.channelID extras:@{@"messageContent": message.messageContent[@"text"], @"messageId": message.messageID}];
[MMXBookmark createBookmark:bookmark success:^(MMXBookmark * bookmark) {
NSLog(@"created bookmark");
} failure:^(NSError * error) {
NSLog(@"%@", error.localizedDescription);
}];
Update Bookmark
We now have successfully bookmarked the message. Here's how to update it:
[MMXBookmark updateBookmark:bookmark success:^(MMXBookmark * bookmark) {
NSLog(@"updated bookmark");
} failure:^(NSError * error) {
NSLog(@"%@", error.localizedDescription);
}];
Retrieve Bookmarks
There are a few ways to retrieve bookmarks.
To retrieve a list of bookmarks:
[MMXBookmark bookmarksByObjectType:MMXBookmarkObjectTypeCHANNEL success:^(NSArray<MMXBookmark *> * bookmarks) {
NSLog(@"bookmarks");
} failure:^(NSError * error) {
NSLog(@"%@", error.localizedDescription);
}];
To retrieve bookmarks by object ID (in this case, channel ID):
[MMXBookmark bookmarksByObjectID:MMXBookmarkObjectTypeCHANNEL objectID:@"ChannelID" success:^(NSArray<MMXBookmark *> * bookmarks) {
NSLog(@"bookmarks");
} failure:^(NSError * error) {
NSLog(@"%@", error.localizedDescription);
}];
Delete Bookmark
This final example shows how to delete a bookmark:
[MMXBookmark deleteBookmark:@"BookmarkID" success:^{
NSLog(@"bookmark deleted");
} failure:^(NSError * error) {
NSLog(@"%@", error.localizedDescription);
}];