---
source_url: https://www.pubnub.com/docs/chat/swift-chat-sdk/build/features/messages/reactions
title: Reactions
updated_at: 2026-06-16T12:48:54.241Z
---

> Documentation Index
> For a curated overview of PubNub documentation, see: https://www.pubnub.com/docs/llms.txt
> For the full list of all documentation pages, see: https://www.pubnub.com/docs/llms-full.txt


# Reactions

Manage emoji reactions on messages in your Chat SDK app. Users can add, remove, and view reactions on any message.

:::note Message Actions vs. Message Reactions
**Message Actions** is the flexible, low-level API for adding any metadata to messages (read receipts, delivery confirmations, custom data), while **Message Reactions** specifically refers to using Message Actions for emoji/social reactions.
In PubNub [Core](https://www.pubnub.com/docs/sdks) and [Chat](https://www.pubnub.com/docs/chat/overview) SDKs, the same underlying Message Actions API is referred to as **Message Reactions** when used for emoji reactions - it's the same functionality, just different terminology depending on the use case.
:::

## Add & delete

`toggleReaction()` is a method for both adding and removing message reactions. It adds a string flag to the message if the current user hasn't added it yet or removes it if the current user already added it before.

Use this method for emoji reactions in your app's UI or for other purposes like marking a message as pinned to a channel if you implement the [pinning feature](https://www.pubnub.com/docs/chat/swift-chat-sdk/build/features/messages/pinned).

### Method signature

This method takes the following parameters:

```swift
message.toggleReaction(
    reaction: String
) async throws -> MessageImpl
```

#### Input

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| reaction | String | Yes |  | Emoji added to the message or removed from it by the current user. |

#### Output

| Parameter | Description |
| --- | --- |
| `MessageImpl` | Updated message instance with an added `reactions` action type. |

### Sample code

:::tip Sample code
The code samples in Swift Chat SDK focus on asynchronous code execution.
You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.
:::

Add the "thumb up" emoji (`\u{1F44D}`) to the last message on the `support` channel.

```swift
// Assumes a "ChatImpl" reference named "chat"
Task {
  if let channel = try await chat.getChannel(channelId: "support") {
    if let message = try await channel.getHistory(count: 1).messages.first {
      let updatedMessage = try await message.toggleReaction(reaction: "\u{1F44D}")
      debugPrint("Reaction added successfully to message: \(updatedMessage)")
    } else {
      debugPrint("No messages found in history")
    }
  } else {
    debugPrint("Channel not found")
  }
}
```

## Get updates

To learn how to receive updates whenever a message reaction is added, edited, or removed on other clients, head to the [Get updates](https://www.pubnub.com/docs/chat/swift-chat-sdk/build/features/messages/updates#get-message-updates) section.

## Get reactions for one message

`reactions` is a property that returns a list of all reactions added to the given message. Each reaction is a `MessageReaction` struct containing the reaction value, whether the current user added it, the list of user IDs, and the count.

```swift
public struct MessageReaction {
    public let value: String
    public let isMine: Bool
    public let userIds: [String]
    public var count: Int { userIds.count }
}
```

### Sample code

:::tip Sample code
The code samples in Swift Chat SDK focus on asynchronous code execution.
You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.
:::

List all reactions added to the last message on the `support` channel.

```swift
// Assumes a "ChatImpl" reference named "chat"
Task {
  if let channel = try await chat.getChannel(channelId: "support") {
    if let message = try await channel.getHistory(count: 1).messages.first {
      debugPrint("Reactions for the latest message: \(message.reactions)")
    } else {
      debugPrint("No messages found in history")
    }
  } else {
    debugPrint("Channel not found")
  }
}
```

## Get historical reactions

If you have [Message Persistence](https://www.pubnub.com/docs/sdks/swift/api-reference/storage-and-playback) enabled on your keyset, PubNub stores all historical info about messages, their metadata, and reactions.

If you want to fetch historical info about message reactions, use the [getHistory()](https://www.pubnub.com/docs/chat/swift-chat-sdk/build/features/messages/history) method. By default, when you fetch historical messages, PubNub returns all message reactions and metadata attached to the retrieved messages.

## Check

`hasUserReaction()` checks if the current user added a given emoji to the message.

### Method signature

This method takes the following parameters:

```swift
message.hasUserReaction(reaction: String) -> Bool
```

#### Input

| Parameter | Description |
| --- | --- |
| `reaction` *Type: `String`Default: n/a | Specific emoji added to the message. |

#### Output

| Parameter | Description |
| --- | --- |
| `Bool` | Specifies if the current user added a given emoji to the message or not. |

### Sample code

:::tip Sample code
The code samples in Swift Chat SDK focus on asynchronous code execution.
You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.
:::

Check if the current user added the "thumb up" emoji (👍) to the last message on the `support` channel.

```swift
// Assumes a "ChatImpl" reference named "chat"
Task {
  if let channel = try await chat.getChannel(channelId: "support") {
    if let message = try await channel.getHistory(count: 1).messages.first {
      if message.hasUserReaction(reaction: "\u{1F44D}") {
        print("The current user has added the 'thumb up' emoji to the latest message.")
      } else {
        print("The current user has not added the 'thumb up' emoji to the latest message.")
      }
    } else {
      debugPrint("No messages found in history")
    }
  } else {
    debugPrint("Channel not found")
  }
}
```