diff --git a/keyBoard/Class/AiTalk/V/Chat/KBChatMessageActionPopView.h b/keyBoard/Class/AiTalk/V/Chat/KBChatMessageActionPopView.h index df4967a..6052f9f 100644 --- a/keyBoard/Class/AiTalk/V/Chat/KBChatMessageActionPopView.h +++ b/keyBoard/Class/AiTalk/V/Chat/KBChatMessageActionPopView.h @@ -28,6 +28,13 @@ typedef NS_ENUM(NSInteger, KBChatMessageActionType) { @property (nonatomic, weak) id delegate; +/// 是否显示 “Report” 操作(默认 YES)。 +/// - 当长按的是右侧用户消息(KBChatUserMessageCell)时,可设置为 NO。 +@property (nonatomic, assign) BOOL showsReportAction; + +/// 根据是否显示 Report 计算推荐高度 ++ (CGFloat)preferredHeightWithShowsReportAction:(BOOL)showsReportAction; + @end NS_ASSUME_NONNULL_END diff --git a/keyBoard/Class/AiTalk/V/Chat/KBChatMessageActionPopView.m b/keyBoard/Class/AiTalk/V/Chat/KBChatMessageActionPopView.m index 5532647..c4c2271 100644 --- a/keyBoard/Class/AiTalk/V/Chat/KBChatMessageActionPopView.m +++ b/keyBoard/Class/AiTalk/V/Chat/KBChatMessageActionPopView.m @@ -22,10 +22,20 @@ static CGFloat const kKBChatActionRowHeight = 52.0; @implementation KBChatMessageActionPopView ++ (CGFloat)preferredHeightWithShowsReportAction:(BOOL)showsReportAction { + // 2 行:Copy + Delete + // 3 行:Copy + Delete + Report + NSInteger rows = showsReportAction ? 3 : 2; + NSInteger lines = showsReportAction ? 2 : 1; + return kKBChatActionRowHeight * rows + 0.5 * lines; +} + - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { + _showsReportAction = YES; [self setupUI]; + [self applyReportVisibility]; } return self; } @@ -73,6 +83,32 @@ static CGFloat const kKBChatActionRowHeight = 52.0; }]; } +- (void)setShowsReportAction:(BOOL)showsReportAction { + if (_showsReportAction == showsReportAction) { + return; + } + _showsReportAction = showsReportAction; + [self applyReportVisibility]; +} + +- (void)applyReportVisibility { + BOOL show = self.showsReportAction; + self.reportRow.hidden = !show; + self.reportRow.userInteractionEnabled = show; + self.line2.hidden = !show; + + // 通过约束把高度收起来,避免外部把 frame 调小后出现约束冲突 + [self.line2 mas_updateConstraints:^(MASConstraintMaker *make) { + make.height.mas_equalTo(show ? 0.5 : 0.0); + }]; + [self.reportRow mas_updateConstraints:^(MASConstraintMaker *make) { + make.height.mas_equalTo(show ? kKBChatActionRowHeight : 0.0); + }]; + + [self setNeedsLayout]; + [self layoutIfNeeded]; +} + - (UIControl *)buildRowWithTitle:(NSString *)title iconName:(NSString *)iconName action:(KBChatMessageActionType)action { diff --git a/keyBoard/Class/AiTalk/V/Chat/KBPersonaChatCell.m b/keyBoard/Class/AiTalk/V/Chat/KBPersonaChatCell.m index 99b8358..8d11c4b 100644 --- a/keyBoard/Class/AiTalk/V/Chat/KBPersonaChatCell.m +++ b/keyBoard/Class/AiTalk/V/Chat/KBPersonaChatCell.m @@ -970,10 +970,13 @@ static NSString * const KBChatSessionDidResetNotification = @"KBChatSessionDidRe self.selectedActionMessage = message; CGFloat width = 240; - CGFloat height = 156; + BOOL isUserMessage = (message.type == KBAiChatMessageTypeUser); + BOOL showsReport = !isUserMessage; + CGFloat height = [KBChatMessageActionPopView preferredHeightWithShowsReportAction:showsReport]; KBChatMessageActionPopView *content = [[KBChatMessageActionPopView alloc] initWithFrame:CGRectMake(0, 0, width, height)]; content.delegate = self; + content.showsReportAction = showsReport; UIWindow *window = [UIApplication sharedApplication].keyWindow; if (!window) { @@ -988,7 +991,6 @@ static NSString * const KBChatSessionDidResetNotification = @"KBChatSessionDidRe [window addSubview:mask]; self.messageActionMaskView = mask; - BOOL isUserMessage = (message.type == KBAiChatMessageTypeUser); CGFloat margin = 12.0; CGFloat spacing = 8.0; CGFloat topSafe = 0.0;