Skip to content

fix: Voluntary leaves now render as "left the group" instead of Kicked#223

Merged
highesttt merged 3 commits into
mainfrom
highest/plat-38138
Jul 24, 2026
Merged

fix: Voluntary leaves now render as "left the group" instead of Kicked#223
highesttt merged 3 commits into
mainfrom
highest/plat-38138

Conversation

@highesttt

Copy link
Copy Markdown
Collaborator

No description provided.

@indent-zero

indent-zero Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor
PR Summary

Fixes voluntary group leaves being rendered as bot-issued kicks on Matrix by attributing the outgoing ChatInfoChange to the departing member so mautrix produces sender == state_key and clients show "left the group". Splits the previously merged LINE leave/remove paths so removals still render as kicks.

  • Introduces handleMemberLeft, handleMemberLeaveWithSender, and emitMemberChangeWithSender, and extracts a pure makeMemberChangeEvent helper.
  • Routes OpNotifiedLeaveChat (op 61) and system messages C_ML/A_ML through the new voluntary-leave path with the leaver as the change sender.
  • Splits C_MR/A_MR from C_ML/A_ML in handleSystemMessage, keeps the empty-sender (kick) semantics for removals, and renames the log field leaver_midremoved_mid.
  • Adds a sync_test.go unit test covering makeMemberChangeEvent's propagation of the change sender, timestamp, and member entry.

Issues

All clear! No issues remaining. 🎉

2 issues already resolved
  • Self-leave cache-cleanup logic is duplicated between handleSelfLeave (sync.go:2355) and the self branch of handleMemberLeaveWithSender (sync.go:2375-2381) — future changes to self-leave state will silently miss one of the two callers. (fixed by commit 6cd2056)
  • Self-initiated leaves via OpDeleteSelfFromChat (op 127) and OpSendChatRemoved still route through handleSelfLeave, which emits with an empty EventMeta.Sender and therefore still renders as a bot-issued kick — the fix only covers OpNotifiedLeaveChat and C_ML/A_ML, so a bridge-user-initiated leave still shows as "Kicked" on Matrix. (fixed by commit 6cd2056)

CI Checks

All CI checks pass on 6cd2056.

@linear-code

linear-code Bot commented Jul 24, 2026

Copy link
Copy Markdown

PLAT-38138

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8ae6650e-851d-4652-aa72-9c3c8229c7b0

📥 Commits

Reviewing files that changed from the base of the PR and between 8f9b591 and 6cd2056.

📒 Files selected for processing (1)
  • pkg/connector/sync.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/connector/sync.go
📜 Recent review details
⏰ Context from checks skipped due to timeout. (4)
  • GitHub Check: build-docker
  • GitHub Check: Lint with 1.25
  • GitHub Check: Lint with 1.25
  • GitHub Check: build-docker

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Improved Matrix membership-leave event handling to preserve correct sender metadata for both voluntary departures and forced removals.
    • Updated group membership removal processing so membership-leave change events emit with the appropriate sender context.
  • Tests
    • Added unit coverage to confirm membership-leave events preserve the intended “change sender” behavior, including correct member sender and membership values for leave vs. removal scenarios.

Walkthrough

Membership-leave handling now propagates an explicit change sender through Matrix and LINE connector paths. Event construction preserves sender metadata, leave handlers use sender-aware helpers, and tests cover voluntary leaves and removals.

Changes

Membership change sender propagation

Layer / File(s) Summary
Sender-aware event pipeline
pkg/connector/sync.go, pkg/connector/sync_test.go
Member-change helpers accept an explicit change sender, leave handling emits sender-aware events, and regression tests verify sender metadata for voluntary leaves and removals.
Leave event wiring
pkg/connector/sync.go
LINE leave notifications normalize chat and leaver identifiers before invoking sender-aware handling; C_ML/A_ML messages use sender-aware emission, while C_MR/A_MR retain distinct logging and cache-removal behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant LINE
  participant LeaveHandler
  participant MemberChangeEmitter
  LINE->>LeaveHandler: notify member leave
  LeaveHandler->>MemberChangeEmitter: emit leave with leaver sender
  MemberChangeEmitter-->>LINE: produce membership-leave ChatInfoChange
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive No pull request description was provided, so the check cannot assess meaningful alignment beyond its absence. Add a brief PR description summarizing the behavior change and why it was needed.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: voluntary leaves now render as "left the group" instead of "Kicked".
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch highest/plat-38138

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

