Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EXPERIMENTAL Matrix support #576

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
949 changes: 949 additions & 0 deletions bridge/matrix/matrix.go

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions bridge/matrix/room.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package matrix

import (
"sync"

"maunium.net/go/mautrix/event"
"maunium.net/go/mautrix/id"
)

type User struct {
ID id.UserID
*event.MemberEventContent
}

type Channel struct {
ID id.RoomID
Alias id.RoomAlias
AltAliases []id.RoomAlias
Members map[id.UserID]*User
IsDirect bool
Encrypted bool
Topic string
sync.RWMutex
}
65 changes: 65 additions & 0 deletions bridge/matrix/sync.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package matrix

import (
"fmt"
"time"

"maunium.net/go/mautrix"
"maunium.net/go/mautrix/event"
"maunium.net/go/mautrix/id"

"github.com/davecgh/go-spew/spew"
)

type Syncer struct {
m *Matrix
}

func NewSyncer(m *Matrix) *Syncer {
return &Syncer{
m: m,
}
}

func (s *Syncer) ProcessResponse(resp *mautrix.RespSync, since string) error {
for room, sync := range resp.Rooms.Join {
fmt.Println(room)

for _, ev := range append(append(
append(sync.State.Events, sync.Timeline.Events...),
sync.Ephemeral.Events...),
sync.AccountData.Events...) {
ev.Content.ParseRaw(ev.Type) //nolint:errcheck
ev.RoomID = room
spew.Dump(ev)

switch ev.Type {
case event.StateCanonicalAlias:
s.m.handleCanonicalAlias(mautrix.EventSourceState, ev)
case event.StateRoomName:
s.m.handleRoomName(mautrix.EventSourceState, ev)
case event.StateMember:
s.m.handleMember(mautrix.EventSourceState, ev)
case event.AccountDataDirectChats:
s.m.handleDM(mautrix.EventSourceAccountData, ev)
}
}
return nil
}

return nil
}

func (s *Syncer) OnFailedSync(res *mautrix.RespSync, err error) (time.Duration, error) {
return 10 * time.Second, nil
}

func (s *Syncer) GetFilterJSON(userID id.UserID) *mautrix.Filter {
return &mautrix.Filter{
Room: mautrix.RoomFilter{
Timeline: mautrix.FilterPart{
Limit: 50,
},
},
}
}
30 changes: 20 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
module github.com/42wim/matterircd

require (
github.com/alecthomas/chroma/v2 v2.9.1
github.com/42wim/matterbridge v1.26.0
github.com/alecthomas/chroma/v2 v2.12.0
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f
github.com/google/gops v0.3.27
Expand All @@ -20,30 +21,37 @@ require (
github.com/spf13/viper v1.17.0
github.com/stretchr/testify v1.8.4
go.etcd.io/bbolt v1.3.7
maunium.net/go/mautrix v0.8.0
)

require (
github.com/Benau/go_rlottie v0.0.0-20210807002906-98c1b2421989 // indirect
github.com/Benau/tgsconverter v0.0.0-20210809170556-99f4a4f6337f // indirect
github.com/av-elier/go-decimal-to-rational v0.0.0-20191127152832-89e6aad02ecf // indirect
github.com/blang/semver v3.5.1+incompatible // indirect
github.com/btcsuite/btcutil v1.0.2 // indirect
github.com/dlclark/regexp2 v1.10.0 // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/dyatlov/go-opengraph v0.0.0-20210112100619-dae8665a5b09 // indirect
github.com/francoispqt/gojay v1.2.13 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-asn1-ber/asn1-ber v1.5.3 // indirect
github.com/gomarkdown/markdown v0.0.0-20221013030248-663e2500819c // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/graph-gophers/graphql-go v1.3.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/jpillora/backoff v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kettek/apng v0.0.0-20191108220231-414630eed80f // indirect
github.com/klauspost/compress v1.17.0 // indirect
github.com/klauspost/cpuid/v2 v2.0.12 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattermost/go-i18n v1.11.1-0.20211013152124-5c415071e404 // indirect
github.com/mattermost/ldap v0.0.0-20201202150706-ee0e6284187d // indirect
github.com/mattermost/logr/v2 v2.0.15 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/minio/md5-simd v1.1.2 // indirect
Expand All @@ -60,9 +68,10 @@ require (
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/rs/xid v1.4.0 // indirect
github.com/rs/xid v1.5.0 // indirect
github.com/sagikazarmark/locafero v0.3.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sizeofint/webpanimation v0.0.0-20210809145948-1d2b32119882 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.10.0 // indirect
github.com/spf13/cast v1.5.1 // indirect
Expand All @@ -75,14 +84,15 @@ require (
github.com/wiggin77/srslog v1.0.1 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/crypto v0.13.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/term v0.12.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3 // indirect
golang.org/x/image v0.3.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/term v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Expand Down
Loading
Loading