JMSGUser.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  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 userInfo 用户名. 长度 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 handler 结果回调
  124. *
  125. * - devices 用户登录设备信息,NSArray<JMSGDeviceInfo>
  126. * - error 错误信息,为 nil 时表示成功
  127. *
  128. * @discussion 回调中 devices 返回的是设备信息,具体属性请查看 JMSGDeviceInfo 类
  129. */
  130. + (void)loginWithUsername:(NSString *)username
  131. password:(NSString *)password
  132. handler:(void(^)(NSArray <__kindof JMSGDeviceInfo *>*devices,NSError *error))handler;
  133. /*!
  134. * @abstract 当前用户退出登录
  135. *
  136. * @param handler 结果回调。正常返回时 resultObject 也是 nil。
  137. *
  138. */
  139. + (void)logout:(JMSGCompletionHandler JMSG_NULLABLE)handler;
  140. /*!
  141. * @abstract 批量获取用户信息
  142. *
  143. * @param usernameArray 用户名列表。NSArray 里的数据类型为 NSString
  144. * @param handler 结果回调。正常返回时 resultObject 的类型为 NSArray,数组里的数据类型为 JMSGUser
  145. *
  146. * @discussion 这是一个批量接口。
  147. */
  148. + (void)userInfoArrayWithUsernameArray:(NSArray JMSG_GENERIC(__kindof NSString *)*)usernameArray
  149. completionHandler:(JMSGCompletionHandler)handler;
  150. /*!
  151. * @abstract 批量获取跨应用的用户信息
  152. */
  153. + (void)userInfoArrayWithUsernameArray:(NSArray JMSG_GENERIC(__kindof NSString *)*)usernameArray
  154. appKey:( NSString *JMSG_NULLABLE)userAppKey
  155. completionHandler:(JMSGCompletionHandler)handler;
  156. /*!
  157. * @abstract 获取用户本身个人信息接口
  158. *
  159. * @return 当前登陆账号个人信息
  160. *
  161. * @discussion 注意:返回值有可能为空
  162. */
  163. + (JMSGUser *)myInfo;
  164. /*!
  165. * @abstract 更新用户信息接口
  166. *
  167. * @param parameter 新的属性值
  168. * Birthday&&Gender 是NSNumber类型, Avatar NSData类型, extras是 NSDictionary 类型, 其他 NSString
  169. * @param type 更新属性类型
  170. * @param handler 更新用户信息回调接口函数
  171. *
  172. * @discussion 注意:建议使用 [+(void)updateMyInfoWithUserInfo:completionHandler:] 接口修改信息
  173. */
  174. + (void)updateMyInfoWithParameter:(id)parameter
  175. userFieldType:(JMSGUserField)type
  176. completionHandler:(JMSGCompletionHandler JMSG_NULLABLE)handler;
  177. /*!
  178. * @abstract 更新用户信息(支持将字段统一上传)
  179. *
  180. * @param userInfo 用户信息对象,类型是 JMSGUserInfo
  181. * @param handler 更新用户信息回调接口函数
  182. *
  183. * @discussion 参数 userInfo 是 JMSGUserInfo 类,JMSGUserInfo 仅可用于修改用户信息
  184. */
  185. + (void)updateMyInfoWithUserInfo:(JMSGUserInfo *)userInfo
  186. completionHandler:(JMSGCompletionHandler)handler;
  187. /*!
  188. * @abstract 更新头像(支持传图片格式)
  189. *
  190. * @param avatarData 头像数据
  191. * @param avatarFormat 头像格式,可以为空,不包括"."
  192. * @param handler 回调
  193. *
  194. * @discussion 头像格式参数直接填格式名称,不要带点。正确:@"png",错误:@".png"
  195. */
  196. + (void)updateMyAvatarWithData:(NSData *)avatarData
  197. avatarFormat:(NSString *)avatarFormat
  198. completionHandler:(JMSGCompletionHandler)handler;
  199. /*!
  200. * @abstract 更新密码接口
  201. *
  202. * @param newPassword 用户新的密码
  203. * @param oldPassword 用户旧的密码
  204. * @param handler 更新密码回调接口函数
  205. */
  206. + (void)updateMyPasswordWithNewPassword:(NSString *)newPassword
  207. oldPassword:(NSString *)oldPassword
  208. completionHandler:(JMSGCompletionHandler JMSG_NULLABLE)handler;
  209. /*!
  210. * @abstract 添加黑名单
  211. * @param usernameArray 作用对象的username数组
  212. * @param handler 结果回调。回调参数: error 为 nil, 表示设置成功
  213. *
  214. * @discussion 可以一次添加多个用户
  215. */
  216. + (void)addUsersToBlacklist:(NSArray JMSG_GENERIC(__kindof NSString *)*)usernameArray
  217. completionHandler:(JMSGCompletionHandler)handler;
  218. /*!
  219. * @abstract 删除黑名单
  220. * @param usernameArray 作用对象的username数组
  221. * @param handler 结果回调。回调参数:error 为 nil, 表示设置成功
  222. *
  223. * @discussion 可以一次删除多个黑名单用户
  224. */
  225. + (void)delUsersFromBlacklist:(NSArray JMSG_GENERIC(__kindof NSString *)*)usernameArray
  226. completionHandler:(JMSGCompletionHandler)handler;
  227. /*!
  228. * @abstract 跨应用添加黑名单
  229. * @param usernameArray 作用对象的username数组
  230. * @param appKey 应用的appKey
  231. * @param handler 结果回调。回调参数:error 为 nil, 表示设置成功
  232. *
  233. * @discussion 可以一次添加多个用户
  234. */
  235. + (void)addUsersToBlacklist:(NSArray JMSG_GENERIC(__kindof NSString *)*)usernameArray
  236. appKey:(NSString *)userAppKey
  237. completionHandler:(JMSGCompletionHandler)handler;
  238. /*!
  239. * @abstract 跨应用删除黑名单
  240. * @param usernameArray 作用对象的username数组
  241. * @param appKey 应用的appKey
  242. * @param handler 结果回调。回调参数:error 为 nil, 表示设置成功
  243. *
  244. * @discussion 可以一次删除多个黑名单用户
  245. */
  246. + (void)delUsersFromBlacklist:(NSArray JMSG_GENERIC(__kindof NSString *)*)usernameArray
  247. appKey:(NSString *)userAppKey
  248. completionHandler:(JMSGCompletionHandler)handler;
  249. ///----------------------------------------------------
  250. /// @name Basic Fields 基本属性
  251. ///----------------------------------------------------
  252. /*!
  253. * @abstract 用户名
  254. *
  255. * @discussion 这是用户帐号,注册后不可变更。App 级别唯一。这是所有用户相关 API 的用户标识。
  256. */
  257. @property(nonatomic, copy, readonly) NSString *username;
  258. /*!
  259. * @abstract 用户昵称
  260. *
  261. * @discussion 用户自定义的昵称,可任意定义。
  262. */
  263. @property(nonatomic, copy, readonly) NSString * JMSG_NULLABLE nickname;
  264. /*!
  265. * @abstract 用户头像(媒体文件ID)
  266. *
  267. * @discussion 此文件ID仅用于内部更新,不支持外部URL。
  268. */
  269. @property(nonatomic, copy, readonly) NSString * JMSG_NULLABLE avatar;
  270. /*!
  271. * @abstract 性别
  272. *
  273. * @discussion 这是一个 enum 类型,支持 3 个选项:未知,男,女
  274. */
  275. @property(nonatomic, assign, readonly) JMSGUserGender gender;
  276. /*!
  277. * @abstract 生日
  278. */
  279. @property(nonatomic, copy, readonly) NSString * JMSG_NULLABLE birthday;
  280. @property(nonatomic, copy, readonly) NSString * JMSG_NULLABLE region;
  281. @property(nonatomic, copy, readonly) NSString * JMSG_NULLABLE signature;
  282. @property(nonatomic, copy, readonly) NSString * JMSG_NULLABLE address;
  283. /*!
  284. * @abstract 备注名
  285. */
  286. @property(nonatomic, copy, readonly) NSString * JMSG_NULLABLE noteName;
  287. /*!
  288. * @abstract 备注信息
  289. */
  290. @property(nonatomic, copy, readonly) NSString * JMSG_NULLABLE noteText;
  291. /*!
  292. * @abstract 此用户所在的 appKey
  293. * @discussion 为主应用时, 此字段为空
  294. */
  295. @property(nonatomic, copy, readonly) NSString * JMSG_NULLABLE appKey;
  296. /*!
  297. * @abstract 用户扩展字段
  298. */
  299. @property(nonatomic, strong, readonly) NSDictionary * JMSG_NULLABLE extras;
  300. /*!
  301. * @abstract 该用户是否已被设置为免打扰
  302. *
  303. * @discussion YES:是 , NO: 否
  304. */
  305. @property(nonatomic, assign, readonly) BOOL isNoDisturb;
  306. /*!
  307. * @abstract 该用户是否已被加入黑名单
  308. *
  309. * @discussion YES:是 , NO: 否
  310. */
  311. @property(nonatomic, assign, readonly) BOOL isInBlacklist;
  312. /*!
  313. * @abstract 是否是好友关系
  314. *
  315. * @discussion 如果已经添加了好友,isFriend = YES ,否则为NO;
  316. */
  317. @property(nonatomic, assign, readonly) BOOL isFriend;
  318. /*!
  319. * @abstract 设置用户免打扰(支持跨应用设置)
  320. *
  321. * @param isNoDisturb 是否全局免打扰 YES:是 NO: 否
  322. * @param handler 结果回调。回调参数: error 为 nil, 表示设置成功
  323. *
  324. * @discussion 针对单个用户设置免打扰,这个接口支持跨应用设置免打扰
  325. */
  326. - (void)setIsNoDisturb:(BOOL)isNoDisturb handler:(JMSGCompletionHandler)handler;
  327. /*!
  328. * @abstract 修改好友备注名
  329. *
  330. * @param noteName 备注名
  331. *
  332. * @discussion 注意:这是建立在是好友关系的前提下,修改好友的备注名
  333. */
  334. - (void)updateNoteName:(NSString *)noteName completionHandler:(JMSGCompletionHandler)handler;
  335. /*!
  336. * @abstract 修改好友备注信息
  337. *
  338. * @param noteText 备注信息
  339. *
  340. * @discussion 注意:这是建立在是好友关系的前提下,修改好友的备注信息
  341. */
  342. - (void)updateNoteText:(NSString *)noteText completionHandler:(JMSGCompletionHandler)handler;
  343. /*!
  344. * @abstract 获取头像缩略图文件数据
  345. *
  346. * @param handler 结果回调。回调参数:
  347. *
  348. * - data 头像数据;
  349. * - objectId 用户username;
  350. * - error 不为nil表示出错;
  351. *
  352. * 如果 error 为 ni, data 也为 nil, 表示没有头像数据.
  353. *
  354. * @discussion 需要展示缩略图时使用。
  355. * 如果本地已经有文件,则会返回本地,否则会从服务器上下载。
  356. */
  357. - (void)thumbAvatarData:(JMSGAsyncDataHandler)handler;
  358. /*!
  359. * @abstract 获取头像缩略文件的本地路径
  360. *
  361. * @return 返回本地路,返回值只有在下载完成之后才有意义
  362. */
  363. - (NSString *JMSG_NULLABLE)thumbAvatarLocalPath;
  364. /*!
  365. * @abstract 获取头像大图文件数据
  366. *
  367. * @param handler 结果回调。回调参数:
  368. *
  369. * - data 头像数据;
  370. * - objectId 用户username;
  371. * - error 不为nil表示出错;
  372. *
  373. * 如果 error 为 ni, data 也为 nil, 表示没有头像数据.
  374. *
  375. * @discussion 需要展示大图图时使用
  376. * 如果本地已经有文件,则会返回本地,否则会从服务器上下载。
  377. */
  378. - (void)largeAvatarData:(JMSGAsyncDataHandler)handler;
  379. /*!
  380. * @abstract 获取头像大图文件的本地路径
  381. *
  382. * @return 返回本地路,返回值只有在下载完成之后才有意义
  383. */
  384. - (NSString *JMSG_NULLABLE)largeAvatarLocalPath;
  385. /*!
  386. * @abstract 用户展示名
  387. *
  388. * @discussion 展示优先级:备注名(noteName) -> 昵称(nickname) -> 用户名(username)
  389. */
  390. - (NSString *)displayName;
  391. - (BOOL)isEqualToUser:(JMSGUser * JMSG_NULLABLE)user;
  392. JMSG_ASSUME_NONNULL_END
  393. @end