Mention in Post
You can mention users in text, image, video and file posts. You can search the display name of the user that you want to mention.
AmityPost contains new properties related to mention feature:
  1. 1.
    metadata
    Dictionary which can contain any information about the post content. Our default structure to represent mentions is inside the metadata property. You can use any structure to represent mentions. The AmityMentionMapper helper class can transform metadata into mentions and vice versa. This class uses our custom structure of representing mentions in text messages.
  2. 2.
    mentionees
    Array of AmityMentionees objects. You can only mention users in a post.

How mention works

You are free to define your own structure to represent mentions. To do this, use the metadata property of AmityPost and store mentions in metadata property.
To help you in this task, the SDK also provides the pre-defined mention structure. You can use our own mention structure by using these classes:
  • AmityMention stores the auxiliary data; attached in a post metadata.
  • AmityMentionMapper A helper class to transform AmityMention into metadata; or to extract AmityMention from metadata.
The following example demonstrate how AmityMentionMapper and AmityMention works in a post.
The function getAttributedString uses AmityMentionMapper to extract AmityMention from metadata, and return the highlighted text.
Get the highlighted text from a post with mention.

Create a mention in post

To create a mention in text, image, video and file post, use this method
The API the create post with mention.
To create a post with mention using our own structure, these are steps:
  1. 1.
    Build a post normally with post builder as mentioned in Create Post.
  2. 2.
    Create metadata containing AmityMention with AmityMentionMapper.
  3. 3.
    Create mentionees with AmityMentioneesBuilder.
  4. 4.
    Pass (1) (2) and (3) into post creation API.
The following code demonstrates how to create a post with mention.
The example of how to create a post with mention.
In this example, we show a text post with mention. However the pattern of adding mention to a post; is the same for all post types. You can change the post builder to the desired post type.

Update post with Mentions

To update a post with mentions, use this method:
The API to update a post with mention.
The following code demonstrates how to update a post with mention.
The example of how to update a post with mention.