# User Mentions

## Overview

You can mention users in both **activities** and **comments**. When you include `mentioned_user_ids`, the API stores the mentions and returns enriched `mentioned_users` in the response. Optionally, you can create [notification activities](https://getstream.io/activity-feeds/docs/java/notification-feeds/) for mentioned users or [send push notifications](https://getstream.io/docs/platform/push-notifications/).

## Adding user mentions

`mentioned_user_ids` can only contain existing user ids, you can use [`queryUsers` endpoint](https://getstream.io/docs/platform/users/#filter-examples) to search for users to mention.

Please note that it's up to you to include user mentions (for example @Alice) in the activity/comment text, the Stream API won't modify these fields based on `mentioned_user_ids`.

### Adding an activity with mentions

```java label="Java"
AddActivityRequest request = AddActivityRequest.builder()
    .feeds(List.of("user:eric"))
    .type("post")
    .text("Hey @bob and @alice, check this out!")
    .userID("eric")
    .mentionedUserIDs(List.of("bob", "alice"))
    .createNotificationActivity(true)
    .build();

AddActivityResponse response = client.feeds().addActivity(request).execute().getData();
// response.getActivity().getMentionedUsers() contains enriched user objects
```

### Adding a comment with mentions

```java label="Java"
AddCommentRequest request = AddCommentRequest.builder()
    .comment("Thanks @bob for the tip!")
    .objectID("activity_123")
    .objectType("activity")
    .userID("alice")
    .mentionedUserIDs(List.of("bob"))
    .createNotificationActivity(true)
    .build();

AddCommentResponse response = feeds.addComment(request).execute().getData();
// response.getComment().getMentionedUsers() contains enriched user objects
```

## Reading mentioned users

Activities and comments returned by the API include a `mentioned_users` array with enriched user objects (id, name, image, etc.). Use them to render @mentions in your UI.

```java label="Java"
// From activities
GetOrCreateFeedResponse response = feed.getOrCreate().execute().getData();
response.getActivities().forEach(activity -> {
  if (activity.getMentionedUsers() != null && !activity.getMentionedUsers().isEmpty()) {
    String names = activity.getMentionedUsers().stream()
        .map(UserResponse::getName)
        .collect(Collectors.joining(", "));
    System.out.println("Mentioned: " + names);
  }
});
// From comments
GetActivityResponse activityResponse = client.feeds().getActivity(activityId).withRecentReplies(10).execute().getData();
activityResponse.getActivity().getLatestReplies().forEach(comment -> {
  if (comment.getMentionedUsers() != null && !comment.getMentionedUsers().isEmpty()) {
    String names = comment.getMentionedUsers().stream()
        .map(UserResponse::getName)
        .collect(Collectors.joining(", "));
    System.out.println("Comment mentioned: " + names);
  }
});
```

## Mentions in notification feed

- **Activities:** When `create_notification_activity` is `true`, each mentioned user receives a `mention` notification in their notification feed.
- **Comments:** When `create_notification_activity` is `true`, each mentioned user receives a `comment_mention` notification (the activity author does not get an extra notification for mentions; they already get a comment notification).

For updating or deleting activities/comments and managing mention notifications (e.g. `handle_mention_notifications`, `delete_notification_activity`), see [Notification feeds](https://getstream.io/activity-feeds/docs/java/notification-feeds/).

## Push notifications

Use the `skip_push` parameter to control if push notifications are sent to mentioned users or not. For more information check the [Push notification guide](https://getstream.io/docs/platform/push-notifications/) that contains all relevant information about setting up push notification providers, customizing notifications and user preferences.

---

For the most recent version of this documentation, visit [https://getstream.io/activity-feeds/docs/java/user-mentions/](https://getstream.io/activity-feeds/docs/java/user-mentions/).