Skip to content

Add Matrix metadata for LINE images#189

Open
Adri11334 wants to merge 8 commits into
beeper:mainfrom
Adri11334:line-image-fileinfo
Open

Add Matrix metadata for LINE images#189
Adri11334 wants to merge 8 commits into
beeper:mainfrom
Adri11334:line-image-fileinfo

Conversation

@Adri11334

Copy link
Copy Markdown

Summary

  • derive inbound LINE image filename, MIME type, size, and dimensions from the downloaded bytes
  • attach Matrix content.info to bridged image events so clients can identify them as images
  • stop ignoring Go test files so the new image metadata tests are included

Fixes #155

Notes

I haven't verified this on the iOS client yet, but this fills the missing Matrix media metadata that clients normally use to identify image attachments.

Testing

  • GOWORK=off go test ./pkg/connector/handlers
  • go test ./... in Docker
  • go vet $(go list ./... | grep -v /ltsm) in Docker
  • staticcheck $(go list ./... | grep -v /ltsm) in Docker
  • goimports -local "github.com/highesttt/matrix-line-messenger" -l ... in Docker
  • docker build .

@Adri11334

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@Adri11334, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 13 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 264f7d3e-5d4d-4965-b843-5f58becbe75a

📥 Commits

Reviewing files that changed from the base of the PR and between 7677aaf and eb5f321.

📒 Files selected for processing (2)
  • pkg/connector/handlers/image.go
  • pkg/connector/handlers/image_test.go
📝 Walkthrough

Walkthrough

Replaces hardcoded image.jpg/image/jpeg in LINE image uploads with byte-sniffed MIME type, filename, and dimension detection supporting JPEG, PNG, HEIC/HEIF/AVIF, and WebP via new helpers. Adds comprehensive unit tests validating format detection across multiple image types and removes the *_test.go gitignore rule.

Changes

Dynamic LINE image format detection

Layer / File(s) Summary
Image format detection helpers
pkg/connector/handlers/image.go
Adds WebP decoder import. Introduces detectLineImageMimeType to detect MIME via http.DetectContentType with ftyp brand parsing for HEIC/HEIF/AVIF and fallback to JPEG. Adds imageExtensionForMIME to map normalized MIME types to file extensions. Introduces lineImageMediaInfo to compute filename/MIME and populate event.FileInfo with size and optional image.DecodeConfig width/height. Adds lineImageEventContent to build event.MessageEventContent with proper message type, body filename, and FileInfo attachment.
ConvertImage integration
pkg/connector/handlers/image.go
Replaces hardcoded UploadMedia arguments with dynamically derived fileName, mimeType, and imageInfo from lineImageMediaInfo. Adds optional debug logging for MIME fallback and decode errors.
Comprehensive unit tests and gitignore fix
.gitignore, pkg/connector/handlers/image_test.go
Removes *_test.go gitignore entry. Expands TestLineImageMediaInfo across JPEG, PNG, HEIC, HEIF, AVIF, BMP, and invalid inputs, asserting filename, MIME type, FileInfo presence, and decoded dimensions. Adds TestLineImageMediaInfoFallbackState asserting MIME fallback behavior and decode error presence. Adds TestImageExtensionForMIME validating MIME-to-extension mappings. Updates TestLineImageEventContentIncludesFileInfo verifying MessageEventContent construction. Includes testJPEG, testPNG, and testImage encoding helpers.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 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 (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Add Matrix metadata for LINE images' directly and concisely summarizes the main change: adding metadata to image events.
Description check ✅ Passed The description clearly explains the changes: deriving image metadata, attaching Matrix content.info, and removing test file ignores.
Linked Issues check ✅ Passed The PR addresses issue #155 by deriving image MIME type and dimensions from bytes and attaching Matrix metadata, enabling iOS clients to properly identify and save images.
Out of Scope Changes check ✅ Passed All changes are directly related to image metadata handling: .gitignore removal of test exclusion, image.go metadata derivation logic, and image_test.go test expansion are all in scope.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

Billing warning: we have not been able to collect payment for this subscription for more than 72 hours. Please update the payment method or pay any pending invoices in Billing to avoid service interruption.


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.

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
pkg/connector/handlers/image.go (2)

180-198: ⚡ Quick win

Consider logging the fallback to image/jpeg.

When the MIME type cannot be detected, the function silently defaults to image/jpeg. Logging this fallback would improve observability and help identify unexpected formats from LINE.

📊 Proposed enhancement for observability

If you add a logger parameter (or refactor to a method), you could log the fallback:

 		}
 	}
 
+	// Fallback to JPEG; log for observability
+	// (Consider adding logger param to enable this)
 	return "image/jpeg"
 }

