update barrage module.
Showing
2 changed files
with
37 additions
and
3 deletions
No preview for this file type
@@ -97,9 +97,14 @@ | @@ -97,9 +97,14 @@ | ||
97 | __strong typeof (weakSelf) strongSelf = weakSelf; | 97 | __strong typeof (weakSelf) strongSelf = weakSelf; |
98 | 98 | ||
99 | if (itemDic && ![itemDic isEqual:[NSNull null]] && !IsStrEmpty([itemDic objectForKey:@"name"])) { | 99 | if (itemDic && ![itemDic isEqual:[NSNull null]] && !IsStrEmpty([itemDic objectForKey:@"name"])) { |
100 | -// if ([[itemDic objectForKey:@"uid"] isEqualToString:[GVUserDefaults standardUserDefaults].yohoId] && [[itemDic objectForKey:@"cmd"] longValue] == 5 && !self.manualScrolling) { | 100 | + if (0) { |
101 | // [self greenChannel:itemDic]; | 101 | // [self greenChannel:itemDic]; |
102 | -// } else { | 102 | + } else { |
103 | + | ||
104 | + if ([[itemDic objectForKey:@"cmd"] longValue] == 4) { | ||
105 | + // 如果是用户加入的消息,则不加入到缓冲区 | ||
106 | + [self newUserJoin:itemDic]; | ||
107 | + } else { | ||
103 | // 现将数据插入到cache | 108 | // 现将数据插入到cache |
104 | dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ | 109 | dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ |
105 | 110 | ||
@@ -127,12 +132,35 @@ | @@ -127,12 +132,35 @@ | ||
127 | 132 | ||
128 | } | 133 | } |
129 | 134 | ||
130 | -// } | 135 | + } |
136 | + | ||
137 | + } | ||
131 | 138 | ||
132 | 139 | ||
133 | 140 | ||
134 | } | 141 | } |
135 | 142 | ||
143 | +- (void)newUserJoin:(NSDictionary *)item { | ||
144 | + __weak typeof (self) weakSelf = self; | ||
145 | + dispatch_sync(dispatch_get_main_queue(), ^{ | ||
146 | + [weakSelf caculateContentInset]; | ||
147 | + YH_BarrageMsgModel *newMessage = [[YH_BarrageMsgModel alloc]initWithDictionary:item error:nil]; | ||
148 | + YH_BarrageMsgModel *oldMessage = [weakSelf.dataMutableArray lastObject]; | ||
149 | + | ||
150 | + if ([weakSelf.dataMutableArray count] && oldMessage && oldMessage.cmd == newMessage.cmd && oldMessage.cmd == 4) { | ||
151 | + [weakSelf.dataMutableArray replaceObjectAtIndex:[weakSelf.dataMutableArray count]-1 withObject:newMessage]; | ||
152 | + } else { | ||
153 | + [weakSelf.dataMutableArray addObject:newMessage]; | ||
154 | + } | ||
155 | + | ||
156 | + [weakSelf reloadData]; | ||
157 | + CGPoint bottomOffset = CGPointMake(0, weakSelf.contentSize.height - weakSelf.bounds.size.height); | ||
158 | + [weakSelf setContentOffset:bottomOffset animated:YES]; | ||
159 | + | ||
160 | + | ||
161 | + | ||
162 | + }); | ||
163 | +} | ||
136 | // 将缓冲区中的数据存入tableview的数据源 | 164 | // 将缓冲区中的数据存入tableview的数据源 |
137 | - (void)appendCacheToDataArray { | 165 | - (void)appendCacheToDataArray { |
138 | 166 | ||
@@ -209,12 +237,18 @@ | @@ -209,12 +237,18 @@ | ||
209 | CGPoint bottomOffset = CGPointMake(0, self.contentSize.height - self.bounds.size.height); | 237 | CGPoint bottomOffset = CGPointMake(0, self.contentSize.height - self.bounds.size.height); |
210 | [self setContentOffset:bottomOffset animated:YES]; | 238 | [self setContentOffset:bottomOffset animated:YES]; |
211 | 239 | ||
240 | + if ([self.barrageScrollingDelegate respondsToSelector:@selector(autoScollingCallback)]) { | ||
241 | + [self.barrageScrollingDelegate autoScollingCallback]; | ||
242 | + } | ||
243 | + | ||
244 | + | ||
212 | if (_scrollingTableViewTimer == nil) { | 245 | if (_scrollingTableViewTimer == nil) { |
213 | _scrollingTableViewTimer = [NSTimer timerWithTimeInterval:1 target:self selector:@selector(scrollingTableViewToBottom) userInfo:nil repeats:YES]; | 246 | _scrollingTableViewTimer = [NSTimer timerWithTimeInterval:1 target:self selector:@selector(scrollingTableViewToBottom) userInfo:nil repeats:YES]; |
214 | [[NSRunLoop mainRunLoop] addTimer:_scrollingTableViewTimer forMode:NSRunLoopCommonModes]; | 247 | [[NSRunLoop mainRunLoop] addTimer:_scrollingTableViewTimer forMode:NSRunLoopCommonModes]; |
215 | } | 248 | } |
216 | } | 249 | } |
217 | 250 | ||
251 | + | ||
218 | // 判断tableview是否滑到底部 | 252 | // 判断tableview是否滑到底部 |
219 | - (BOOL)isLastTableViewCell { | 253 | - (BOOL)isLastTableViewCell { |
220 | return (self.contentOffset.y >= (self.contentSize.height - self.frame.size.height)); | 254 | return (self.contentOffset.y >= (self.contentSize.height - self.frame.size.height)); |
-
Please register or login to post a comment