IMSDK
IM features a comprehensive suite of solutions including global access, one-to-one chat, group chat, message push, profile and relationship chain hosting, and account authentication. It also provides complete app access and backend management APIs.
V2TIMManager+Conversationabstract
Swift - V2TIMManager
Swift

Extensions on V2TIMManager

Methods

add​Conversation​Listener(listener:​)

public func addConversationListener(listener: V2TIMConversationListener)  

1.1 Add the conversation listener

remove​Conversation​Listener(listener:​)

public func removeConversationListener(listener: V2TIMConversationListener)  

1.2 Remove the conversation listener

get​Conversation​List(next​Seq:​count:​succ:​fail:​)

public func getConversationList(nextSeq: UInt, count: Int32, succ: @escaping V2TIMConversationResultSucc, fail: @escaping V2TIMFail)  

1.3 Get the conversation list

  • Each conversation corresponds to a chat window. For example, a one-to-one chat or a chat group is a conversation.

  • Since there may be a large number of historical conversations, you are advised to call this API in query-by-page mode and pull 100 historical conversations per page at a time.

  • This API pulls locally cached conversations. If conversations on the server are updated, the SDK automatically synchronizes the updates internally and then notifies users via @ref V2TIMConversationListener callback.

  • If all conversations are pulled, the value of the isFinished field in V2TIMConversationResult in the success callback is true.

  • For 5.5.892 and later versions, conversations on the conversion list obtained by this API are sorted by orderKey by default. The larger the orderKey value, the higher the order of the conversation.

  • For versions earlier than 5.5.892, conversations on the conversion list obtained by this API are sorted by "lastMessage -> timestamp" by default. The later the timestamp, the higher the order of the conversation.

Parameters

next​Seq UInt

Pulling-by-page cursor. It is set to 0 when the information is pulled for the first time. The value of this field in the callback for the current paginated pulling is passed in for the next pull.

count Int32

Number of conversations pulled per page. The value of this field cannot be too large; otherwise, the pulling speed is affected. We recommend that you pull 100 conversations per page.

get​Conversation(conversation​ID:​succ:​fail:​)

public func getConversation(conversationID: String, succ: @escaping V2TIMConversationSucc, fail: @escaping V2TIMFail)  

1.4 Get a single conversation

Parameters

conversation​ID String

Unique ID of a conversation. For one-to-one chats, the value format is String.format("c2c_%s", "userID"). For group chats, the value format is String.format("group_%s", "groupID").

get​Conversation​List(conversation​IDList:​succ:​fail:​)

public func getConversationList(conversationIDList: Array<String>, succ: @escaping V2TIMConversationListSucc, fail: @escaping V2TIMFail)  

1.5 Get a specified conversation list

Parameters

conversation​IDList Array<String>

List of the unique IDs of conversations. For one-to-one chats, the value format is String.format("c2c_%s", "userID"). For group chats, the value format is String.format("group_%s", "groupID").

get​Conversation​List​ByFilter(filter:​next​Seq:​count:​succ:​fail:​)

public func getConversationListByFilter(filter: V2TIMConversationListFilter, nextSeq:UInt, count:UInt, succ: @escaping V2TIMConversationResultSucc, fail: @escaping V2TIMFail)  

1.6 Get the conversation list (advanced API,supported only in 6.5 and later versions)

Parameters

filter V2TIMConversation​List​Filter

conversation filter

next​Seq UInt

The next pulling-by-page cursor

count UInt

Number of conversations to be pulled

delete​Conversation(conversation:​succ:​fail:​)

public func deleteConversation(conversation: String, succ: V2TIMSucc?, fail: V2TIMFail?)  

1.7 Delete a conversation

  • When a conversation is deleted from local storage, it is also deleted from the server.

  • When messages in a conversation are deleted from local storage, they are also deleted from the server.

Parameters

conversation​ID

Unique ID of a conversation. For one-to-one chats, the value format is String.format("c2c_%s", "userID"). For group chats, the value format is String.format("group_%s", "groupID").

delete​Conversation​List(conversation​IDList:​clear​Message:​succ:​fail:​)

public func deleteConversationList(conversationIDList: Array<String>, clearMessage: Bool, succ: V2TIMConversationOperationResultSucc?, fail: V2TIMFail?)  

1.8 Delete the conversation list (Supported only in 7.1 and later versions)

Parameters

