diff --git a/config/bridge.go b/config/bridge.go index ee92a28..a2d5dfd 100644 --- a/config/bridge.go +++ b/config/bridge.go @@ -104,6 +104,11 @@ type BridgeConfig struct { displaynameTemplate *template.Template `yaml:"-"` } +func (bc BridgeConfig) GetDoublePuppetConfig() bridgeconfig.DoublePuppetConfig { + //TODO implement me + panic("implement me") +} + func (bc BridgeConfig) GetEncryptionConfig() bridgeconfig.EncryptionConfig { return bc.Encryption } diff --git a/go.mod b/go.mod index fb0eca8..ed02605 100644 --- a/go.mod +++ b/go.mod @@ -11,9 +11,11 @@ require ( github.com/mattn/go-sqlite3 v1.14.17 github.com/prometheus/client_golang v1.11.1 maunium.net/go/maulogger/v2 v2.4.1 - maunium.net/go/mautrix v0.16.0 + maunium.net/go/mautrix v0.16.1-0.20230821105106-ac5c2c22102c ) +require go.mau.fi/util v0.0.0-20230805171708-199bf3eec776 + require ( github.com/beorn7/perks v1.0.1 // indirect github.com/cespare/xxhash/v2 v2.1.1 // indirect @@ -36,7 +38,6 @@ require ( github.com/tidwall/pretty v1.2.0 // indirect github.com/tidwall/sjson v1.2.5 // indirect github.com/yuin/goldmark v1.5.5 // indirect - go.mau.fi/util v0.0.0-20230805171708-199bf3eec776 // indirect go.mau.fi/zeroconfig v0.1.2 // indirect golang.org/x/crypto v0.12.0 // indirect golang.org/x/exp v0.0.0-20230810033253-352e893a4cad // indirect diff --git a/go.sum b/go.sum index 3f02186..9ef4575 100644 --- a/go.sum +++ b/go.sum @@ -223,3 +223,5 @@ maunium.net/go/mautrix v0.15.0 h1:gkK9HXc1SSPwY7qOAqchzj2xxYqiOYeee8lr28A2g/o= maunium.net/go/mautrix v0.15.0/go.mod h1:1v8QVDd7q/eJ+eg4sgeOSEafBAFhkt4ab2i97M3IkNQ= maunium.net/go/mautrix v0.16.0 h1:iUqCzJE2yqBC1ddAK6eAn159My8rLb4X8g4SFtQh2Dk= maunium.net/go/mautrix v0.16.0/go.mod h1:XAjE9pTSGcr6vXaiNgQGiip7tddJ8FQV1a29u2QdBG4= +maunium.net/go/mautrix v0.16.1-0.20230821105106-ac5c2c22102c h1:oRIaFbS4ds9biwJVguT+9Zu7n5zDbKQeuGklXHQxvCU= +maunium.net/go/mautrix v0.16.1-0.20230821105106-ac5c2c22102c/go.mod h1:XAjE9pTSGcr6vXaiNgQGiip7tddJ8FQV1a29u2QdBG4= diff --git a/main.go b/main.go index 3e7262e..b855623 100644 --- a/main.go +++ b/main.go @@ -22,6 +22,7 @@ import ( "github.com/beeper/groupme-lib" "go.mau.fi/util/configupgrade" "maunium.net/go/mautrix/bridge/bridgeconfig" + "maunium.net/go/mautrix/event" "regexp" "sync" @@ -70,6 +71,12 @@ type GMBridge struct { puppetsLock sync.Mutex } +var ( + TypeMSC3381PollStart = event.Type{Class: event.MessageEventType, Type: "org.matrix.msc3381.poll.start"} + TypeMSC3381PollResponse = event.Type{Class: event.MessageEventType, Type: "org.matrix.msc3381.poll.response"} + TypeMSC3381V2PollResponse = event.Type{Class: event.MessageEventType, Type: "org.matrix.msc3381.v2.poll.response"} +) + func (br *GMBridge) Init() { br.CommandProcessor = commands.NewProcessor(&br.Bridge) br.RegisterCommands() @@ -476,7 +483,8 @@ func (bridge *GMBridge) NewPortal(dbPortal *database.Portal) *Portal { recentlyHandled: make([]string, recentlyHandledLength), - messages: make(chan PortalMessage, bridge.Config.Bridge.PortalMessageBuffer), + messages: make(chan PortalMessage, bridge.Config.Bridge.PortalMessageBuffer), + matrixMessages: make(chan PortalMatrixMessage, bridge.Config.Bridge.PortalMessageBuffer), } go portal.handleMessageLoop() return portal diff --git a/portal.go b/portal.go index 603f967..57905d9 100644 --- a/portal.go +++ b/portal.go @@ -611,23 +611,32 @@ func (portal *Portal) HandleMatrixInvite(sender *User, evt *event.Event) { } func (portal *Portal) handleMessageLoop() { - for msg := range portal.messages { - if len(portal.MXID) == 0 { - if msg.timestamp+MaxMessageAgeToCreatePortal < uint64(time.Now().Unix()) { - portal.log.Debugln("Not creating portal room for incoming message: message is too old") - continue - } - portal.log.Debugln("Creating Matrix room from incoming message") - err := portal.createMatrixRoom(msg.source) - if err != nil { - portal.log.Errorln("Failed to create portal room:", err) - continue - } + for { + select { + case msg := <-portal.messages: + portal.handleMessageLoopItem(msg) + case msg := <-portal.matrixMessages: + portal.HandleMatrixMessage(msg.user, msg.evt) } - portal.handleMessage(msg) } } +func (portal *Portal) handleMessageLoopItem(msg PortalMessage) { + if len(portal.MXID) == 0 { + if msg.timestamp+MaxMessageAgeToCreatePortal < uint64(time.Now().Unix()) { + portal.log.Debugln("Not creating portal room for incoming message: message is too old") + return + } + portal.log.Debugln("Creating Matrix room from incoming message") + err := portal.createMatrixRoom(msg.source) + if err != nil { + portal.log.Errorln("Failed to create portal room:", err) + return + } + } + portal.handleMessage(msg) +} + func (portal *Portal) handleMessage(msg PortalMessage) { if len(portal.MXID) == 0 { portal.log.Warnln("handleMessage called even though portal.MXID is empty") diff --git a/puppet.go b/puppet.go index 8fb3998..4907561 100644 --- a/puppet.go +++ b/puppet.go @@ -50,6 +50,11 @@ type Puppet struct { syncLock sync.Mutex } +func (puppet *Puppet) ClearCustomMXID() { + //TODO implement me + panic("implement me") +} + // Public Properties func (puppet *Puppet) GetMXID() id.UserID { diff --git a/user.go b/user.go index 8d06d17..ae6c4cf 100644 --- a/user.go +++ b/user.go @@ -716,8 +716,6 @@ func (user *User) syncPortals(createAll bool) { } for _, dm := range user.ChatList { portal := user.bridge.GetPortalByGMID(database.NewPortalKey(dm.OtherUser.ID, user.GMID)) - portal.Name = dm.OtherUser.Name - portal.NameSet = true chats = append(chats, Chat{ Portal: portal,