“@A @B @C......”
形式显示在输入框,并可以继续编辑消息内容,完成消息发送。
接收方会在会话界面的群聊天列表,重点显示 “有人@我”
或者 “@所有人”
标识,提醒用户有人在群里 @ 自己了。监听 @ 字符选择群成员 | 编辑群 @ 消息发送 | 收到群 @ 消息 |
| | |
V2TIMMessage
,昵称用于在文本框显示。createAtSignedGroupMessage
(Android / iOS & Mac / Windows) 接口创建一条群 @ 消息,拿到消息对象 V2TIMMessage
,并在其中指定需要 @ 的成员。// 创建一条原始文本消息V2TIMMessage textMsg = V2TIMManager.getMessageManager().createTextMessage("这是一条文本消息");// 使用原始文本消息创建一条群 @ 消息,@ 群成员 "user1" 和 "user2"List<String> atUserList = new ArrayList<>();atUserList.add("user1");atUserList.add("user2");V2TIMMessage atMsg = V2TIMManager.getMessageManager().createAtSignedGroupMessage(textMsg, atUserList);// 发送群 @ 消息V2TIMManager.getMessageManager().sendMessage(atMsg, null, "toGroupID", V2TIMMessage.V2TIM_PRIORITY_DEFAULT, false, null, new V2TIMSendCallback<V2TIMMessage>() {@Overridepublic void onError(int code, String desc) {// 群@消息发送失败}@Overridepublic void onSuccess(V2TIMMessage v2TIMMessage) {// 群@消息发送成功}@Overridepublic void onProgress(int progress) {}});
// 创建一条原始文本消息V2TIMMessage *textMsg = [[V2TIMManager sharedInstance] createTextMessage:@"这是一条文本消息"];// 使用原始文本消息创建一条群 @ 消息,@ 群成员 "xixi" 和 "yahaha"V2TIMMessage *atMsg = [[V2TIMManager sharedInstance] createAtSignedGroupMessage:textMsg atUserList:@[@"xixi", @"yahaha"]];// 发送群 @ 消息[[V2TIMManager sharedInstance] sendMessage:atMsg receiver:nil groupID:@"groupA" priority:V2TIM_PRIORITY_NORMAL onlineUserOnly:NO offlinePushInfo:nil progress:nil succ:nil fail:nil];
class SendCallback final : public V2TIMSendCallback {public:using SuccessCallback = std::function<void(const V2TIMMessage&)>;using ErrorCallback = std::function<void(int, const V2TIMString&)>;using ProgressCallback = std::function<void(uint32_t)>;SendCallback() = default;~SendCallback() override = default;void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback,ProgressCallback progress_callback) {success_callback_ = std::move(success_callback);error_callback_ = std::move(error_callback);progress_callback_ = std::move(progress_callback);}void OnSuccess(const V2TIMMessage& message) override {if (success_callback_) {success_callback_(message);}}void OnError(int error_code, const V2TIMString& error_message) override {if (error_callback_) {error_callback_(error_code, error_message);}}void OnProgress(uint32_t progress) override {if (progress_callback_) {progress_callback_(progress);}}private:SuccessCallback success_callback_;ErrorCallback error_callback_;ProgressCallback progress_callback_;};V2TIMStringVector atUserList;atUserList.PushBack("user1");atUserList.PushBack("user2");V2TIMMessage message = V2TIMManager::GetInstance()->GetMessageManager()->CreateTextMessage(u8"这是一条文本消息");V2TIMMessage at_message = V2TIMManager::GetInstance()->GetMessageManager()->CreateAtSignedGroupMessage(message, atUserList);auto callback = new SendCallback{};callback->SetCallback([=](const V2TIMMessage& message) {// 群@消息发送成功delete callback;},[=](int error_code, const V2TIMString& error_message) {// 群@消息发送失败delete callback;},[=](uint32_t progress) {});V2TIMManager::GetInstance()->GetMessageManager()->SendMessage(at_message, "denny", {}, V2TIMMessagePriority::V2TIM_PRIORITY_NORMAL, false, {}, callback);
V2TIMConversation
的 groupAtInfolist
(Android / iOS & Mac / Windows) 接口获取会话的 @ 数据列表。//获取群@数据列表List<V2TIMGroupAtInfo> atInfoList = conversation.getGroupAtInfoList();// 解析@类型(@我,@所有人, @我且@所有人)boolean atMe = false;boolean atAll = false;String atTips = "";for(V2TIMGroupAtInfo atInfo : atInfoList){if (atInfo.getAtType() == V2TIMGroupAtInfo.TIM_AT_ME){atMe = true;continue;}if (atInfo.getAtType() == V2TIMGroupAtInfo.TIM_AT_ALL){atAll = true;continue;}}// 根据@类型,提示if (atMe && !atAll) {atTips = "[有人@我]";} else if (!atMe && atAll) {atTips = "[@所有人]";} else if (atMe && atAll) {atTips = "[有人@我][@所有人]";}
// 获取群@数据列表NSArray<V2TIMGroupAtInfo *> *atInfoList = conversation.groupAtInfolist;// 解析@类型(@我,@所有人, @我且@所有人)BOOL atMe = NO; // 是否@我BOOL atAll = NO; // 是否@所有人NSString *atTipsStr = @"";for (V2TIMGroupAtInfo *atInfo in atInfoList) {switch (atInfo.atType) {case V2TIM_AT_ME:atMe = YES;break;case V2TIM_AT_ALL:atAll = YES;break;case V2TIM_AT_ALL_AT_ME:atMe = YES;atAll = YES;break;default:break;}}// 根据@类型,提示if (atMe && !atAll) {atTipsStr = @"[有人@我]";}if (!atMe && atAll) {atTipsStr = @"[@所有人]";}if (atMe && atAll) {atTipsStr = @"[有人@我][@所有人]";}
// 获取群@数据列表V2TIMGroupAtInfoVector groupAtInfolist = conversation.groupAtInfolist;// 解析@类型(@我,@所有人, @我且@所有人)bool atMe = false;bool atAll = false;std::string atTips = "";for (size_t i = 0; i < groupAtInfolist.Size(); ++i) {const V2TIMGroupAtInfo& atInfo = groupAtInfolist[i];switch (atInfo.atType) {case V2TIM_AT_ME:atMe = true;break;case V2TIM_AT_ALL:atAll = true;break;case V2TIM_AT_ALL_AT_ME:atMe = true;atAll = true;break;default:break;}}// 根据@类型,提示if (atMe && !atAll) {atTips = u8"[有人@我]";} else if (!atMe && atAll) {atTips = u8"[@所有人]";} else if (atMe && atAll) {atTips = u8"[有人@我][@所有人]";}
本页内容是否解决了您的问题?