Pin Message
Extension settings
- Login to CometChat and select your app.
- Go to the Extensions section and enable the Pin message extension.
How does it work?
Pin message extension provides you the ability to:
- Pin messages
- Unpin messages
- Fetch all the pinned messages for a conversation.
Messages pinned in a conversation (be it one-on-one or group) are visible to the receiver(s) as well.
1. Pin a message
To pin a message, use the callExtension
method provided by the SDK to make an HTTP POST request with the parameters as shown below.
You need to pass the msgId
that has to be pinned.
- Javascript
- Java
- Swift
CometChat.callExtension('pin-message', 'POST', 'v1/pin', {
"msgId": 280 // The ID of the message to be pinned. Here 280.
}).then(response => {
// { success: true }
})
.catch(error => {
// Error occurred
});
import org.json.simple.JSONObject;
JSONObject body=new JSONObject();
body.put("msgId", 280);
CometChat.callExtension("pin-message", "POST", "/v1/pin", body,
new CometChat.CallbackListener < JSONObject > () {
@Override
public void onSuccess(JSONObject jsonObject) {
//On Success
}
@Override
public void onError(CometChatException e) {
//On Failure
}
});
CometChat.callExtension(slug: "pin-message", type: .post, endPoint: "v1/pin", body: ["msgId": 280] as [String : Any], onSuccess: { (response) in
// Success
}) { (error) in
// Error occured
}
2. Unpin a message
To unpin a message, use the callExtension
method provided by the SDK to make an HTTP DELETE request with the parameters as shown below.
You need to pass the msgId
, receiverType
and the receiver
(can be either UID or GUID based on receiverType
).
- Javascript
- Java
- Swift
CometChat.callExtension('pin-message', 'DELETE', 'v1/unpin', {
"msgId": 111,
"receiverType": "group",
"receiver": "supergroup"
}).then(response => {
// { success: true }
})
.catch(error => {
// Error occurred
});
import org.json.simple.JSONObject;
JSONObject body=new JSONObject();
body.put("msgId", 111);
body.put("receiverType", "group");
body.put("receiver", "supergroup");
CometChat.callExtension("pin-message", "DELETE", "/v1/unpin", body,
new CometChat.CallbackListener < JSONObject > () {
@Override
public void onSuccess(JSONObject jsonObject) {
//On Success
}
@Override
public void onError(CometChatException e) {
//On Failure
}
});
CometChat.callExtension(slug: "pin-message", type: .delete, endPoint: "v1/unpin", body: ["msgId": 111, "receiverType": "group", "receiver": "supergroup"] as [String : Any], onSuccess: { (response) in
// Success
}) { (error) in
// Error occured
}
3. Fetch pinned messages
To fetch the pinned messages for a conversation, use the callExtension
method provided by the SDK to make an HTTP GET request with the query parameters as shown below.
You need to pass the receiverType
and the receiver
(can be either UID or GUID based on receiverType
).
- Javascript
- Java
- Swift
const URL = `v1/fetch?receiverType=${RECEIVER_TYPE}&receiver=${RECEIVER}`;
CometChat.callExtension('pin-message', 'GET', URL, null).then(response => {
// {pinnedMessages: []}
})
.catch(error => {
// Error occured
});
String URL = "/v1/fetch?receiverType=" + RECEIVER_TYPE + "&receiver=" + RECEIVER;
CometChat.callExtension("pin-message", "GET", URL, null,
new CometChat.CallbackListener < JSONObject > () {
@Override
public void onSuccess(JSONObject jsonObject) {
// {pinnedMessages: []}
}
@Override
public void onError(CometChatException e) {
// Some error occured
}
});
CometChat.callExtension(slug: "pin-message", type: .get, endPoint: "v1/fetch?receiverType=\(RECEIVER_TYPE)&receiver=\(RECEIVER)", body: nil, onSuccess: { (response) in
// {pinnedMessages: []}
}) { (error) in
// Some error occured
}
}