HyphenateChatSDK 4.5.0
构造函数 | 属性 | 所有成员列表
EMConversation类 参考

#import <EMConversation.h>

类 EMConversation 继承关系图:

构造函数

(EMChatMessage *_Nullable) - lastReceivedMessage
 
(void) - insertMessage:error:
 
(void) - appendMessage:error:
 
(void) - deleteMessageWithId:error:
 
(void) - deleteAllMessages:
 
(void) - removeMessagesFromServerMessageIds:completion:
 
(void) - removeMessagesFromServerWithTimeStamp:completion:
 
(void) - updateMessageChange:error:
 
(void) - markMessageAsReadWithId:error:
 
(void) - markAllMessagesAsRead:
 
(NSArray< EMChatMessage * > *_Nullable) - pinnedMessages
 
(EMChatMessage *_Nullable) - loadMessageWithId:error:
 
(NSArray< EMChatMessage * > *_Nullable) - loadMessagesStartFromId:count:searchDirection:
 
(void) - loadMessagesStartFromId:count:searchDirection:completion:
 
(NSArray< EMChatMessage * > *_Nullable) - loadMessagesWithType:timestamp:count:fromUser:searchDirection:
 
(void) - loadMessagesWithType:timestamp:count:fromUser:searchDirection:completion:
 
(NSArray< EMChatMessage * > *_Nullable) - loadMessagesWithKeyword:timestamp:count:fromUser:searchDirection:
 
(void) - loadMessagesWithKeyword:timestamp:count:fromUser:searchDirection:completion:
 
(void) - loadMessagesWithKeyword:timestamp:count:fromUser:searchDirection:scope:completion:
 
(NSArray< EMChatMessage * > *_Nullable) - loadCustomMsgWithKeyword:timestamp:count:fromUser:searchDirection:
 
(void) - loadCustomMsgWithKeyword:timestamp:count:fromUser:searchDirection:completion:
 
(NSArray< EMChatMessage * > *_Nullable) - loadMessagesFrom:to:count:
 
(void) - loadMessagesFrom:to:count:completion:
 
(EMError *_Nullable) - removeMessagesStart:to:
 

属性

NSString * conversationId
 
EMConversationType type
 
int unreadMessagesCount
 
int messagesCount
 
NSDictionary * ext
 
BOOL isChatThread
 
BOOL isPinned
 
int64_t pinnedTime
 
EMChatMessagelatestMessage
 
NSArray< NSNumber * > * marks
 

详细描述

聊天会话类。

函数文档

◆ appendMessage:error:

- (void) appendMessage: (EMChatMessage *_Nonnull)  aMessage
error: (EMError **_Nullable)  pError 

插入一条消息到 SDK 本地数据库会话尾部。

消息的 conversationId 应该和会话的 conversationId 一致。

消息会被插入 SDK 本地数据库,并且更新会话的 latestMessage 等属性。

参数
aMessage消息实例。
pError错误信息。

◆ deleteAllMessages:

- (void) deleteAllMessages: (EMError **_Nullable)  pError

清除内存和数据库中指定会话中的消息。

参数
pError错误信息。

◆ deleteMessageWithId:error:

- (void) deleteMessageWithId: (NSString *_Nonnull)  aMessageId
error: (EMError **_Nullable)  pError 

从 SDK 本地数据库删除一条消息。

参数
aMessageId要删除的 ID。
pError错误信息。

◆ insertMessage:error:

- (void) insertMessage: (EMChatMessage *_Nonnull)  aMessage
error: (EMError **_Nullable)  pError 

插入一条消息在 SDK 本地数据库

消息的会话 ID 应与会话的 ID 保持一致。

消息会根据消息里的时间戳被插入 SDK 本地数据库,SDK 会更新会话的 latestMessage 等属性。

参数
aMessage消息实例。
pError错误信息。

◆ lastReceivedMessage

- (EMChatMessage *_Nullable) lastReceivedMessage

收到的对方发送的最后一条消息。

返回
消息实例。

◆ loadCustomMsgWithKeyword:timestamp:count:fromUser:searchDirection:

- (NSArray< EMChatMessage * > *_Nullable) loadCustomMsgWithKeyword: (NSString *)  aKeyword
timestamp: (long long)  aTimestamp
count: (int)  aCount
fromUser: (NSString *_Nullable)  aSender
searchDirection: (EMMessageSearchDirection)  aDirection 

从本地数据库获取会话中的指定用户发送的包含特定关键词的自定义消息。

同步方法,会阻塞当前线程。

参数
aKeywords关键词。设为 NIL 表示忽略该参数。
aTimestamp传入的时间戳,单位为毫秒。如果该参数设置的时间戳为负数,则从最新消息向前获取。
aCount每次获取的消息条数。如果设为小于等于 0,SDK 会获取 1 条消息。
aSender消息发送方。设为 NIL 表示忽略该参数。
aDirection消息搜索方向,详见 EMMessageSearchDirection
返回
消息列表。

