Skip to content

Read-mentions “mark all”, link-entity creation, logout cleanup, and read-model sync#43

Open
AliKhadivi wants to merge 7 commits into
loyldg:devfrom
AliKhadivi:bugfix/somebugs
Open

Read-mentions “mark all”, link-entity creation, logout cleanup, and read-model sync#43
AliKhadivi wants to merge 7 commits into
loyldg:devfrom
AliKhadivi:bugfix/somebugs

Conversation

@AliKhadivi

Copy link
Copy Markdown
Contributor
  • Mentions: ReadMention(messageId, bool readAllMentions); command/handler updated; messages.readMentions now clears all unread mentions.
  • Link entity creation: Stronger URL detection (capped TLDs, balanced parens, max length, no email overlap) and safer mention/hashtag parsing; extracted to MessageAppService.
  • Send flow: Proper bot-command entity (^/… length), invite preview via service, channel initial views = 0, one-shot draft clear.
  • Logout: New LogOutEventHandler unregisters device auth keys on UserLoggedOutEvent.
  • Read models: DialogReadModel tracks mention create/read; MessageReadModel updates Views.

Notes: Interface changes to IMessageAppService and IUsernameHelper; ReadMentionCommand adds readAllMentions.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When extracting MessageEntity, what issues couldn't be handled before the modification, and what problems were fixed after it? Could you list some examples?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧩 Summary of Fixes in MessageAppService.cs

Before:

  • URL detection was basic — only matched https://..., missed schemeless links, IPs, and ports.
  • URLs sometimes merged or included punctuation (like example.com).).
  • Mentions (@user) were falsely detected inside emails or URLs.
  • Hashtags accepted digits or underscores as first char, no length limit.
  • Bot commands (/create image) marked entire message, not just /create.
  • Duplicate URL logic appeared in multiple classes.

After (Fixes & Improvements):

  1. Unified & Strong URL Regex

    • Handles http/https, schemeless (example.com), IPv4, and ports.
    • Skips trailing punctuation and clamps overly long URLs.
    • Caps TLD length (rejects invalid domains like ofd.registrarpersonid).
    • Prevents overlapping/merged URL entities.
  2. Centralized Entity Extraction

    • All entity detection (URL, mention, hashtag, bot command) happens in MessageAppService — no duplication in handlers.
  3. Safer Mentions

    • Ignores @gmail in emails and @user inside URLs.
  4. Improved Hashtags

    • Regex: #[A-Za-z][A-Za-z0-9_]{0,254}
    • Must start with a letter; max length = 256 characters.
  5. Stricter Bot Command Parsing

    • /command limited to [A-Za-z0-9_] and ≤ 64 chars (so /create image → only /create).
  6. Consistent Invite Link Preview

    • Moved invite URL detection into a reusable method (CreateInvitePreviewIfAnyAsync) inside the service.

Result:
Message entities (URLs, mentions, hashtags, commands) are now parsed correctly, bounded, and non-overlapping — giving Telegram-accurate behavior, better safety, and zero duplication between service and handler.

@loyldg

loyldg commented Oct 7, 2025

Copy link
Copy Markdown
Owner

The current PR changes too many things. Could you make each PR address only one issue and submit them separately?


return new TAffectedHistory
{
Pts = ptsHelper.GetCachedPts(input.UserId),

@loyldg loyldg Oct 7, 2025

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If executing the command requires modifying pts, you may need to create a new XXXSaga to handle it. After incrementing pts, publish a DomainEvent, then return the result to the client in the DomainEventHandler. You can refer to EditMessageSaga/ClearHistorySaga as an example.

KevvoGeek pushed a commit to KevvoGeek/mytelegram that referenced this pull request Feb 7, 2026
- ReadMentionCommand, ReadMentionCommandHandler, MentionReadEvent: Removed (refactored in dev)
- DialogAggregate, handlers: Kept dev version (architecture evolved)
- Note: PR loyldg#43 was 4+ months old with 721 commits divergence
- ReadMentions feature still partially available through updated handlers
- Manual merge required due to significant architecture changes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants