TIMMsgGetMsgList

Introduction

Get history message list

You can specify msg_getmsglist_param_last_msg to get message list from local message list, and msg_getmsglist_param_count is the count of the message list. You can also set msg_getmsglist_param_last_msg as NULL, and it sets the latest message in the conversation as the LastMsg.

If set msg_getmsglist_param_is_ramble as true, it will get cloud messages when local messages are undernumbered.

If set msg_getmsglist_param_is_forward as true, get messages that are newer to msg_getmsglist_param_last_msg, otherwise get messages that are older to msg_getmsglist_param_last_msg.

When get C2C messages, you can only use msg_getmsglist_param_last_msg as the start point, and if you don't specify it, IM SDK sets the latest message in the conversation as the LastMsg.

When get Group messages, you can use msg_getmsglist_param_last_msg or msg_getmsglist_param_last_msgSeq as the start point. The differences are

Use msg_getmsglist_param_last_msg as the start point, returned message list doesn't contain msg_getmsglist_param_last_msg.

Use msg_getmsglist_param_last_msgSeq as the start point, returned message list contains msg_getmsglist_param_last_msgSeq.

When getting Group messages

If specified msg_getmsglist_param_last_msg and msg_getmsglist_param_last_msgSeq, IM SDK prefers msg_getmsglist_param_last_msg as message start point.

If msg_getmsglist_param_last_msg and msg_getmsglist_param_last_msgSeq are all undefined, there are two situations

If set message period, IM SDK will use msg_getmsglist_param_time_begin as the start point.

If doesn't set message period, by default IM SDK will use the latest message in the conversation as the LastMsg.

Parameter details

Parameter name Parameter type Required Description
msgGetMsgListParams MsgGetMsgListParams yes Param of getting history message list

Returned template

Promise<commonResult<Array<Json_value_msg>>>

{
    code: TIMResult | TIMErrCode;
    desc?: string | undefined;
    json_param?: Array<Json_value_msg> | undefined;
    json_params?: Array<Json_value_msg> | undefined; 
    user_data?: string | undefined;
}

Return value details

name type description
code TIMResultTIMErrCode Request result: Error codes. 0 means success.
desc string | undefined The description of the error. It will be empty if success.
json_param Array< Json_value_msg > | undefined Return value of calling API
json_params Array< Json_value_msg > | undefined Return value of calling API. Compatible field, which is returned in some cases.
user_data string | undefined ImSDK is responsible for transporting user-defined data without any processing

Code example

import TimRender from "im_electron_sdk/dist/renderer";
const timRenderInstance = new TimRender();
import { MsgGetMsgListParams, Json_get_msg_param, userProfileCustom, GroupMemberInfoCustemString, GroupMemberInfo, userProfile, Json_value_msg } from "im_electron_sdk/dist/interfaces";
let convId = ''
let convType = 0
let userProfileCustom: userProfileCustom = {
    user_profile_custom_string_info_key: '',
    user_profile_custom_string_info_value: 'string;'
}

let groupMemberCustom: GroupMemberInfoCustemString = {
    group_member_info_custom_string_info_key: '',
    group_member_info_custom_string_info_value: '',
}

let groupMemberInfo: GroupMemberInfo = {
    group_member_info_identifier: '',
    group_member_info_join_time: 0,
    group_member_info_member_role: 0,
    group_member_info_msg_flag: 0,
    group_member_info_msg_seq: 0,
    group_member_info_shutup_time: 0,
    group_member_info_name_card: '',
    group_member_info_custom_info: [groupMemberCustom]
}

let senderProfile: userProfile = {
    user_profile_add_permission: 0,
    user_profile_birthday: 0,
    user_profile_custom_string_array: [userProfileCustom],
    user_profile_face_url: '',
    user_profile_gender: 0,
    user_profile_identifier: '',
    user_profile_language: 0,
    user_profile_level: 0,
    user_profile_location: '',
    user_profile_nick_name: '',
    user_profile_role: 0,
    user_profile_self_signature: '',
}

let last_msg: Json_value_msg = {
    message_elem_array: [{
        elem_type: 1,
        text_elem_content: '',
    }],
    message_conv_id: '',
    message_conv_type: 0,
    message_sender: '',
    message_priority: 0,
    message_client_time: 0,
    message_server_time: 0,
    message_is_from_self: false,
    message_platform: 0,
    message_is_read: false,
    message_is_online_msg: false,
    message_status: 0,
    message_custom_int: 0,
    message_custom_str: '',
    message_is_excluded_from_unread_count: false,
    message_group_at_user_array: [''],
    message_is_forward_message: false,
    message_sender_profile: senderProfile,
    message_sender_group_member_info: groupMemberInfo,
    message_offline_push_config: {}
}
let params: Json_get_msg_param = {
    msg_getmsglist_param_last_msg: last_msg,    // optional
    msg_getmsglist_param_count: 0,    // optional
    msg_getmsglist_param_is_ramble: true,    // optional
    msg_getmsglist_param_is_forward: false,    // optional
    msg_getmsglist_param_last_msg_seq: 0,    // optional
    msg_getmsglist_param_time_begin: 0,    // optional
    msg_getmsglist_param_time_period: 0,    // optional
}

let param: MsgGetMsgListParams = {
    conv_id: convId,    // required
    conv_type: convType,    // required
    params: params,    // required
    user_data: ''     // optional
}

const { code } = await timRenderInstance.TIMMsgGetMsgList(param);
if (code == 0) {
    // success
}

results matching ""

    No results matching ""