TIMMessage.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809
  1. //
  2. // TIMMessage.h
  3. // ImSDK
  4. //
  5. // Created by bodeng on 28/1/15.
  6. // Copyright (c) 2015 tencent. All rights reserved.
  7. //
  8. #ifndef ImSDK_TIMMessage_h
  9. #define ImSDK_TIMMessage_h
  10. #import <Foundation/Foundation.h>
  11. #import "TIMComm.h"
  12. #import "TIMCallback.h"
  13. @class TIMUserProfile;
  14. @class TIMGroupMemberInfo;
  15. @class TIMConversation;
  16. /**
  17. * 消息Elem基类
  18. */
  19. @interface TIMElem : NSObject
  20. @end
  21. /**
  22. * 文本消息Elem
  23. */
  24. @interface TIMTextElem : TIMElem
  25. /**
  26. * 消息文本
  27. */
  28. @property(nonatomic,strong) NSString * text;
  29. @end
  30. #pragma mark - 普通消息类型
  31. @interface TIMImage : NSObject
  32. /**
  33. * 图片ID,内部标识,可用于外部缓存key
  34. */
  35. @property(nonatomic,strong) NSString * uuid;
  36. /**
  37. * 图片类型
  38. */
  39. @property(nonatomic,assign) TIM_IMAGE_TYPE type;
  40. /**
  41. * 图片大小
  42. */
  43. @property(nonatomic,assign) int size;
  44. /**
  45. * 图片宽度
  46. */
  47. @property(nonatomic,assign) int width;
  48. /**
  49. * 图片高度
  50. */
  51. @property(nonatomic,assign) int height;
  52. /**
  53. * 下载URL
  54. */
  55. @property(nonatomic, strong) NSString * url;
  56. /**
  57. * 获取图片
  58. *
  59. * @param path 图片保存路径
  60. * @param succ 成功回调,返回图片数据
  61. * @param fail 失败回调,返回错误码和错误描述
  62. */
  63. - (void)getImage:(NSString*)path succ:(TIMSucc)succ fail:(TIMFail)fail;
  64. @end
  65. /**
  66. * 图片消息Elem
  67. */
  68. @interface TIMImageElem : TIMElem
  69. /**
  70. * 要发送的图片路径
  71. */
  72. @property(nonatomic,strong) NSString * path;
  73. /**
  74. * 所有类型图片,只读
  75. */
  76. @property(nonatomic,strong) NSArray * imageList;
  77. /**
  78. * 上传时任务Id,可用来查询上传进度
  79. */
  80. @property(nonatomic,assign) uint32_t taskId;
  81. /**
  82. * 图片压缩等级,详见 TIM_IMAGE_COMPRESS_TYPE(仅对jpg格式有效)
  83. */
  84. @property(nonatomic,assign) TIM_IMAGE_COMPRESS_TYPE level;
  85. /**
  86. * 图片格式,详见 TIM_IMAGE_FORMAT
  87. */
  88. @property(nonatomic,assign) TIM_IMAGE_FORMAT format;
  89. /**
  90. * 查询上传进度
  91. */
  92. - (uint32_t)getUploadingProgress;
  93. @end
  94. /**
  95. * 文件消息Elem
  96. */
  97. @interface TIMFileElem : TIMElem
  98. /**
  99. * 上传时任务Id,可用来查询上传进度
  100. */
  101. @property(nonatomic,assign) uint32_t taskId;
  102. /**
  103. * 上传时,文件的路径(设置path时,优先上传文件)
  104. */
  105. @property(nonatomic,strong) NSString * path;
  106. /**
  107. * 文件内部ID
  108. */
  109. @property(nonatomic,strong) NSString * uuid;
  110. /**
  111. * 文件大小
  112. */
  113. @property(nonatomic,assign) int fileSize;
  114. /**
  115. * 文件显示名,发消息时设置
  116. */
  117. @property(nonatomic,strong) NSString * filename;
  118. /**
  119. * 获取文件数据到指定路径的文件中
  120. *
  121. * @param path 文件保存路径
  122. * @param succ 成功回调,返回数据
  123. * @param fail 失败回调,返回错误码和错误描述
  124. */
  125. - (void)getFile:(NSString*)path succ:(TIMSucc)succ fail:(TIMFail)fail;
  126. /**
  127. * 查询上传进度
  128. */
  129. - (uint32_t)getUploadingProgress;
  130. @end
  131. /**
  132. * 语音消息Elem
  133. */
  134. @interface TIMSoundElem : TIMElem
  135. /**
  136. * 上传时任务Id,可用来查询上传进度
  137. */
  138. @property(nonatomic,assign) uint32_t taskId;
  139. /**
  140. * 上传时,语音文件的路径,接收时使用getSound获得数据
  141. */
  142. @property(nonatomic,strong) NSString * path;
  143. /**
  144. * 语音消息内部ID
  145. */
  146. @property(nonatomic,strong) NSString * uuid;
  147. /**
  148. * 语音数据大小
  149. */
  150. @property(nonatomic,assign) int dataSize;
  151. /**
  152. * 语音长度(秒),发送消息时设置
  153. */
  154. @property(nonatomic,assign) int second;
  155. /**
  156. * 获取语音数据到指定路径的文件中
  157. *
  158. * @param path 语音保存路径
  159. * @param succ 成功回调
  160. * @param fail 失败回调,返回错误码和错误描述
  161. */
  162. - (void)getSound:(NSString*)path succ:(TIMSucc)succ fail:(TIMFail)fail;
  163. /**
  164. * 查询上传进度
  165. */
  166. - (uint32_t) getUploadingProgress;
  167. @end
  168. /**
  169. * 地理位置Elem
  170. */
  171. @interface TIMLocationElem : TIMElem
  172. /**
  173. * 地理位置描述信息,发送消息时设置
  174. */
  175. @property(nonatomic,strong) NSString * desc;
  176. /**
  177. * 纬度,发送消息时设置
  178. */
  179. @property(nonatomic,assign) double latitude;
  180. /**
  181. * 经度,发送消息时设置
  182. */
  183. @property(nonatomic,assign) double longitude;
  184. @end
  185. /**
  186. * 自定义消息类型
  187. */
  188. @interface TIMCustomElem : TIMElem
  189. /**
  190. * 自定义消息二进制数据
  191. */
  192. @property(nonatomic,strong) NSData * data;
  193. /**
  194. * 自定义消息描述信息,做离线Push时文本展示(已废弃,请使用TIMMessage中offlinePushInfo进行配置)
  195. */
  196. @property(nonatomic,strong) NSString * desc DEPRECATED_ATTRIBUTE;
  197. /**
  198. * 离线Push时扩展字段信息(已废弃,请使用TIMMessage中offlinePushInfo进行配置)
  199. */
  200. @property(nonatomic,strong) NSString * ext DEPRECATED_ATTRIBUTE;
  201. /**
  202. * 离线Push时声音字段信息(已废弃,请使用TIMMessage中offlinePushInfo进行配置)
  203. */
  204. @property(nonatomic,strong) NSString * sound DEPRECATED_ATTRIBUTE;
  205. @end
  206. /**
  207. * 表情消息类型
  208. */
  209. @interface TIMFaceElem : TIMElem
  210. /**
  211. * 表情索引,用户自定义
  212. */
  213. @property(nonatomic, assign) int index;
  214. /**
  215. * 额外数据,用户自定义
  216. */
  217. @property(nonatomic,strong) NSData * data;
  218. @end
  219. @interface TIMVideo : NSObject
  220. /**
  221. * 视频ID,不用设置
  222. */
  223. @property(nonatomic,strong) NSString * uuid;
  224. /**
  225. * 视频文件类型,发送消息时设置
  226. */
  227. @property(nonatomic,strong) NSString * type;
  228. /**
  229. * 视频大小,不用设置
  230. */
  231. @property(nonatomic,assign) int size;
  232. /**
  233. * 视频时长,发送消息时设置
  234. */
  235. @property(nonatomic,assign) int duration;
  236. /**
  237. * 获取视频
  238. *
  239. * @param path 视频保存路径
  240. * @param succ 成功回调
  241. * @param fail 失败回调,返回错误码和错误描述
  242. */
  243. - (void)getVideo:(NSString*)path succ:(TIMSucc)succ fail:(TIMFail)fail;
  244. @end
  245. @interface TIMSnapshot : NSObject
  246. /**
  247. * 图片ID,不用设置
  248. */
  249. @property(nonatomic,strong) NSString * uuid;
  250. /**
  251. * 截图文件类型,发送消息时设置
  252. */
  253. @property(nonatomic,strong) NSString * type;
  254. /**
  255. * 图片大小,不用设置
  256. */
  257. @property(nonatomic,assign) int size;
  258. /**
  259. * 图片宽度,发送消息时设置
  260. */
  261. @property(nonatomic,assign) int width;
  262. /**
  263. * 图片高度,发送消息时设置
  264. */
  265. @property(nonatomic,assign) int height;
  266. /**
  267. * 获取图片
  268. *
  269. * @param path 图片保存路径
  270. * @param succ 成功回调,返回图片数据
  271. * @param fail 失败回调,返回错误码和错误描述
  272. */
  273. - (void)getImage:(NSString*)path succ:(TIMSucc)succ fail:(TIMFail)fail;
  274. @end
  275. /**
  276. * 微视频消息
  277. */
  278. @interface TIMVideoElem : TIMElem
  279. /**
  280. * 上传时任务Id,可用来查询上传进度
  281. */
  282. @property(nonatomic,assign) uint32_t taskId;
  283. /**
  284. * 视频文件路径,发送消息时设置
  285. */
  286. @property(nonatomic,strong) NSString * videoPath;
  287. /**
  288. * 视频信息,发送消息时设置
  289. */
  290. @property(nonatomic,strong) TIMVideo * video;
  291. /**
  292. * 截图文件路径,发送消息时设置
  293. */
  294. @property(nonatomic,strong) NSString * snapshotPath;
  295. /**
  296. * 视频截图,发送消息时设置
  297. */
  298. @property(nonatomic,strong) TIMSnapshot * snapshot;
  299. /**
  300. * 查询上传进度
  301. */
  302. - (uint32_t) getUploadingProgress;
  303. @end
  304. /**
  305. * UGC视频(加载UGC扩展包有效)
  306. */
  307. @interface TIMUGCVideo : NSObject
  308. /**
  309. * 视频url,不用设置
  310. */
  311. @property(nonatomic,strong) NSString * url;
  312. /**
  313. * 视频文件类型,发送消息时设置
  314. */
  315. @property(nonatomic,strong) NSString * type;
  316. /**
  317. * 视频时长,发送消息时设置
  318. */
  319. @property(nonatomic,assign) int duration;
  320. /**
  321. * 视频大小,不用设置
  322. */
  323. @property(nonatomic,assign) int size;
  324. /**
  325. * 获取视频
  326. *
  327. * @param path 视频保存路径
  328. * @param succ 成功回调
  329. * @param fail 失败回调,返回错误码和错误描述
  330. */
  331. - (void)getVideo:(NSString*)path succ:(TIMSucc)succ fail:(TIMFail)fail;
  332. @end
  333. /**
  334. * UGC封面(加载UGC扩展包有效)
  335. */
  336. @interface TIMUGCCover : NSObject
  337. /**
  338. * 视频url,不用设置
  339. */
  340. @property(nonatomic,strong) NSString * url;
  341. /**
  342. * 封面图片类型,发送消息时设置
  343. */
  344. @property(nonatomic,strong) NSString * type;
  345. /**
  346. * 图片宽度,发送消息时设置
  347. */
  348. @property(nonatomic,assign) int width;
  349. /**
  350. * 图片高度,发送消息时设置
  351. */
  352. @property(nonatomic,assign) int height;
  353. /**
  354. * 视频大小,不用设置
  355. */
  356. @property(nonatomic,assign) int size;
  357. /**
  358. * 获取图片
  359. *
  360. * @param path 图片保存路径
  361. * @param succ 成功回调,返回图片数据
  362. * @param fail 失败回调,返回错误码和错误描述
  363. */
  364. - (void)getImage:(NSString*)path succ:(TIMSucc)succ fail:(TIMFail)fail;
  365. @end
  366. /**
  367. * UGC消息(加载UGC扩展包有效)
  368. */
  369. @interface TIMUGCElem : TIMElem
  370. /**
  371. * UGC视频id
  372. */
  373. @property(nonatomic,strong) NSString * videoId;
  374. /**
  375. * UGC视频文件地址,发送消息时设置
  376. */
  377. @property(nonatomic,strong) NSString * videoPath;
  378. /**
  379. * 视频信息,发送消息时设置
  380. */
  381. @property(nonatomic,strong) TIMUGCVideo * video;
  382. /**
  383. * UGC封面图片,发送消息时设置
  384. */
  385. @property(nonatomic,strong) NSString * coverPath;
  386. /**
  387. * 封面信息,发送消息时设置
  388. */
  389. @property(nonatomic,strong) TIMUGCCover * cover;
  390. @end
  391. #pragma mark - 群系统消息和tip消息
  392. /**
  393. * 群tips,成员变更信息
  394. */
  395. @interface TIMGroupTipsElemMemberInfo : NSObject
  396. /**
  397. * 变更用户
  398. */
  399. @property(nonatomic,strong) NSString * identifier;
  400. /**
  401. * 禁言时间(秒,表示还剩多少秒可以发言)
  402. */
  403. @property(nonatomic,assign) uint32_t shutupTime;
  404. @end
  405. /**
  406. * 群tips,群变更信息
  407. */
  408. @interface TIMGroupTipsElemGroupInfo : NSObject
  409. /**
  410. * 变更类型
  411. */
  412. @property(nonatomic, assign) TIM_GROUP_INFO_CHANGE_TYPE type;
  413. /**
  414. * 根据变更类型表示不同含义
  415. */
  416. @property(nonatomic,strong) NSString * value;
  417. @end
  418. /**
  419. * 群Tips
  420. */
  421. @interface TIMGroupTipsElem : TIMElem
  422. /**
  423. * 群组Id
  424. */
  425. @property(nonatomic,strong) NSString * group;
  426. /**
  427. * 群Tips类型
  428. */
  429. @property(nonatomic,assign) TIM_GROUP_TIPS_TYPE type;
  430. /**
  431. * 操作人用户名
  432. */
  433. @property(nonatomic,strong) NSString * opUser;
  434. /**
  435. * 被操作人列表 NSString* 数组
  436. */
  437. @property(nonatomic,strong) NSArray * userList;
  438. /**
  439. * 在群名变更时表示变更后的群名,否则为 nil
  440. */
  441. @property(nonatomic,strong) NSString * groupName;
  442. /**
  443. * 群信息变更: TIM_GROUP_TIPS_TYPE_INFO_CHANGE 时有效,为 TIMGroupTipsElemGroupInfo 结构体列表
  444. */
  445. @property(nonatomic,strong) NSArray * groupChangeList;
  446. /**
  447. * 成员变更: TIM_GROUP_TIPS_TYPE_MEMBER_INFO_CHANGE 时有效,为 TIMGroupTipsElemMemberInfo 结构体列表
  448. */
  449. @property(nonatomic,strong) NSArray * memberChangeList;
  450. /**
  451. * 操作者用户资料
  452. */
  453. @property(nonatomic,strong) TIMUserProfile * opUserInfo;
  454. /**
  455. * 操作者群成员资料
  456. */
  457. @property(nonatomic,strong) TIMGroupMemberInfo * opGroupMemberInfo;
  458. /**
  459. * 变更成员资料
  460. */
  461. @property(nonatomic,strong) NSDictionary * changedUserInfo;
  462. /**
  463. * 变更成员群内资料
  464. */
  465. @property(nonatomic,strong) NSDictionary * changedGroupMemberInfo;
  466. /**
  467. * 当前群人数: TIM_GROUP_TIPS_TYPE_INVITE、TIM_GROUP_TIPS_TYPE_QUIT_GRP、
  468. * TIM_GROUP_TIPS_TYPE_KICKED时有效
  469. */
  470. @property(nonatomic,assign) uint32_t memberNum;
  471. /**
  472. * 操作方平台信息
  473. * 取值: iOS Android Windows Mac Web RESTAPI Unknown
  474. */
  475. @property(nonatomic,strong) NSString * platform;
  476. @end
  477. /**
  478. * 群系统消息
  479. */
  480. @interface TIMGroupSystemElem : TIMElem
  481. /**
  482. * 操作类型
  483. */
  484. @property(nonatomic,assign) TIM_GROUP_SYSTEM_TYPE type;
  485. /**
  486. * 群组Id
  487. */
  488. @property(nonatomic,strong) NSString * group;
  489. /**
  490. * 操作人
  491. */
  492. @property(nonatomic,strong) NSString * user;
  493. /**
  494. * 操作理由
  495. */
  496. @property(nonatomic,strong) NSString * msg;
  497. /**
  498. * 消息标识,客户端无需关心
  499. */
  500. @property(nonatomic,assign) uint64_t msgKey;
  501. /**
  502. * 消息标识,客户端无需关心
  503. */
  504. @property(nonatomic,strong) NSData * authKey;
  505. /**
  506. * 用户自定义透传消息体(type=TIM_GROUP_SYSTEM_CUSTOM_INFO时有效)
  507. */
  508. @property(nonatomic,strong) NSData * userData;
  509. /**
  510. * 操作人资料
  511. */
  512. @property(nonatomic,strong) TIMUserProfile * opUserInfo;
  513. /**
  514. * 操作人群成员资料
  515. */
  516. @property(nonatomic,strong) TIMGroupMemberInfo * opGroupMemberInfo;
  517. /**
  518. * 操作方平台信息
  519. * 取值: iOS Android Windows Mac Web RESTAPI Unknown
  520. */
  521. @property(nonatomic,strong) NSString * platform;
  522. @end
  523. #pragma mark - 消息体TIMMessage
  524. /**
  525. 填入sound字段表示接收时不会播放声音
  526. */
  527. //extern NSString * const kIOSOfflinePushNoSound;
  528. @interface TIMOfflinePushInfo : NSObject
  529. /**
  530. * 自定义消息描述信息,做离线Push时文本展示
  531. */
  532. @property(nonatomic,strong) NSString * desc;
  533. /**
  534. * 离线Push时扩展字段信息
  535. */
  536. @property(nonatomic,strong) NSString * ext;
  537. /**
  538. * 推送规则标志
  539. */
  540. @property(nonatomic,assign) TIMOfflinePushFlag pushFlag;
  541. /**
  542. * iOS离线推送配置
  543. */
  544. @property(nonatomic,strong) TIMIOSOfflinePushConfig * iosConfig;
  545. /**
  546. * Android离线推送配置
  547. */
  548. @property(nonatomic,strong) TIMAndroidOfflinePushConfig * androidConfig;
  549. @end
  550. /**
  551. * 消息
  552. */
  553. @interface TIMMessage : NSObject
  554. /**
  555. * 增加Elem
  556. *
  557. * @param elem elem结构
  558. *
  559. * @return 0 表示成功
  560. * 1 禁止添加Elem(文件或语音多于两个Elem)
  561. * 2 未知Elem
  562. */
  563. - (int)addElem:(TIMElem*)elem;
  564. /**
  565. * 获取对应索引的Elem
  566. *
  567. * @param index 对应索引
  568. *
  569. * @return 返回对应Elem
  570. */
  571. - (TIMElem*)getElem:(int)index;
  572. /**
  573. * 获取Elem数量
  574. *
  575. * @return elem数量
  576. */
  577. - (int)elemCount;
  578. /**
  579. * 设置离线推送配置信息
  580. *
  581. * @param info 配置信息
  582. *
  583. * @return 0 成功
  584. */
  585. - (int)setOfflinePushInfo:(TIMOfflinePushInfo*)info;
  586. /**
  587. * 获得本消息离线推送配置信息
  588. *
  589. * @return 配置信息,没设置返回nil
  590. */
  591. - (TIMOfflinePushInfo*)getOfflinePushInfo;
  592. /**
  593. * 设置业务命令字
  594. *
  595. * @param buzCmds 业务命令字列表
  596. * @"im_open_busi_cmd.msg_robot" 表示发送给IM机器人
  597. * @"im_open_busi_cmd.msg_nodb" 表示不存离线
  598. * @"im_open_busi_cmd.msg_noramble" 表示不存漫游
  599. * @"im_open_busi_cmd.msg_nopush" 表示不实时下发给用户
  600. *
  601. * @return 0 成功
  602. */
  603. -(int) setBusinessCmd:(NSArray*)buzCmds;
  604. /**
  605. * 获取会话
  606. *
  607. * @return 该消息所对应会话
  608. */
  609. - (TIMConversation*)getConversation;
  610. /**
  611. * 消息状态
  612. *
  613. * @return TIMMessageStatus 消息状态
  614. */
  615. - (TIMMessageStatus)status;
  616. /**
  617. * 是否发送方
  618. *
  619. * @return TRUE 表示是发送消息 FALSE 表示是接收消息
  620. */
  621. - (BOOL)isSelf;
  622. /**
  623. * 获取发送方
  624. *
  625. * @return 发送方标识
  626. */
  627. - (NSString*)sender;
  628. /**
  629. * 消息Id
  630. */
  631. - (NSString*)msgId;
  632. /**
  633. * 获取消息uniqueId
  634. *
  635. * @return uniqueId
  636. */
  637. - (uint64_t)uniqueId;
  638. /**
  639. * 当前消息的时间戳
  640. *
  641. * @return 时间戳
  642. */
  643. - (NSDate*)timestamp;
  644. /**
  645. * 获取发送者资料(发送者为自己时可能为空)
  646. *
  647. * @return 发送者资料,nil 表示没有获取资料,目前只有字段:identifier、nickname、faceURL、customInfo
  648. */
  649. - (TIMUserProfile*)getSenderProfile;
  650. /**
  651. * 获取发送者群内资料(发送者为自己时可能为空)
  652. *
  653. * @return 发送者群内资料,nil 表示没有获取资料或者不是群消息,目前只有字段:member、nameCard、role、customInfo
  654. */
  655. - (TIMGroupMemberInfo*)getSenderGroupMemberProfile;
  656. /**
  657. * 设置消息的优先级
  658. *
  659. * @param priority 优先级
  660. *
  661. * @return TRUE 设置成功
  662. */
  663. - (BOOL)setPriority:(TIMMessagePriority)priority;
  664. /**
  665. * 获取消息的优先级
  666. *
  667. * @return 优先级
  668. */
  669. - (TIMMessagePriority)getPriority;
  670. /**
  671. * 获取消息所属会话的接收消息选项(仅对群组消息有效)
  672. *
  673. * @return 接收消息选项
  674. */
  675. - (TIMGroupReceiveMessageOpt)getRecvOpt;
  676. /**
  677. * 拷贝消息中的属性(ELem、priority、online、offlinePushInfo)
  678. *
  679. * @param srcMsg 源消息
  680. *
  681. * @return 0 成功
  682. */
  683. - (int)copyFrom:(TIMMessage*)srcMsg;
  684. @end
  685. #endif