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

未关闭
#79 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
52/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
swift
领域
mobile

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

环境

  • 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 合并后匹配)。聊天内展示、会话列表、通知、
未读计数四处调用点应一致处理。

影响

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

主要语言
Swift
星标
151
派生
22
平均合并
1 天 10 小时
30 天内合并 PR
3

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

NextAlone/Nagram-iOS 的其他 Issue

查看 NextAlone/Nagram-iOS 的全部 Issue

相似的 Issue

更多 Swift Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。