...
|
...
|
@@ -97,42 +97,70 @@ |
|
|
__strong typeof (weakSelf) strongSelf = weakSelf;
|
|
|
|
|
|
if (itemDic && ![itemDic isEqual:[NSNull null]] && !IsStrEmpty([itemDic objectForKey:@"name"])) {
|
|
|
// if ([[itemDic objectForKey:@"uid"] isEqualToString:[GVUserDefaults standardUserDefaults].yohoId] && [[itemDic objectForKey:@"cmd"] longValue] == 5 && !self.manualScrolling) {
|
|
|
if (0) {
|
|
|
// [self greenChannel:itemDic];
|
|
|
// } else {
|
|
|
// 现将数据插入到cache
|
|
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
|
|
|
|
|
YH_BarrageMsgModel *message = [[YH_BarrageMsgModel alloc]initWithDictionary:itemDic error:nil];
|
|
|
|
|
|
[strongSelf->_messageBuffer enqueue:message];
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
if (weakSelf.manualScrolling) {
|
|
|
weakSelf.newMsgCount ++ ;
|
|
|
if ([weakSelf.barrageScrollingDelegate respondsToSelector:@selector(manualScrollingWithNewMsgCount:)]) {
|
|
|
[weakSelf.barrageScrollingDelegate manualScrollingWithNewMsgCount:[NSString stringWithFormat:@"%ld", weakSelf.newMsgCount]];
|
|
|
}
|
|
|
} else {
|
|
|
weakSelf.newMsgCount = 0;
|
|
|
if ([weakSelf.barrageScrollingDelegate respondsToSelector:@selector(autoScollingCallback)]) {
|
|
|
[weakSelf.barrageScrollingDelegate autoScollingCallback];
|
|
|
CGPoint bottomOffset = CGPointMake(0, weakSelf.contentSize.height - weakSelf.bounds.size.height);
|
|
|
[weakSelf setContentOffset:bottomOffset animated:YES];
|
|
|
} else {
|
|
|
|
|
|
if ([[itemDic objectForKey:@"cmd"] longValue] == 4) {
|
|
|
// 如果是用户加入的消息,则不加入到缓冲区
|
|
|
[self newUserJoin:itemDic];
|
|
|
} else {
|
|
|
// 现将数据插入到cache
|
|
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
|
|
|
|
|
YH_BarrageMsgModel *message = [[YH_BarrageMsgModel alloc]initWithDictionary:itemDic error:nil];
|
|
|
|
|
|
[strongSelf->_messageBuffer enqueue:message];
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
if (weakSelf.manualScrolling) {
|
|
|
weakSelf.newMsgCount ++ ;
|
|
|
if ([weakSelf.barrageScrollingDelegate respondsToSelector:@selector(manualScrollingWithNewMsgCount:)]) {
|
|
|
[weakSelf.barrageScrollingDelegate manualScrollingWithNewMsgCount:[NSString stringWithFormat:@"%ld", weakSelf.newMsgCount]];
|
|
|
}
|
|
|
} else {
|
|
|
weakSelf.newMsgCount = 0;
|
|
|
if ([weakSelf.barrageScrollingDelegate respondsToSelector:@selector(autoScollingCallback)]) {
|
|
|
[weakSelf.barrageScrollingDelegate autoScollingCallback];
|
|
|
CGPoint bottomOffset = CGPointMake(0, weakSelf.contentSize.height - weakSelf.bounds.size.height);
|
|
|
[weakSelf setContentOffset:bottomOffset animated:YES];
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
// }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
- (void)newUserJoin:(NSDictionary *)item {
|
|
|
__weak typeof (self) weakSelf = self;
|
|
|
dispatch_sync(dispatch_get_main_queue(), ^{
|
|
|
[weakSelf caculateContentInset];
|
|
|
YH_BarrageMsgModel *newMessage = [[YH_BarrageMsgModel alloc]initWithDictionary:item error:nil];
|
|
|
YH_BarrageMsgModel *oldMessage = [weakSelf.dataMutableArray lastObject];
|
|
|
|
|
|
if ([weakSelf.dataMutableArray count] && oldMessage && oldMessage.cmd == newMessage.cmd && oldMessage.cmd == 4) {
|
|
|
[weakSelf.dataMutableArray replaceObjectAtIndex:[weakSelf.dataMutableArray count]-1 withObject:newMessage];
|
|
|
} else {
|
|
|
[weakSelf.dataMutableArray addObject:newMessage];
|
|
|
}
|
|
|
|
|
|
[weakSelf reloadData];
|
|
|
CGPoint bottomOffset = CGPointMake(0, weakSelf.contentSize.height - weakSelf.bounds.size.height);
|
|
|
[weakSelf setContentOffset:bottomOffset animated:YES];
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
}
|
|
|
// 将缓冲区中的数据存入tableview的数据源
|
|
|
- (void)appendCacheToDataArray {
|
|
|
|
...
|
...
|
@@ -209,12 +237,18 @@ |
|
|
CGPoint bottomOffset = CGPointMake(0, self.contentSize.height - self.bounds.size.height);
|
|
|
[self setContentOffset:bottomOffset animated:YES];
|
|
|
|
|
|
if ([self.barrageScrollingDelegate respondsToSelector:@selector(autoScollingCallback)]) {
|
|
|
[self.barrageScrollingDelegate autoScollingCallback];
|
|
|
}
|
|
|
|
|
|
|
|
|
if (_scrollingTableViewTimer == nil) {
|
|
|
_scrollingTableViewTimer = [NSTimer timerWithTimeInterval:1 target:self selector:@selector(scrollingTableViewToBottom) userInfo:nil repeats:YES];
|
|
|
[[NSRunLoop mainRunLoop] addTimer:_scrollingTableViewTimer forMode:NSRunLoopCommonModes];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
// 判断tableview是否滑到底部
|
|
|
- (BOOL)isLastTableViewCell {
|
|
|
return (self.contentOffset.y >= (self.contentSize.height - self.frame.size.height));
|
...
|
...
|
|