@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 (1)
pkg/connector/sync.go (1)

2341-2350: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Replace deprecated Members with MemberMap.
pkg/connector/sync.go#L2341-L2350 should build the member list with MemberMap, and pkg/connector/sync_test.go#L57-L60 should assert the entry for member.Sender instead of indexing Members.

🤖 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/sync.go` around lines 2341 - 2350, The member-list construction
in pkg/connector/sync.go lines 2341-2350 must replace deprecated Members with
MemberMap, keyed by member.Sender while preserving the existing ChatMember value
and fields. Update the corresponding assertion in pkg/connector/sync_test.go
lines 57-60 to inspect the MemberMap entry for member.Sender instead of indexing
Members.

Sources: Coding guidelines, Linters/SAST tools

🤖 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/sync.go`:
- Around line 2341-2350: The member-list construction in pkg/connector/sync.go
lines 2341-2350 must replace deprecated Members with MemberMap, keyed by
member.Sender while preserving the existing ChatMember value and fields. Update
the corresponding assertion in pkg/connector/sync_test.go lines 57-60 to inspect
the MemberMap entry for member.Sender instead of indexing Members.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7838cd1b-98fa-4295-b2b6-2c653db45521

📥 Commits

Reviewing files that changed from the base of the PR and between 52c22da and a9d8902.

📒 Files selected for processing (2)
  • pkg/connector/sync.go
  • pkg/connector/sync_test.go
📜 Review details
⏰ Context from checks skipped due to timeout. (2)
  • GitHub Check: build-docker
  • GitHub Check: Lint with 1.25
🧰 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/sync_test.go
  • pkg/connector/sync.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/sync_test.go
  • pkg/connector/sync.go
🪛 GitHub Actions: CI / 3_Lint with 1.25.txt
pkg/connector/sync_test.go

[error] 57-57: staticcheck (go-staticcheck) failed with exit code 1. SA1019: evt.ChatInfoChange.MemberChanges.Members is deprecated: Use MemberMap instead to avoid duplicate entries.

🪛 GitHub Actions: CI / Lint with 1.25
pkg/connector/sync_test.go

[error] 57-57: staticcheck (go-staticcheck) failed: SA1019: evt.ChatInfoChange.MemberChanges.Members is deprecated. Use MemberMap instead to avoid duplicate entries.

🪛 GitHub Check: Lint with 1.25
pkg/connector/sync_test.go

[failure] 57-57:
evt.ChatInfoChange.MemberChanges.Members is deprecated: Use MemberMap instead to avoid duplicate entries (SA1019)

🔇 Additional comments (4)
pkg/connector/sync.go (3)

1863-1865: LGTM!


2363-2383: LGTM!


2507-2519: LGTM!

pkg/connector/sync_test.go (1)

13-17: LGTM!

@clins1994

Copy link
Copy Markdown
Contributor

@highesttt beast 🤝

Comment thread pkg/connector/sync.go Outdated
@highesttt
highesttt merged commit 6329262 into main Jul 24, 2026
10 checks passed
@highesttt
highesttt deleted the highest/plat-38138 branch July 24, 2026 20:22
@indent

indent Bot commented Jul 24, 2026

Copy link
Copy Markdown
PR Summary

Generating summary...

Issues

Review closed.

CI Checks

1 CI check failed on a9d8902.

Failing Lint with 1.25
  • Lint with 1.25 finished with failure.

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.

2 participants