conversation​IDList Array<String>

List of the unique IDs of conversations. For one-to-one chats, the value format is String.format("c2c_%s", "userID"). For group chats, the value format is String.format("group_%s", "groupID").

clear​Message Bool

Whether to delete messages in the conversation; when set to false, retain the messages; when set to true, the local and server messages will be deleted together and cannot be reverted.

set​Conversation​Draft(conversation​ID:​draft​Text:​succ:​fail:​)

public func setConversationDraft(conversationID: String, draftText: String?, succ: V2TIMSucc?, fail: V2TIMFail?)  

1.9 Set a draft for a conversation

  • Drafts are stored only locally and are not stored on the server. Therefore, drafts cannot be synchronized across multiple devices. If the app is uninstalled and reinstalled, drafts become invalid.

Parameters

conversation​ID String

Unique ID of a conversation. For one-to-one chats, the value format is String.format("c2c_%s", "userID"). For group chats, the value format is String.format("group_%s", "groupID").

draft​Text String?

Draft content. The value null indicates cancelling the draft.

set​Conversation​Custom​Data(conversation​IDList:​custom​Data:​succ:​fail:​)

public func setConversationCustomData(conversationIDList: Array<String>, customData: Data?, succ: V2TIMConversationOperationResultSucc?, fail: V2TIMFail?)  

1.10 Set conversation custom data(supported only in 6.5 and later versions)

Parameters

custom​Data Data?

Maximum support 256 bytes

pin​Conversation(conversation​ID:​is​Pinned:​succ:​fail:​)

public func pinConversation(conversationID: String, isPinned: Bool, succ: V2TIMSucc?, fail: V2TIMFail?)  

1.11 Pin a conversion to the top (supported only in 5.3.425 and later versions)

Parameters

conversation​ID String

Unique ID of a conversation. For one-to-one chats, the value format is String.format("c2c_%s", "userID"). For group chats, the value format is String.format("group_%s", "groupID").

is​Pinned Bool

Whether to pin a conversation to the top

mark​Conversation(conversation​IDList:​mark​Type:​enable​Mark:​succ:​fail:​)

public func markConversation(conversationIDList: Array<String>, markType: V2TIMConversationMarkType, enableMark: Bool, succ: V2TIMConversationOperationResultSucc?, fail: V2TIMFail?)  

1.12 Mark conversation(supported only in 6.5 and later versions, need to buy Flagship Edition)

If the existing mark does not meet your needs, you can customize the extension mark. The extension mark needs to meet the following two conditions:

1、Extended mark values ​​must not conflict with existing mark values ​​in TIIMConversationMarkType.

2、Extended mark values must be 0x1LL << n (32 <= n < 64, that is, n must be greater than or equal to 32 and less than 64), such as the extension mark value 0x1LL << 32 means "iPhone online". - Parameters: - conversationIDList : conversation list - markType : mark type of the conversation. For the value, see the V2TIMConversationMarkType definition. - enableMark : true:mark false:unmark - Warning: The extension mark value cannot be set to 0x1 << 32, it must be set to 0x1LL << 32, which explicitly tells the compiler that it is a 64-bit integer constant.

get​Total​Unread​Message​Count(succ:​fail:​)

public func getTotalUnreadMessageCount(succ: @escaping V2TIMTotalUnreadMessageCountSucc, fail: @escaping V2TIMFail)  

1.13 Get the total message unread count in conversations (supported only in 5.3.425 and later versions)

  • The total unread message count excludes the unread message count of Do-Not-Disturb conversations (conversations whose message receiving option is V2TIMMessage.V2TIM_NOT_RECEIVE_MESSAGE or V2TIMMessage.V2TIM_RECEIVE_NOT_NOTIFY_MESSAGE).

get​Unread​Message​Count​ByFilter(filter:​succ:​fail:​)

public func getUnreadMessageCountByFilter(filter: V2TIMConversationListFilter, succ: @escaping V2TIMTotalUnreadMessageCountSucc, fail: @escaping V2TIMFail)  

1.14 Get the total message unread count of conversations by filter (supported only in 7.0 and later versions)

  • The total unread message count excludes the unread message count of Do-Not-Disturb conversations (conversations whose message receiving option is V2TIMMessage.V2TIM_NOT_RECEIVE_MESSAGE or V2TIMMessage.V2TIM_RECEIVE_NOT_NOTIFY_MESSAGE).

Parameters

filter V2TIMConversation​List​Filter

conversation filter

subscribe​Unread​Message​Count​ByFilter(filter:​)

public func subscribeUnreadMessageCountByFilter(filter: V2TIMConversationListFilter)  

1.15 Subscribe changing notification of total unread message count for conversations specified by filter parameter.(supported only in 7.0 and later versions)

  • After you call this API, the newest value of total unread message count for conversations that match the filter parameter will be notified to you through the onUnreadMessageCountChangedByFilter callback.

Parameters

filter V2TIMConversation​List​Filter

conversation filter

unsubscribe​Unread​Message​Count​ByFilter(filter:​)

public func unsubscribeUnreadMessageCountByFilter(filter: V2TIMConversationListFilter)  

1.16 Unsubscribe changing notification of total unread message count for conversations specified by filter parameter.(supported only in 7.0 and later versions)

Parameters

filter V2TIMConversation​List​Filter

conversation filter

clean​Conversation​Unread​Message​Count(conversation​ID:​clean​Timestamp:​clean​Sequence:​succ:​fail:​)

public func cleanConversationUnreadMessageCount(conversationID: String?, cleanTimestamp: UInt64, cleanSequence: UInt64, succ: V2TIMSucc?, fail: V2TIMFail?)  

1.17 Clean up the unread message count of the conversation (supported only in 7.1 and later versions)

  • When you want to clear unread messages count of all one-on-one conversations, please input conversationID with value "c2c", i.e., don't specify the userID;

  • When you want to clear unread messages count of all group conversations, please input conversationID with value "group", i.e., don't specify the groupID;

  • When you want to clear unread messages count of all conversations,please input conversationID with value "" or nil;

  • After the API is successfully called, you will receive the onConversationChanged callback that carries the latest unread message number of the corresponding conversation.

Parameters

conversation​ID String?

Unique ID of a conversation. For one-to-one chats, the value format is String.format("c2c_%s", "userID"). For group chats, the value format is String.format("group_%s", "groupID").

clean​Timestamp UInt64

The specified timestamp in seconds that needs to be cleared (only valid for one-to-one chats). The count of unread messages before the specified timestamp will be cleared, and when the value is 0, all unread messages of the corresponding conversation will be cleared, and the unread message count of the corresponding conversation will be set to 0 ;

clean​Sequence UInt64

The specified sequence that needs to be cleared (only valid for group chats). The count of unread messages before the specified sequence will be cleared, and when the value is 0, all unread messages of the corresponding conversation will be cleared, and the unread message count of the corresponding conversation will be set to 0 ;

create​Conversation​Group(group​Name:​conversation​IDList:​succ:​fail:​)

public func createConversationGroup(groupName: String, conversationIDList: Array<String>, succ: @escaping V2TIMConversationOperationResultSucc, fail: @escaping V2TIMFail)  

2.1 Create a conversation group.

Parameters

group​Name String

group name(Required parameters, length must be greater than 0, maximum support 32 bytes)

conversation​IDList Array<String>

conversation ID list(Required parameters,can not be empty)

get​Conversation​Group​List(succ:​fail:​)

public func getConversationGroupList(succ: @escaping V2TIMConversationGroupListSucc, fail: @escaping V2TIMFail)  

2.2 Get a list of conversation groups.

delete​Conversation​Group(group​Name:​succ:​fail:​)

public func deleteConversationGroup(groupName: String, succ: V2TIMSucc?, fail: V2TIMFail?)  

2.3 Delete a conversation group.

rename​Conversation​Group(old​Name:​new​Name:​succ:​fail:​)

public func renameConversationGroup(oldName: String, newName: String, succ: V2TIMSucc?, fail: V2TIMFail?)  

2.4 Rename a conversation group.

add​Conversations​ToGroup(group​Name:​conversation​IDList:​succ:​fail:​)

public func addConversationsToGroup(groupName: String, conversationIDList: Array<String>, succ: V2TIMConversationOperationResultSucc?, fail: V2TIMFail?)  

2.5 Add conversation list to a group.

delete​Conversations​From​Group(group​Name:​conversation​IDList:​succ:​fail:​)

public func deleteConversationsFromGroup(groupName: String, conversationIDList: Array<String>, succ: V2TIMConversationOperationResultSucc?, fail: V2TIMFail?)  

2.6 Delete conversation list from a group.