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

Open
#79 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
52/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
swift
Domain
mobile

Research direction

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.

Written by the indexing model from the issue text.

Description

环境

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

影响

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

Dominant language
Swift
Stars
151
Forks
22
Avg merge
1d 10h
Merged PRs (30d)
3

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from NextAlone/Nagram-iOS

All issues in NextAlone/Nagram-iOS

Similar issues

More Swift issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.