JMSGConversation.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. /*
  2. * | | | | \ \ / / | | | | / _______|
  3. * | |____| | \ \/ / | |____| | / /
  4. * | |____| | \ / | |____| | | | _____
  5. * | | | | / \ | | | | | | |____ |
  6. * | | | | / /\ \ | | | | \ \______| |
  7. * | | | | /_/ \_\ | | | | \_________|
  8. *
  9. * Copyright (c) 2011 ~ 2015 Shenzhen HXHG. All rights reserved.
  10. */
  11. #import <Foundation/Foundation.h>
  12. #import <JMessage/JMSGConstants.h>
  13. #import <JMessage/JMSGUser.h>
  14. #import <JMessage/JMSGGroup.h>
  15. #import <JMessage/JMSGChatRoom.h>
  16. @class JMSGMessage;
  17. @class JMSGAbstractContent;
  18. @class JMSGImageContent;
  19. @class JMSGOptionalContent;
  20. @class JMSGMediaAbstractContent;
  21. /*!
  22. * 会话
  23. *
  24. * 会话是整个 IM 的核心. 所有的消息行为都是基于"会话"的.
  25. *
  26. * 会话由会话类型, 会话对象组成. 比如: 与某username的单聊, 某个groupId的群聊.
  27. *
  28. * 几乎所有的消息行为, 都是由本类 JMSGConversation 提供的.
  29. * 而聊天对象的信息, 则通过 [target] 来直接访问到.
  30. *
  31. * JMSGMessage 上提供了部分消息相关 API, 是快捷方式的概念, 其背后还是依赖于会话的.
  32. * 提供这个快捷方式的目的在于: 某些聊天场景简单的应用, 可能不必去理解"会话"这个概念, 只是简单地收发消息即可.
  33. *
  34. * 本类主要提供两类 API: 会话类, 消息类.
  35. *
  36. * 设计提示: 考虑到会话列表性能问题, SDK 把一些会话信息冗余到了会话数据库表里, 从而只需要读取一张表.
  37. * 设计上准备, 在会话列表时, 不要访问会话对象的 target 对象. 只是进入一个会话(聊天界面)时, 才会访问 target 对象.
  38. *
  39. */
  40. @interface JMSGConversation : NSObject
  41. JMSG_ASSUME_NONNULL_BEGIN
  42. ///----------------------------------------------------
  43. /// @name Conversation Operations 会话相关操作
  44. ///----------------------------------------------------
  45. /*!
  46. * @abstract 获取单聊会话
  47. *
  48. * @param username 单聊对象 username
  49. *
  50. * @discussion 如果会话还不存在,则返回 nil
  51. */
  52. + (JMSGConversation * JMSG_NULLABLE)singleConversationWithUsername:(NSString *)username;
  53. /*!
  54. * @abstract 获取跨应用单聊会话
  55. */
  56. + (JMSGConversation * JMSG_NULLABLE)singleConversationWithUsername:(NSString *)username
  57. appKey:(NSString *)userAppKey;
  58. /*!
  59. * @abstract 获取群聊会话
  60. *
  61. * @param groupId 群聊群组ID。此 ID 由创建群组时返回的。
  62. *
  63. * @discussion 如果会话还不存在,则返回 nil
  64. */
  65. + (JMSGConversation * JMSG_NULLABLE)groupConversationWithGroupId:(NSString *)groupId;
  66. /*!
  67. * @abstract 获取聊天室会话
  68. *
  69. * @param roomId 聊天室 ID
  70. *
  71. * @discussion 如果会话还不存在,则返回 nil
  72. */
  73. + (JMSGConversation * JMSG_NULLABLE)chatRoomConversationWithRoomId:(NSString *)roomId;
  74. /*!
  75. * @abstract 创建单聊会话
  76. *
  77. * @param username 单聊对象 username
  78. * @param handler 结果回调。正常返回时 resultObject 类型为 JMSGConversation。
  79. *
  80. * @discussion 如果会话已经存在,则直接返回。如果不存在则创建。
  81. * 创建会话时如果发现该 username 的信息本地还没有,则需要从服务器上拉取。
  82. * 服务器端如果找不到该 username,或者某种原因查找失败,则创建会话失败。
  83. */
  84. + (void)createSingleConversationWithUsername:(NSString *)username
  85. completionHandler:(JMSGCompletionHandler JMSG_NULLABLE)handler;
  86. /*!
  87. * @abstract 创建跨应用单聊会话
  88. */
  89. + (void)createSingleConversationWithUsername:(NSString *)username
  90. appKey:(NSString *)userAppKey
  91. completionHandler:(JMSGCompletionHandler JMSG_NULLABLE)handler;
  92. /*!
  93. * @abstract 创建群聊会话
  94. *
  95. * @param groupId 群聊群组ID。由创建群组时返回。
  96. * @param handler 结果回调。正常返回时 resultObject 类型为 JMSGConversation。
  97. *
  98. * @discussion 如果会话已经存在,则直接返回。如果不存在则创建。
  99. * 创建会话时如果发现该 groupId 的信息本地还没有,则需要从服务器端上拉取。
  100. * 如果从服务器上获取 groupId 的信息不存在或者失败,则创建会话失败。
  101. */
  102. + (void)createGroupConversationWithGroupId:(NSString *)groupId
  103. completionHandler:(JMSGCompletionHandler JMSG_NULLABLE)handler;
  104. /*!
  105. * @abstract 创建聊天室会话
  106. *
  107. * @param roomId 聊天室 ID。
  108. * @param handler 结果回调。正常返回时 resultObject 类型为 JMSGConversation。
  109. *
  110. * @discussion 如果会话已经存在,则直接返回。如果不存在则创建。
  111. * 创建会话时如果发现该 roomId 的信息本地还没有,则需要从服务器端上拉取。
  112. * 如果从服务器上获取 roomId 的信息不存在或者失败,则创建会话失败。
  113. */
  114. + (void)createChatRoomConversationWithRoomId:(NSString *)roomId
  115. completionHandler:(JMSGCompletionHandler JMSG_NULLABLE)handler;
  116. /*!
  117. * @abstract 删除单聊会话
  118. *
  119. * @param username 单聊用户名
  120. *
  121. * @discussion 除了删除会话本身,还会删除该会话下所有的聊天消息。
  122. */
  123. + (BOOL)deleteSingleConversationWithUsername:(NSString *)username;
  124. /*!
  125. * @abstract 删除跨应用单聊会话
  126. */
  127. + (BOOL)deleteSingleConversationWithUsername:(NSString *)username
  128. appKey:(NSString *)userAppKey;
  129. /*!
  130. * @abstract 删除群聊会话
  131. *
  132. * @param groupId 群聊群组ID
  133. *
  134. * @discussion 除了删除会话本身,还会删除该会话下所有的聊天消息。
  135. */
  136. + (BOOL)deleteGroupConversationWithGroupId:(NSString *)groupId;
  137. /*!
  138. * @abstract 删除聊天室会话
  139. *
  140. * @param roomId 聊天室 ID
  141. *
  142. * @discussion 除了删除会话本身,还会删除该会话下所有的聊天消息。
  143. */
  144. + (BOOL)deleteChatRoomConversationWithRoomId:(NSString *)roomId;
  145. /*!
  146. * @abstract 返回 conversation 列表(异步,已排序)
  147. *
  148. * @param handler 结果回调。正常返回时 resultObject 的类型为 NSArray,数组里成员的类型为 JMSGConversation
  149. *
  150. * @discussion 当前是返回所有的 conversation 列表,不包括聊天室会话,默认是已经排序。
  151. */
  152. + (void)allConversations:(JMSGCompletionHandler)handler;
  153. /*!
  154. * @abstract 返回 conversation 列表(异步,没有排序)
  155. *
  156. * @param handler 结果回调。正常返回时 resultObject 的类型为 NSArray,数组里成员的类型为 JMSGConversation
  157. *
  158. * @discussion 返回所有的 conversation 列表,不包括聊天室会话,返回是没有排序的列表。
  159. */
  160. + (void)allUnsortedConversations:(JMSGCompletionHandler)handler;
  161. /*!
  162. * @abstract 返回聊天室 conversation 列表(异步,已排序)
  163. *
  164. * @param handler 结果回调。正常返回时 resultObject 的类型为 NSArray,数组里成员的类型为 JMSGConversation
  165. *
  166. * @discussion 当前是返回所有的chatroom conversation 列表,不包括单聊和群聊会话,默认是已经排序。
  167. */
  168. + (void)allChatRoomConversation:(JMSGCompletionHandler)handler;
  169. /*!
  170. * @abstract 获取当前所有会话的未读消息的总数
  171. *
  172. * @discussion 获取所有会话未读消息总数,开启免打扰的会话未读数不会加入计数;此接口有可能会阻塞线程,请在子线程使用。
  173. */
  174. + (NSNumber *)getAllUnreadCount;
  175. ///----------------------------------------------------------
  176. /// @name Conversation Basic Properties 会话基本属性:用于会话列表
  177. ///----------------------------------------------------------
  178. /*!
  179. * @abstract 会话标题
  180. */
  181. @property(nonatomic, strong, readonly) NSString * JMSG_NULLABLE title;
  182. /*!
  183. * @abstract 最后一条消息
  184. */
  185. @property(nonatomic, strong, readonly) JMSGMessage * JMSG_NULLABLE latestMessage;
  186. /*!
  187. * @abstract 会话最近一条消息的创建时间
  188. *
  189. * @discussion 可用于会话排序,单位为毫秒
  190. */
  191. @property(nonatomic, strong, readonly) NSNumber *latestMsgTime;
  192. /*!
  193. * @abstract 未读数
  194. * @discussion 有新消息来时, SDK 会对未读数自动加 1
  195. */
  196. @property(nonatomic, strong, readonly) NSNumber * JMSG_NULLABLE unreadCount;
  197. ///--------------------------------------------------------
  198. /// @name Conversation Extend Properties 会话扩展属性:用于聊天
  199. ///--------------------------------------------------------
  200. /*!
  201. * @abstract 会话类型 - 单聊,群聊,聊天室
  202. * @discussion 详细定义见 JMSGConversationType
  203. */
  204. @property(nonatomic, assign, readonly) JMSGConversationType conversationType;
  205. /*!
  206. * @abstract 聊天对象
  207. *
  208. * @discussion 需要根据会话类型转型。单聊时转型为 JMSGUser,群聊时转型为 JMSGGroup,聊天时转型为 JMSGChatRoom
  209. *
  210. * 注意: 在会话列表上, 请不要使用此属性, 否则有性能问题. 只在进入聊天界面(单个会话) 时使用此属性.
  211. *
  212. * 进入会话(聊天界面)后, 访问会话对象的各种信息, 包括群聊的群组成员, 都应使用此属性,
  213. * 而没有必要再通过接口查询 UserInfo / GroupInfo / ChatRoomInfo.
  214. */
  215. @property(nonatomic, strong, readonly) id target;
  216. /*!
  217. * @abstract 会话目标用户所在的 appKey
  218. *
  219. * @discussion 这是为了跨应用聊天而新增的一个字段.
  220. * 如果此字段为空, 则表示为默认的主应用.
  221. *
  222. * 单聊会话时, 如果单聊对象用户不属于主应用, 则此字段会有值.
  223. *
  224. */
  225. @property(nonatomic, strong, readonly) NSString *targetAppKey;
  226. ///----------------------------------------------------
  227. /// @name Message Operations 消息相关操作
  228. ///----------------------------------------------------
  229. /*!
  230. * @abstract 获取某条消息
  231. *
  232. * @param msgId 本地消息ID
  233. *
  234. * @discussion 这个接口在正常场景下不需要单独使用到. 获取消息一般应使用 [JSMGConversation messageArrayFromNewestWithOffset::]
  235. *
  236. * 注意: 这里的 msgId 概念同 [JMSGMessage msgId], 是本地生成的消息ID, 而非 [JMSGMessage serverMessageId]
  237. */
  238. - (JMSGMessage * JMSG_NULLABLE)messageWithMessageId:(NSString *)msgId;
  239. /*!
  240. * @abstract 获取某条消息
  241. *
  242. * @param serverMessageId 服务器下发的消息ID
  243. *
  244. * @discussion 这个接口在正常场景下不需要单独使用到. 获取消息一般应使用 [JSMGConversation messageArrayFromNewestWithOffset::]
  245. *
  246. * 注意: 这里的 serverMessageId 概念同 [JMSGMessage serverMessageId], 是服务端生成的消息ID
  247. */
  248. - (JMSGMessage * JMSG_NULLABLE)messageWithServerMessageId:(NSString *)serverMessageId;
  249. /*!
  250. * @abstract 同步分页获取最新的消息
  251. *
  252. * @param offset 开始的位置。nil 表示从最初开始。
  253. * @param limit 获取的数量。nil 表示不限。
  254. *
  255. * @return 返回消息列表(数组)。数组成员的类型是 JMSGMessage*
  256. *
  257. * @discussion 排序规则是:最新
  258. *
  259. * 参数举例:
  260. *
  261. * - offset = nil, limit = nil,表示获取全部。相当于 allMessages。
  262. * - offset = nil, limit = 100,表示从最新开始取 100 条记录。
  263. * - offset = 100, limit = nil,表示从最新第 100 条开始,获取余下所有记录。
  264. */
  265. - (NSArray JMSG_GENERIC(__kindof JMSGMessage *) *)messageArrayFromNewestWithOffset:(NSNumber *JMSG_NULLABLE)offset limit:(NSNumber *JMSG_NULLABLE)limit;
  266. /*!
  267. * @abstract 异步获取所有消息记录
  268. *
  269. * @param handler 结果回调。正常返回时 resultObject 类型为 NSArray,数据成员类型为 JMSGMessage。
  270. *
  271. * @discussion 排序规则:最新
  272. */
  273. - (void)allMessages:(JMSGCompletionHandler)handler;
  274. /*!
  275. * @abstract 删除一条消息
  276. *
  277. * @param msgId 本地消息ID
  278. *
  279. * @discussion 注意:如果被删除消息是多媒体消息,也会将本地缓存的多媒体文件删除
  280. */
  281. - (BOOL)deleteMessageWithMessageId:(NSString *)msgId;
  282. /*!
  283. * @abstract 删除全部消息
  284. *
  285. * @discussion 清空当前会话的所有消息,并清空当前会话的所有本地文件缓存。
  286. */
  287. - (BOOL)deleteAllMessages;
  288. /*!
  289. * @abstract 创建消息对象
  290. *
  291. * @param content 消息的内容对象。当前直接的内容对象有:
  292. * JMSGTextContent, JMSGImageContent, JMSGVoiceContent, JMSGCustomContent
  293. *
  294. * @return JMSGMessage对象。该对象里包含了 content。
  295. *
  296. * @discussion 这是推荐的创建新的消息拿到 JMSGMessage 对象接口。
  297. *
  298. * 此接口创建消息后, SDK 会进行落地, 包括: 消息保存数据库, 媒体文件保存到文件系统.
  299. * 这意味着, 这个创建后的消息对象, App 可以用来放到 UI 上展示.
  300. *
  301. * 新创建的消息对象, 其消息状态 status 为: kJMSGMessageStatusSendDraft
  302. *
  303. * 调用此接口前需要先创建消息内容,以作为 content 参数传入。举例:
  304. *
  305. * ```
  306. * NSData *imageData = … // 可能来自拍照或者相册
  307. * JMSGImageContent *imageContent = [[JMSGImageContent alloc] initWithImageData:imageData];
  308. * ```
  309. *
  310. * 另外更快捷的作法是,不通过此接口创建 JMSGMessage 而是直接调用具体的发送接口,如 sendSingleTextMessage.
  311. *
  312. * 通过此接口先创建 JMSGMessage 的好处是,可以对 JMSGMessage 做更多的定制控制,比如加附加字段。举例:
  313. *
  314. * ```
  315. * [imageContent addExtraValue:@"extra_value" forKey:@"extra_key"]
  316. * ```
  317. *
  318. * 注意:如果创建消息的内容是图片,并且图片可能比较大,则建议不要使用这个同步接口,
  319. * 改用 createMessageAsyncWithImageContent:completionHandler: 方法。
  320. */
  321. - (JMSGMessage * JMSG_NULLABLE)createMessageWithContent:(JMSGAbstractContent *)content;
  322. /*!
  323. * @abstract 创建消息对象(图片,异步)
  324. *
  325. * 注意:此方法已过期,请使用 createMessageAsyncWithMediaContent: 方法
  326. */
  327. - (void)createMessageAsyncWithImageContent:(JMSGImageContent *)content
  328. completionHandler:(JMSGCompletionHandler JMSG_NULLABLE)handler __attribute__((deprecated("first deprecated in JMessage 3.3.0 - Use -createMessageAsyncWithMediaContent:")));
  329. /*!
  330. * @abstract 创建消息对象(多媒体消息,异步)
  331. *
  332. * @param content 准备好的多媒体内容,如:图片、语音、文件等
  333. * @param handler 结果回调. 正常返回时 resultObject 类型为 JMSGMessage.
  334. *
  335. * @discussion 注意:对于多媒体消息,因为 SDK 要做缩图有一定的性能损耗,图片文件很大时存储落地也会较慢。
  336. * 所以创建图片消息,建议使用这个异步接口。
  337. */
  338. - (void)createMessageAsyncWithMediaContent:(JMSGMediaAbstractContent *)content
  339. completionHandler:(JMSGCompletionHandler JMSG_NULLABLE)handler;
  340. /*!
  341. * @abstract 发送消息(已经创建好对象的)
  342. *
  343. * @param message 通过消息创建类接口,创建好的消息对象
  344. *
  345. * @discussion 发送消息的多个接口,都未在方法上直接提供回调。你应通过 JMSGMessageDelegate中的onReceiveMessage: error:方法来注册消息发送结果
  346. */
  347. - (void)sendMessage:(JMSGMessage *)message;
  348. /*!
  349. * @abstract 发送消息(附带可选功能,如:控制离线消息存储、自定义通知栏内容、消息已读回执等)
  350. *
  351. * @param message 通过消息创建类接口,创建好的消息对象
  352. * @param optionalContent 可选功能,具体请查看 JMSGOptionalContent 类
  353. *
  354. * @discussion 可选功能里可以设置离线消息存储、自定义通知栏内容、消息已读回执等,具体请查看 JMSGOptionalContent 类。
  355. *
  356. */
  357. - (void)sendMessage:(JMSGMessage *)message optionalContent:(JMSGOptionalContent *)optionalContent;
  358. /*!
  359. * @abstract 发送@人消息(已经创建好对象的)
  360. *
  361. * @param message 通过消息创建类接口,创建好的消息对象
  362. * @param userList @对象的数组
  363. *
  364. * @discussion 发送消息的多个接口,都未在方法上直接提供回调。你应通过 JMSGMessageDelegate中的onReceiveMessage: error:方法来注册消息发送结果
  365. */
  366. - (void)sendMessage:(JMSGMessage *)message at_list:(NSArray<__kindof JMSGUser *> *)userList;
  367. /*!
  368. * @abstract 发送@所有人消息(已经创建好对象的)
  369. *
  370. * @param message 通过消息创建类接口,创建好的消息对象
  371. *
  372. * @discussion 发送消息的多个接口,都未在方法上直接提供回调。你应通过 JMSGMessageDelegate中的onReceiveMessage: error:方法来注册消息发送结果
  373. */
  374. - (void)sendAtAllMessage:(JMSGMessage *)message;
  375. /*!
  376. * @abstract 发送文本消息
  377. * @param text 文本消息内容
  378. * @discussion 快捷发消息接口。如果发送文本消息不需要附加 extra,则使用此接口更方便。
  379. */
  380. - (void)sendTextMessage:(NSString *)text;
  381. /*!
  382. * @abstract 发送图片消息
  383. * @param imageData 图片消息数据
  384. * @discussion 快捷发送消息接口。如果发送图片消息不需要附加 extra,则使用此接口更方便。
  385. */
  386. - (void)sendImageMessage:(NSData *)imageData;
  387. /*!
  388. * @abstract 发送语音消息
  389. * @param voiceData 语音消息数据
  390. * @param duration 语音消息时长(秒). 长度必须大于 0.
  391. * @discussion 快捷发送消息接口。如果发送语音消息不需要附加 extra,则使用此接口更方便。
  392. */
  393. - (void)sendVoiceMessage:(NSData *)voiceData
  394. duration:(NSNumber *)duration;
  395. /*!
  396. * @abstract 发送视频消息
  397. *
  398. * @param videoData 视频消息数据
  399. * @param thumbData 视频封面图片
  400. * @param videoFormat 视频格式,如:mp4、mov
  401. * @param duration 视频消息时长(秒). 长度必须大于 0.
  402. *
  403. * @discussion 快捷发送消息接口。如果发送语音消息不需要附加 extra,则使用此接口更方便。
  404. */
  405. - (void)sendVideoMessage:(NSData *)videoData
  406. thumbData:(NSData *JMSG_NULLABLE)thumbData
  407. videoFormat:(NSString *JMSG_NULLABLE)videoFormat
  408. duration:(NSNumber *)duration;
  409. /*!
  410. * @abstract 发送文件消息
  411. * @param fileData 文件消息数据
  412. * @param fileName 文件名
  413. * @discussion 快捷发送消息接口。如果发送文件消息不需要附加 extra,则使用此接口更方便。
  414. */
  415. - (void)sendFileMessage:(NSData *)fileData
  416. fileName:(NSString *)fileName;
  417. /*!
  418. * @abstract 发送地理位置消息
  419. * @param latitude 纬度
  420. * @param longitude 经度
  421. * @param scale 缩放比例
  422. * @param address 详细地址
  423. * @discussion 快捷发送消息接口。如果发送文件消息不需要附加 extra,则使用此接口更方便。
  424. */
  425. - (void)sendLocationMessage:(NSNumber *)latitude
  426. longitude:(NSNumber *)longitude
  427. scale:(NSNumber *)scale
  428. address:(NSString *)address;
  429. /*!
  430. * @abstract 消息撤回
  431. *
  432. * @param message 需要撤回的消息
  433. * @param handler 结果回调
  434. *
  435. * - resultObject 撤回后的消息
  436. * - error 错误信息
  437. *
  438. * @discussion 注意:SDK可撤回3分钟内的消息
  439. */
  440. - (void)retractMessage:(JMSGMessage *)message completionHandler:(JMSGCompletionHandler)handler;
  441. /*!
  442. * @abstract 消息透传
  443. *
  444. * @param transparentText 用户自定义透传内容,仅限 NSString 类型
  445. * @param handler 回调,error=nil 表示成功
  446. *
  447. * @discussion 注意:
  448. *
  449. * 1. 消息透传功能,消息不会进入到后台的离线存储中去,仅当对方用户当前在线时才会成功送达,可以快速响应,方便开发者拓展自定义行为;
  450. *
  451. * 2. 可用来快速实现一些在线场景下的辅助功能 :输入状态提示、位置信息提示、开发者自定义等。
  452. *
  453. * 3. 透传命令到达是,接收方通过 [JMSGEventDelegate onReceiveMessageTransparentEvent:] 方法监听
  454. */
  455. - (void)sendTransparentMessage:(NSString *JMSG_NONNULL)transparentText
  456. completionHandler:(JMSGCompletionHandler JMSG_NULLABLE)handler;
  457. /*!
  458. * @abstract 异步获取会话头像
  459. *
  460. * @param handler 结果回调。回调参数:
  461. *
  462. * - data 头像数据;
  463. * - objectId 为 targetId_conversationType 的组合, 用下划线隔开.
  464. * 其中 targetId 单聊时为 username_targetAppKey,
  465. * 群聊时为 groupId
  466. * - error 不为nil表示出错;
  467. *
  468. * 如果 error 为 ni, data 也为 nil, 表示没有数据.
  469. *
  470. * @discussion 会话的头像来自于聊天对象, 单聊就是用户的头像.
  471. * 建议在会话列表时, 使用此接口来显示会话的头像, 而不要使用 target 属性里的用户头像.
  472. */
  473. - (void)avatarData:(JMSGAsyncDataHandler)handler;
  474. /*!
  475. * @abstract 获取会话头像的本地路径
  476. *
  477. * @return 返回本地路,返回值只有在下载完成之后才有意义
  478. */
  479. - (NSString *JMSG_NULLABLE)avatarLocalPath;
  480. ///----------------------------------------------------
  481. /// @name Conversation State Maintenance 会话状态维护
  482. ///----------------------------------------------------
  483. /*!
  484. * @abstract 清除会话未读数
  485. *
  486. * @discussion 把未读数设置为 0
  487. */
  488. - (void)clearUnreadCount;
  489. /*!
  490. * @abstract 获取最后一条消息的内容文本
  491. *
  492. * @discussion 通常用来展示在会话列表的第 2 行. 如果是图片消息,通常是文本 [图片] 之类. CustomContent 可以定制这个文本.
  493. */
  494. - (NSString *)latestMessageContentText;
  495. /*!
  496. * @abstract 获取会话所有扩展字段
  497. *
  498. * @return 返回所有值,NSDictionary 类型
  499. *
  500. * @discussion 与 [- (void)setExtraValue:forKey:] 配套使用,可用于对会话属性的扩展
  501. */
  502. - (NSDictionary *JMSG_NULLABLE)getConversationExtras;
  503. /*!
  504. * @abstract 获取单个扩展字段
  505. *
  506. * @return 返回 key 对应值,NSString 类型
  507. *
  508. * @discussion 与 [- (void)setExtraValue:forKey:] 配套使用,可用于对会话属性的扩展
  509. */
  510. - (NSString *JMSG_NULLABLE)getExtraValueForKey:(NSString *JMSG_NONNULL)key;
  511. /*!
  512. * @abstract 增加或更新扩展字段,可扩展会话属性,比如:会话置顶、标识特殊会话等
  513. *
  514. * @param value 新增键值对的值. String 类型.
  515. * @param key 新增键值对的键
  516. *
  517. * @discussion 如果 value = nil,则删除 extras 中 key 对应的值
  518. */
  519. - (void)setExtraValue:(NSString *JMSG_NULLABLE)value forKey:(NSString *JMSG_NONNULL)key;
  520. /*!
  521. * @abstract 判断消息是否属于这个 Conversation
  522. *
  523. * @param message 待判断的消息对象
  524. *
  525. * @discussion 当前在聊天界面时,接收到消息通知,需要通过这个接口判断该消息是否属于当前这个会话,从而做不同的动作
  526. *
  527. * 如果注册消息接收事件时,只注册接收当前会话的消息,则不需要用此接口判断.
  528. */
  529. - (BOOL)isMessageForThisConversation:(JMSGMessage *)message;
  530. /*!
  531. * @abstract 从服务器端刷新会话信息
  532. *
  533. * @param handler 结果回调。返回正常时 resultObject 为当前 conversation 对象.
  534. *
  535. * @discussion 会话信息的 title/avatar 信息, 单聊来自于 UserInfo,对于群聊来自于 GroupInfo。
  536. * 建议在进入聊天界面时,调用此接口,来更新会话属性。
  537. * 典型的情况是, 此接口返回时, 刷新单聊界面顶部的会话标题. (有可能聊天对方昵称改变了, 或者群组名称改变了, 聊天标题需要刷新)
  538. *
  539. * 此接口供暂时使用。JMessage 整体的 Sync 机制生效后,将不需要客户端主动去刷新信息。
  540. */
  541. - (void)refreshTargetInfoFromServer:(JMSGCompletionHandler)handler;
  542. ///----------------------------------------------------
  543. /// @name Class Normal 类基本方法
  544. ///----------------------------------------------------
  545. - (BOOL)isEqualToConversation:(JMSGConversation * JMSG_NULLABLE)conversation;
  546. JMSG_ASSUME_NONNULL_END
  547. @end