Skip to content

Add initial draft - #1

Merged
hloeung merged 2 commits into
matterbridge:masterfrom
hloeung:master
Oct 11, 2026
Merged

hloeung merged 2 commits into
matterbridge:masterfrom
hloeung:master

Conversation

@hloeung

@hloeung hloeung commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

No description provided.

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.

🟡 Changes recommended

Direct-room state handling and callback concurrency currently produce incorrect and potentially racy behavior.

6 open findings
What changed in this PR

Introduces the initial Matrix client library for matterircd/matterbridge.

Changes:

  • Adds login, synchronization, room/user tracking, and messaging.
  • Defines event handlers and public data types.
  • Adds dependencies, licensing, lint configuration, and CI.
File Description
client.go Implements the Matrix client API and sync lifecycle.
handlers.go Processes room state, messages, reactions, and direct chats.
types.go Defines credentials, entities, and handler interfaces.
go.mod Declares the module and dependencies.
go.sum Locks dependency checksums.
.golangci.yaml Configures Go linting and formatting.
.github/​workflows/​development.yml Runs lint checks in CI.
LICENSE Adds the Apache 2.0 license.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread client.go
c.register(syncer)

go c.syncLoop()
go c.waitReady()
Comment thread client.go
Comment on lines +291 to +293
c.Lock()
c.dmChannels[roomID] = []id.UserID{userID}
c.Unlock()
Comment thread handlers.go
Comment on lines +47 to +49
for userID, rooms := range *chats {
for _, roomID := range rooms {
c.addDirectLocked(roomID, userID, &event.MemberEventContent{})
Comment thread handlers.go

for userID, rooms := range *chats {
for _, roomID := range rooms {
c.addDirectLocked(roomID, userID, &event.MemberEventContent{})
Comment thread handlers.go
c.Lock()
defer c.Unlock()

u, ok := c.users[targetID]
Comment thread handlers.go
ch := c.channelLocked(ev.RoomID)

ch.Lock()
ch.Alias, ch.AltAliases = alias.Alias, alias.AltAliases
@hloeung

hloeung commented Oct 11, 2026

Copy link
Copy Markdown
Contributor Author

Follow up PR addressing the issues identifed by Copilot - #2

@hloeung
hloeung merged commit 64d3f67 into matterbridge:master Oct 11, 2026
hloeung added a commit that referenced this pull request Oct 11, 2026
…ient (#2)

Addresses the six Copilot review comments on the initial draft (#1) and
makes logging consistent with `matterclient`, using logrus with the
`matterbridge/logrus-prefixed-formatter`.

- **Ready / handler serialization**
- `Ready` is no longer fired from a separate timer goroutine. A
`readySyncer` wrapper around `DefaultSyncer` calls it once, on the sync
goroutine, after the first sync response has been fully processed.
- This keeps `Ready`, `OnMessage` and `OnReaction` serialized as the
`Handler` contract says.

- **Direct rooms**
- `SendDirect` now persists the updated `m.direct` account data via
`SetAccountData`. Previously the new room existed only in memory, so a
relogin could create a duplicate.
- If persisting fails, the error is logged and the message is still
sent. Returning the error would invite a retry that creates another
room.
- `handleDM` treats `m.direct` as a full snapshot. It rebuilds
`dmChannels` and clears `IsDirect` on rooms that were removed.
- Registering a direct room no longer overwrites a cached member
profile, so `DisplayName` doesn't regress to empty.

- **Rooms**
- Membership events now create the `Channel` and maintain its `Members`,
so unnamed joined rooms show up in `Rooms()`.
- `Channel` gets a separate `Name` field. `Rooms()` resolves the alias
first, then the name, then the room ID. Clearing the canonical alias no
longer discards the room name.

- **Logging**
- `New` builds two logrus loggers with the prefixed formatter, as
matterclient does:
    - `matrixclient` with padding 13.
    - `matrixclient: API` with padding 18, at error level.
  - Sync errors go through the API logger.
  - The formatter dependency is added to `go.mod` and `go.sum`.
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