Alternatively, consider returning an explicit indicator (like a second bool return value) when using the fallback, so the caller can log it.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/connector/handlers/image.go` around lines 180 - 198, The
detectLineImageMimeType function silently falls back to returning "image/jpeg"
when the MIME type cannot be detected, which reduces observability. Either add a
logger parameter to the function and log when the fallback to "image/jpeg"
occurs (just before the final return statement), or refactor the function to
return both the MIME type string and a boolean flag indicating whether a
fallback was used, so the caller can log it. Choose the approach that best fits
your codebase's error handling patterns.

172-175: ⚡ Quick win

Consider logging DecodeConfig failures for observability.

The error from image.DecodeConfig is silently ignored. While the fallback behavior (omitting dimensions) is safe, logging the error would help diagnose format support issues, especially for formats like HEIC/HEIF that may not decode with the standard library.

📊 Proposed enhancement for observability
 	if config, _, err := image.DecodeConfig(bytes.NewReader(data)); err == nil {
 		info.Width = config.Width
 		info.Height = config.Height
+	} else {
+		// Log decode failure for observability; dimensions will be omitted
+		// Note: HEIC/HEIF and some formats may not have stdlib decoder support
+		h.Log.Debug().
+			Err(err).
+			Str("mime_type", mimeType).
+			Msg("Could not decode image dimensions")
 	}

Note: This would require passing the logger (h.Log) to the function or refactoring to a method.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/connector/handlers/image.go` around lines 172 - 175, The error returned
from image.DecodeConfig is being silently ignored, which prevents observability
into why image dimensions cannot be decoded, especially for formats like
HEIC/HEIF. When the err returned from image.DecodeConfig is not nil, log this
error using the logger (h.Log) instead of silently ignoring it. This may require
refactoring the function to accept the logger as a parameter or converting the
logic to a method that has access to h.Log.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@pkg/connector/handlers/image.go`:
- Around line 180-198: The detectLineImageMimeType function silently falls back
to returning "image/jpeg" when the MIME type cannot be detected, which reduces
observability. Either add a logger parameter to the function and log when the
fallback to "image/jpeg" occurs (just before the final return statement), or
refactor the function to return both the MIME type string and a boolean flag
indicating whether a fallback was used, so the caller can log it. Choose the
approach that best fits your codebase's error handling patterns.
- Around line 172-175: The error returned from image.DecodeConfig is being
silently ignored, which prevents observability into why image dimensions cannot
be decoded, especially for formats like HEIC/HEIF. When the err returned from
image.DecodeConfig is not nil, log this error using the logger (h.Log) instead
of silently ignoring it. This may require refactoring the function to accept the
logger as a parameter or converting the logic to a method that has access to
h.Log.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1ce4ce9b-63a9-4f62-8088-d30b9a5537f1

📥 Commits

Reviewing files that changed from the base of the PR and between 593cd2d and 29c67c7.

📒 Files selected for processing (3)
  • .gitignore
  • pkg/connector/handlers/image.go
  • pkg/connector/handlers/image_test.go
💤 Files with no reviewable changes (1)
  • .gitignore
📜 Review details
🧰 Additional context used
📓 Path-based instructions (2)
**/*.go

📄 CodeRabbit inference engine (AGENTS.md)

**/*.go: Use go fmt for code formatting across all Go files
Use goimports with -local "github.com/highesttt/matrix-line-messenger" flag to group project-local imports correctly
Use zerolog for logging throughout the codebase
Do not use Msgf in logging; use Msg with structured fields instead
Use Stringer interface where applicable in Go code

Files:

  • pkg/connector/handlers/image.go
  • pkg/connector/handlers/image_test.go
**/!(ltsm)/**/*.go

📄 CodeRabbit inference engine (AGENTS.md)

**/!(ltsm)/**/*.go: Run staticcheck on all Go files excluding pkg/ltsm package (transpiled WASM code)
Run go vet on all Go files excluding pkg/ltsm package (transpiled WASM code)

Files:

  • pkg/connector/handlers/image.go
  • pkg/connector/handlers/image_test.go
🔇 Additional comments (10)
pkg/connector/handlers/image.go (6)

4-22: LGTM!


116-118: LGTM!


147-148: LGTM!


154-163: LGTM!


200-217: LGTM!


1-243: Verify compliance with coding guidelines — Unable to complete verification.

The review comment requests verification that this file passes staticcheck, go vet, and goimports checks as specified in the coding guidelines. The initial linting verification failed due to a network error and could not be completed.

However, from code inspection, the file does comply with zerolog usage requirements: all logging calls use .Msg() with structured fields (.Str(), .Bool(), .Dur(), .Err(), .Int()) and do not use .Msgf(). Stringer interface is not applicable to this file.

Complete verification of go vet, staticcheck, and goimports compliance requires running these tools directly.

pkg/connector/handlers/image_test.go (4)

15-78: LGTM!


80-98: LGTM!


100-128: LGTM!


1-129: Manual verification required: staticcheck, go vet, and goimports compliance.

Repository access is currently unavailable for automated verification. Please ensure this test file passes the following checks as required by the coding guidelines:

  • go vet ./pkg/connector/handlers/image_test.go
  • staticcheck ./pkg/connector/handlers/image_test.go
  • goimports -local "github.com/highesttt/matrix-line-messenger" -d ./pkg/connector/handlers/image_test.go

@Adri11334 Adri11334 marked this pull request as ready for review June 17, 2026 12:20
Copilot AI review requested due to automatic review settings June 17, 2026 12:20

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR improves Matrix image message conversion by detecting the actual image MIME type, generating an appropriate filename/extension, and attaching FileInfo (including dimensions when decodable), with new tests to validate the behavior.

Changes:

  • Add lineImageMediaInfo to detect MIME type, compute filename/extension, and populate event.FileInfo (size + optional dimensions).
  • Factor message content creation into lineImageEventContent to consistently attach Info and preserve relates_to.
  • Add Go tests for JPEG/PNG dimension extraction and HEIC/fallback MIME detection; update .gitignore to allow tracking _test.go files.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 4 comments.

File Description
pkg/connector/handlers/image.go Detect image MIME type/extension, attach FileInfo, refactor content creation.
pkg/connector/handlers/image_test.go Add table-driven tests for MIME/filename/dimension behavior and content wiring.
.gitignore Stop ignoring *_test.go so tests are committed.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/connector/handlers/image.go Outdated
Comment thread pkg/connector/handlers/image.go
Comment thread pkg/connector/handlers/image_test.go
Comment thread pkg/connector/handlers/image.go Outdated
@Adri11334 Adri11334 requested a review from Copilot June 17, 2026 12:59

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 3 changed files in this pull request and generated 3 comments.

Comment thread pkg/connector/handlers/image.go
Comment thread pkg/connector/handlers/image.go Outdated
Comment thread pkg/connector/handlers/image.go
@Adri11334 Adri11334 marked this pull request as draft June 17, 2026 13:08

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/connector/handlers/image_test.go`:
- Line 156: The test case for image/svg+xml in the test data lacks an explicit
switch case in the imageExtensionForMIME function, making it depend on the
system's MIME type database instead of having deterministic behavior like other
image types. Either add an explicit case statement in the imageExtensionForMIME
function to handle "image/svg+xml" and return "svg" for consistency with other
image types, or remove the test case from the test data if SVG support is not a
required feature. Choose the approach based on whether SVG image handling is
needed in your application.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 14c0bbbb-25c7-4927-9d73-8d4c4e0a61de