◆ loadCustomMsgWithKeyword:timestamp:count:fromUser:searchDirection:completion:

- (void) loadCustomMsgWithKeyword: (NSString *_Nullable)  aKeyword
timestamp: (long long)  aTimestamp
count: (int)  aCount
fromUser: (NSString *_Nullable)  aSender
searchDirection: (EMMessageSearchDirection)  aDirection
completion: (void(^)(NSArray< EMChatMessage * > *_Nullable aMessages, EMError *_Nullable aError))  aCompletionBlock 

从本地数据库获取会话中的指定用户发送的包含特定关键词的自定义消息。

参数
aKeywords关键词。设为 NIL 表示忽略该参数。
aTimestamp传入的 Unix 时间戳,单位为毫秒。如果该参数设置的时间戳为负数,则从最新消息向前获取。
aCount每次获取的消息条数。如果设为小于等于 0,SDK 会获取 1 条消息。
aSender消息发送方。设为 NIL 表示忽略该参数。
aDirection消息搜索方向,详见 EMMessageSearchDirection
aCompletionBlock该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。

◆ loadMessagesFrom:to:count:

- (NSArray< EMChatMessage * > *_Nullable) loadMessagesFrom: (long long)  aStartTimestamp
to: (long long)  aEndTimestamp
count: (int)  aCount 

从本地数据库中搜索指定时间段内发送或接收的一定数量的消息。

该方法返回的消息按时间正序排列。

同步方法,会阻塞当前线程。

参数
aStartTimestamp搜索的起始时间戳。单位为毫秒。
aEndTimestamp搜索的结束时间戳。单位为毫秒。
aCount每次获取的消息条数。如果设为小于等于 0,SDK 会获取 1 条消息。
返回
消息列表。

◆ loadMessagesFrom:to:count:completion:

- (void) loadMessagesFrom: (long long)  aStartTimestamp
to: (long long)  aEndTimestamp
count: (int)  aCount
completion: (void(^)(NSArray< EMChatMessage * > *_Nullable aMessages, EMError *_Nullable aError))  aCompletionBlock 

从本地数据库中搜索指定时间段内发送或接收的一定数量的消息。

参数
aStartTimestamp搜索的起始时间戳。单位为毫秒。
aEndTimestamp搜索的结束时间戳。单位为毫秒。
aCount每次获取的消息条数。如果设为小于等于 0,SDK 会获取 1 条消息。
aCompletionBlock该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。

◆ loadMessagesStartFromId:count:searchDirection:

- (NSArray< EMChatMessage * > *_Nullable) loadMessagesStartFromId: (NSString *_Nullable)  aMessageId
count: (int)  aCount
searchDirection: (EMMessageSearchDirection)  aDirection 

从 SDK 本地数据库获取指定数量的消息。

同步方法,会阻塞当前线程。

参数
aMessageId查询的起始消息 ID。该参数设置后,SDK 从指定的消息 ID 开始按消息检索方向加载。 如果传入消息的 ID 为空,SDK 忽略该参数,按搜索方向查询消息:
  • aDirectionUP,SDK 从最新消息开始,按消息时间戳的倒序获取;
  • aDirectionDOWN,SDK 从最早消息开始,按消息时间戳的正序获取。
aCount每次获取的消息条数。如果设为小于等于 0,SDK 获取 1 条消息。
aDirection消息搜索方向,详见 EMMessageSearchDirection
返回
消息列表。

◆ loadMessagesStartFromId:count:searchDirection:completion:

- (void) loadMessagesStartFromId: (NSString *_Nullable)  aMessageId
count: (int)  aCount
searchDirection: (EMMessageSearchDirection)  aDirection
completion: (void(^)(NSArray< EMChatMessage * > *_Nullable aMessages, EMError *_Nullable aError))  aCompletionBlock 

从 SDK 本地数据库获取指定数量的消息。

参数
aMessageId查询的起始消息 ID。该参数设置后,SDK 从指定的消息 ID 开始按消息检索方向加载。 如果传入消息的 ID 为空,SDK 忽略该参数,按搜索方向查询消息:
  • aDirectionUP,SDK 从最新消息开始,按消息时间戳的倒序获取;
  • aDirectionDOWN,SDK 从最早消息开始,按消息时间戳的正序获取。
aCount每次获取的消息条数。如果设为小于等于 0,SDK 获取 1 条消息。
aDirection消息搜索方向,详见 EMMessageSearchDirection
aCompletionBlock该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。

◆ loadMessagesWithKeyword:timestamp:count:fromUser:searchDirection:

- (NSArray< EMChatMessage * > *_Nullable) loadMessagesWithKeyword: (NSString *_Nullable)  aKeyword
timestamp: (long long)  aTimestamp
count: (int)  aCount
fromUser: (NSString *_Nullable)  aSender
searchDirection: (EMMessageSearchDirection)  aDirection 

从本地数据库获取会话中的指定用户发送的包含特定关键词的消息。

同步方法,会阻塞当前线程。

参数
aKeywords搜索关键词,设为 NIL 表示忽略该参数。
aTimestamp查询的起始消息 Unix 时间戳,单位为毫秒。该参数设置后,SDK 从指定时间戳的消息开始,按消息搜索方向获取。 如果该参数设置为负数,SDK 从当前时间开始搜索。
aCount每次获取的消息条数。如果设为小于等于 0,SDK 会获取 1 条消息。
aSender消息发送方,设为 NIL 表示忽略该参数。
aDirection消息搜索方向,详见 EMMessageSearchDirection
返回
消息列表。

◆ loadMessagesWithKeyword:timestamp:count:fromUser:searchDirection:completion:

- (void) loadMessagesWithKeyword: (NSString *_Nullable)  aKeyword
timestamp: (long long)  aTimestamp
count: (int)  aCount
fromUser: (NSString *_Nullable)  aSender
searchDirection: (EMMessageSearchDirection)  aDirection
completion: (void(^)(NSArray< EMChatMessage * > *_Nullable aMessages, EMError *_Nullable aError))  aCompletionBlock 

从本地数据库获取会话中的指定用户发送的包含特定关键词的消息。

参数
aKeywords关键词。设为 NIL 表示忽略该参数。
aTimestamp传入的 Unix 时间戳,单位为毫秒。如果该参数设置的时间戳为负数,则从最新消息向前获取。
aCount每次获取的消息条数。如果设为小于等于 0,SDK 会获取 1 条消息。
aSender消息发送方。设为 NIL 表示忽略该参数。
aDirection消息搜索方向,详见 EMMessageSearchDirection
aCompletionBlock该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。

◆ loadMessagesWithKeyword:timestamp:count:fromUser:searchDirection:scope:completion:

- (void) loadMessagesWithKeyword: (NSString *_Nullable)  aKeyword
timestamp: (long long)  aTimestamp
count: (int)  aCount
fromUser: (NSString *_Nullable)  aSender
searchDirection: (EMMessageSearchDirection)  aDirection
scope: (EMMessageSearchScope)  aScope
completion: (void(^)(NSArray< EMChatMessage * > *_Nullable aMessages, EMError *_Nullable aError))  aCompletionBlock 

从本地数据库获取会话中的指定用户发送的包含特定关键词的消息。

SDK 返回的消息按时间顺序排列。

参数
aKeywords关键词。设为 nil 表示忽略该参数。
aTimestamp搜索开始的 Unix 时间戳。单位为毫秒。如果该参数设置的时间戳为负数,则从最新消息向前获取。
aCount每次获取的消息条数。如果设为小于等于 0,SDK 会获取 1 条消息。
aSender消息发送方。设为 nil 表示忽略该参数。
aDirection消息搜索方向,详见 EMMessageSearchDirection
aScope消息搜索范围,详见 EMMessageSearchScope
aCompletionBlock该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。

◆ loadMessagesWithType:timestamp:count:fromUser:searchDirection:

- (NSArray< EMChatMessage * > *_Nullable) loadMessagesWithType: (EMMessageBodyType)  aType
timestamp: (long long)  aTimestamp
count: (int)  aCount
fromUser: (NSString *_Nullable)  aUsername
searchDirection: (EMMessageSearchDirection)  aDirection 

从本地数据库中获取会话中指定用户发送的一定数量的特定类型的消息。

同步方法,会阻塞当前线程。

参数
aType消息类型,txt:文本消息,img:图片消息,loc:位置消息,audio:语音消息,video:视频消息,file:文件消息,cmd: 透传消息。
aTimestamp当前传入消息的设备时间戳,单位为毫秒。如果该参数设置的时间戳为负数,则从最新消息向前获取。
aCount每次获取的消息条数。如果设为小于等于 0,SDK 会获取 1 条消息。
aUsername消息发送方。设为 NIL 表示忽略该参数。
aDirection消息搜索方向,详见 EMMessageSearchDirection
返回
消息列表。

◆ loadMessagesWithType:timestamp:count:fromUser:searchDirection:completion:

- (void) loadMessagesWithType: (EMMessageBodyType)  aType
timestamp: (long long)  aTimestamp
count: (int)  aCount
fromUser: (NSString *_Nullable)  aUsername
searchDirection: (EMMessageSearchDirection)  aDirection
completion: (void(^)(NSArray< EMChatMessage * > *_Nullable aMessages, EMError *_Nullable aError))  aCompletionBlock 

从本地数据库中获取会话中指定用户发送的一定数量的特定类型的消息。

