Authored by 郁健超

修改弹幕相关问题 review by阿瑟

... ... @@ -11,7 +11,7 @@
#import "YH_BarrageMsgCell.h"
#import "YH_BarrageJoinCell.h"
#import "UtilsMacros.h"
#import <pthread.h>
#define kMessageCellID @"MessageCelliden"
#define kJoinCellID @"JoinCellIden"
#define MaxMessageCacheCapacity 20
... ... @@ -142,7 +142,8 @@
- (void)newUserJoin:(NSDictionary *)item {
__weak typeof (self) weakSelf = self;
dispatch_sync(dispatch_get_main_queue(), ^{
if (pthread_main_np() != 0) {
// main thread
[weakSelf caculateContentInset];
YH_BarrageMsgModel *newMessage = [[YH_BarrageMsgModel alloc]initWithDictionary:item error:nil];
YH_BarrageMsgModel *oldMessage = [weakSelf.dataMutableArray lastObject];
... ... @@ -156,10 +157,24 @@
[weakSelf reloadData];
CGPoint bottomOffset = CGPointMake(0, weakSelf.contentSize.height - weakSelf.bounds.size.height);
[weakSelf setContentOffset:bottomOffset animated:YES];
});
}else {
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 {
... ... @@ -189,15 +204,24 @@
// 如果返回的数据是本机用户所发,则立即显示,不需要走缓冲策略,直接加入到tableview数据源,刷新列表
- (void)greenChannel:(NSDictionary *)item {
__weak typeof (self) weakSelf = self;
dispatch_sync(dispatch_get_main_queue(), ^{
if (pthread_main_np() != 0) {
// main thread
[weakSelf caculateContentInset];
YH_BarrageMsgModel *message = [[YH_BarrageMsgModel alloc]initWithDictionary:item error:nil];
[weakSelf.dataMutableArray addObject:message];
[weakSelf reloadData];
CGPoint bottomOffset = CGPointMake(0, weakSelf.contentSize.height - weakSelf.bounds.size.height);
[weakSelf setContentOffset:bottomOffset animated:YES];
});
}else {
dispatch_sync(dispatch_get_main_queue(), ^{
[weakSelf caculateContentInset];
YH_BarrageMsgModel *message = [[YH_BarrageMsgModel alloc]initWithDictionary:item error:nil];
[weakSelf.dataMutableArray addObject:message];
[weakSelf reloadData];
CGPoint bottomOffset = CGPointMake(0, weakSelf.contentSize.height - weakSelf.bounds.size.height);
[weakSelf setContentOffset:bottomOffset animated:YES];
});
}
}
... ...