/ SDKs / .NET
SDKs
Chat SDKs .NET v4
Chat SDKs .NET
Chat SDKs
.NET
Version 4

Manage channel metadata

Copy link

You can store additional information to channels such as background color or channel description with channel metadata, which can be fetched or rendered into the UI. Channel metadata is Dictionary<string, string> and it can be stored into a Channel object.


Create metadata

Copy link

To store channel metadata into a channel object, create a new object of key-value items in which the data type of the key and value is Dictionary<string, string>. Then, pass the object as an argument to a parameter when calling the CreateMetaData() method. You can put multiple key-value items in the dictionary.

Dictionary<string, string> metaData = new Dictionary<string, string>
{
    { "key1", "value1" },
    { "key2", "value2" }
};

channel.CreateMetaData(metaData, (inMetaData, inError) =>
{
    if (inError != null)
        return; // Handle error.
});

Update metadata

Copy link

The process of updating channel metadata is the same as creating one. Values of existing keys can be updated and values of new keys can be added by calling the UpdateMetaData method.

Dictionary<string, string> metaData = new Dictionary<string, string>
{
    { "key1", "valueToUpdate1" }, // Updates an existing item with new value.
    { "key3", "valueToUpdate3" }  // Adds a new key-value item.
};

channel.UpdateMetaData(metaData, (inMetaData, inError) =>
{
    if (inError != null)
        return; // Handle error.
});

Retrieve metadata

Copy link

You can retrieve channel metadata by creating a List<string> of keys to retrieve and passing it as an argument to a parameter in the GetMetaData() method. A Dictionary<string, string> collection is returned in the result with the corresponding key-value items.

channel.GetMetaData(new List<string> {"key1", "key2"}, (inMetaData, inError) =>
{
    if (inError != null)
        return; // Handle error.
});

Retrieve cached metadata

Copy link

When Sendbird Chat SDK detects any of the create, read, update, and delete operations on the channel metadata, the SDK caches the metadata. The cached metadata is also updated whenever a channel list is fetched.

You can retrieve the cached metadata through the CachedMetaData() method without having to query the server.

IReadOnlyDictionary<string, string> cachedMetaData = channel.CachedMetaData;

Delete metadata

Copy link

You can delete channel metadata through the DeleteMetaData() method as shown below.

channel.DeleteMetaData("key1", inError =>
{
    if (inError != null)
        return; // Handle error.
});