[Bug][iOS] 正则消息过滤对 Rich Message(富文本帖)不生效:正文不在 message.text 中

Đang mở
#79 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
52/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
swift
Lĩnh vực
mobile

Hướng nghiên cứu

Start by reading NagramRegexFilters.swift and the listed call sites in ChatHistoryEntriesForView.swift, ChatController.swift, ChatListNodeEntries.swift, NotificationService.swift, and NagramFilteredUnreadBadge.swift. Trace how RichTextMessageAttribute stores block text and how the filter currently handles empty message.text; then check existing regex filter tests. Done means Rich Message text is filtered consistently in chat, lists, notifications, and unread counts, with coverage for rich and ordinary messages.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

环境

  • Nagram iOS(App Store 版)
  • iPhone 15 Pro / iOS 27.3 beta 1

现象

同一频道、同一分钟内的四条机场广告帖,普通图文帖被正则过滤正确隐藏,
三条富文本帖(Rich Message)全部漏过。规则、开关均确认无误
(同一条正则对普通帖生效;把富文本内容拼成纯文本后离线测试也能命中)。

证据(MTProto 原始消息结构)

公开频道「破解软件资源分享」(channel_id 1538893263),2026-11-17:

  • msg 11812(芒果云):普通 MessageMediaPhoto + caption,message 字段为
    完整正文(570 字)→ 被正确隐藏
  • msg 11809(Matcha)、11810(9527)、11813(星驰):未被隐藏。三者的
    原始结构一致:message=""、media=null、entities=[]、reply_markup=null,
    全部内容位于 rich_message.blocks 中(PageBlockPhoto /
    PageBlockHeading2 / PageBlockBlockquoteBlocks / PageBlockParagraph,
    文本由 TextPlain / TextBold / TextUrl / TextCustomEmoji 段组成)

根因(源码)

过滤的全部调用点只把 message.text 送入匹配:

  • submodules/TelegramUI/Sources/ChatHistoryEntriesForView.swift:192
    nagramRegexFilterMatcher.apply(to: message.text, ...)
  • submodules/TelegramUI/Sources/ChatController.swift:7754
    matcher.isHidden(text: message.text, ...)
  • ChatListNodeEntries.swift:652、707,NotificationService.swift:2287,
    NagramFilteredUnreadBadge.swift:170 同理

Rich Message 的正文存放在 RichTextMessageAttribute 中,Message.text
为空;而 NagramRegexFilters.swift 的 applyUncached 对空文本直接跳过
(guard !currentText.isEmpty),因此这类消息永远不可能命中任何规则。

建议修复

构造待匹配文本时:若 message.text 为空且消息带有
RichTextMessageAttribute,按 blocks 顺序提取其纯文本参与匹配
(或与 message.text 合并后匹配)。聊天内展示、会话列表、通知、
未读计数四处调用点应一致处理。

影响

富文本帖正被频道广告大量采用(排版更好,且恰好完全绕过文本过滤),
随着采用率上升,正则过滤对频道广告将整体失效。

Ngôn ngữ chính
Swift
Star
151
Fork
22
Merge trung bình
1 ngày 10 giờ
Pull request đã merge (30 ngày)
3

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của NextAlone/Nagram-iOS

Tất cả issue của NextAlone/Nagram-iOS

Issue tương tự

Thêm issue về Swift

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.