Mute functionality

Learn how to enable your users to mute notifications for certain conversations

You can silence one-on-one and/or group conversations for a specific amount of time using the Mute functionality. Aside from that, you can include a Push Notifications section in your apps' settings.
Your users can use this feature to turn off Push Notifications for certain chats or to opt-out of receiving Push Notifications altogether.

Mute or Unmute Chats

Chat comprises anything related to messages like:

  1. New Message (Text, media, or Custom messages like Polls)
  2. Edited Message
  3. Deleted Message
  4. Response in threads

Mute Chats

You can specify the UIDs and/or GUIDs to be muted. You can mute chats for these conversations for a specific amount of time.

Parameters

Value

Description

uids

Array of UIDs

This parameter allows you to mute one-on-one chat for the mentioned UIDs.

guids

Array of GUIDs

This parameter allows you to mute group chat for the mentioned GUIDs.

timeInMS

String consisting of UNIX timestamp.

This parameter allows you to mute chats for a specific amount of time for the required UIDs or GUIDs
After the mentioned duration, the Push Notifications are received.
Eg: "1628425767881"

This functionality uses the callExtension() method provided by CometChat Pro SDK.

CometChat.callExtension('push-notification', 'POST', 'v1/mute-chat', {
    "uids": ["superhero1"],
    "guids": ["supergroup"],
    "timeInMS": "1628610749081"
}).then(response => {
    // Success
})
.catch(error => {
    // Error occured
});
import org.json.simple.JSONObject;

JSONObject body=new JSONObject();
JSONArray uids = new JSONArray();
JSONArray guids = new JSONArray();

uids.add("superhero1");
guids.add("supergroup");

body.put("uids", uids);
body.put("guids", guids);
body.put("timeInMS", "1628425767881");

CometChat.callExtension("push-notification", "POST", "/v1/mute-chat", body,
 new CometChat.CallbackListener < JSONObject > () {
    @Override
    public void onSuccess(JSONObject jsonObject) {
        //On Success
    }
    @Override
    public void onError(CometChatException e) {
        //On Failure
    }
});
CometChat.callExtension(slug: "push-notification", type: .post, endPoint: "v1/mute-chat", body: ["uids":["superhero1"], "guids":["supergroup"], "timeInMS":"1628610749081"] as [String : Any], onSuccess: { (response) in
         // Success
      }) { (error) in
         // Error occured
      }

Unmute Chats

Used to unmute the chats for certain conversations before the mentioned time during muting.

Parameters

Value

Description

uids

Array of UIDs

This parameter allows you to unmute one-on-one chat for the mentioned UIDs.

guids

Array of GUIDs

This parameter allows you to unmute group chat for the mentioned GUIDs.

This functionality uses the callExtension() method provided by CometChat Pro SDK.

CometChat.callExtension('push-notification', 'POST', 'v1/unmute-chat', {
    "uids": ["superhero1"],
    "guids": ["supergroup"]
}).then(response => {
    // Success
})
.catch(error => {
    // Error occured
});
import org.json.simple.JSONObject;

JSONObject body=new JSONObject();
JSONArray uids = new JSONArray();
JSONArray guids = new JSONArray();

uids.add("superhero1");
guids.add("supergroup");

body.put("uids", uids);
body.put("guids", guids);

CometChat.callExtension("push-notification", "POST", "/v1/unmute-chat", body,
 new CometChat.CallbackListener < JSONObject > () {
    @Override
    public void onSuccess(JSONObject jsonObject) {
        //On Success
    }
    @Override
    public void onError(CometChatException e) {
        //On Failure
    }
});
CometChat.callExtension(slug: "push-notification", type: .post, endPoint: "v1/unmute-chat", body: ["uids":["superhero1"], "guids":["supergroup"]] as [String : Any], onSuccess: { (response) in
         // Success
      }) { (error) in
         // Error occured
      }

Mute or Unmute Calls

You can mute the notifications for one-on-one or group calls. This works for Default calling (video or audio calls) offered by CometChat.

Mute Calls

You can specify the UIDs and/or GUIDs to be muted. You can mute calls for these conversations for the said amount of time.

Parameters

Value

Description

uids

Array of UIDs

This parameter allows you to mute one-on-one calls for the mentioned UIDs.

guids

Array of GUIDs

This parameter allows you to unmute group calls for the mentioned GUIDs.

timeInMS

String consisting of UNIX timestamp.

This parameter allows you to mute calls for a specific amount of time for the required UIDs or GUIDs
After the mentioned duration, the Push Notifications are received.
Eg: "1628425767881"

This functionality uses the callExtension() method provided by CometChat Pro SDK.

CometChat.callExtension('push-notification', 'POST', 'v1/mute-calls', {
    "uids": ["superhero1"],
    "guids": ["supergroup"],
    "timeInMS": "1628610749081"
}).then(response => {
    // Success
})
.catch(error => {
    // Error occured
});
import org.json.simple.JSONObject;

JSONObject body=new JSONObject();
JSONArray uids = new JSONArray();
JSONArray guids = new JSONArray();

uids.add("superhero1");
guids.add("supergroup");

body.put("uids", uids);
body.put("guids", guids);
body.put("timeInMS", "1628425767881");

CometChat.callExtension("push-notification", "POST", "/v1/mute-calls", body,
 new CometChat.CallbackListener < JSONObject > () {
    @Override
    public void onSuccess(JSONObject jsonObject) {
        //On Success
    }
    @Override
    public void onError(CometChatException e) {
        //On Failure
    }
});
CometChat.callExtension(slug: "push-notification", type: .post, endPoint: "v1/mute-calls", body: ["uids":["superhero1"], "guids":["supergroup"], "timeInMS":"1628610749081"] as [String : Any], onSuccess: { (response) in
         // Success
      }) { (error) in
         // Error occured
      }

