PinGroupMessage
API (Android/iOS and macOS/Windows) can set a message to be pinned at the top.Attribute | Meaning | Description |
groupID | Group ID | Indicates the ID of the group chat that requires message pinning/unpinning. |
message | Message object | The message must have been sent successfully. |
isPinned | Pinning/Unpinning action | Specifies whether to pin or unpin group messages. |
V2TIMManager.getMessageManager().pinGroupMessage(groupID, message, true, new V2TIMCallback() {@Overridepublic void onSuccess() {// Message pinning succeeded.}@Overridepublic void onError(int code, String desc) {// Message pinning failed.}});
[[V2TIMManager sharedInstance] pinGroupMessage:self.groupID message:message isPinned:YES succ:^{// Message pinning succeeded.} fail:^(int code, NSString *desc) {// Message pinning failed.}];
class Callback final : public V2TIMCallback {public:using SuccessCallback = std::function<void()>;using ErrorCallback = std::function<void(int, const V2TIMString &)>;Callback() = default;~Callback() override = default;void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {success_callback_ = std::move(success_callback);error_callback_ = std::move(error_callback);}void OnSuccess() override {if (success_callback_) {success_callback_();}}void OnError(int error_code, const V2TIMString & error_message) override {if (error_callback_) {error_callback_(error_code, error_message);}}private:SuccessCallback success_callback_;ErrorCallback error_callback_;};auto *callback = new Callback{};callback->SetCallback([=]() {// Message pinning succeeded.delete callback;},[=](int error_code, const V2TIMString & error_message) {// Message pinning failed.delete callback;});V2TIMManager::GetInstance()->GetMessageManager()->PinGroupMessage(groupID, message, true, callback);
GetPinnedGroupMessageList
API (Android/iOS and macOS/Windows) can obtain the pinned message list.Attribute | Meaning | Description |
groupID | Group ID | Indicates the ID of the group chat for which the pinned message list needs to be obtained. |
V2TIMManager.getMessageManager().getPinnedGroupMessageList(groupID, new V2TIMValueCallback<List<V2TIMMessage>>() {@Overridepublic void onSuccess(List<V2TIMMessage> v2TIMMessages) {// Succeeded in obtaining the pinned message list.}@Overridepublic void onError(int code, String desc) {// Failed to obtain the pinned message list.}});
[[V2TIMManager sharedInstance] getPinnedGroupMessageList:self.groupID succ:^(NSArray<V2TIMMessage *> *messageList) {// Succeeded in obtaining the pinned message list.} fail:^(int code, NSString *desc) {// Failed to obtain the pinned message list.}];
template <class T>class ValueCallback final : public V2TIMValueCallback<T> {public:using SuccessCallback = std::function<void(const T&)>;using ErrorCallback = std::function<void(int, const V2TIMString&)>;ValueCallback() = default;~ValueCallback() override = default;void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {success_callback_ = std::move(success_callback);error_callback_ = std::move(error_callback);}void OnSuccess(const T& value) override {if (success_callback_) {success_callback_(value);}}void OnError(int error_code, const V2TIMString & error_message) override {if (error_callback_) {error_callback_(error_code, error_message);}}private:SuccessCallback success_callback_;ErrorCallback error_callback_;};auto callback = new ValueCallback<V2TIMMessageVector>{};callback->SetCallback([=](const V2TIMMessageVector& messageVector) {// Succeeded in obtaining the pinned message list.delete callback;},[=](int error_code, const V2TIMString & error_message) {// Failed to obtain the pinned message list.delete callback;});V2TIMManager::GetInstance()->GetMessageManager()->GetPinnedGroupMessageList(groupID, callback);
addAdvancedMsgListener
, you will receive the onGroupMessagePinned
(Android/iOS and macOS/Windows) callback when the pinned message list is updated.V2TIMManager.getMessageManager().addAdvancedMsgListener(new V2TIMAdvancedMsgListener() {@Overridepublic void onGroupMessagePinned(String groupID, V2TIMMessage message, boolean isPinned, V2TIMGroupMemberInfo opUser) {// Receives notification of changes to the pinned message list.}});
[[V2TIMManager sharedInstance] addAdvancedMsgListener:self];- (void)onGroupMessagePinned:(NSString *)groupID message:(V2TIMMessage *)message isPinned:(BOOL)isPinned opUser:(V2TIMGroupMemberInfo *)opUser {// Receives notification of changes to the pinned message list.}
V2TIMManager::GetInstance()->GetMessageManager()->AddAdvancedMsgListener(this);void OnGroupMessagePinned(const V2TIMString &groupID, const V2TIMMessage &message,bool isPinned, const V2TIMGroupMemberInfo &opUser) override {// Receives notification of changes to the pinned message list.}
Was this page helpful?