JMSGUser.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  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. @class JMSGDeviceInfo;
  14. /*!
  15. * @abstract 更新用户字段
  16. */
  17. typedef NS_ENUM(NSUInteger, JMSGUserField) {
  18. /// 用户信息字段: 昵称
  19. kJMSGUserFieldsNickname = 0,
  20. /// 用户信息字段: 生日
  21. kJMSGUserFieldsBirthday = 1,
  22. /// 用户信息字段: 签名
  23. kJMSGUserFieldsSignature = 2,
  24. /// 用户信息字段: 性别
  25. kJMSGUserFieldsGender = 3,
  26. /// 用户信息字段: 区域
  27. kJMSGUserFieldsRegion = 4,
  28. /// 用户信息字段: 头像 (内部定义的 media_id)
  29. kJMSGUserFieldsAvatar = 5,
  30. /// 用户信息字段: 地址
  31. kJMSGUserFieldsAddress = 6,
  32. /// 用户信息字段: 扩展字段
  33. kJMSGUserFieldsExtras = 7,
  34. };
  35. /*!
  36. * @abstract 用户性别
  37. */
  38. typedef NS_ENUM(NSUInteger, JMSGUserGender) {
  39. /// 用户性别类型: 未知
  40. kJMSGUserGenderUnknown = 0,
  41. /// 用户性别类型: 男
  42. kJMSGUserGenderMale,
  43. /// 用户性别类型: 女
  44. kJMSGUserGenderFemale,
  45. };
  46. /*!
  47. * 用户信息类(用于修改用户信息、注册新用户)
  48. */
  49. @interface JMSGUserInfo : NSObject
  50. JMSG_ASSUME_NONNULL_BEGIN
  51. /** 昵称 */
  52. @property(nonatomic, strong) NSString * nickname;
  53. /** 生日,格式:时间戳 */
  54. @property(nonatomic, strong) NSNumber * birthday;
  55. /** 签名 */
  56. @property(nonatomic, strong) NSString * signature;
  57. /** 性别 */
  58. @property(nonatomic, assign) JMSGUserGender gender;
  59. /** 区域 */
  60. @property(nonatomic, strong) NSString * region;
  61. /** 地址 */
  62. @property(nonatomic, strong) NSString * address;
  63. /** 头像数据,注意:注册新用户时不支持同时上传头像 */
  64. @property(nonatomic, strong) NSData * avatarData;
  65. /** 信息扩展字段,value 仅支持 NSString 类型*/
  66. @property(nonatomic, strong) NSDictionary * extras;
  67. JMSG_ASSUME_NONNULL_END
  68. @end
  69. /*!
  70. * 用户
  71. */
  72. @interface JMSGUser : NSObject <NSCopying>
  73. JMSG_ASSUME_NONNULL_BEGIN
  74. ///----------------------------------------------------
  75. /// @name Class Methods 类方法
  76. ///----------------------------------------------------
  77. /*!
  78. * @abstract 新用户注册
  79. *
  80. * @param username 用户名. 长度 4~128 位.
  81. * 支持的字符: 字母,数字,下划线,英文减号,英文点,@邮件符号. 首字母只允许是字母或者数字.
  82. * @param password 用户密码. 长度 4~128 位.
  83. * @param handler 结果回调. 返回正常时 resultObject 为 nil.
  84. */
  85. + (void)registerWithUsername:(NSString *)username
  86. password:(NSString *)password
  87. completionHandler:(JMSGCompletionHandler JMSG_NULLABLE)handler;
  88. /*!
  89. * @abstract 新用户注册(支持携带用户信息字段)
  90. *
  91. * @param username 用户名. 长度 4~128 位.
  92. * 支持的字符: 字母,数字,下划线,英文减号,英文点,@邮件符号. 首字母只允许是字母或者数字.
  93. * @param password 用户密码. 长度 4~128 位.
  94. * @param userInfo 用户信息类,注册时携带用户信息字段,除用户头像字段
  95. * @param handler 结果回调. 返回正常时 resultObject 为 nil.
  96. *
  97. * @discussion 注意: 注册时不支持上传头像,其他信息全部支持
  98. */
  99. + (void)registerWithUsername:(NSString *)username
  100. password:(NSString *)password
  101. userInfo:(JMSGUserInfo *JMSG_NULLABLE)userInfo
  102. completionHandler:(JMSGCompletionHandler JMSG_NULLABLE)handler;
  103. /*!
  104. * @abstract 用户登录
  105. *
  106. * @param username 登录用户名. 规则与注册接口相同.
  107. * @param password 登录密码. 规则与注册接口相同.
  108. * @param handler 结果回调
  109. *
  110. * - resultObject 简单封装的user对象
  111. * - error 错误信息
  112. *
  113. * 注意:上层不要直接使用 resultObject 对象做操作, 因为 resultOjbect 只是一个简单封装的user对象.
  114. */
  115. + (void)loginWithUsername:(NSString *)username
  116. password:(NSString *)password
  117. completionHandler:(JMSGCompletionHandler JMSG_NULLABLE)handler;
  118. /*!
  119. * @abstract 用户登录,返回登录设备信息
  120. *
  121. * @param username 登录用户名. 规则与注册接口相同.
  122. * @param password 登录密码. 规则与注册接口相同.
  123. * @param devicesInfo 登录设备回调,返回数据为 NSArray<JMSGDeviceInfo>
  124. * @param handler 结果回调
  125. *
  126. * - resultObject 简单封装的user对象,上层不要直接使用 resultObject 对象做操作, 因为它只是一个简单封装的user对象
  127. * - error 错误信息
  128. *
  129. * @discussion 回调中 devices 返回的是设备信息,具体属性请查看 JMSGDeviceInfo 类
  130. */
  131. + (void)loginWithUsername:(NSString *)username
  132. password:(NSString *)password
  133. devicesInfo:(nullable void(^)(NSArray <__kindof JMSGDeviceInfo *>*devices))devicesInfo
  134. completionHandler:(JMSGCompletionHandler JMSG_NULLABLE)handler;
  135. /*!
  136. * @abstract 当前用户退出登录
  137. *
  138. * @param handler 结果回调。正常返回时 resultObject 也是 nil。
  139. *
  140. */
  141. + (void)logout:(JMSGCompletionHandler JMSG_NULLABLE)handler;
  142. /*!
  143. * @abstract 批量获取用户信息
  144. *
  145. * @param usernameArray 用户名列表。NSArray 里的数据类型为 NSString
  146. * @param handler 结果回调。正常返回时 resultObject 的类型为 NSArray,数组里的数据类型为 JMSGUser
  147. *
  148. * @discussion 这是一个批量接口。
  149. */
  150. + (void)userInfoArrayWithUsernameArray:(NSArray JMSG_GENERIC(__kindof NSString *)*)usernameArray
  151. completionHandler:(JMSGCompletionHandler)handler;
  152. /*!
  153. * @abstract 批量获取跨应用的用户信息
  154. */
  155. + (void)userInfoArrayWithUsernameArray:(NSArray JMSG_GENERIC(__kindof NSString *)*)usernameArray
  156. appKey:( NSString *JMSG_NULLABLE)userAppKey
  157. completionHandler:(JMSGCompletionHandler)handler;
  158. /*!
  159. * @abstract 获取用户信息
  160. *
  161. * @param uid 用户的 uid
  162. *
  163. * @return 该 uid 用户信息
  164. *
  165. * @discussion 注意:返回值有可能为空,仅仅是本地查询
  166. */
  167. + (JMSGUser *JMSG_NULLABLE)userWithUid:(SInt64)uid;
  168. /*!
  169. * @abstract 获取用户本身个人信息接口
  170. *
  171. * @return 当前登陆账号个人信息
  172. *
  173. * @discussion 注意:返回值有可能为空
  174. */
  175. + (JMSGUser *)myInfo;
  176. /*!
  177. * @abstract 更新用户信息接口
  178. *
  179. * @param parameter 新的属性值
  180. * Birthday&&Gender 是NSNumber类型, Avatar NSData类型, extras是 NSDictionary 类型, 其他 NSString
  181. * @param type 更新属性类型
  182. * @param handler 更新用户信息回调接口函数
  183. *
  184. * @discussion 注意:建议使用 [+(void)updateMyInfoWithUserInfo:completionHandler:] 接口修改信息
  185. */
  186. + (void)updateMyInfoWithParameter:(id)parameter
  187. userFieldType:(JMSGUserField)type
  188. completionHandler:(JMSGCompletionHandler JMSG_NULLABLE)handler;
  189. /*!
  190. * @abstract 更新用户信息(支持将字段统一上传)
  191. *
  192. * @param userInfo 用户信息对象,类型是 JMSGUserInfo
  193. * @param handler 更新用户信息回调接口函数
  194. *
  195. * @discussion 参数 userInfo 是 JMSGUserInfo 类,JMSGUserInfo 仅可用于修改用户信息
  196. */
  197. + (void)updateMyInfoWithUserInfo:(JMSGUserInfo *)userInfo
  198. completionHandler:(JMSGCompletionHandler)handler;
  199. /*!
  200. * @abstract 更新头像(支持传图片格式)
  201. *
  202. * @param avatarData 头像数据
  203. * @param avatarFormat 头像格式,可以为空,不包括"."
  204. * @param handler 回调
  205. *
  206. * @discussion 头像格式参数直接填格式名称,不要带点。正确:@"png",错误:@".png"
  207. */
  208. + (void)updateMyAvatarWithData:(NSData *)avatarData
  209. avatarFormat:(NSString *)avatarFormat
  210. completionHandler:(JMSGCompletionHandler)handler;
  211. /*!
  212. * @abstract 更新密码接口
  213. *
  214. * @param newPassword 用户新的密码
  215. * @param oldPassword 用户旧的密码
  216. * @param handler 更新密码回调接口函数
  217. */
  218. + (void)updateMyPasswordWithNewPassword:(NSString *)newPassword
  219. oldPassword:(NSString *)oldPassword
  220. completionHandler:(JMSGCompletionHandler JMSG_NULLABLE)handler;
  221. /*!
  222. * @abstract 添加黑名单
  223. * @param usernameArray 作用对象的username数组
  224. * @param handler 结果回调。回调参数: error 为 nil, 表示设置成功
  225. *
  226. * @discussion 可以一次添加多个用户
  227. */
  228. + (void)addUsersToBlacklist:(NSArray JMSG_GENERIC(__kindof NSString *)*)usernameArray
  229. completionHandler:(JMSGCompletionHandler)handler;
  230. /*!
  231. * @abstract 删除黑名单
  232. * @param usernameArray 作用对象的username数组
  233. * @param handler 结果回调。回调参数:error 为 nil, 表示设置成功
  234. *
  235. * @discussion 可以一次删除多个黑名单用户
  236. */
  237. + (void)delUsersFromBlacklist:(NSArray JMSG_GENERIC(__kindof NSString *)*)usernameArray
  238. completionHandler:(JMSGCompletionHandler)handler;
  239. /*!
  240. * @abstract 跨应用添加黑名单
  241. * @param usernameArray 作用对象的username数组
  242. * @param userAppKey 应用的appKey
  243. * @param handler 结果回调。回调参数:error 为 nil, 表示设置成功
  244. *
  245. * @discussion 可以一次添加多个用户
  246. */
  247. + (void)addUsersToBlacklist:(NSArray JMSG_GENERIC(__kindof NSString *)*)usernameArray
  248. appKey:(NSString *)userAppKey
  249. completionHandler:(JMSGCompletionHandler)handler;
  250. /*!
  251. * @abstract 跨应用删除黑名单
  252. * @param usernameArray 作用对象的username数组
  253. * @param userAppKey 应用的appKey
  254. * @param handler 结果回调。回调参数:error 为 nil, 表示设置成功
  255. *
  256. * @discussion 可以一次删除多个黑名单用户
  257. */
  258. + (void)delUsersFromBlacklist:(NSArray JMSG_GENERIC(__kindof NSString *)*)usernameArray
  259. appKey:(NSString *)userAppKey
  260. completionHandler:(JMSGCompletionHandler)handler;
  261. ///----------------------------------------------------
  262. /// @name Basic Fields 基本属性
  263. ///----------------------------------------------------
  264. /*!
  265. * @abstract 用户uid
  266. */
  267. @property(nonatomic, assign, readonly) SInt64 uid;
  268. /*!
  269. * @abstract 用户名
  270. *
  271. * @discussion 这是用户帐号,注册后不可变更。App 级别唯一。这是所有用户相关 API 的用户标识。
  272. */
  273. @property(nonatomic, copy, readonly) NSString *username;
  274. /*!
  275. * @abstract 用户昵称
  276. *
  277. * @discussion 用户自定义的昵称,可任意定义。
  278. */
  279. @property(nonatomic, copy, readonly) NSString * JMSG_NULLABLE nickname;
  280. /*!
  281. * @abstract 用户头像(媒体文件ID)
  282. *
  283. * @discussion 此文件ID仅用于内部更新,不支持外部URL。
  284. */
  285. @property(nonatomic, copy, readonly) NSString * JMSG_NULLABLE avatar;
  286. /*!
  287. * @abstract 性别
  288. *
  289. * @discussion 这是一个 enum 类型,支持 3 个选项:未知,男,女
  290. */
  291. @property(nonatomic, assign, readonly) JMSGUserGender gender;
  292. /*!
  293. * @abstract 生日
  294. */
  295. @property(nonatomic, copy, readonly) NSString * JMSG_NULLABLE birthday;
  296. @property(nonatomic, copy, readonly) NSString * JMSG_NULLABLE region;
  297. @property(nonatomic, copy, readonly) NSString * JMSG_NULLABLE signature;
  298. @property(nonatomic, copy, readonly) NSString * JMSG_NULLABLE address;
  299. /*!
  300. * @abstract 备注名
  301. */
  302. @property(nonatomic, copy, readonly) NSString * JMSG_NULLABLE noteName;
  303. /*!
  304. * @abstract 备注信息
  305. */
  306. @property(nonatomic, copy, readonly) NSString * JMSG_NULLABLE noteText;
  307. /*!
  308. * @abstract 此用户所在的 appKey
  309. * @discussion 为主应用时, 此字段为空
  310. */
  311. @property(nonatomic, copy, readonly) NSString * JMSG_NULLABLE appKey;
  312. /*!
  313. * @abstract 用户扩展字段
  314. */
  315. @property(nonatomic, strong, readonly) NSDictionary * JMSG_NULLABLE extras;
  316. /*!
  317. * @abstract 该用户是否已被设置为免打扰
  318. *
  319. * @discussion YES:是 , NO: 否
  320. */
  321. @property(nonatomic, assign, readonly) BOOL isNoDisturb;
  322. /*!
  323. * @abstract 该用户是否已被加入黑名单
  324. *
  325. * @discussion YES:是 , NO: 否
  326. */
  327. @property(nonatomic, assign, readonly) BOOL isInBlacklist;
  328. /*!
  329. * @abstract 是否是好友关系
  330. *
  331. * @discussion 如果已经添加了好友,isFriend = YES ,否则为NO;
  332. */
  333. @property(nonatomic, assign, readonly) BOOL isFriend;
  334. /*!
  335. * @abstract 设置用户免打扰(支持跨应用设置)
  336. *
  337. * @param isNoDisturb 是否全局免打扰 YES:是 NO: 否
  338. * @param handler 结果回调。回调参数: error 为 nil, 表示设置成功
  339. *
  340. * @discussion 针对单个用户设置免打扰,这个接口支持跨应用设置免打扰
  341. */
  342. - (void)setIsNoDisturb:(BOOL)isNoDisturb handler:(JMSGCompletionHandler)handler;
  343. /*!
  344. * @abstract 修改好友备注名
  345. *
  346. * @param noteName 备注名
  347. *
  348. * @discussion 注意:这是建立在是好友关系的前提下,修改好友的备注名
  349. */
  350. - (void)updateNoteName:(NSString *)noteName completionHandler:(JMSGCompletionHandler)handler;
  351. /*!
  352. * @abstract 修改好友备注信息
  353. *
  354. * @param noteText 备注信息
  355. *
  356. * @discussion 注意:这是建立在是好友关系的前提下,修改好友的备注信息
  357. */
  358. - (void)updateNoteText:(NSString *)noteText completionHandler:(JMSGCompletionHandler)handler;
  359. /*!
  360. * @abstract 获取头像缩略图文件数据
  361. *
  362. * @param handler 结果回调。回调参数:
  363. *
  364. * - data 头像数据;
  365. * - objectId 用户username;
  366. * - error 不为nil表示出错;
  367. *
  368. * 如果 error 为 ni, data 也为 nil, 表示没有头像数据.
  369. *
  370. * @discussion 需要展示缩略图时使用。
  371. * 如果本地已经有文件,则会返回本地,否则会从服务器上下载。
  372. */
  373. - (void)thumbAvatarData:(JMSGAsyncDataHandler)handler;
  374. /*!
  375. * @abstract 获取头像缩略文件的本地路径
  376. *
  377. * @return 返回本地路,返回值只有在下载完成之后才有意义
  378. */
  379. - (NSString *JMSG_NULLABLE)thumbAvatarLocalPath;
  380. /*!
  381. * @abstract 获取头像大图文件数据
  382. *
  383. * @param handler 结果回调。回调参数:
  384. *
  385. * - data 头像数据;
  386. * - objectId 用户username;
  387. * - error 不为nil表示出错;
  388. *
  389. * 如果 error 为 ni, data 也为 nil, 表示没有头像数据.
  390. *
  391. * @discussion 需要展示大图图时使用
  392. * 如果本地已经有文件,则会返回本地,否则会从服务器上下载。
  393. */
  394. - (void)largeAvatarData:(JMSGAsyncDataHandler)handler;
  395. /*!
  396. * @abstract 获取头像大图文件的本地路径
  397. *
  398. * @return 返回本地路,返回值只有在下载完成之后才有意义
  399. */
  400. - (NSString *JMSG_NULLABLE)largeAvatarLocalPath;
  401. /*!
  402. * @abstract 用户展示名
  403. *
  404. * @discussion 展示优先级:备注名(noteName) -> 昵称(nickname) -> 用户名(username)
  405. */
  406. - (NSString *)displayName;
  407. - (BOOL)isEqualToUser:(JMSGUser * JMSG_NULLABLE)user;
  408. JMSG_ASSUME_NONNULL_END
  409. @end