Skip to content

fix: 引用メッセージの展開が正しく行われるように#58

Merged
cp-20 merged 1 commit intostagingfrom
fix/expand-embeds
Feb 23, 2026
Merged

fix: 引用メッセージの展開が正しく行われるように#58
cp-20 merged 1 commit intostagingfrom
fix/expand-embeds

Conversation

@cp-20
Copy link
Contributor

@cp-20 cp-20 commented Feb 23, 2026

Summary by CodeRabbit

新機能

  • メッセージ内の埋め込み要素が正しくフォーマットされるようになりました
  • 引用メッセージのフォーマット機能を追加し、より見やすく表示されるようになりました

改善

  • システムパフォーマンスの最適化を実施しました

@cp-20 cp-20 changed the base branch from main to staging February 23, 2026 06:16
@cp-20 cp-20 self-assigned this Feb 23, 2026
@coderabbitai
Copy link

coderabbitai bot commented Feb 23, 2026

Caution

Review failed

Failed to post review comments

📝 Walkthrough

Walkthrough

新しいキャッシング依存関係を導入し、チャネルおよびユーザー情報取得機能を実装しました。メッセージフォーマット機能として埋め込みコンテンツと引用メッセージの処理を追加し、メッセージハンドラーに統合しました。

Changes

Cohort / File(s) Summary
依存関係管理
go.mod
キャッシング機能を提供する sc ライブラリを間接依存として追加(v1.8.2)。
キャッシング機能
internal/bot/channel.go, internal/bot/user.go
チャネルパスおよびユーザー詳細情報を取得する関数を実装。1時間の TTL を持つ sc キャッシュで結果を段階的にキャッシュし、API 呼び出しを最適化。
メッセージハンドラー
internal/handler/OnMessageCreated.go, internal/handler/OnDirectMessageCreated.go
メッセージテキスト処理パイプラインを拡張。埋め込みコンテンツをフォーマットし、引用メッセージの処理を試行、エラー時はフォールバック。
フォーマッター実装
internal/pkg/formatter/embed.go, internal/pkg/formatter/embed_test.go, internal/pkg/formatter/quotes.go
埋め込みコンテンツ処理用の正規表現ベースのフォーマッターと、チャネル・ユーザー権限チェックを含む引用メッセージフォーマッターを新規実装。テストカバレッジを追加。

Sequence Diagram

sequenceDiagram
    participant Handler as Message Handler
    participant Formatter as Formatter
    participant BotAPI as Bot API
    participant Cache as Cache
    participant Message as Message Response

    Handler->>Formatter: FormatEmbeds(text)
    Formatter->>Formatter: Extract & replace embeds
    Formatter->>Handler: formatted text

    Handler->>Formatter: FormatQuotedMessage(userID, text)
    Formatter->>Formatter: Extract quote IDs
    
    loop For each quoted message
        Formatter->>Cache: GetMessage(messageID)
        Cache->>BotAPI: GetMessage (if not cached)
        BotAPI->>Message: Fetch message details
        Message->>Cache: Return message
        Cache->>Formatter: Return cached message
        
        Formatter->>Cache: GetChannelPath(channelID)
        Cache->>Formatter: Return channel path
        
        Formatter->>Cache: GetUser(userID)
        Cache->>BotAPI: GetUser (if not cached)
        BotAPI->>Formatter: Return user details
        
        Formatter->>Formatter: Check permissions & format quote
    end
    
    Formatter->>Handler: Return formatted message with quotes
    Handler->>Handler: Use formatted message
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • feat: 引用メッセージを展開するように #57: 同じ go.mod 依存関係追加、internal/bot/channel.go、internal/bot/user.go、internal/pkg/formatter/quotes.go、ハンドラー修正が含まれており、GetChannelPath・GetUser・FormatQuotedMessage の実装が完全に一致しています。

Suggested labels

Review effort 3/5

Suggested reviewers

  • kaitoyama
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed Pull request title clearly describes the main change: fixing quoted message expansion functionality.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/expand-embeds

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Error Handling

The error handling logic in the DirectMessageReceived function assigns formattedMessage to textWithoutMention when an error occurs. This should be reviewed to ensure it is the desired fallback behavior.

formattedMessage, err := formatter.FormatQuotedMessage(p.Message.User.ID, textWithoutMention)
if err != nil {
	log.Printf("Error formatting quoted message: %v\n", err)
	formattedMessage = textWithoutMention
Error Handling

Similar to DirectMessageReceived, the MessageReceived function assigns formattedMessage to textWithoutMention upon encountering an error. This fallback behavior should be validated.

formattedMessage, err := formatter.FormatQuotedMessage(p.Message.User.ID, textWithoutMention)
if err != nil {
	log.Printf("Error formatting quoted message: %v\n", err)
	formattedMessage = textWithoutMention

Copy link
Contributor

@kaitoyama kaitoyama left a comment

Choose a reason for hiding this comment

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

LGTMです!

@cp-20 cp-20 merged commit fd201a4 into staging Feb 23, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants