一、功能描述
注意:说明:
注意:目前仅支持文本 @ 消息。
二、发送群 @ 消息
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. 在加载和更新会话处,需要调用 ConvInfo 的 conv_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) { // @ 群里所有人并且单独 @ 我 } } }});