属性 | 含义 | 说明 |
groupID | 群ID | 置顶/取消置顶的群聊ID |
message | 消息对象 | 消息必须是发送成功的状态。 |
isPinned | 置顶/取消置顶 | 设置群消息是否置顶。 |
V2TIMManager.getMessageManager().pinGroupMessage(groupID, message, true, new V2TIMCallback() {@Overridepublic void onSuccess() {// 消息置顶成功}@Overridepublic void onError(int code, String desc) {// 消息置顶失败}});
[[V2TIMManager sharedInstance] pinGroupMessage:self.groupID message:message isPinned:YES succ:^{// 消息置顶成功} fail:^(int code, NSString *desc) {// 消息置顶失败}];
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([=]() {// 消息置顶成功delete callback;},[=](int error_code, const V2TIMString &error_message) {// 消息置顶失败delete callback;});V2TIMManager::GetInstance()->GetMessageManager()->PinGroupMessage(groupID, message, true, callback);
属性 | 含义 | 说明 |
groupID | 群ID | 需要获取置顶消息列表的群聊ID |
V2TIMManager.getMessageManager().getPinnedGroupMessageList(groupID, new V2TIMValueCallback<List<V2TIMMessage>>() {@Overridepublic void onSuccess(List<V2TIMMessage> v2TIMMessages) {// 获取置顶消息列表成功}@Overridepublic void onError(int code, String desc) {// 获取置顶消息列表失败}});
[[V2TIMManager sharedInstance] getPinnedGroupMessageList:self.groupID succ:^(NSArray<V2TIMMessage *> *messageList) {// 获取置顶消息列表成功} fail:^(int code, NSString *desc) {// 获取置顶消息列表失败}];
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) {// 获取置顶消息列表成功delete callback;},[=](int error_code, const V2TIMString& error_message) {// 获取置顶消息列表失败delete callback;});V2TIMManager::GetInstance()->GetMessageManager()->GetPinnedGroupMessageList(groupID, callback);
addAdvancedMsgListener
添加了高级消息事件监听器,当置顶消息列表发生了更新,您会收onGroupMessagePinned
V2TIMManager.getMessageManager().addAdvancedMsgListener(new V2TIMAdvancedMsgListener() {@Overridepublic void onGroupMessagePinned(String groupID, V2TIMMessage message, boolean isPinned, V2TIMGroupMemberInfo opUser) {// 收到置顶消息列表变更的通知}});
[[V2TIMManager sharedInstance] addAdvancedMsgListener:self];- (void)onGroupMessagePinned:(NSString *)groupID message:(V2TIMMessage *)message isPinned:(BOOL)isPinned opUser:(V2TIMGroupMemberInfo *)opUser {// 收到置顶消息列表变更的通知}
V2TIMManager::GetInstance()->GetMessageManager()->AddAdvancedMsgListener(this);void OnGroupMessagePinned(const V2TIMString &groupID, const V2TIMMessage &message,bool isPinned, const V2TIMGroupMemberInfo &opUser) override {// 收到置顶消息列表变更的通知}
本页内容是否解决了您的问题?