Преглед на файлове

修改了最近消息推送

Apple преди 5 години
родител
ревизия
c9241900f8
променени са 1 файла, в които са добавени 57 реда и са изтрити 4 реда
  1. 57 4
      shiku_im/ClassesNew/classes/messageVc/JXMsgViewController.m

+ 57 - 4
shiku_im/ClassesNew/classes/messageVc/JXMsgViewController.m

@@ -123,7 +123,8 @@
 @property (nonatomic, assign) BOOL iskeFugongzong;
 
 @property (nonatomic, assign) int isRecordkeFugongzong;
-
+// 是否获取到了最近消息列表
+@property (nonatomic, assign) BOOL isGetLastMsgList;
 @end
 
 @implementation JXMsgViewController
@@ -153,7 +154,7 @@
           _webAddPointV=[CYWebAddPointVC new];
         _isRecordkeFugongzong=0;
         _indexNums=0;
-        
+        _isGetLastMsgList = NO;
         dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
 
              
@@ -2763,7 +2764,7 @@
     
     if([aDownload.action isEqualToString:act_roomListHis]){
             
-        
+        NSMutableArray *listArr = [NSMutableArray array];
         //            [[JXXMPP sharedInstance].roomPool joinRoom:tempDict[@"jid"] title:tempDict[@"name"] lastDate:nil isNew:NO];
         /*-------------------*/
         for (int i = 0; i < [array1 count]; i++) {
@@ -2828,16 +2829,67 @@
                 }
             }
             
+            /********************  ****************************/
+            // 如果最近一条信息接口没有获取到,就更新
+            if ([[dict objectForKey:@"jid"] intValue] > 0 && !_isGetLastMsgList) {
+                // 获取最近一条记录
+                NSArray *arr = [[JXMessageObject sharedInstance] fetchMessageListWithUser:[dict objectForKey:@"jid"] byAllNum:0 pageCount:20 startTime:[NSDate dateWithTimeIntervalSince1970:0]];
+                
+                // 去除
+                JXMessageObject *lastMsg = arr.lastObject;
+                if (!lastMsg) {
+                    lastMsg = arr.firstObject;
+                }
+                JXUserObject *user = [[JXUserObject sharedInstance] getUserById:dict[@"jid"]];
+                NSMutableDictionary *taskDic = [NSMutableDictionary dictionary];
+                [taskDic setObject:[dict objectForKey:@"jid"] forKey:@"userId"];
+                [taskDic setObject:[NSDate dateWithTimeIntervalSince1970:[dict[@"timeSend"] longLongValue]] forKey:@"lastTime"];
+                if (lastMsg) {
+                    [taskDic setObject:lastMsg.timeSend forKey:@"startTime"];
+                    if (lastMsg.messageId) {
+                        [taskDic setObject:lastMsg.messageId forKey:@"startMsgId"];
+                    }
+                }
+                if (user.roomId) {
+                    [taskDic setObject:user.roomId forKey:@"roomId"];
+                }
+                if ([g_myself.chatSyncTimeLen longLongValue] != -2) {
+                    
+                    [self createSynTask:taskDic];
+                    
+                    [_taskArray addObject:taskDic];
+                }
+                
+                long value = (long)([lastMsg.timeSend timeIntervalSince1970]*1000);
+                if (!lastMsg) {
+                    // 没有最后一条消息的记录就拉取一周前的数据
+                    value = (long)(g_server.lastOfflineTime*1000)-(7*24*3600*1000);
+                }
+                
+                NSString *listStr = [NSString stringWithFormat:@"%@,%ld",dict[@"jid"],value];
+                [listArr addObject:listStr];
+            }
+                       
+                /********************  ****************************/
+            
             //                        [tempArray addObject:user];
         }
         /*-------------------*/
-        
+        if (listArr.count > 0) {
+            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
+                // 如果最近一条信息接口没有获取到,批量拉取消息
+                if (!_isGetLastMsgList) {
+                    [g_xmpp pullBatchGroupMessageReqWithJidListArray:listArr];
+                }
+            });
+        }
         
         [_table reloadData];
     }
 
     if ([aDownload.action isEqualToString:act_tigaseGetLastChatList]) {
         [self.header endRefreshing];
+        _isGetLastMsgList = YES;
         [g_default setBool:YES forKey:kISFirstGetLastChatList];
         if ([g_myself.chatSyncTimeLen longLongValue] != -2) {
             [[JXUserObject sharedInstance] updateUserLastChatList:array1];
@@ -3019,6 +3071,7 @@
     [_wait hide];
     
     if ([aDownload.action isEqualToString:act_tigaseGetLastChatList]) {
+        _isGetLastMsgList = NO;
         [self.header endRefreshing];
         [self getAllChatList];
         //[self getFriend];