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:

let bookmark = MMXBookmark(name: "MyBookmark", objectID:message.channel!.channelID!, extras: ["messageContent": message.messageContent["text"]!, "messageId": message.messageID!]) MMXBookmark.createBookmark(bookmark, success: { bookmark in print("created bookmark") }, failure: { error in print(error.localizedDescription) })

Update Bookmark

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

MMXBookmark.updateBookmark(bookmark, success: { bookmark in print("updated bookmark") }, failure: { error in print(error.localizedDescription) })

Retrieve Bookmarks

There are a few ways to retrieve bookmarks.

To retrieve a list of bookmarks:

MMXBookmark.bookmarksByObjectType(.CHANNEL, success: { bookmarks in print("bookmarks") }, failure: { error in print("\(error.localizedDescription)") })

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

MMXBookmark.bookmarksByObjectID(.CHANNEL, objectID: "ChannelID", success: { bookmarks in print("bookmarks") }, failure: { error in print("\(error.localizedDescription)") })

Delete Bookmark

This final example shows how to delete a bookmark:

MMXBookmark.deleteBookmark("BookmarkID", success: { bookmarks in print("bookmark deleted") }, failure: { error in print("\(error.localizedDescription)") })