Successful two way communication in direct chats

This commit is contained in:
Brandon Watson 2023-09-11 16:44:58 -05:00
parent 2074d45d9d
commit 22a9faa3ca
7 changed files with 46 additions and 18 deletions

View File

@ -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
}

5
go.mod
View File

@ -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

2
go.sum
View File

@ -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=

10
main.go
View File

@ -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

View File

@ -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")

View File

@ -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 {

View File

@ -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,