Unmute Calls

Used to unmute calls for certain conversations before the mentioned time during muting.

Parameters

Value

Description

uids

Array of UIDs

This parameter allows you to unmute one-on-one calls for the mentioned UIDs.

guids

Array of GUIDs

This parameter allows you to unmute group chat for the mentioned GUIDs.

This functionality uses the callExtension() method provided by CometChat Pro SDK.

CometChat.callExtension('push-notification', 'POST', 'v1/unmute-calls', {
    "uids": ["superhero1"],
    "guids": ["supergroup"]
}).then(response => {
    // Success
})
.catch(error => {
    // Error occured
});
import org.json.simple.JSONObject;

JSONObject body=new JSONObject();
JSONArray uids = new JSONArray();
JSONArray guids = new JSONArray();

uids.add("superhero1");
guids.add("supergroup");

body.put("uids", uids);
body.put("guids", guids);

CometChat.callExtension("push-notification", "POST", "/v1/unmute-calls", body,
 new CometChat.CallbackListener < JSONObject > () {
    @Override
    public void onSuccess(JSONObject jsonObject) {
        //On Success
    }
    @Override
    public void onError(CometChatException e) {
        //On Failure
    }
});
CometChat.callExtension(slug: "push-notification", type: .post, endPoint: "v1/unmute-calls", body: ["uids":["superhero1"], "guids":["supergroup"]] as [String : Any], onSuccess: { (response) in
         // Success
      }) { (error) in
         // Error occured
      }

User settings

Apart from the feature to mute/unmute a set of UIDs or GUIDs using the above APIs, apps can have push notifications according to the user settings.

The following user settings can be set:

Settings

Description

Do Not Disturb

When turned ON, the "Do Not Disturb" parameter disables the Push Notifications entirely for the user. The user stops receiving push notifications until this setting is explicitly turned OFF. This overrides all the following settings.

Allow only Mentions

Until turned OFF, the notifications are only sent for text messages for the mentioned receiver of the message

Mute all one-on-one chat

This parameter can be used to mute chat notifications for all one-on-one conversations. The user will not receive push notifications until this is turned OFF.

Mute all group chat

This parameter can be used to mute chat notifications for all group conversations. The user will not receive push notifications until the parameter is turned OFF.

Mute all one-on-one calls

This preference can be used to mute call notifications for all one-on-one conversations. The user will not receive push notifications until the parameter is turned OFF.

Mute all group calls

This parameter can be used to mute call notifications for all group conversations. The user will not receive push notifications until this is turned OFF.

Save User Settings

The User settings object needs to be submitted as follows. All the fields are mandatory:

{
    "user-settings": {
        "dnd": true/false,
        "chat": {
            "allow_only_mentions": true/false,
            "mute_group_actions": true/false,
            "mute_all_guids": true/false,
            "mute_all_uids": true/false
        },
        "call": {
            "mute_all_guids": true/false,
            "mute_all_uids":true/false
        }
    }
}

This functionality uses the callExtension() method provided by CometChat Pro SDK.

CometChat.callExtension('push-notification', 'POST', 'v1/user-settings', {
    "user-settings": {
        "dnd": true/false,
        "chat": {
            "allow_only_mentions": true/false,
            "mute_group_actions": true/false,
            "mute_all_guids": true/false,
            "mute_all_uids": true/false
        },
        "call": {
            "mute_all_guids": true/false,
            "mute_all_uids":true/false
        }
    }
}).then(response => {
    // Success
})
.catch(error => {
    // Error occured
});
import org.json.simple.JSONObject;

JSONObject body = new JSONObject();
JSONObject chat = new JSONObject();
JSONObject call = new JSONObject();

chat.put("allow_only_mentions", true);
chat.put("mute_group_actions": false);
chat.put("mute_all_guids": true);
chat.put("mute_all_uids": false);

call.put("mute_all_guids": true);
call.put("mute_all_uids": false);

body.put("dnd", false);
body.put("chat", chat);
body.put("call", call);

CometChat.callExtension("push-notification", "POST", "/v1/user-settings", body,
 new CometChat.CallbackListener < JSONObject > () {
    @Override
    public void onSuccess(JSONObject jsonObject) {
        //On Success
    }
    @Override
    public void onError(CometChatException e) {
        //On Failure
    }
});
CometChat.callExtension(slug: "push-notification", type: .post, endPoint: "v1/user-settings", body:
    "user-settings": [
        "dnd": false,
        "chat": [
            "allow_only_mentions": true,
            "mute_group_actions": false,
            "mute_all_guids": true,
            "mute_all_uids": false
        ],
        "call": [
            "mute_all_guids": true,
            "mute_all_uids": false
        ]
    ] as [String : Any], onSuccess: { (response) in
         // Success
      }) { (error) in
         // Error occured
      }

Fetch User settings

Fetches all the user settings that are saved by the user. This also returns the list of muted UIDs and GUIDs along with the said time for muting.

This functionality uses the callExtension() method provided by CometChat Pro SDK.

CometChat.callExtension('push-notification', 'GET', 'v1/user-settings', null).then(response => {
    // Success
})
.catch(error => {
    // Error occured
});
CometChat.callExtension("push-notification", "GET", "/v1/user-settings", null,
 new CometChat.CallbackListener < JSONObject > () {
    @Override
    public void onSuccess(JSONObject jsonObject) {
        //On Success
    }
    @Override
    public void onError(CometChatException e) {
        //On Failure
    }
});
CometChat.callExtension(slug: "push-notification", type: .get, endPoint: "v1/user-settings", body: nil, onSuccess: { (response) in
         // Success
      }) { (error) in
         // Error occured
      }

Did this page help you?