GroupDBMgr.m 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287
  1. //
  2. // GroupDBMgr.m
  3. // zhuxun
  4. //
  5. // Created by winsoft on 17/4/24.
  6. //
  7. //
  8. #import "GroupDBMgr.h"
  9. #import "DBOperation.h"
  10. //#import "HttpManager.h"
  11. //#import "GroupMsgRSMgrCenter.h"
  12. //#import "MessageHandleCenter.h"
  13. #define MuiltTextPicExpression @"([\\s\\S]*?)\\[image\\-src=\"([a-zA-Z0-9]{32})\"\\]([\\s\\S]*?)"
  14. #define TeamShareExpression @"\\<TeamShare\\>(.*)\\<\\/TeamShare\\>"
  15. @interface GroupDBMgr()
  16. /**
  17. * addrbook
  18. */
  19. @property (nonatomic , strong) NSMutableDictionary *allUserDict;
  20. /**
  21. * usergroupEntity
  22. */
  23. @property (nonatomic , strong) NSMutableDictionary *allUserGroupsDict;
  24. /**
  25. * recentEntiy
  26. */
  27. @property (nonatomic , strong) NSMutableDictionary *allUserRecentsDict;
  28. @end
  29. @implementation GroupDBMgr
  30. + (instancetype)shareInstance
  31. {
  32. static GroupDBMgr * groupDBMgr;
  33. static dispatch_once_t onceToken;
  34. dispatch_once(&onceToken, ^{
  35. groupDBMgr = [[GroupDBMgr alloc] init];
  36. });
  37. return groupDBMgr;
  38. }
  39. - (NSString *)getMessageID
  40. {
  41. NSString *uuid = [[[[NSUUID UUID]UUIDString]stringByReplacingOccurrencesOfString:@"-" withString:@""]lowercaseString];
  42. return uuid;
  43. }
  44. - (NSMutableDictionary *)allUserDict
  45. {
  46. if (!_allUserDict) {
  47. _allUserDict = [NSMutableDictionary dictionary];
  48. }
  49. return _allUserDict;
  50. }
  51. - (NSMutableDictionary *)allUserRecentsDict
  52. {
  53. if (!_allUserRecentsDict) {
  54. _allUserRecentsDict = [NSMutableDictionary dictionary];
  55. }
  56. return _allUserRecentsDict;
  57. }
  58. - (NSMutableDictionary *)allUserGroupsDict
  59. {
  60. if (!_allUserGroupsDict) {
  61. _allUserGroupsDict = [NSMutableDictionary dictionary];
  62. }
  63. return _allUserGroupsDict;
  64. }
  65. //- (void)getGroupEntityWithGroupID:(NSString *)groupID resultGroupEntityBlock:(void(^)(UserGroupEntity *userGroupEntity))resultGroupEntityBlock
  66. //{
  67. // __block UserGroupEntity *userGroupEntity = [self.allUserGroupsDict objectForKey:groupID];
  68. //
  69. // __weak typeof(self)weakSelf = self;
  70. //
  71. // if (!userGroupEntity) {
  72. // //此类型的待移至dboperation.
  73. // userGroupEntity = [UserGroupEntity findUserGroupEntityWithGroupID:groupID];
  74. //
  75. // if (!userGroupEntity) {
  76. //
  77. //
  78. // [[GroupMsgRSMgrCenter shareInstance]getGroupDetailWithGroupID:groupID withResultBlock:^(BOOL result, NSString *uuid, NSDictionary *message) {
  79. //
  80. //
  81. // userGroupEntity = [weakSelf createGroupEntityWithGroupParams:message[@"group"] resultBlock:^{
  82. //
  83. // resultGroupEntityBlock(userGroupEntity);
  84. //
  85. // }];
  86. //
  87. //
  88. // }];
  89. //
  90. // }
  91. // }
  92. //
  93. // if (userGroupEntity) {
  94. // resultGroupEntityBlock(userGroupEntity);
  95. // }
  96. //
  97. //}
  98. //- (void)getMyAllGroupsWithResultGroupsBlock:(void(^)(NSArray *))groups
  99. //{
  100. // NSArray *array = nil;
  101. //
  102. // if (self.allUserGroupsDict.allValues.count) {
  103. // array = self.allUserGroupsDict.allValues;
  104. // }else{
  105. //
  106. // array = [UserGroupEntity MR_findAll];
  107. //
  108. //
  109. // for (UserGroupEntity *userGroupEntity in array) {
  110. //
  111. // [self.allUserGroupsDict setObject:userGroupEntity forKey:userGroupEntity.iD];
  112. // }
  113. // }
  114. //
  115. // groups(array);
  116. //}
  117. //暂时无对重复数据的过滤
  118. //发
  119. //- (MessageEntity *)createMessageWithUUID:(NSString *)uuid sessionID:(NSString *)sessionID content:(NSString *)content voiceLength:(NSNumber *)voiceLength localPath:(NSString *)localPath msgContentType:(int)conteType msgType:(int)msgType fileDownUpStatus:(int)fileDownUpStatus msgState:(int)msgState name:(NSString *)name time:(NSDate *)date unreadCount:(int)unreadCount resultBlock:(void(^)())resultBlock
  120. //{
  121. //
  122. //
  123. // NSString *messageId = nil;
  124. // if (!uuid) {
  125. // messageId = [self getMessageID];
  126. // }else messageId = uuid;
  127. //
  128. // //创建发送消息时间
  129. //
  130. //
  131. //
  132. //
  133. // NSDate *msgTime = date;
  134. // if (!date) msgTime = [NSDate date];
  135. //
  136. // NSString* senderID = User_Name;
  137. //
  138. // MessageEntity *msgEntity = [MessageEntity MR_createEntity];
  139. //
  140. // msgEntity.uuid = messageId;
  141. //
  142. // msgEntity.msgType = @(msgType);
  143. //
  144. // msgEntity.msgTime = msgTime;
  145. //
  146. // msgEntity.senderId = senderID;
  147. //
  148. // msgEntity.receiverId = sessionID;
  149. //
  150. // msgEntity.sessionId = sessionID;
  151. //
  152. // //默认为upload
  153. // msgEntity.fileDownUpStatus = @(fileDownUpStatus);
  154. // //默认为doing
  155. // msgEntity.msgState = @(msgState);
  156. //
  157. // msgEntity.msgContentType = @(conteType);
  158. //
  159. // msgEntity.msgContent = content;
  160. //
  161. // msgEntity.localPath = localPath;
  162. //
  163. // msgEntity.voiceLength = voiceLength;
  164. //
  165. // msgEntity.voicePlayed = @(1);
  166. //
  167. // //注意对富文本的处理.
  168. //
  169. // [[msgEntity managedObjectContext]MR_saveWithBlock:^(NSManagedObjectContext * _Nonnull localContext) {
  170. //
  171. // if (resultBlock) {
  172. // resultBlock();
  173. // }
  174. // }];
  175. //
  176. //// [self updateRecent];
  177. // [self updateRecentEntityWithMsgEntity:msgEntity unreadCount:unreadCount title:name resultBlock:^{
  178. //
  179. //
  180. // }];
  181. //
  182. // return msgEntity;
  183. //}
  184. //待移出数据层,此逻辑应该归入消息处理层
  185. //收
  186. //- (NSArray *)createSingleMessageWithJSONParams:(NSDictionary *)params resultBlock:(void(^)())resultBlock
  187. //{
  188. //
  189. // NSString *isDes = params[@"isDes"];
  190. // NSString *msgContent = params[@"content"];
  191. // if (isDes.intValue) {
  192. // msgContent = [[MessageHandleCenter alloc]decryptMsgWithMsgDict:params];
  193. // }
  194. // NSInteger status = [params[@"status"] integerValue];
  195. // NSString *msgContentType = params[@"msgType"];
  196. // NSString *receiver = params[@"receiver"];
  197. // receiver = [receiver stringByReplacingOccurrencesOfString:ContentServerID(USERDEFAULT_ContentServer) withString:@""];
  198. // NSString *sender = params[@"sender"];
  199. // sender = [sender stringByReplacingOccurrencesOfString:ContentServerID(USERDEFAULT_ContentServer) withString:@""];
  200. // NSString *time = params[@"time"];
  201. // NSDate *date = [NSDate dateWithTimeIntervalSince1970:[time doubleValue]/1000];
  202. // NSString *uuid = params[@"uuid"];
  203. // NSString *length = params[@"length"];
  204. //#warning 2017-05-24 接口补充.
  205. // //
  206. //
  207. // NSString *sessionID = nil;
  208. // //SESSION 先判断是否同步消息,否则为sender.
  209. // if ([receiver isEqualToString:User_Name])
  210. // {
  211. // sessionID = sender;
  212. //
  213. // }else sessionID = receiver;
  214. //
  215. // AddrBook *addrBook = [self getAddrbookWithUerID:sessionID];
  216. //
  217. // int unreadCount = 0;
  218. //
  219. // if (status == 0 && ![sender isEqualToString:User_Name]) {
  220. // unreadCount = 1;
  221. // }
  222. //
  223. // //先判断是否是富文本
  224. // NSMutableArray *msgArray = [NSMutableArray array];
  225. //
  226. // if (msgContentType.intValue == MessageTypeText) {
  227. //
  228. // __block NSArray *judgeStringArray = nil;
  229. // NSRange range = [msgContent rangeOfString:MuiltTextPicExpression options:NSRegularExpressionSearch];
  230. //
  231. // if (range.location != NSNotFound) {
  232. // [Utils getPCScreenPhotoAndTextWithExpression:MuiltTextPicExpression content:msgContent resultBlock:^(NSArray *subData) {
  233. // judgeStringArray = subData;
  234. // }];
  235. //
  236. //
  237. // int i = 0;
  238. // for (NSArray *onePicTextArray in judgeStringArray) {
  239. //
  240. // i++;
  241. //
  242. // NSString *textFront = onePicTextArray[1];
  243. // NSString *imageMD5 = onePicTextArray[2];
  244. // NSString *textBack = onePicTextArray[3];
  245. //
  246. // NSString *childUUID= [NSString stringWithFormat:@"%@-%d",uuid,i];
  247. //
  248. //
  249. // if (textFront.length) {
  250. //
  251. //
  252. //
  253. // MessageEntity *msgEntity = [self createMessageWithUUID:childUUID sessionID:sessionID content:textFront voiceLength:0 localPath:nil msgContentType:MessageTypeText msgType:MESSAGE_TYPE_SINGLE fileDownUpStatus:FileDownUpStatusDown msgState:MessageSendSuccess name:addrBook.disPlayName time:date unreadCount:unreadCount resultBlock:^{
  254. //
  255. //
  256. //
  257. // }];
  258. //
  259. // [msgArray addObject:msgEntity];
  260. // }
  261. //
  262. // if (imageMD5.length) {
  263. //
  264. //
  265. // MessageEntity *msgEntity = [self createMessageWithUUID:childUUID sessionID:sessionID content:[NSString stringWithFormat:@"http://%@:%@/file/%@",[userDefaults objectForKey:USERDEFAULT_GROUP_STORAGE_HOST], [userDefaults objectForKey:USERDEFAULT_GROUP_STORAGE_PORT],imageMD5] voiceLength:0 localPath:nil msgContentType:MessageTypeImage msgType:MESSAGE_TYPE_SINGLE fileDownUpStatus:FileDownUpStatusDown msgState:MessageSendSuccess name:addrBook.disPlayName time:date unreadCount:unreadCount resultBlock:^{
  266. //
  267. //
  268. //
  269. // }];
  270. //
  271. // [msgArray addObject:msgEntity];
  272. // }
  273. //
  274. // if (textBack.length) {
  275. //
  276. // MessageEntity *msgEntity = [self createMessageWithUUID:childUUID sessionID:sessionID content:textBack voiceLength:0 localPath:nil msgContentType:MessageTypeText msgType:MESSAGE_TYPE_SINGLE fileDownUpStatus:FileDownUpStatusDown msgState:MessageSendSuccess name:addrBook.disPlayName time:date unreadCount:unreadCount resultBlock:^{
  277. //
  278. //
  279. //
  280. // }];
  281. //
  282. // [msgArray addObject:msgEntity];
  283. // }
  284. //
  285. // }
  286. // }else{
  287. //
  288. //
  289. // MessageEntity *msgEntity = [self createMessageWithUUID:uuid sessionID:sessionID content:msgContent voiceLength:@([length doubleValue]) localPath:nil msgContentType:[msgContentType intValue] msgType:MESSAGE_TYPE_SINGLE fileDownUpStatus:FileDownUpStatusDown msgState:MessageSendSuccess name:addrBook.disPlayName time:date unreadCount:unreadCount resultBlock:^{
  290. //
  291. // if (resultBlock) {
  292. // resultBlock();
  293. // }
  294. //
  295. // }];
  296. //
  297. // [msgArray addObject:msgEntity];
  298. //
  299. // }
  300. //
  301. //
  302. //
  303. // }else{
  304. //
  305. //
  306. // MessageEntity *msgEntity = [self createMessageWithUUID:uuid sessionID:sessionID content:msgContent voiceLength:@([length doubleValue]) localPath:nil msgContentType:[msgContentType intValue] msgType:MESSAGE_TYPE_SINGLE fileDownUpStatus:FileDownUpStatusDown msgState:MessageSendSuccess name:addrBook.disPlayName time:date unreadCount:unreadCount resultBlock:^{
  307. //
  308. // if (resultBlock) {
  309. // resultBlock();
  310. // }
  311. //
  312. // }];
  313. //
  314. // [msgArray addObject:msgEntity];
  315. //
  316. // }
  317. //
  318. //
  319. //
  320. //
  321. //
  322. // return msgArray;
  323. //}
  324. //- (NSArray *)createGroupMessageWithJSONParams:(NSDictionary *)params resultBlock:(void(^)())resultBlock
  325. //{
  326. // NSString *uuid = params[@"id"];
  327. //
  328. // NSNumber *voiceLength = params[@"length"];
  329. //
  330. // NSString *content = params[@"content"];
  331. //
  332. // if(!content) content = params[@"txt"];
  333. //
  334. //// NSString *isDes = params[@"isDes"];
  335. //// NSString *msgContent = params[@"content"];
  336. //// if (isDes.intValue) {
  337. //// msgContent = [[MessageHandleCenter alloc]decryptMsgWithMsgDict:params];
  338. //// }
  339. // NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",TeamShareExpression];
  340. //
  341. // if ([predicate evaluateWithObject:content]) {
  342. // return nil;
  343. // }
  344. //
  345. // NSDictionary *receiveGroupDict = params[@"group"];
  346. //
  347. // NSString *sender = params[@"sender"];
  348. //
  349. // sender = [sender stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"%@",ContentServerID(USERDEFAULT_ContentServer)] withString:@""];
  350. //
  351. // int unreadCount = 0 ;
  352. //
  353. // if (![sender isEqualToString:User_Name]) {
  354. // unreadCount = 1;
  355. // }
  356. //
  357. // NSString *receiver = receiveGroupDict[@"id"];
  358. //
  359. // NSNumber *time = params[@"ts"];
  360. //
  361. // NSNumber *isDes = params[@"isDes"];
  362. //
  363. // NSNumber *fromClient = params[@"fromClient"];
  364. //
  365. // NSDate *msgTime = [NSDate dateWithTimeIntervalSince1970:[time doubleValue]/1000];
  366. //
  367. // MessageContentType msgContentType = [params[@"msgType"]integerValue];
  368. //
  369. // if (msgContentType == 0) {
  370. // msgContentType = MessageTypeText;
  371. // }
  372. //
  373. // UserGroupEntity *userGroup = [self.allUserGroupsDict objectForKey:receiver];
  374. //
  375. // if (!userGroup) {
  376. // userGroup = [UserGroupEntity findUserGroupEntityWithGroupID:receiver];
  377. //
  378. // //理论上不可能.
  379. // if (!userGroup) {
  380. // //
  381. // userGroup = [UserGroupEntity MR_createEntity];
  382. // userGroup.iD = receiver;
  383. // userGroup.name = receiver;
  384. //
  385. // [userGroup.managedObjectContext MR_saveWithBlock:^(NSManagedObjectContext * _Nonnull localContext) {
  386. //
  387. // }];
  388. //
  389. //
  390. // }
  391. //
  392. // [self.allUserGroupsDict setObject:userGroup forKey:receiver];
  393. //
  394. // }
  395. //
  396. // //先判断是否是富文本
  397. // NSMutableArray *msgArray = [NSMutableArray array];
  398. //
  399. // if (msgContentType == MessageTypeText) {
  400. //
  401. // __block NSArray *judgeStringArray = nil;
  402. // NSRange range = [content rangeOfString:MuiltTextPicExpression options:NSRegularExpressionSearch];
  403. //
  404. // if (range.location != NSNotFound) {
  405. // [Utils getPCScreenPhotoAndTextWithExpression:MuiltTextPicExpression content:content resultBlock:^(NSArray *subData) {
  406. // judgeStringArray = subData;
  407. // }];
  408. //
  409. //
  410. // int i = 0;
  411. // for (NSArray *onePicTextArray in judgeStringArray) {
  412. //
  413. // i++;
  414. //
  415. // NSString *textFront = onePicTextArray[1];
  416. // NSString *imageMD5 = onePicTextArray[2];
  417. // NSString *textBack = onePicTextArray[3];
  418. //
  419. // NSString *childUUID= [NSString stringWithFormat:@"%@-%d",uuid,i];
  420. //
  421. //
  422. // if (textFront.length) {
  423. //
  424. //
  425. //
  426. // MessageEntity *msgEntity = [self createMessageWithUUID:childUUID sessionID:receiver content:textFront voiceLength:0 localPath:nil msgContentType:MessageTypeText msgType:MESSAGE_TYPE_GROUP fileDownUpStatus:FileDownUpStatusDown msgState:MessageSendSuccess name:userGroup.name time:msgTime unreadCount:unreadCount resultBlock:^{
  427. //
  428. //
  429. //
  430. // }];
  431. //
  432. // [msgArray addObject:msgEntity];
  433. // }
  434. //
  435. // if (imageMD5.length) {
  436. //
  437. //
  438. // MessageEntity *msgEntity = [self createMessageWithUUID:childUUID sessionID:receiver content:[NSString stringWithFormat:@"http://%@:%@/file/%@",[userDefaults objectForKey:USERDEFAULT_GROUP_STORAGE_HOST], [userDefaults objectForKey:USERDEFAULT_GROUP_STORAGE_PORT],imageMD5] voiceLength:0 localPath:nil msgContentType:MessageTypeImage msgType:MESSAGE_TYPE_GROUP fileDownUpStatus:FileDownUpStatusDown msgState:MessageSendSuccess name:userGroup.name time:msgTime unreadCount:unreadCount resultBlock:^{
  439. //
  440. //
  441. //
  442. // }];
  443. //
  444. // [msgArray addObject:msgEntity];
  445. // }
  446. //
  447. // if (textBack.length) {
  448. //
  449. // MessageEntity *msgEntity = [self createMessageWithUUID:childUUID sessionID:receiver content:textFront voiceLength:0 localPath:nil msgContentType:MessageTypeText msgType:MESSAGE_TYPE_GROUP fileDownUpStatus:FileDownUpStatusDown msgState:MessageSendSuccess name:userGroup.name time:msgTime unreadCount:unreadCount resultBlock:^{
  450. //
  451. //
  452. //
  453. // }];
  454. //
  455. // [msgArray addObject:msgEntity];
  456. // }
  457. //
  458. // }
  459. // }else{
  460. //
  461. //
  462. // MessageEntity *msgEntity = [self createMessageWithUUID:uuid sessionID:receiver content:content voiceLength:voiceLength localPath:nil msgContentType:msgContentType msgType:MESSAGE_TYPE_GROUP fileDownUpStatus:FileDownUpStatusDown msgState:MessageSendSuccess name:userGroup.name time:msgTime unreadCount:unreadCount resultBlock:^{
  463. //
  464. // if (resultBlock) {
  465. // resultBlock();
  466. // }
  467. //
  468. // }];
  469. //
  470. // [msgArray addObject:msgEntity];
  471. //
  472. // }
  473. //
  474. //
  475. //
  476. // }else{
  477. //
  478. //
  479. // MessageEntity *msgEntity = [self createMessageWithUUID:uuid sessionID:receiver content:content voiceLength:voiceLength localPath:nil msgContentType:msgContentType msgType:MESSAGE_TYPE_GROUP fileDownUpStatus:FileDownUpStatusDown msgState:MessageSendSuccess name:userGroup.name time:msgTime unreadCount:unreadCount resultBlock:^{
  480. //
  481. // if (resultBlock) {
  482. // resultBlock();
  483. // }
  484. //
  485. // }];
  486. //
  487. // [msgArray addObject:msgEntity];
  488. //
  489. // }
  490. //
  491. // return msgArray;
  492. //}
  493. //- (void)deleteMessageWithTitle:(NSString *)title UUID:(NSString *)uuid sessionID:(NSString *)sessionID resultBlock:(void(^)())resultBlock{
  494. //
  495. // //删除后获取最后一条新消息..update recentEntity
  496. // MessageEntity *msgEntity = [MessageEntity findMessageWithUUID:uuid];
  497. //
  498. // NSDate *lastTime = msgEntity.msgTime;
  499. //
  500. //
  501. // if (msgEntity) {
  502. // [msgEntity MR_deleteEntity];
  503. //
  504. // [msgEntity.managedObjectContext MR_saveWithBlock:^(NSManagedObjectContext * _Nonnull localContext) {
  505. //
  506. // if (resultBlock) {
  507. // resultBlock();
  508. // }
  509. //
  510. // NSPredicate *predicte = [NSPredicate predicateWithFormat:@"sessionId==%@ AND msgTime<=%@", sessionID,lastTime];
  511. //
  512. // //限制条数
  513. // NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"MessageEntity"];
  514. // request.fetchLimit = 1;
  515. // request.predicate = predicte;
  516. //
  517. // NSSortDescriptor *sortDES = [NSSortDescriptor sortDescriptorWithKey:@"msgTime" ascending:NO];
  518. // request.sortDescriptors = [NSArray arrayWithObject:sortDES];
  519. //
  520. // NSArray *msgEntitys = [MessageEntity MR_executeFetchRequest:request inContext:defaultContext];
  521. //
  522. // if (msgEntitys.count) {
  523. //
  524. // MessageEntity *msgEntity = msgEntitys[0];
  525. //
  526. // [self updateRecentEntityWithMsgEntity:msgEntity unreadCount:0 title:title resultBlock:^{
  527. //
  528. // }];
  529. //
  530. // }
  531. //
  532. //
  533. // }];
  534. // }
  535. //}
  536. //- (void)deleteAllMessagesWithSessionID:(NSString *)sessionID resultBlock:(void(^)())resultBlock
  537. //{
  538. // NSArray * chatMessages = [MessageEntity MR_findAllWithPredicate:[NSPredicate predicateWithFormat:@"sessionId == %@",sessionID]];
  539. //
  540. // [chatMessages enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
  541. // //最新的消息在前,所以要反着加
  542. // // MessageEntity *tempMessage = offlineMessages[offlineMessages.count - 1 - idx];
  543. // MessageEntity *tempMessage = chatMessages[idx];
  544. //
  545. // [tempMessage MR_deleteEntity];
  546. //
  547. // }];
  548. //
  549. // dispatch_async(dispatch_get_global_queue(0, 0), ^{
  550. // NSManagedObjectContext *privateContext= [NSManagedObjectContext MR_contextWithParent:[NSManagedObjectContext MR_defaultContext]];
  551. // [privateContext MR_saveWithBlock:^(NSManagedObjectContext * _Nonnull localContext) {
  552. //
  553. // }];
  554. // });
  555. //
  556. // RecentEntity *recentEntity = [self.allUserRecentsDict objectForKey:sessionID];
  557. //
  558. // if (!recentEntity) {
  559. //
  560. // recentEntity = [RecentEntity fetchEntityByRecentID:sessionID];
  561. //
  562. // }
  563. //
  564. // [recentEntity MR_deleteEntity];
  565. //
  566. // [[recentEntity managedObjectContext]MR_saveWithBlock:^(NSManagedObjectContext * _Nonnull localContext) {
  567. //
  568. //
  569. // }];
  570. //
  571. //}
  572. //- (void)getLatestMessageInGroupWithGroupID:(NSString *)groupID resultBlock:(void(^)(MessageEntity *msgEntity))resultBlock
  573. //{
  574. // NSDate *lastTime = [NSDate date];
  575. //
  576. // NSPredicate *predicte = [NSPredicate predicateWithFormat:@"sessionId==%@ AND msgTime<=%@", groupID,lastTime];
  577. //
  578. // //限制条数
  579. // NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"MessageEntity"];
  580. // request.fetchLimit = 1;
  581. // request.predicate = predicte;
  582. //
  583. // NSSortDescriptor *sortDES = [NSSortDescriptor sortDescriptorWithKey:@"msgTime" ascending:NO];
  584. // request.sortDescriptors = [NSArray arrayWithObject:sortDES];
  585. //
  586. // NSArray *msgEntitys = [MessageEntity MR_executeFetchRequest:request inContext:defaultContext];
  587. //
  588. // if (msgEntitys.count) {
  589. //
  590. // MessageEntity *msgEntity = msgEntitys[0];
  591. //
  592. // if (resultBlock) {
  593. //
  594. // resultBlock(msgEntity);
  595. // }
  596. //
  597. // }
  598. //
  599. //}
  600. //- (NoticeModels *)createNoticeModelWithJSONParams:(NSDictionary *)params resultBlock:(void(^)())resultBlock{
  601. //
  602. // NoticeModels *noticeModel = [NoticeModels MR_findFirstWithPredicate:[NSPredicate predicateWithFormat:@"uuid = %@",params[@"uuid"]]];
  603. //
  604. // if (noticeModel) {
  605. // return nil;
  606. // }else{
  607. //
  608. // noticeModel = [NoticeModels MR_createEntity];
  609. //
  610. // noticeModel.sender = params[@"sender"];
  611. // noticeModel.receiver = params[@"receiver"];
  612. // noticeModel.title = params[@"title"];
  613. // noticeModel.content = params[@"content"];
  614. // noticeModel.url = params[@"url"];
  615. //
  616. // //字典新增几个字段.
  617. // NSMutableArray *tempArray = [NSMutableArray array];
  618. //
  619. // int i = 0;
  620. // for (NSDictionary *attachmentDict in params [@"attachments"]) {
  621. //
  622. //
  623. // NSString *uuid = [NSString stringWithFormat:@"%@-%d",params[@"uuid"],i];
  624. //
  625. // NSMutableDictionary *newAttachmentDict = [NSMutableDictionary dictionaryWithDictionary:attachmentDict];
  626. // [newAttachmentDict setObject:uuid forKey:@"uuid"];
  627. // [newAttachmentDict setObject:@0 forKey:@"isDownloaded"];
  628. // [newAttachmentDict setObject:@"null" forKey:@"localPath"];
  629. //
  630. // [tempArray addObject:newAttachmentDict];
  631. //
  632. // i++;
  633. //
  634. //
  635. // }
  636. //
  637. // noticeModel.attachments = tempArray;
  638. // //来源
  639. // noticeModel.appName = params[@"appName"];
  640. // noticeModel.uuid = params[@"uuid"];
  641. // noticeModel.unreadIndifier = @1;
  642. //
  643. // NSString *time = [NSString stringWithFormat:@"%@",params[@"timestamp"]];
  644. //
  645. // NSDate *date = [NSDate dateWithTimeIntervalSince1970:[time doubleValue]/1000];
  646. // noticeModel.timeStamp = date;
  647. //
  648. // [noticeModel.managedObjectContext MR_saveWithBlock:^(NSManagedObjectContext * _Nonnull localContext) {
  649. //
  650. //
  651. // }];
  652. //
  653. //
  654. // return noticeModel;
  655. // }
  656. //
  657. //}
  658. //- (RecentEntity *)updateRecentEntityWithSessionID:(NSString *)sessionID type:(int)type title:(NSString *)title uuid:(NSString *)uuid lastTime:(NSDate *)lastTime unreadCount:(NSInteger)unreadCount lastMsg:(NSString *)lastMsg resultBlock:(void(^)())resultBlock
  659. //{
  660. //
  661. // return nil;
  662. //}
  663. //- (RecentEntity *)updateRecentEntityWithMsgEntity:(MessageEntity *)msgEntity unreadCount:(int)unreadCount title:(NSString *)title resultBlock:(void(^)())resultBlock
  664. //{
  665. //
  666. // RecentEntity *recentEntity = [self.allUserRecentsDict objectForKey:msgEntity.sessionId];
  667. //
  668. // if (!recentEntity) {
  669. // recentEntity = [RecentEntity fetchEntityByRecentID:msgEntity.sessionId];
  670. //
  671. // if (!recentEntity) {
  672. // recentEntity = [RecentEntity MR_createEntity];
  673. // }
  674. //
  675. //
  676. //
  677. // recentEntity.recentId = msgEntity.sessionId;
  678. //
  679. // recentEntity.type = msgEntity.msgType;
  680. //
  681. // //待调整...
  682. // recentEntity.title = title;
  683. //
  684. // [self.allUserRecentsDict setObject:recentEntity forKey:msgEntity.sessionId];
  685. // }
  686. //
  687. // if([msgEntity.msgTime compare:recentEntity.lastTime] == NSOrderedDescending || !recentEntity.lastTime)
  688. // {
  689. // //未读消息数有问题.
  690. // recentEntity.uuid = msgEntity.uuid;
  691. //
  692. // recentEntity.lastTime = msgEntity.msgTime;
  693. //
  694. // recentEntity.unreadCount = @([recentEntity.unreadCount intValue] + unreadCount);
  695. //
  696. // switch (msgEntity.msgContentType.integerValue) {
  697. //
  698. // case MessageTypeText:
  699. //
  700. // recentEntity.lastMsg = msgEntity.msgContent;
  701. // break;
  702. // case MessageTypeNotice:
  703. //
  704. // recentEntity.lastMsg = msgEntity.msgContent;
  705. // break;
  706. // case MessageTypeFile:
  707. //
  708. // recentEntity.lastMsg = @"[文件]";
  709. // break;
  710. // case MessageTypeVoice:
  711. //
  712. // recentEntity.lastMsg = @"[语音]";
  713. // break;
  714. // case MessageTypeImage:
  715. //
  716. //
  717. // recentEntity.lastMsg = @"[图片]";
  718. // break;break;
  719. // case MessageTypeLocation:
  720. //
  721. // recentEntity.lastMsg = @"[位置]";
  722. // break;break;
  723. // default:
  724. // break;
  725. // }
  726. //
  727. // [[recentEntity managedObjectContext]MR_saveWithBlock:^(NSManagedObjectContext * _Nonnull localContext) {
  728. //
  729. // if (resultBlock) {
  730. // resultBlock();
  731. // }
  732. //
  733. // }];
  734. //
  735. //
  736. // }
  737. //
  738. // return recentEntity;
  739. //}
  740. //- (RecentEntity *)updateRecentEntityWithSessionID:(NSString *)sessionID type:(MessageType)type title:(NSString *)title lastTime:(NSDate *)date lastMsg:(NSString *)lastMsg unreadCount:(int)unreadCount resultBlock:(void(^)())resultBlock
  741. //{
  742. // RecentEntity *recentEntity = [self.allUserRecentsDict objectForKey:sessionID];
  743. //
  744. // if (!recentEntity) {
  745. // recentEntity = [RecentEntity fetchEntityByRecentID:sessionID];
  746. //
  747. // if (!recentEntity) {
  748. // recentEntity = [RecentEntity MR_createEntity];
  749. // }
  750. //
  751. //
  752. //
  753. // recentEntity.recentId = sessionID;
  754. //
  755. // recentEntity.type = @(type);
  756. //
  757. // recentEntity.title = title;
  758. //
  759. // [self.allUserRecentsDict setObject:recentEntity forKey:sessionID];
  760. // }
  761. //
  762. // if([date compare:recentEntity.lastTime] == NSOrderedDescending || !recentEntity.lastTime)
  763. // {
  764. //
  765. //
  766. // recentEntity.lastTime = [NSDate date];
  767. // recentEntity.lastMsg = lastMsg;
  768. // recentEntity.unreadCount = @(recentEntity.unreadCount.intValue + unreadCount);
  769. // [recentEntity.managedObjectContext MR_saveWithBlock:^(NSManagedObjectContext * _Nonnull localContext) {
  770. //
  771. // if (resultBlock) {
  772. // resultBlock();
  773. // }
  774. // }];
  775. //
  776. // }
  777. //
  778. // return recentEntity;
  779. //}
  780. //手动创造
  781. //- (UserGroupEntity *)createGroupEntityWithGroupID:(NSString *)groupID groupName:(NSString *)groupName creator:(NSString *)creator managers:(NSArray *)managers groupMembers:(NSArray *)groupMembers groupHeaderImage:(UIImage *)groupHeaderImage createTs:(NSDate *)ts ActiveAs:(NSDate *)as JoinJs:(NSDate *)js ignores:(NSArray *)ignors tags:(NSArray *)tags notice:(NSString *)notice intro:(NSString *)intro invite:(NSNumber *)invite type:(NSNumber *)type ver:(NSNumber *)ver auth:(NSNumber *)auth msgReceiveLevel:(NSNumber *)msgReceiveLevel unreadMsgCount:(NSNumber *)unradMsgCount unreadMsgIdentifierDict:(NSDictionary *)unreadMsgIdentifierDict resultBlock:(void(^)())resultBlock{
  782. //
  783. // UserGroupEntity *userGroupEntity = [UserGroupEntity findUserGroupEntityWithGroupID:groupID];
  784. //
  785. // if (userGroupEntity) {
  786. // return nil;
  787. // }else{
  788. //
  789. // userGroupEntity = [UserGroupEntity MR_createEntity];
  790. //
  791. // userGroupEntity.iD = groupID;
  792. //
  793. // NSComparator cmptr = ^(NSDictionary *userA, NSDictionary *userB){
  794. // if ([userA[@"ts"]integerValue] > [userB[@"ts"]integerValue]) {
  795. // return (NSComparisonResult)NSOrderedDescending;
  796. // }
  797. //
  798. // if ([userA[@"ts"]integerValue] < [userB[@"ts"]integerValue]) {
  799. // return (NSComparisonResult)NSOrderedAscending;
  800. // }
  801. // return (NSComparisonResult)NSOrderedSame;
  802. //
  803. // };
  804. // NSArray *array = [groupMembers sortedArrayUsingComparator:cmptr];
  805. //
  806. // userGroupEntity.members = array;
  807. //
  808. // userGroupEntity.managers = managers;
  809. //
  810. // userGroupEntity.tags = tags;
  811. //
  812. // userGroupEntity.ignores = ignors;
  813. //
  814. // userGroupEntity.as = as;
  815. //
  816. // userGroupEntity.ts = ts;
  817. //
  818. // //自己创建时...
  819. // userGroupEntity.js = [NSDate date];
  820. //
  821. // userGroupEntity.invite = @(invite.boolValue);
  822. //
  823. // userGroupEntity.creator = creator;
  824. //
  825. // userGroupEntity.intro = intro;
  826. //
  827. // userGroupEntity.name = groupName;
  828. //
  829. // userGroupEntity.notice = notice;
  830. //
  831. // userGroupEntity.ver = ver;
  832. //
  833. // userGroupEntity.type = type;
  834. //
  835. // userGroupEntity.auth = auth;
  836. //
  837. // userGroupEntity.groupHeaderImage = groupHeaderImage;
  838. //
  839. // [userGroupEntity.managedObjectContext MR_saveWithBlock:^(NSManagedObjectContext * _Nonnull localContext) {
  840. //
  841. // if (resultBlock) {
  842. // resultBlock();
  843. // }
  844. // }];
  845. //
  846. // [self.allUserGroupsDict setObject:userGroupEntity forKey:groupID];
  847. //
  848. // }
  849. //
  850. // //update recent..
  851. // [self updateRecentEntityWithSessionID:userGroupEntity.iD type:MESSAGE_TYPE_GROUP title:userGroupEntity.name lastTime:[NSDate date] lastMsg:@"群创建成功" unreadCount:1 resultBlock:^{
  852. //
  853. //
  854. // }];
  855. //
  856. // return userGroupEntity;
  857. //
  858. //
  859. //}
  860. //- (UserGroupEntity *)createGroupEntityWithGroupParams:(NSDictionary *)dict resultBlock:(void(^)())resultBlock
  861. //{
  862. //
  863. // NSDictionary *memebersDict = dict[@"members"];
  864. // //头像
  865. // GroupHeaderImageView *headerImageView = [[GroupHeaderImageView alloc]initWithHeaderWH:UserGroupShowCellHeaderViewWH];
  866. // headerImageView.bounds = CGRectMake(0, 0, UserGroupShowCellHeaderViewWH, UserGroupShowCellHeaderViewWH);
  867. // headerImageView.groupMembersArray = memebersDict.allValues;
  868. // UIImage *groupHeaderImage = [Utils imageWithView:headerImageView];
  869. //
  870. //
  871. // UserGroupEntity *userGroupEntity = [self createGroupEntityWithGroupID:dict[@"id"] groupName: dict[@"name"] creator:dict[@"creator"] managers: dict[@"managers"]groupMembers:dict[@"members"] groupHeaderImage:groupHeaderImage createTs:[NSDate dateWithTimeIntervalSince1970:[dict[@"ts"] doubleValue]/1000] ActiveAs:[NSDate dateWithTimeIntervalSince1970:[dict[@"as"] doubleValue]/1000] JoinJs:[NSDate date] ignores: dict[@"ignores"] tags: dict[@"tags"] notice: dict[@"notice"] intro:dict[@"intro"] invite:dict[@"invite"] type:dict[@"type"] ver: dict[@"ver"] auth: dict[@"auth"] msgReceiveLevel:nil unreadMsgCount:nil unreadMsgIdentifierDict:nil resultBlock:^{
  872. //
  873. // }];
  874. //
  875. // return userGroupEntity;
  876. //
  877. //}
  878. //待新增启动更新
  879. //- (UserGroupEntity *)updateGroupEntityWithParams:(NSDictionary *)params resultBlock:(void(^)())resultBlock
  880. //{
  881. // NSString *ID = params[@"id"];
  882. // UserGroupEntity *userGroupEntity = [self.allUserGroupsDict objectForKey:ID];
  883. //
  884. // if (!userGroupEntity) {
  885. // userGroupEntity = [UserGroupEntity findUserGroupEntityWithGroupID:ID];
  886. //
  887. // if (!userGroupEntity) {
  888. //
  889. // NSDictionary *memebersDict = params[@"members"];
  890. // //头像
  891. // GroupHeaderImageView *headerImageView = [[GroupHeaderImageView alloc]initWithHeaderWH:UserGroupShowCellHeaderViewWH];
  892. // headerImageView.bounds = CGRectMake(0, 0, UserGroupShowCellHeaderViewWH, UserGroupShowCellHeaderViewWH);
  893. // headerImageView.groupMembersArray = memebersDict.allValues;
  894. // UIImage *groupHeaderImage = [Utils imageWithView:headerImageView];
  895. //
  896. //#warning 2017-05-27 js 不清不楚.
  897. // userGroupEntity = [self createGroupEntityWithGroupID:ID groupName:params[@"name"] creator:params[@"creator"] managers:params[@"managers"] groupMembers:params[@"members"] groupHeaderImage:groupHeaderImage createTs:[NSDate dateWithTimeIntervalSince1970:[params[@"ts"] doubleValue]/1000] ActiveAs:[NSDate dateWithTimeIntervalSince1970:[params[@"as"] doubleValue]/1000] JoinJs:nil ignores:params[@"ignores"] tags:params[@"tags"] notice:params[@"notice"] intro:params[@"intro"] invite:[NSNumber numberWithBool:[params[@"invite"]boolValue]] type:params[@"type"] ver:params[@"ver"] auth:params[@"auth"] msgReceiveLevel:nil unreadMsgCount:nil unreadMsgIdentifierDict:nil resultBlock:^{
  898. //
  899. // if (resultBlock) {
  900. // resultBlock();
  901. // }
  902. //
  903. // }];
  904. //
  905. //
  906. // }
  907. //
  908. // [self.allUserGroupsDict setObject:userGroupEntity forKey:ID];
  909. // }
  910. //
  911. // if (userGroupEntity && [userGroupEntity.ver longLongValue] < [params[@"ver"]longLongValue]) {
  912. //
  913. // NSDictionary *memebersDict = params[@"members"];
  914. // //头像
  915. // GroupHeaderImageView *headerImageView = [[GroupHeaderImageView alloc]initWithHeaderWH:UserGroupShowCellHeaderViewWH];
  916. // headerImageView.bounds = CGRectMake(0, 0, UserGroupShowCellHeaderViewWH, UserGroupShowCellHeaderViewWH);
  917. // headerImageView.groupMembersArray = memebersDict.allValues;
  918. // UIImage *groupHeaderImage = [Utils imageWithView:headerImageView];
  919. //
  920. // [self updateGroupEntityWithGroupID:ID groupName:params[@"name"] creator:params[@"creator"] managers:params[@"managers"] groupMembers:params[@"members"] groupHeaderImage:groupHeaderImage createTs:[NSDate dateWithTimeIntervalSince1970:[params[@"ts"] doubleValue]/1000] ActiveAs:[NSDate dateWithTimeIntervalSince1970:[params[@"as"] doubleValue]/1000] JoinJs:[NSDate date] ignores:params[@"ignores"] tags:params[@"tags"] notice:params[@"notice"] intro:params[@"intro"] invite:[NSNumber numberWithBool:[params[@"invite"]boolValue]] type:params[@"type"] ver:params[@"ver"] auth:params[@"auth"] resultBlock:^{
  921. //
  922. // if (resultBlock) {
  923. // resultBlock();
  924. // }
  925. //
  926. // }];
  927. // }
  928. //
  929. //
  930. // return userGroupEntity;
  931. //
  932. //}
  933. //群解散
  934. //- (void)deleteGroupWithGroupID:(NSString *)groupID resultBlock:(void(^)())resultBlock
  935. //{
  936. // UserGroupEntity *userGroupEntity = [self.allUserGroupsDict objectForKey:groupID];
  937. //
  938. // if (!userGroupEntity) {
  939. // userGroupEntity = [UserGroupEntity findUserGroupEntityWithGroupID:groupID];
  940. // }
  941. //
  942. // NSString *title = userGroupEntity.name;
  943. //
  944. // [userGroupEntity MR_deleteEntity];
  945. //
  946. // [userGroupEntity.managedObjectContext MR_saveWithBlock:^(NSManagedObjectContext * _Nonnull localContext) {
  947. //
  948. // RecentEntity *recentEntity = [self.allUserRecentsDict objectForKey:groupID];
  949. //
  950. // if (!recentEntity) {
  951. // recentEntity = [RecentEntity fetchEntityByRecentID:groupID];
  952. //
  953. // if (!recentEntity) {
  954. //
  955. //#warning ...
  956. // [self updateRecentEntityWithSessionID:groupID type:MESSAGE_TYPE_GROUP title:title lastTime:[NSDate date] lastMsg:@"该群组已被解散" unreadCount:1 resultBlock:^{
  957. //
  958. // if (resultBlock) {
  959. // resultBlock();
  960. // }
  961. //
  962. // }];
  963. //
  964. // }
  965. // }
  966. //
  967. //
  968. // }];
  969. //}
  970. //- (void)kickOutFromGroupWithGroupID:(NSString *)groupID resultBlock:(void(^)())resultBlock
  971. //{
  972. // UserGroupEntity *userGroupEntity = [self.allUserGroupsDict objectForKey:groupID];
  973. //
  974. // if (!userGroupEntity) {
  975. // userGroupEntity = [UserGroupEntity findUserGroupEntityWithGroupID:groupID];
  976. // }
  977. //
  978. //
  979. // [userGroupEntity MR_deleteEntity];
  980. //
  981. // [userGroupEntity.managedObjectContext MR_saveWithBlock:^(NSManagedObjectContext * _Nonnull localContext) {
  982. //
  983. // RecentEntity *recentEntity = [self.allUserRecentsDict objectForKey:groupID];
  984. //
  985. // if (!recentEntity) {
  986. // recentEntity = [RecentEntity fetchEntityByRecentID:groupID];
  987. //
  988. // [recentEntity MR_deleteEntity];
  989. //
  990. // [[recentEntity managedObjectContext]MR_saveWithBlock:^(NSManagedObjectContext * _Nonnull localContext) {
  991. //
  992. // }];
  993. //
  994. // }
  995. //
  996. //
  997. // }];
  998. //}
  999. //群未读消息标记及群的提醒等级单独接口. //msgReceiveLevel:(NSNumber *)msgReceiveLevel unreadMsgCount:(NSNumber *)unradMsgCount unreadMsgIdentifierDict:(NSDictionary *)unreadMsgIdentifierDict
  1000. //- (UserGroupEntity *)updateGroupEntityWithGroupID:(NSString *)groupID groupName:(NSString *)groupName creator:(NSString *)creator managers:(NSArray *)managers groupMembers:(NSArray *)groupMembers groupHeaderImage:(UIImage *)groupHeaderImage createTs:(NSDate *)ts ActiveAs:(NSDate *)as JoinJs:(NSDate *)js ignores:(NSArray *)ignors tags:(NSArray *)tags notice:(NSString *)notice intro:(NSString *)intro invite:(NSNumber *)invite type:(NSNumber *)type ver:(NSNumber *)ver auth:(NSNumber *)auth resultBlock:(void(^)())resultBlock{
  1001. //
  1002. // //理论上无需判断是否group存在..
  1003. //
  1004. // UserGroupEntity *userGroup = [self.allUserGroupsDict objectForKey:groupID];
  1005. //
  1006. // if (groupName) {
  1007. // userGroup.name = groupName;
  1008. // }
  1009. //
  1010. // if (creator) {
  1011. // userGroup.creator = creator;
  1012. // }
  1013. //
  1014. // if (managers) {
  1015. // userGroup.managers = managers;
  1016. // }
  1017. //
  1018. // if (groupMembers) {
  1019. //
  1020. // NSComparator cmptr = ^(NSDictionary *userA, NSDictionary *userB){
  1021. // if ([userA[@"ts"]integerValue] > [userB[@"ts"]integerValue]) {
  1022. // return (NSComparisonResult)NSOrderedDescending;
  1023. // }
  1024. //
  1025. // if ([userA[@"ts"]integerValue] < [userB[@"ts"]integerValue]) {
  1026. // return (NSComparisonResult)NSOrderedAscending;
  1027. // }
  1028. // return (NSComparisonResult)NSOrderedSame;
  1029. //
  1030. // };
  1031. // NSArray *array = [groupMembers sortedArrayUsingComparator:cmptr];
  1032. //
  1033. // userGroup.members = array;
  1034. // }
  1035. //
  1036. // if (groupHeaderImage) {
  1037. // userGroup.groupHeaderImage = groupHeaderImage;
  1038. // }
  1039. //
  1040. // if (ts) {
  1041. // userGroup.ts = ts;
  1042. // }
  1043. //
  1044. // if (as) {
  1045. // userGroup.as = as;
  1046. // }
  1047. //
  1048. // if (js) {
  1049. // userGroup.js = js;
  1050. // }
  1051. //
  1052. // if (ignors) {
  1053. // userGroup.ignores = ignors;
  1054. // }
  1055. //
  1056. // if (tags) {
  1057. // userGroup.tags = tags;
  1058. // }
  1059. //
  1060. // if (notice) {
  1061. // userGroup.notice = notice;
  1062. // }
  1063. //
  1064. // if (intro) {
  1065. // userGroup.intro = intro;
  1066. // }
  1067. //
  1068. // userGroup.invite = invite;
  1069. //
  1070. // userGroup.type = type;
  1071. //
  1072. // userGroup.ver = ver;
  1073. //
  1074. // userGroup.auth = auth;
  1075. //
  1076. // [[userGroup managedObjectContext]MR_saveWithBlock:^(NSManagedObjectContext * _Nonnull localContext) {
  1077. // if (resultBlock) {
  1078. // resultBlock();
  1079. // }
  1080. // }];
  1081. //
  1082. // //更新recent的title.
  1083. // RecentEntity *recentEntity = [self.allUserRecentsDict objectForKey:groupID];
  1084. //
  1085. // if (!recentEntity) {
  1086. //
  1087. // recentEntity = [RecentEntity fetchEntityByRecentID:groupID];
  1088. //
  1089. // }
  1090. //
  1091. //
  1092. // if (recentEntity) {
  1093. // recentEntity.title = groupName;
  1094. //
  1095. // [[recentEntity managedObjectContext]MR_saveWithBlock:^(NSManagedObjectContext * _Nonnull localContext) {
  1096. //
  1097. // }];
  1098. // }
  1099. //
  1100. //
  1101. // return userGroup;
  1102. //}
  1103. //返回用户对象<用户信息已经得到>
  1104. //-(AddrBook*) p_fetchAddrBookForReceivedMessage:(NSString*)senderId
  1105. //{
  1106. // /*
  1107. // componentsSeparatedByString: 将字符串切割成数组, 参数是作为分割辨认用的
  1108. // */
  1109. // //通过 '-' 为切割点,将字符串切割成数组
  1110. // NSArray *tempArray = [senderId componentsSeparatedByString:@"-"];
  1111. // //获取字符
  1112. // if (tempArray.count != 2) {
  1113. // return nil;
  1114. // }
  1115. // NSString *loginName = tempArray[1];
  1116. // NSString *serverID = tempArray[0];
  1117. // /*
  1118. // fetchEntityByLoginName: serverID: 是通过这 loginName 和 serverID 作为唯一标识符 , 来查询对象
  1119. // */
  1120. // //获取对象 <相当于创建了一个对象 对象里面有信息>
  1121. // __block AddrBook *addrbook = [AddrBook fetchEntityByLoginName:loginName serverID:serverID];
  1122. // if (!addrbook) {
  1123. //
  1124. //
  1125. //
  1126. // NSDictionary *params = @{
  1127. // @"serverID":serverID,
  1128. // @"userName":loginName
  1129. // };
  1130. // [HttpManager postRequestToUrlSynchornize:FULL_URL(@"users/getUserDetail") params:params complete:^(BOOL successed, NSDictionary *result) {
  1131. // //成功并返回一个正确的 bool 值
  1132. // if (successed && [result[@"success"]boolValue]) {
  1133. // //从 result 取得字典数据
  1134. // NSDictionary *userDic = result[@"data"];
  1135. // //从字典数据中获取 id 数据
  1136. // NSNumber *idx = userDic[@"id"];
  1137. //
  1138. //
  1139. // NSLog(@"userDic: - - - > %@ < - - - ",userDic);
  1140. //
  1141. //
  1142. // if (idx!=0) {
  1143. // //获取用户对象
  1144. // addrbook = [AddrBook insertEntityByID:idx];
  1145. // //获取对象的所有属性数据
  1146. // [addrbook updatePropertyByDictionary:userDic];
  1147. // }
  1148. // //保存
  1149. //
  1150. // dispatch_async(dispatch_get_global_queue(0, 0), ^{
  1151. // NSManagedObjectContext *privateContext= [NSManagedObjectContext MR_contextWithParent:[NSManagedObjectContext MR_defaultContext]]; [privateContext MR_saveToPersistentStoreAndWait];
  1152. // });
  1153. // }
  1154. // }];
  1155. // }
  1156. // return addrbook;
  1157. //}
  1158. //- (AddrBook *)getAddrbookWithUerID:(NSString *)userID
  1159. //{
  1160. //
  1161. // AddrBook *addrBook = [self.allUserDict objectForKey:userID];
  1162. //
  1163. // if (!addrBook) {
  1164. // addrBook = [self p_fetchAddrBookForReceivedMessage:userID];
  1165. //
  1166. // [self.allUserDict setObject:addrBook forKey:userID];
  1167. // }
  1168. //
  1169. //
  1170. // return addrBook;
  1171. //
  1172. //}
  1173. //- (AddrBook *)createUserDetailsWithJSONParams:(NSDictionary *)prams resultBlock:(void(^)())resultBlock
  1174. //{
  1175. // /*
  1176. // Dictionary2Object(dictionary, @"id", self.addrBookID);
  1177. // self.postion = [NSString stringWithFormat:@"%@",dictionary[@"position"]];
  1178. // // Dictionary2Object(dictionary, @"position", self.postion);
  1179. // Dictionary2Object(dictionary, @"groupId", self.groupID);
  1180. // Dictionary2Object(dictionary, @"defaultLoginName", self.defaultLoginName);
  1181. // Dictionary2Object(dictionary, @"telephone", self.telephone);
  1182. // Dictionary2Object(dictionary, @"cellphone", self.cellTelephone);
  1183. // Dictionary2Object(dictionary, @"celltelephone", self.cellTelephone);
  1184. // Dictionary2Object(dictionary, @"serverID", self.serverID);
  1185. // Dictionary2Object(dictionary, @"email", self.email);
  1186. // Dictionary2Object(dictionary, @"remark", self.remark);
  1187. // Dictionary2Object(dictionary, @"postion", self.postion);
  1188. // Dictionary2Object(dictionary, @"branchId", self.branchId);
  1189. // Dictionary2Object(dictionary, @"branchID", self.branchId);
  1190. // Dictionary2Object(dictionary, @"mobile", self.cellTelephone);
  1191. //
  1192. // Dictionary2Object(dictionary, @"shortMobile", self.shortMobile);
  1193. // Dictionary2Object(dictionary, @"tel", self.telephone);
  1194. // // Dictionary2Object(dictionary, @"department", self.department);
  1195. // // Dictionary2Object(dictionary, @"company", self.company);
  1196. // Dictionary2Object(dictionary, @"secret", self.secret);
  1197. // // self.secret = Numberi(2);
  1198. //
  1199. // // Dictionary2TimeObject(dictionary, @"createTime", self.createTime);
  1200. // Dictionary2Object(dictionary, @"deleted", self.deleted);
  1201. // Dictionary2Object(dictionary, @"branch", self.department);
  1202. // Dictionary2Object(dictionary, @"duty", self.duty);
  1203. // Dictionary2Object(dictionary, @"gender", self.gender);
  1204. // Dictionary2Object(dictionary, @"loginName", self.name);
  1205. // // Dictionary2Object(dictionary, @"version", self.version);
  1206. // if (self.loginState) {
  1207. // Dictionary2Object(dictionary, @"loginState", self.loginState);
  1208. // }
  1209. // if (self.appState){
  1210. // Dictionary2Object(dictionary, @"appState", self.appState);
  1211. // }
  1212. //
  1213. // Dictionary2Object(dictionary, @"loginName", self.loginName);
  1214. // Dictionary2Object(dictionary, @"displayName", self.disPlayName);
  1215. // Dictionary2Object(dictionary, @"headImageUrl", self.avatar);
  1216. // Dictionary2Object(dictionary, @"company", self.company);
  1217. // Dictionary2Object(dictionary, @"watchword", self.signature);
  1218. //
  1219. // // Dictionary2Object(dictionary, @"avatarColor", self.avatarColor);
  1220. // //同步loginName 和 defaultLoginName
  1221. // if (self.loginName.length!=0) {
  1222. // self.defaultLoginName = self.loginName;
  1223. // }else{
  1224. // self.loginName = self.defaultLoginName;
  1225. // }
  1226. //
  1227. // self.state = @(0);
  1228. //
  1229. // */
  1230. // return nil;
  1231. //}
  1232. //- (AddrBook *)updateUserDetailsWithJSONParams:(NSDictionary *)prams resultBlock:(void(^)())resultBlock
  1233. //{
  1234. //// [AddrBook updateUsersDetail:prams];
  1235. // return nil;
  1236. //}
  1237. @end