📥 Commits

Reviewing files that changed from the base of the PR and between 29c67c7 and 5950144.

📒 Files selected for processing (2)
  • pkg/connector/handlers/image.go
  • pkg/connector/handlers/image_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/connector/handlers/image.go
📜 Review details
🧰 Additional context used
📓 Path-based instructions (2)
**/*.go

📄 CodeRabbit inference engine (AGENTS.md)

**/*.go: Use go fmt for code formatting across all Go files
Use goimports with -local "github.com/highesttt/matrix-line-messenger" flag to group project-local imports correctly
Use zerolog for logging throughout the codebase
Do not use Msgf in logging; use Msg with structured fields instead
Use Stringer interface where applicable in Go code

Files:

  • pkg/connector/handlers/image_test.go
**/!(ltsm)/**/*.go

📄 CodeRabbit inference engine (AGENTS.md)

**/!(ltsm)/**/*.go: Run staticcheck on all Go files excluding pkg/ltsm package (transpiled WASM code)
Run go vet on all Go files excluding pkg/ltsm package (transpiled WASM code)

Files:

  • pkg/connector/handlers/image_test.go
🔇 Additional comments (1)
pkg/connector/handlers/image_test.go (1)

46-155: LGTM!

Also applies to: 157-217

Comment thread pkg/connector/handlers/image_test.go
@Adri11334 Adri11334 marked this pull request as ready for review June 17, 2026 14:55
@Adri11334 Adri11334 requested a review from Copilot June 17, 2026 14:59

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 3 changed files in this pull request and generated 3 comments.

Comment thread pkg/connector/handlers/image.go
Comment thread pkg/connector/handlers/image_test.go
Comment thread pkg/connector/handlers/image.go Outdated
@Adri11334 Adri11334 requested a review from Copilot June 17, 2026 15:11

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 3 changed files in this pull request and generated 4 comments.

Comment thread pkg/connector/handlers/image.go Outdated
Comment thread pkg/connector/handlers/image_test.go
Comment thread pkg/connector/handlers/image.go
Comment thread pkg/connector/handlers/image.go Outdated
@Adri11334 Adri11334 requested a review from Copilot June 17, 2026 15:20

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 3 changed files in this pull request and generated 3 comments.

Comment thread pkg/connector/handlers/image.go Outdated
Comment thread pkg/connector/handlers/image.go Outdated
Comment thread pkg/connector/handlers/image_test.go
@Adri11334 Adri11334 requested a review from Copilot June 17, 2026 15:34

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.

Comment thread pkg/connector/handlers/image.go Outdated
Comment thread pkg/connector/handlers/image_test.go
@highesttt

Copy link
Copy Markdown
Collaborator

@clins1994 this might fix your download issue on ios too?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

bug: 🐛 on ios can't save as image

3 participants