MsgSendMessageReadReceipts
introduction
Send message read receipts
If a message sender wants to know who has or has not read the message, the sender needs to enable the message read receipt feature.
After this feature is enabled, the sender can set whether a message requires a read receipt when sending the message; if yes, the sender will receive a receipt after the message is read by the receiver.
Read receipts are supported for both one-to-one and group messages in the same way.
Specifying a group type for which to support message read receipts:
Log in to the IM console, select Feature Configuration > Login and Message > Group Message Read Receipts.
Once success, total unread count will not change, but the message sender will receive MsgReadedReceiptCallback, which includes the read receipts info.
After receiving the message, the receiver determines whether the message requires a read receipt based on the message_need_read_receipt field in Message. If yes, after the user reads the message, the receiver calls the MsgSendMessageReadReceipts to send a read receipt.
Ultimate package only. Buy Ultimate package to enable this feature.
Only support C2C or Group message. When calling on group messages, messages in msg_array must belong to the same group conversation.
Parameter details
overload1
Parameter name | Parameter type | Required | Description |
---|---|---|---|
msg_array | List< Message > | Required | Message list |
callback | NullValueCallback | Required | Asynchronous callback |
overload2
Parameter name | Parameter type | Required | Description |
---|---|---|---|
msg_array | List< Message > | Required | Message list |
callback | ValueCallback< string > | Required | Asynchronous callback The format of json_param in the return value is string |
Returned template
TIMResult
The parameters of the callback function after successfully calling the API:
code:int
desc:string
json_param:'' // json_ Params is an empty string ""
user_data:string
Return value details
name | type | description |
---|---|---|
TIMResult | TIMResult | Return value of calling API |
code | int | Result error code: Error Codes |
desc | string | The description of the error. |
json_param | string | Json string. Calling different API will get different Json strings. |
user_data | string | User-defined data transfered by ImSDK without any processing |
Code example
using UnityEngine;
using UnityEngine.UI;
using com.tencent.im.unity.demo.types;
using com.tencent.imsdk.unity;
using com.tencent.imsdk.unity.types;
using com.tencent.imsdk.unity.enums;
using System;
using com.tencent.im.unity.demo.utils;
using EasyUI.Toast;
using System.Collections;
using System.Text;
using System.Collections.Generic;
public class MsgSendMessageReadReceipts : MonoBehaviour
{
string[] Labels = new string[] { "SelectGroupLabel" };
public Text Header;
public Dropdown SelectedGroup;
public Text Result;
public Button Submit;
public Button Copy;
private List<string> GroupList;
void Start()
{
foreach (string label in Labels)
{
GameObject.Find(label).GetComponent<Text>().text = Utils.t(label);
}
GroupGetJoinedGroupListSDK();
Header = GameObject.Find("HeaderText").GetComponent<Text>();
SelectedGroup = GameObject.Find("Group").GetComponent<Dropdown>();
Result = GameObject.Find("ResultText").GetComponent<Text>();
Submit = GameObject.Find("Submit").GetComponent<Button>();
Copy = GameObject.Find("Copy").GetComponent<Button>();
Submit.onClick.AddListener(MsgGetMsgListSDK);
Copy.GetComponentInChildren<Text>().text = Utils.t("Copy");
Copy.onClick.AddListener(CopyText);
if (CurrentSceneInfo.info != null)
{
Header.text = Utils.IsCn() ? CurrentSceneInfo.info.apiText + " " + CurrentSceneInfo.info.apiName : CurrentSceneInfo.info.apiName;
Submit.GetComponentInChildren<Text>().text = CurrentSceneInfo.info.apiName;
}
}
void GetGroupList(params object[] parameters)
{
try
{
GroupList = new List<string>();
SelectedGroup.ClearOptions();
string text = (string)parameters[1];
List<GroupBaseInfo> List = Utils.FromJson<List<GroupBaseInfo>>(text);
foreach (GroupBaseInfo item in List)
{
print(item.group_base_info_group_id);
GroupList.Add(item.group_base_info_group_id);
var option = new Dropdown.OptionData();
option.text = item.group_base_info_group_id;
SelectedGroup.options.Add(option);
}
if (List.Count > 0)
{
SelectedGroup.captionText.text = List[SelectedGroup.value].group_base_info_group_id;
}
else
{
SelectedGroup.captionText.text = "";
}
}
catch (Exception ex)
{
Toast.Show(Utils.t("getGroupListFailed"));
}
}
void HandleMsgListRes(params object[] parameters)
{
try
{
string text = (string)parameters[1];
List<Message> msg_list = Utils.FromJson<List<Message>>(text);
print($"msg_list: {parameters[1]}");
MsgSendMessageReadReceiptsSDK(msg_list);
}
catch (Exception ex)
{
Toast.Show(Utils.t("getMsgListFailed"));
}
}
void MsgGetMsgListSDK()
{
var get_message_list_param = new MsgGetMsgListParam
{
msg_getmsglist_param_count = 20
};
print(GroupList[SelectedGroup.value]);
TIMResult res = TencentIMSDK.MsgGetMsgList(GroupList[SelectedGroup.value], TIMConvType.kTIMConv_Group, get_message_list_param, Utils.addAsyncStringDataToScreen(HandleMsgListRes));
}
void GroupGetJoinedGroupListSDK()
{
TIMResult res = TencentIMSDK.GroupGetJoinedGroupList(Utils.addAsyncStringDataToScreen(GetGroupList));
print($"GroupGetJoinedGroupListSDK {res}");
}
void MsgSendMessageReadReceiptsSDK(List<Message> msg_list)
{
print(GroupList[SelectedGroup.value]);
if (msg_list.Count < 1)
{
Toast.Show("No Message Found");
return;
}
TIMResult res = TencentIMSDK.MsgSendMessageReadReceipts(msg_list, Utils.addAsyncNullDataToScreen(GetResult));
Result.text = Utils.SynchronizeResult(res);
}
void GetResult(params object[] parameters)
{
Result.text += (string)parameters[0];
}
void CopyText()
{
Utils.Copy(Result.text);
}
void OnApplicationQuit()
{
TencentIMSDK.Uninit();
}
}