Authored by 盖剑秋

update barrage module.

@@ -97,42 +97,70 @@ @@ -97,42 +97,70 @@
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 {  
103 - // 现将数据插入到cache  
104 - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{  
105 -  
106 - YH_BarrageMsgModel *message = [[YH_BarrageMsgModel alloc]initWithDictionary:itemDic error:nil];  
107 -  
108 - [strongSelf->_messageBuffer enqueue:message];  
109 -  
110 - dispatch_async(dispatch_get_main_queue(), ^{  
111 - if (weakSelf.manualScrolling) {  
112 - weakSelf.newMsgCount ++ ;  
113 - if ([weakSelf.barrageScrollingDelegate respondsToSelector:@selector(manualScrollingWithNewMsgCount:)]) {  
114 - [weakSelf.barrageScrollingDelegate manualScrollingWithNewMsgCount:[NSString stringWithFormat:@"%ld", weakSelf.newMsgCount]];  
115 - }  
116 - } else {  
117 - weakSelf.newMsgCount = 0;  
118 - if ([weakSelf.barrageScrollingDelegate respondsToSelector:@selector(autoScollingCallback)]) {  
119 - [weakSelf.barrageScrollingDelegate autoScollingCallback];  
120 - CGPoint bottomOffset = CGPointMake(0, weakSelf.contentSize.height - weakSelf.bounds.size.height);  
121 - [weakSelf setContentOffset:bottomOffset animated:YES]; 102 + } else {
  103 +
  104 + if ([[itemDic objectForKey:@"cmd"] longValue] == 4) {
  105 + // 如果是用户加入的消息,则不加入到缓冲区
  106 + [self newUserJoin:itemDic];
  107 + } else {
  108 + // 现将数据插入到cache
  109 + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  110 +
  111 + YH_BarrageMsgModel *message = [[YH_BarrageMsgModel alloc]initWithDictionary:itemDic error:nil];
  112 +
  113 + [strongSelf->_messageBuffer enqueue:message];
  114 +
  115 + dispatch_async(dispatch_get_main_queue(), ^{
  116 + if (weakSelf.manualScrolling) {
  117 + weakSelf.newMsgCount ++ ;
  118 + if ([weakSelf.barrageScrollingDelegate respondsToSelector:@selector(manualScrollingWithNewMsgCount:)]) {
  119 + [weakSelf.barrageScrollingDelegate manualScrollingWithNewMsgCount:[NSString stringWithFormat:@"%ld", weakSelf.newMsgCount]];
  120 + }
  121 + } else {
  122 + weakSelf.newMsgCount = 0;
  123 + if ([weakSelf.barrageScrollingDelegate respondsToSelector:@selector(autoScollingCallback)]) {
  124 + [weakSelf.barrageScrollingDelegate autoScollingCallback];
  125 + CGPoint bottomOffset = CGPointMake(0, weakSelf.contentSize.height - weakSelf.bounds.size.height);
  126 + [weakSelf setContentOffset:bottomOffset animated:YES];
  127 + }
122 } 128 }
123 - } 129 + });
  130 +
124 }); 131 });
125 -  
126 - }); 132 +
  133 + }
127 134
128 } 135 }
129 -  
130 -// } 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));