WIP
This commit is contained in:
parent
3db8e1da05
commit
d6f94287d4
@ -188,10 +188,13 @@ type UsernameTemplateArgs struct {
|
||||
|
||||
func (bc BridgeConfig) FormatDisplayname(gmid groupme.ID, member groupme.Member) string {
|
||||
var buf strings.Builder
|
||||
_ = bc.displaynameTemplate.Execute(&buf, map[string]string{
|
||||
err := bc.displaynameTemplate.Execute(&buf, map[string]string{
|
||||
"Name": member.Nickname,
|
||||
"GMID": gmid.String(),
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,11 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"go.mau.fi/util/random"
|
||||
"strings"
|
||||
|
||||
up "go.mau.fi/util/configupgrade"
|
||||
"maunium.net/go/mautrix/bridge/bridgeconfig"
|
||||
"maunium.net/go/mautrix/util"
|
||||
up "maunium.net/go/mautrix/util/configupgrade"
|
||||
)
|
||||
|
||||
func DoUpgrade(helper *up.Helper) {
|
||||
@ -103,7 +103,7 @@ func DoUpgrade(helper *up.Helper) {
|
||||
if secret, ok := helper.Get(up.Str, "appservice", "provisioning", "shared_secret"); ok && secret != "generate" {
|
||||
helper.Set(up.Str, secret, "bridge", "provisioning", "shared_secret")
|
||||
} else if secret, ok = helper.Get(up.Str, "bridge", "provisioning", "shared_secret"); !ok || secret == "generate" {
|
||||
sharedSecret := util.RandomString(64)
|
||||
sharedSecret := random.String(64)
|
||||
helper.Set(up.Str, sharedSecret, "bridge", "provisioning", "shared_secret")
|
||||
} else {
|
||||
helper.Copy(up.Str, "bridge", "provisioning", "shared_secret")
|
||||
|
@ -18,6 +18,7 @@ package database
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"go.mau.fi/util/dbutil"
|
||||
"net"
|
||||
|
||||
"github.com/lib/pq"
|
||||
@ -25,7 +26,6 @@ import (
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
|
||||
"maunium.net/go/maulogger/v2"
|
||||
"maunium.net/go/mautrix/util/dbutil"
|
||||
|
||||
"github.com/beeper/groupme/database/upgrades"
|
||||
)
|
||||
|
@ -19,11 +19,11 @@ package database
|
||||
import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"go.mau.fi/util/dbutil"
|
||||
"time"
|
||||
|
||||
log "maunium.net/go/maulogger/v2"
|
||||
"maunium.net/go/mautrix/id"
|
||||
"maunium.net/go/mautrix/util/dbutil"
|
||||
|
||||
"github.com/beeper/groupme-lib"
|
||||
)
|
||||
|
@ -19,12 +19,12 @@ package database
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"go.mau.fi/util/dbutil"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
log "maunium.net/go/maulogger/v2"
|
||||
"maunium.net/go/mautrix/id"
|
||||
"maunium.net/go/mautrix/util/dbutil"
|
||||
|
||||
"github.com/beeper/groupme-lib"
|
||||
)
|
||||
|
@ -18,11 +18,11 @@ package database
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"go.mau.fi/util/dbutil"
|
||||
|
||||
log "maunium.net/go/maulogger/v2"
|
||||
|
||||
"maunium.net/go/mautrix/id"
|
||||
"maunium.net/go/mautrix/util/dbutil"
|
||||
|
||||
"github.com/beeper/groupme-lib"
|
||||
)
|
||||
@ -151,8 +151,8 @@ func (puppet *Puppet) Update() {
|
||||
_, err := puppet.db.Exec(`
|
||||
UPDATE puppet
|
||||
SET displayname=$1, name_set=$2, avatar=$3, avatar_url=$4, avatar_set=$5, custom_mxid=$6,
|
||||
access_token=$7, next_batch=$8, enable_receipts=$10
|
||||
WHERE username=$11
|
||||
access_token=$7, next_batch=$8, enable_receipts=$9
|
||||
WHERE GMID=$10
|
||||
`, puppet.Displayname, puppet.NameSet, puppet.Avatar, puppet.AvatarURL.String(), puppet.AvatarSet,
|
||||
puppet.CustomMXID, puppet.AccessToken, puppet.NextBatch, puppet.EnableReceipts,
|
||||
puppet.GMID)
|
||||
|
@ -3,12 +3,11 @@ package database
|
||||
import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
|
||||
log "maunium.net/go/maulogger/v2"
|
||||
"maunium.net/go/mautrix/id"
|
||||
"maunium.net/go/mautrix/util/dbutil"
|
||||
"go.mau.fi/util/dbutil"
|
||||
|
||||
"github.com/beeper/groupme-lib"
|
||||
log "maunium.net/go/maulogger/v2"
|
||||
"maunium.net/go/mautrix/id"
|
||||
)
|
||||
|
||||
type ReactionQuery struct {
|
||||
|
@ -19,7 +19,7 @@ package upgrades
|
||||
import (
|
||||
"embed"
|
||||
|
||||
"maunium.net/go/mautrix/util/dbutil"
|
||||
"go.mau.fi/util/dbutil"
|
||||
)
|
||||
|
||||
var Table dbutil.UpgradeTable
|
||||
|
@ -18,16 +18,15 @@ package database
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"go.mau.fi/util/dbutil"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
log "maunium.net/go/maulogger/v2"
|
||||
|
||||
"maunium.net/go/mautrix/id"
|
||||
"maunium.net/go/mautrix/util/dbutil"
|
||||
|
||||
"github.com/beeper/groupme-lib"
|
||||
"maunium.net/go/mautrix/id"
|
||||
)
|
||||
|
||||
type UserQuery struct {
|
||||
|
@ -92,7 +92,7 @@ bridge:
|
||||
# {{call .UserID.String}} - the number GroupMe assigns to the user
|
||||
# {{.Nickname}} - the nickname in that room
|
||||
# {{.ImageURL}} - User's avatar URL is available but irrelevant here
|
||||
displayname_template: "{{if .Nickname}}{{.Nickname}}{{else}}{{call .UserID.String}}{{end}} (GM)"
|
||||
displayname_template: "{{if .Name}}{{.Name}}{{else}}{{.GMID}}{{end}} (GM)"
|
||||
# Should the bridge create a space for each logged-in user and add bridged rooms to it?
|
||||
# Users who logged in before turning this on should run `!wa sync space` to create and fill the space for the first time.
|
||||
personal_filtering_spaces: false
|
||||
|
@ -18,10 +18,10 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go.mau.fi/util/variationselector"
|
||||
|
||||
"maunium.net/go/mautrix/event"
|
||||
"maunium.net/go/mautrix/format"
|
||||
"maunium.net/go/mautrix/util/variationselector"
|
||||
)
|
||||
|
||||
const formatterContextAllowedMentionsKey = "com.beeper.groupme.allowed_mentions"
|
||||
|
5
go.mod
5
go.mod
@ -4,13 +4,14 @@ go 1.19
|
||||
|
||||
require (
|
||||
github.com/beeper/groupme-lib v0.2.1-0.20221021205945-8f23e04eea71
|
||||
//github.com/beeper/groupme-lib v0.2.1-0.20221021205945-8f23e04eea71 => "../groupme-lib"
|
||||
github.com/gabriel-vasile/mimetype v1.1.2
|
||||
github.com/karmanyaahm/wray v0.0.0-20210303233435-756d58657c14
|
||||
github.com/lib/pq v1.10.9
|
||||
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.15.0
|
||||
maunium.net/go/mautrix v0.16.0
|
||||
)
|
||||
|
||||
require (
|
||||
@ -35,8 +36,10 @@ 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
|
||||
golang.org/x/net v0.14.0 // indirect
|
||||
golang.org/x/sys v0.11.0 // indirect
|
||||
google.golang.org/protobuf v1.26.0-rc.1 // indirect
|
||||
|
6
go.sum
6
go.sum
@ -21,6 +21,7 @@ github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSV
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/densestvoid/groupme v0.2.0/go.mod h1:i+bzB18n8RntitrMbr65boSHU0HfjDcbEUEIPPAV+QU=
|
||||
github.com/gabriel-vasile/mimetype v1.1.2 h1:gaPnPcNor5aZSVCJVSGipcpbgMWiAAj9z182ocSGbHU=
|
||||
github.com/gabriel-vasile/mimetype v1.1.2/go.mod h1:6CDPel/o/3/s4+bp6kIbsWATq8pmgOisOPG40CJa6To=
|
||||
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
|
||||
@ -146,6 +147,8 @@ github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY=
|
||||
github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28=
|
||||
github.com/yuin/goldmark v1.5.5 h1:IJznPe8wOzfIKETmMkd06F8nXkmlhaHqFRM9l1hAGsU=
|
||||
github.com/yuin/goldmark v1.5.5/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
go.mau.fi/util v0.0.0-20230805171708-199bf3eec776 h1:VrxDCO/gLFHLQywGUsJzertrvt2mUEMrZPf4hEL/s18=
|
||||
go.mau.fi/util v0.0.0-20230805171708-199bf3eec776/go.mod h1:AxuJUMCxpzgJ5eV9JbPWKRH8aAJJidxetNdUj7qcb84=
|
||||
go.mau.fi/zeroconfig v0.1.2 h1:DKOydWnhPMn65GbXZOafgkPm11BvFashZWLct0dGFto=
|
||||
go.mau.fi/zeroconfig v0.1.2/go.mod h1:NcSJkf180JT+1IId76PcMuLTNa1CzsFFZ0nBygIQM70=
|
||||
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
@ -153,6 +156,8 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk=
|
||||
golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw=
|
||||
golang.org/x/exp v0.0.0-20230810033253-352e893a4cad h1:g0bG7Z4uG+OgH2QDODnjp6ggkk1bJDsINcuWmJN1iJU=
|
||||
golang.org/x/exp v0.0.0-20230810033253-352e893a4cad/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
|
||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
@ -216,4 +221,5 @@ maunium.net/go/maulogger/v2 v2.4.1 h1:N7zSdd0mZkB2m2JtFUsiGTQQAdP0YeFWT7YMc80yAL
|
||||
maunium.net/go/maulogger/v2 v2.4.1/go.mod h1:omPuYwYBILeVQobz8uO3XC8DIRuEb5rXYlQSuqrbCho=
|
||||
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=
|
||||
|
5
main.go
5
main.go
@ -18,6 +18,8 @@ package main
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"github.com/beeper/groupme-lib"
|
||||
"go.mau.fi/util/configupgrade"
|
||||
"sync"
|
||||
|
||||
"maunium.net/go/mautrix"
|
||||
@ -25,9 +27,6 @@ import (
|
||||
"maunium.net/go/mautrix/bridge/commands"
|
||||
"maunium.net/go/mautrix/bridge/status"
|
||||
"maunium.net/go/mautrix/id"
|
||||
"maunium.net/go/mautrix/util/configupgrade"
|
||||
|
||||
"github.com/beeper/groupme-lib"
|
||||
|
||||
"github.com/beeper/groupme/config"
|
||||
"github.com/beeper/groupme/database"
|
||||
|
@ -336,7 +336,7 @@ func (portal *Portal) finishHandling(source *User, message *groupme.Message, mxi
|
||||
portal.log.Debugln("Handled message", message.ID.String(), "->", mxid)
|
||||
}
|
||||
|
||||
func (portal *Portal) SyncParticipants(metadata *groupme.Group) {
|
||||
func (portal *Portal) SyncParticipants(group *groupme.Group) {
|
||||
changed := false
|
||||
levels, err := portal.MainIntent().PowerLevels(portal.MXID)
|
||||
if err != nil {
|
||||
@ -344,7 +344,7 @@ func (portal *Portal) SyncParticipants(metadata *groupme.Group) {
|
||||
changed = true
|
||||
}
|
||||
participantMap := make(map[groupme.ID]bool)
|
||||
for _, participant := range metadata.Members {
|
||||
for _, participant := range group.Members {
|
||||
participantMap[participant.UserID] = true
|
||||
user := portal.bridge.GetUserByGMID(participant.UserID)
|
||||
portal.userMXIDAction(user, portal.ensureMXIDInvited)
|
||||
@ -558,7 +558,7 @@ func (portal *Portal) Sync(user *User, group *groupme.Group) {
|
||||
if portal.IsPrivateChat() {
|
||||
sub = user.Conn.SubscribeToDM
|
||||
}
|
||||
err := sub(context.TODO(), portal.Key.Receiver, user.Token)
|
||||
err := sub(context.TODO(), portal.Key.GMID, user.Token)
|
||||
if err != nil {
|
||||
portal.log.Errorln("Subscribing failed, live metadata updates won't work", err)
|
||||
}
|
||||
@ -750,7 +750,7 @@ func (portal *Portal) CreateMatrixRoom(user *User) error {
|
||||
portal.Topic = "GroupMe private chat"
|
||||
} else {
|
||||
var err error
|
||||
metadata, err = user.Client.ShowGroup(context.TODO(), groupme.ID(portal.Key.GMID))
|
||||
metadata, err = user.Client.ShowGroup(context.TODO(), portal.Key.GMID)
|
||||
if err == nil {
|
||||
portal.Name = metadata.Name
|
||||
portal.Topic = metadata.Description
|
||||
|
@ -295,7 +295,7 @@ func (puppet *Puppet) updatePortalName() {
|
||||
})
|
||||
}
|
||||
|
||||
func (puppet *Puppet) Sync(source *User, member *groupme.Member, forceAvatarSync, forcePortalSync bool) {
|
||||
func (puppet *Puppet) Sync(source *User, member *groupme.Member, forceAvatarSync bool, forcePortalSync bool) {
|
||||
puppet.syncLock.Lock()
|
||||
defer puppet.syncLock.Unlock()
|
||||
err := puppet.DefaultIntent().EnsureRegistered()
|
||||
@ -303,6 +303,13 @@ func (puppet *Puppet) Sync(source *User, member *groupme.Member, forceAvatarSync
|
||||
puppet.log.Errorln("Failed to ensure registered:", err)
|
||||
}
|
||||
|
||||
update := false
|
||||
update = puppet.UpdateName(*member, forcePortalSync) || update
|
||||
update = puppet.UpdateAvatar(source, forcePortalSync) || update
|
||||
if update {
|
||||
puppet.Update()
|
||||
}
|
||||
|
||||
//puppet.log.Debugfln("Syncing info through %s", source.GMID)
|
||||
|
||||
// TODO
|
||||
|
18
user.go
18
user.go
@ -359,7 +359,7 @@ func (user *User) Connect() bool {
|
||||
|
||||
func (user *User) RestoreSession() bool {
|
||||
if len(user.Token) > 0 {
|
||||
err := user.Conn.SubscribeToUser(context.TODO(), groupme.ID(user.GMID), user.Token)
|
||||
err := user.Conn.SubscribeToUser(context.TODO(), user.GMID, user.Token)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
@ -616,7 +616,7 @@ func (user *User) syncPortals(createAll bool) {
|
||||
})
|
||||
}
|
||||
for _, dm := range user.ChatList {
|
||||
portal := user.bridge.GetPortalByGMID(database.NewPortalKey(dm.OtherUser.ID, user.GMID))
|
||||
portal := user.bridge.GetPortalByGMID(database.NewPortalKey(dm.LastMessage.ConversationID, user.GMID))
|
||||
chats = append(chats, Chat{
|
||||
Portal: portal,
|
||||
LastMessageTime: uint64(dm.UpdatedAt.ToTime().Unix()),
|
||||
@ -624,7 +624,7 @@ func (user *User) syncPortals(createAll bool) {
|
||||
})
|
||||
}
|
||||
|
||||
for _, chat := range chats {
|
||||
//for _, chat := range chats {
|
||||
//var inSpace, ok bool
|
||||
//if inSpace, ok = existingKeys[chat.Portal.Key]; !ok || !inCommunity {
|
||||
// inCommunity = user.addPortalToCommunity(chat.Portal)
|
||||
@ -633,16 +633,16 @@ func (user *User) syncPortals(createAll bool) {
|
||||
// user.ad.addPuppetToCommunity(puppet)
|
||||
// }
|
||||
//}
|
||||
portalKeys = append(portalKeys, chat.Portal.Key)
|
||||
}
|
||||
user.log.Infoln("Read chat list, updating user-portal mapping")
|
||||
//portalKeys = append(portalKeys, chat.Portal.Key)
|
||||
//}
|
||||
//user.log.Infoln("Read chat list, updating user-portal mapping")
|
||||
|
||||
err := user.SetPortalKeys(portalKeys) //user.SetPortalKeys(portalKeys)
|
||||
err := user.SetPortalKeys(portalKeys)
|
||||
if err != nil {
|
||||
user.log.Warnln("Failed to update user-portal mapping:", err)
|
||||
}
|
||||
sort.Sort(chats)
|
||||
limit := user.bridge.Config.Bridge.HistorySync.MaxInitialConversations
|
||||
limit := 5 //user.bridge.Config.Bridge.HistorySync.MaxInitialConversations
|
||||
if limit < 0 {
|
||||
limit = len(chats)
|
||||
}
|
||||
@ -774,7 +774,7 @@ func (user *User) handleMessageLoop() {
|
||||
puppet := user.bridge.GetPuppetByGMID(msg.data.UserID)
|
||||
portal := user.bridge.GetPortalByGMID(msg.chat)
|
||||
if puppet != nil {
|
||||
puppet.Sync(user, &groupme.Member{
|
||||
puppet.Sync(nil, &groupme.Member{
|
||||
UserID: msg.data.UserID,
|
||||
Nickname: msg.data.Name,
|
||||
ImageURL: msg.data.AvatarURL,
|
||||
|
Loading…
Reference in New Issue
Block a user