有奖捉虫:办公协同&微信生态&物联网文档专题 HOT

功能描述

群 @ 消息就是发送方监听输入栏里的输入字符,当用户输入 @ 字符后,弹出群成员选择界面。选择完需要 @ 的成员后以 “@A @B @C......” 形式显示在输入框,并可以继续编辑消息内容,完成消息发送。 接收方会在会话界面的群聊天列表,重点显示 “有人@我” 或者 “@所有人” 标识,提醒用户有人在群里 @ 自己了。
说明
目前仅支持文本 @ 消息。

发送群 @ 消息

1. 发送方监听聊天界面的文本输入框,启动群成员选择界面。选择完成后回传选择群成员的 ID 和昵称信息,ID 用来构建消息对象 Message,昵称用来在文本框显示。
2. 发送方调用 MsgSendMessage (点击查看详情) 接口创建一条 @ 文本消息,创建消息对象 Message,并在其中指定需要 @ 的成员,然后将刚才创建的 @ 消息对象发送出去。
示例代码如下:
// 创建群@消息
var message = new Message
{
message_conv_id = conv_id,
message_conv_type = TIMConvType.kTIMConv_Group,
message_elem_array = new List<Elem>{new Elem
{
elem_type = TIMElemType.kTIMElem_Text,
text_elem_content = Input.text
}},
message_group_at_user_array = userid_list, //群消息中被 @ 的用户 UserID 列表,如果需要 @ALL ,请传入 kImSDK_MesssageAtALL 字段
};
StringBuilder messageId = new StringBuilder(128);
TIMResult res = TencentIMSDK.MsgSendMessage(conv_id, TIMConvType.kTIMConv_Group, message, messageId, (int code, string desc, string json_param, string user_data)=>{
// 消息发送异步结果
});

接收群 @ 消息

1. 在加载和更新会话处,需要调用 ConvInfoconv_group_at_info_array (点击查看详情) 接口获取会话的 @ 数据列表。
2. 通过列表中 GroupAtInfo 对象的 conv_group_at_info_at_type (点击查看详情) 接口获取 @ 数据类型,并更新到当前会话的 @ 信息。
示例代码如下:
TIMResult res = TencentIMSDK.ConvGetConvList((int code, string desc, List<ConvInfo> info_list, string user_data)=>{
foreach (ConvInfo info in info_list)
{
foreach (GroupAtInfo at_info in info.conv_group_at_info_array)
{
if (at_info.conv_group_at_info_at_type == TIMGroupAtType.kTIMGroup_At_Me) {
// @ 我
}
if (at_info.conv_group_at_info_at_type == TIMGroupAtType.kTIMGroup_At_All) {
// @ 群里所有人
}
if (at_info.conv_group_at_info_at_type == TIMGroupAtType.kTIMGroup_At_All_At_ME) {
// @ 群里所有人并且单独 @ 我
}
}
}
});

交流与反馈

点此进入IM社群,享有专业工程师的支持,解决您的难题