/ SDKs / Unity
SDKs
Chat SDKs Unity v4
Chat SDKs Unity
Chat SDKs
Unity
Version 4

Update a message

Copy link

A user can update any of their own text and file messages sent using SbUserMessageUpdateParams and SbFileMessageUpdateParams. An error is returned if a user attempts to update another user's messages. In addition, channel operators can update any messages sent in a channel.

// Update a user message.
SbUserMessageUpdateParams userMessageUpdateParams = new SbUserMessageUpdateParams
{
    Message = NEW_TEXT_MESSAGE,
    CustomType = NEW_CUSTOM_TYPE,
    Data = NEW_DATA
};

channel.UpdateUserMessage(MESSAGE_ID, userMessageUpdateParams, (inMessage, inError) =>
{
    if (inError != null)
        return; // Handle error.

    // The message is successfully updated.
    // You can check if the update operation has been performed correctly.
});

// Update a file message.
SbFileMessageUpdateParams fileMessageUpdateParams = new SbFileMessageUpdateParams
{
    CustomType = NEW_CUSTOM_TYPE
};

channel.UpdateFileMessage(FILE_MESSAGE_ID, fileMessageUpdateParams, (inMessage, inError) =>
{
    if (inError != null)
        return; // Handle error.

    // The message is successfully updated.
    // You can check if the update operation has been performed correctly.
});

If a message is updated, the OnMessageUpdated() method in the channel event handler is invoked on all users' devices except the one that updated the message.

SbGroupChannelHandler channelHandler = new SbGroupChannelHandler
{
    OnMessageUpdated = (inChannel, inMessage) => 
    {
        // Handle the message update here.
    }
};

SendbirdChat.GroupChannel.AddGroupChannelHandler(UNIQUE_HANDLER_ID, channelHandler);