优化长按聊天记录 如果是自己 不要显示举报

This commit is contained in:
2026-02-04 18:39:25 +08:00
parent 3ed120106e
commit db9f07d199
3 changed files with 47 additions and 2 deletions

View File

@@ -28,6 +28,13 @@ typedef NS_ENUM(NSInteger, KBChatMessageActionType) {
@property (nonatomic, weak) id<KBChatMessageActionPopViewDelegate> delegate; @property (nonatomic, weak) id<KBChatMessageActionPopViewDelegate> delegate;
/// 是否显示 “Report” 操作(默认 YES
/// - 当长按的是右侧用户消息KBChatUserMessageCell可设置为 NO。
@property (nonatomic, assign) BOOL showsReportAction;
/// 根据是否显示 Report 计算推荐高度
+ (CGFloat)preferredHeightWithShowsReportAction:(BOOL)showsReportAction;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

View File

@@ -22,10 +22,20 @@ static CGFloat const kKBChatActionRowHeight = 52.0;
@implementation KBChatMessageActionPopView @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 { - (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame]; self = [super initWithFrame:frame];
if (self) { if (self) {
_showsReportAction = YES;
[self setupUI]; [self setupUI];
[self applyReportVisibility];
} }
return self; 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 - (UIControl *)buildRowWithTitle:(NSString *)title
iconName:(NSString *)iconName iconName:(NSString *)iconName
action:(KBChatMessageActionType)action { action:(KBChatMessageActionType)action {

View File

@@ -970,10 +970,13 @@ static NSString * const KBChatSessionDidResetNotification = @"KBChatSessionDidRe
self.selectedActionMessage = message; self.selectedActionMessage = message;
CGFloat width = 240; CGFloat width = 240;
CGFloat height = 156; BOOL isUserMessage = (message.type == KBAiChatMessageTypeUser);
BOOL showsReport = !isUserMessage;
CGFloat height = [KBChatMessageActionPopView preferredHeightWithShowsReportAction:showsReport];
KBChatMessageActionPopView *content = [[KBChatMessageActionPopView alloc] KBChatMessageActionPopView *content = [[KBChatMessageActionPopView alloc]
initWithFrame:CGRectMake(0, 0, width, height)]; initWithFrame:CGRectMake(0, 0, width, height)];
content.delegate = self; content.delegate = self;
content.showsReportAction = showsReport;
UIWindow *window = [UIApplication sharedApplication].keyWindow; UIWindow *window = [UIApplication sharedApplication].keyWindow;
if (!window) { if (!window) {
@@ -988,7 +991,6 @@ static NSString * const KBChatSessionDidResetNotification = @"KBChatSessionDidRe
[window addSubview:mask]; [window addSubview:mask];
self.messageActionMaskView = mask; self.messageActionMaskView = mask;
BOOL isUserMessage = (message.type == KBAiChatMessageTypeUser);
CGFloat margin = 12.0; CGFloat margin = 12.0;
CGFloat spacing = 8.0; CGFloat spacing = 8.0;
CGFloat topSafe = 0.0; CGFloat topSafe = 0.0;