JMSGConversation.h 22 KB

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