参数
aType消息类型,txt:文本消息,img:图片消息,loc:位置消息,audio:语音消息,video:视频消息,file:文件消息,cmd: 透传消息。
aTimestamp当前传入消息的设备时间戳,单位为毫秒。如果该参数设置的时间戳为负数,则从最新消息向前获取。
aCount每次获取的消息条数。如果设为小于等于 0,SDK 会获取 1 条消息。
aUsername消息发送方。设为 NIL 表示忽略该参数。
aDirection消息搜索方向,详见 EMMessageSearchDirection
aCompletionBlock该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。

◆ loadMessageWithId:error:

- (EMChatMessage *_Nullable) loadMessageWithId: (NSString *_Nonnull)  aMessageId
error: (EMError **_Nullable)  pError 

从 SDK 本地数据库获取指定 ID 的消息。

参数
aMessageId消息 ID。
pError错误信息。

◆ markAllMessagesAsRead:

- (void) markAllMessagesAsRead: (EMError **_Nullable)  pError

将 SDK 本地数据库所有未读消息设置为已读。

参数
pError错误信息。

◆ markMessageAsReadWithId:error:

- (void) markMessageAsReadWithId: (NSString *_Nonnull)  aMessageId
error: (EMError **_Nullable)  pError 

将 SDK 本地数据库中的指定消息设置为已读。

参数
aMessageId要设置消息的 ID。
pError错误信息。

◆ pinnedMessages

- (NSArray< EMChatMessage * > *_Nullable) pinnedMessages

获取会话内的置顶消息列表。

◆ removeMessagesFromServerMessageIds:completion:

- (void) removeMessagesFromServerMessageIds: (NSArray< __kindof NSString * > *_Nonnull)  messageIds
completion: (void(^)(EMError *_Nullable aError))  aCompletionBlock 

从会话中删除消息(包括本地存储和服务器存储)。

参数
messageIds要删除消息 ID 字符串数组。
completion该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。

◆ removeMessagesFromServerWithTimeStamp:completion:

- (void) removeMessagesFromServerWithTimeStamp: (NSTimeInterval)  beforeTimeStamp
completion: (void(^)(EMError *_Nullable aError))  aCompletionBlock 

从会话中删除消息(包括本地存储和服务器存储)。

参数
beforeTimeStampUNIX 时间戳,单位为毫秒。若消息的 UNIX 时间戳小于设置的值,则会被删除。
completion该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。

◆ removeMessagesStart:to:

- (EMError *_Nullable) removeMessagesStart: (NSInteger)  aStartTimestamp
to: (NSInteger)  aEndTimestamp 

从本地数据库中删除指定时间段内的消息。

参数
aStartTimestamp删除消息的起始时间。UNIX 时间戳,单位为毫秒。
aEndTimestamp删除消息的结束时间。UNIX 时间戳,单位为毫秒。
返回
EMError 消息是否删除成功:
  • 若操作成功,返回 nil
  • 若操作失败,返回错误原因,例如参数错误或数据库操作失败。

◆ updateMessageChange:error:

- (void) updateMessageChange: (EMChatMessage *_Nonnull)  aMessage
error: (EMError **_Nullable)  pError 

更新 SDK 本地数据库的消息。

消息更新时,消息 ID 不会修改。

消息更新后,SDK 会自动更新会话的 latestMessage 等属性。

参数
aMessage要更新的消息。
pError错误信息。

属性说明

◆ conversationId

- (NSString*) conversationId
readnonatomiccopy

会话 ID。

  • 单聊:会话 ID 为对方的用户 ID。
  • 群聊:会话 ID 为群组 ID。
  • 聊天室:会话 ID 为聊天室的 ID。

◆ ext

- (NSDictionary*) ext
readwritenonatomiccopy

会话扩展属性。

子区功能目前版本暂不可设置。

◆ isChatThread

- (BOOL) isChatThread
readwritenonatomicassign

是否为 thread 会话:

  • YES:是
  • NO:否

◆ isPinned

- (BOOL) isPinned
readatomicassign

是否为置顶会话:

  • YES:是
  • NO:否

◆ latestMessage

- (EMChatMessage*) latestMessage
readnonatomicstrong

会话中的最新一条消息。

◆ marks

- (NSArray<NSNumber*>*) marks
readnonatomicassign

会话标记。

◆ messagesCount

- (int) messagesCount
readnonatomicassign

会话中的消息数量。

◆ pinnedTime

- (int64_t) pinnedTime
readatomicassign

会话置顶的 UNIX 时间戳,单位为毫秒。未置顶时值为 0

◆ type

- (EMConversationType) type
readnonatomicassign

会话类型。

◆ unreadMessagesCount

- (int) unreadMessagesCount
readnonatomicassign

会话中未读取的消息数量。


该类的文档由以下文件生成: