//
//  SLMomentsVc.m
//  SLAiELTS
//
//  Created by Gusont on 2023/4/14.
//

#import "SLMomentsVc.h"

#import "SDTimeLineTableHeaderView.h"
#import "SDTimeLineCell.h"
#import "SDTimeLineCellModel.h"

#import "UITableView+SDAutoTableViewCellHeight.h"

#import "UIView+SDAutoLayout.h"
#import "GlobalDefines.h"

#import "SLMoentsChatView.h"
#import "SLMomentsCommentVc.h"
#import "SLMomentDetailTableVc.h"
#import "SLCreatMomentsVc.h"

#define kTimeLineTableViewCellId @"SDTimeLineCell"

static CGFloat textFieldH = 56;

@interface SLMomentsVc () <SDTimeLineCellDelegate, UITextFieldDelegate, Delegates>


@property (nonatomic, strong) UITextView *textField;
@property (nonatomic, assign) BOOL isReplayingComment;
@property (nonatomic, strong) NSIndexPath *currentEditingIndexthPath;
@property (nonatomic, copy) NSString *commentToUser;

@property (nonatomic, strong) SLMoentsChatView *moentsChatView;

@property (nonatomic, strong) SDTimeLineCellCommentItemModel *currentCommentItemModel;

@property (nonatomic, strong) NSString *currentCacheFriendId;
@end


@implementation SLMomentsVc

{
    CGFloat _lastScrollViewOffsetY;
    CGFloat _totalKeybordHeight;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self confignNavigationBar];
    if (@available(iOS 11.0, *)) {
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    } else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    if (!self.userModel) {
        self.userModel = [SLGlobalInfo SharedInstance].loginInfo.user;
    }
    SDTimeLineTableHeaderView *headerView = [[SDTimeLineTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, 0, 220 * KScaleW)];
    self.tableView.tableHeaderView = headerView;
    self.tableView.tableHeaderView.frame = CGRectMake(0, 0, kSCREEN_WIDTH, 250 * KScaleW);
    //添加分隔线颜色设置
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.tableView registerClass:[SDTimeLineCell class] forCellReuseIdentifier:kTimeLineTableViewCellId];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardNotification:) name:UIKeyboardWillChangeFrameNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(momentsUpdateType:) name:@"SLMomentsUpdateType" object:nil];

    [self creatModelsWithCount:0];
    if (!self.isDetail) {
        NSString *cacheKey = [NSString stringWithFormat:@"SLMomentsCache--%@", self.userModel.userId];
        NSString *cacheStr = [[NSUserDefaults standardUserDefaults] objectForKey:cacheKey];
        NSArray *items = [[cacheStr mj_JSONObject] objectForKey:@"items"];
        if (items.count) {
            NSArray<SDTimeLineCellModel *> *models = [SDTimeLineCellModel mj_objectArrayWithKeyValuesArray:items];
            self.currentCacheFriendId = models.firstObject.friendId;
            [self.dataArray addObjectsFromArray:models];
        }
    }
}

- (void)confignNavigationBar {
    self.navigationBar.separatorHeight = 0.0f;
    if (!self.isFriendList) {
        self.navigationBar.leftBarButtonItem = nil;
        UIImage *creatImage =[UIImage imageNamed:@"icon_home_add"];
        YMBarButtonItem *rightBarItem =[[YMBarButtonItem alloc]initWithImage:creatImage style:YMBarButtonItemPlain target:self action:@selector(creatBtnClick)];
        rightBarItem.titleInsets = UIEdgeInsetsMake(0, 0, 0, 20);
        self.navigationBar.rightBarButtonItem = rightBarItem;
        self.navigationBar.backgroundColor = [UIColor clearColor];
        self.title = @"朋友圈";
    }else {
        UIImage *backImage =[UIImage imageNamed:@"icon_back_w"];
        YMBarButtonItem *backBarButtonItem =[[YMBarButtonItem alloc]initWithImage:backImage style:YMBarButtonItemPlain target:self action:@selector(backBarButtonPressed:)];
        backBarButtonItem.imageInsets = UIEdgeInsetsMake(0, 5, 0, 0);
        self.navigationBar.leftBarButtonItem= backBarButtonItem;
    }
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    if ([self.tableView.tableHeaderView isKindOfClass:SDTimeLineTableHeaderView.class]) {
        SDTimeLineTableHeaderView *headerView = (SDTimeLineTableHeaderView *)self.tableView.tableHeaderView;
        [headerView confignHeaderWith:self.userModel];
    }
    if (self.tableView.contentOffset.y < 300 && !self.tableView.mj_header.refreshing) {
        [self.tableView.mj_header beginRefreshing];
    }
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [self setupTextField];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [_textField resignFirstResponder];
}

- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
    [_moentsChatView removeFromSuperview];
}

- (void)dealloc
{
    [_textField removeFromSuperview];
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}


- (void)creatBtnClick {
    WS(weakSelf);
    [SLCustomizeAlert showBottomAletrWithTitles:@[@"拍照", @"从手机相册选择", @"纯文本"] cancelTitle:@"取消" buttonIndex:^(NSInteger index) {
        if (index != 3) {
            SLCreatMomentsVc *vc = [SLCreatMomentsVc loadViewControllewWithNib];
            vc.photoSelType = index;
            vc.creatMomentSuccess = ^{
                [weakSelf.tableView.mj_header beginRefreshing];
            };
            [weakSelf navPushViewController:vc animated:YES];
        }
    }];
}

- (void)momentsUpdateType:(NSNotification *)notification {
    NSDictionary *dict = notification.userInfo;
    SDTimeLineCellModel *model = [SDTimeLineCellModel mj_objectWithKeyValues:dict];
    __block NSInteger i = 0;
    __block SDTimeLineCellModel *cModel;
    [self.dataArray enumerateObjectsUsingBlock:^(SDTimeLineCellModel * obj, NSUInteger idx, BOOL * _Nonnull stop) {
        if ([obj.friendId isEqualToString:model.friendId]) {
            i = idx;
            cModel = obj;
            *stop = YES;
        }
    }];
    if (cModel) {
        switch (cModel.updateType) {
            case SL_Detail:
            {
                SLMomentDetailTableVc *vc = [SLMomentsVc loadViewControllewWithNib];
                object_setClass(vc, SLMomentDetailTableVc.class);
                vc.isDetail = YES;
                vc.dataArray = [NSMutableArray arrayWithObject:cModel];
                [vc.tableView reloadData];
                [self navPushViewController:vc animated:YES];
            }
                break;
            case SL_CommentUpdate:
            {
                SLMomentsCommentVc *vc = [SLMomentsCommentVc loadViewControllewWithNib];
                WS(weakSelf);
                vc.momentsCommentBlock = ^(NSString * _Nonnull text) {
                    [weakSelf updateCommentWithModel:cModel index:[NSIndexPath indexPathForRow:i inSection:0] text:text];
                };
                [self navPushViewController:vc animated:YES];
                
            }
                break;
            case SL_Update:
            {
                [self updateCellLike:cModel index:[NSIndexPath indexPathForRow:i inSection:0]];
            }
                break;
            default:
                break;
        }
        
    }
}

- (void)updateCommentWithModel:(SDTimeLineCellModel *)model index:(NSIndexPath *)index text:(NSString *)text {
    NSMutableArray *temp = [NSMutableArray new];
    [temp addObjectsFromArray:model.list];
    NSDictionary *parameter = @{@"commendId" : @"",
                                @"friendId" : model.friendId,
                                @"replyUserId" : @"",
                                @"content" : text ?: @"",
                                @"level" : @"0",
    };
    if (!self.isReplayingComment) {
        self.currentCommentItemModel = nil;
    }else {
        parameter = @{@"commendId" : self.currentCommentItemModel.commendId ?: @"",
                      @"friendId" : self.currentCommentItemModel.friendId ?: @"",
                      @"replyUserId" : self.currentCommentItemModel.userId ?: @"",
                      @"content" : text ?: @"",
                      @"level" : @"0",
        };
        self.isReplayingComment = NO;
    }
    [[SLHttpCenter SharedInstance] postWithUrl:@"/api/Friend/InsertComment" parameter:parameter success:^(id responseObject) {
        SDTimeLineCellCommentItemModel *commentItemModel = [SDTimeLineCellCommentItemModel new];
        SLLoginInfo *targetModel = [SLGlobalInfo SharedInstance].loginInfo;
        commentItemModel.userName = targetModel.user.userName;
        commentItemModel.userId = targetModel.user.userId;
        if (self.currentCommentItemModel) {
            commentItemModel.replyUserName = self.currentCommentItemModel.userName;
        }
        commentItemModel.content = text;
        commentItemModel.friendId = model.friendId;
        commentItemModel.level = [parameter objectForKey:@"level"];
        commentItemModel.commendId = [responseObject objectForKey:@"data"];
        [temp addObject:commentItemModel];
        model.list = [temp copy];
        [self.tableView reloadRowsAtIndexPaths:@[index] withRowAnimation:UITableViewRowAnimationNone];
    } failure:^(SPRequestError *error) {
        
    }];
}

- (void)setupTextField
{
    self.moentsChatView = [[SLMoentsChatView alloc] initWithFrame:CGRectMake(0, [UIScreen mainScreen].bounds.size.height, self.view.width_sd, textFieldH)];
    self.moentsChatView.backgroundColor = SLColor(@"#F5F5F5");
    [[UIApplication sharedApplication].keyWindow addSubview:self.moentsChatView];
    
    _textField = self.moentsChatView.nextGrowingTextView.textView;
    _textField.returnKeyType = UIReturnKeyDone;
    self.moentsChatView.nextGrowingTextView.delegates = self;
    WS(weakSelf);
    
    self.moentsChatView.sendTextBlock = ^(NSString * _Nonnull text) {
        if (!text.length) {
            return;
        }
        [weakSelf.textField resignFirstResponder];
        [weakSelf.view endEditing:YES];
        SDTimeLineCellModel *model = weakSelf.dataArray[weakSelf.currentEditingIndexthPath.row];
        [weakSelf updateCommentWithModel:model index:weakSelf.currentEditingIndexthPath text:text];
        weakSelf.textField.text = @"";
    };
}

- (void)creatModelsWithCount:(NSInteger)count
{
    WS(weakSelf);
    [self.tableView tableviewRefresh:self.dataArray TableViewRefresh:^(NSInteger pageNo, TableListCount listCount) {
        NSDictionary *parameter = @{@"PageIndex": @(pageNo),
                                    @"PageSize": @(SLPageSize),
                                    @"type" : @"0",
                                    @"userId" : self.userModel.userId,
        };
        NSString *url = weakSelf.isFriendList ? @"/api/Friend/GetUserFriendList" : @"/api/Friend/GetFriendList";
        
        [[SLHttpCenter SharedInstance] getWithUrl:url parameter:parameter success:^(id responseObject) {
            NSDictionary *data = [responseObject objectForKey:@"data"];
            NSArray *items = [data objectForKey:@"items"];
            if (items.count) {
                NSMutableArray *marr = [SDTimeLineCellModel mj_objectArrayWithKeyValuesArray:items];
                [marr enumerateObjectsUsingBlock:^(SDTimeLineCellModel *obj, NSUInteger idx, BOOL * _Nonnull stop) {
                    
                    obj.likeItemsArray = [NSMutableArray new];
                    [obj.likeStr enumerateObjectsUsingBlock:^(id  _Nonnull obj1, NSUInteger idx1, BOOL * _Nonnull stop) {
                        SDTimeLineCellLikeItemModel *model = [[SDTimeLineCellLikeItemModel alloc] init];
                        model.userName = obj1;
                        model.userId = @"1111";
                        [obj.likeItemsArray addObject:model];
                    }];
                }];
                [weakSelf.dataArray addObjectsFromArray:marr];
                dispatch_async(dispatch_get_main_queue(), ^{
                    [weakSelf.tableView reloadData];
                    SDTimeLineCellModel *firstObj = weakSelf.dataArray.firstObject;
                    if (pageNo == 1 && ![firstObj.friendId isEqualToString:weakSelf.currentCacheFriendId]) {
                        weakSelf.currentCacheFriendId = firstObj.friendId;
                        NSString *cacheKey = [NSString stringWithFormat:@"SLMomentsCache--%@", weakSelf.userModel.userId];
                        [[NSUserDefaults standardUserDefaults] setObject:[data mj_JSONString] forKey:cacheKey];
                        [[NSUserDefaults standardUserDefaults] synchronize];
                    }
                });
                [weakSelf.dataArray enumerateObjectsUsingBlock:^(SDTimeLineCellModel * obj, NSUInteger idx, BOOL * _Nonnull stop) {
                    if ([obj.friendImgUrl componentsSeparatedByString:@","].count == 1) {

                        [weakSelf.KVOController observe:obj keyPath:@"imageSize" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld block:^(id  _Nullable observer, id  _Nonnull object, NSDictionary<NSKeyValueChangeKey,id> * _Nonnull change) {
                            dispatch_async(dispatch_get_main_queue(), ^{
                                [weakSelf.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:[NSIndexPath indexPathForRow:idx inSection:0], nil] withRowAnimation:UITableViewRowAnimationAutomatic];
                            });
                        }];
                    }
                }];
                
            }
            listCount([items count]);
        } failure:^(SPRequestError *error) {
            listCount(-1);
        }];
    }];
}

#pragma -mark scrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    UIColor * color = [UIColor whiteColor];
    CGFloat offsetY = scrollView.contentOffset.y;
    CGFloat alpha = 1.0;
    if (offsetY >= 100) {
        alpha = MIN(1, 1 - ((2 + kNavBarHeight - offsetY) / kNavBarHeight));
        self.navigationBar.backgroundColor = [color colorWithAlphaComponent:alpha];
        self.navigationBar.rightBarButtonItemView.itemImageView.image = ImageName(@"icon_pyq_more_back");
        self.navigationBar.titleItemView.alpha = alpha;
        self.navigationBar.leftBarButtonItemView.itemImageView.image = ImageName(@"icon_back_b");

        if (self.isFriendList) {
        }
    } else {
        self.navigationBar.titleItemView.alpha = 0;
        self.navigationBar.backgroundColor = [color colorWithAlphaComponent:0];
        self.navigationBar.rightBarButtonItemView.itemImageView.image = ImageName(@"icon_pyq_more");
        self.navigationBar.leftBarButtonItemView.itemImageView.image = ImageName(@"icon_back_w");
    }
}



#pragma mark - tableviewDelegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    SDTimeLineCell *cell = [tableView dequeueReusableCellWithIdentifier:kTimeLineTableViewCellId];
    cell.indexPath = indexPath;
    SDTimeLineCellModel *model = self.dataArray[indexPath.row];
    cell.model = model;
    __weak typeof(self) weakSelf = self;
    if (!cell.moreButtonClickedBlock) {
        [cell setMoreButtonClickedBlock:^(NSIndexPath *indexPath) {
            SDTimeLineCellModel *model = weakSelf.dataArray[indexPath.row];
            model.isOpening = !model.isOpening;
            [weakSelf.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
//            [weakSelf.tableView reloadData];
        }];
        
        [cell setDidClickCommentLabelBlock:^(NSString *commentId, CGRect rectInWindow,  NSIndexPath *indexPath1) {
            weakSelf.currentEditingIndexthPath = [NSIndexPath indexPathForRow:indexPath1.row inSection:0];
            SDTimeLineCellModel *editModel = weakSelf.dataArray[indexPath1.row];
            [weakSelf.textField becomeFirstResponder];
            weakSelf.isReplayingComment = YES;
            weakSelf.currentCommentItemModel = [editModel.list objectAtIndex:indexPath1.section];
            weakSelf.commentToUser = commentId;
            [weakSelf adjustTableViewToFitKeyboard];
        }];
        
        [cell setDidLongTouchCommentLabelBlock:^(NSString *commentId, CGRect rectInWindow, NSIndexPath *indexPath1) {
            //indexPath1 row == table row  Section == SDTimeLineCellCommentItemModel.list
            SDTimeLineCellModel *editModel = [weakSelf.dataArray objectAtIndex:indexPath1.row];
            if ([editModel.userId isEqualToString:[SLGlobalInfo SharedInstance].loginInfo.user.userId]) {
                NSMutableArray *temp = [NSMutableArray new];
                [temp addObjectsFromArray:editModel.list];
                SDTimeLineCellCommentItemModel *commentModel = [editModel.list objectAtIndex:indexPath1.section];
                [[SLHttpCenter SharedInstance] getWithUrl:@"/api/Friend/DelateComment" parameter:@{@"commentId":commentModel.commendId} success:^(id responseObject) {
                    [temp removeObjectAtIndex:indexPath1.section];
                    editModel.list = [temp copy];
                    [weakSelf.tableView reloadRowsAtIndexPaths:@[indexPath1] withRowAnimation:UITableViewRowAnimationNone];
                } failure:^(SPRequestError *error) {

                }];
            }
        }];
        
        cell.delegate = self;
    }
    
    ////// 此步设置用于实现cell的frame缓存，可以让tableview滑动更加流畅 //////
    
    [cell useCellFrameCacheWithIndexPath:indexPath tableView:tableView];
    
    ///////////////////////////////////////////////////////////////////////
    
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    // >>>>>>>>>>>>>>>>>>>>> * cell自适应 * >>>>>>>>>>>>>>>>>>>>>>>>
    if (indexPath.row > self.dataArray.count - 1) {
        return 0.0f;
    }
    id model = self.dataArray[indexPath.row];
    return [self.tableView cellHeightForIndexPath:indexPath model:model keyPath:@"model" cellClass:[SDTimeLineCell class] contentViewWidth:[self cellContentViewWith]];
}


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 0.001f;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.001f;
}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    [_textField resignFirstResponder];
}

- (CGFloat)cellContentViewWith
{
    CGFloat width = [UIScreen mainScreen].bounds.size.width;
    
    // 适配ios7横屏
    if ([UIApplication sharedApplication].statusBarOrientation != UIInterfaceOrientationPortrait && [[UIDevice currentDevice].systemVersion floatValue] < 8) {
        width = [UIScreen mainScreen].bounds.size.height;
    }
    return width;
}


#pragma mark - SDTimeLineCellDelegate

- (void)didClickcCommentButtonInCell:(UITableViewCell *)cell
{
    [_textField becomeFirstResponder];
    _currentEditingIndexthPath = [self.tableView indexPathForCell:cell];
    [self adjustTableViewToFitKeyboard];
    
}

- (void)didClickLikeButtonInCell:(UITableViewCell *)cell
{
    NSIndexPath *index = [self.tableView indexPathForCell:cell];
    SDTimeLineCellModel *model = self.dataArray[index.row];
    model.updateType = SL_Update;
    [[NSNotificationCenter defaultCenter] postNotificationName:@"SLMomentsUpdateType" object:nil userInfo:[model mj_JSONObject]];
//    [self updateCellLike:model index:index];
}

- (void)didClickDelButtonInCell:(UITableViewCell *)cell
{
    [SLCustomizeAlert showAletrWithTitle:@"温馨提示" message:@"是否要删除当条朋友圈内容" sureBtnTitle:@"确定" cancelBtnTitle:@"取消" sureBtnAction:^{
        NSIndexPath *index = [self.tableView indexPathForCell:cell];
        SDTimeLineCellModel *model = self.dataArray[index.row];
        [[SLHttpCenter SharedInstance] getWithUrl:@"/api/Friend/DelateFriendCircle" parameter:@{@"id":model.friendId} success:^(id responseObject) {
            [self.dataArray removeObject:model];
            [self.tableView reloadData];
        } failure:^(SPRequestError *error) {
            
        }];
    } cancelBtnAction:^{
        
    }];
}

- (void)updateCellLike:(SDTimeLineCellModel *)model index:(NSIndexPath *)index {
    NSMutableArray *temp = [NSMutableArray arrayWithArray:model.likeItemsArray];
    if ([self isEqual:[UIViewController getCurrentShowVC]]) {
        [[SLHttpCenter SharedInstance] getWithUrl:@"/api/Friend/LikeHe" parameter:@{@"friendId":model.friendId} success:^(id responseObject) {
            
        } failure:^(SPRequestError *error) {
            
        }];
    }
    SLUserModel *userModel = [SLGlobalInfo SharedInstance].loginInfo.user;
    if (!model.isLike) {
        SDTimeLineCellLikeItemModel *likeModel = [SDTimeLineCellLikeItemModel new];
        likeModel.userName = userModel.userName;
        likeModel.userId = userModel.userId;
        [temp addObject:likeModel];
        model.isLike = YES;
    } else {
        SDTimeLineCellLikeItemModel *tempLikeModel = nil;
        for (SDTimeLineCellLikeItemModel *likeModel in model.likeItemsArray) {
            if ([likeModel.userName isEqualToString:userModel.userName]) {
                tempLikeModel = likeModel;
                break;
            }
        }
        [temp removeObject:tempLikeModel];
        model.isLike = NO;
    }
    model.likeItemsArray = [temp copy];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self.tableView reloadRowsAtIndexPaths:@[index] withRowAnimation:UITableViewRowAnimationNone];
    });
}


- (void)adjustTableViewToFitKeyboard
{
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:_currentEditingIndexthPath];
    CGRect rect = [cell.superview convertRect:cell.frame toView:window];
    [self adjustTableViewToFitKeyboardWithRect:rect];
}

- (void)adjustTableViewToFitKeyboardWithRect:(CGRect)rect
{
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    CGFloat delta = CGRectGetMaxY(rect) - (window.bounds.size.height - _totalKeybordHeight);
    
    CGPoint offset = self.tableView.contentOffset;
    offset.y += delta;
    if (offset.y < 0) {
        offset.y = 0;
    }
    
    [self.tableView setContentOffset:offset animated:YES];
}

- (void)keyboardNotification:(NSNotification *)notification
{
    NSDictionary *dict = notification.userInfo;
    CGRect rect = [dict[@"UIKeyboardFrameEndUserInfoKey"] CGRectValue];
        
    CGRect textFieldRect = CGRectMake(0, rect.origin.y - textFieldH, rect.size.width, textFieldH);
    if (rect.origin.y == [UIScreen mainScreen].bounds.size.height) {
        textFieldRect = rect;
    }
    
    [UIView animateWithDuration:0.25 animations:^{
        self.moentsChatView.frame = textFieldRect;
    }];
    
    CGFloat h = rect.size.height + textFieldH;
    if (_totalKeybordHeight != h) {
        _totalKeybordHeight = h;
        [self adjustTableViewToFitKeyboard];
    }
}

- (void)willChangeHeight:(CGFloat)height
{
    [self bottomChangeHeight:height];
}

- (void)didChangeHeight:(CGFloat)height
{
    [self bottomChangeHeight:height];
}

- (void)bottomChangeHeight:(CGFloat)height
{
    CGRect rect = self.moentsChatView.frame;
    CGFloat h = MAX(height + 16, 56);
    rect.origin.y = rect.origin.y - (h - rect.size.height);
    rect.size.height = h;
    self.moentsChatView.frame = rect;
    [self.moentsChatView setNeedsDisplay];
}

- (NSMutableArray *)dataArray {
    if (!_dataArray) {
        _dataArray = [NSMutableArray array];
    }
    return _dataArray;
}


@end
