Update mautrix-go to move stuff to util

This commit is contained in:
Tulir Asokan 2023-08-05 18:59:17 +03:00
parent e07ed17ccd
commit 45e5290f0c
19 changed files with 53 additions and 58 deletions

View File

@ -19,9 +19,9 @@ package config
import (
"strings"
up "go.mau.fi/util/configupgrade"
"go.mau.fi/util/random"
"maunium.net/go/mautrix/bridge/bridgeconfig"
"maunium.net/go/mautrix/util"
up "maunium.net/go/mautrix/util/configupgrade"
)
func DoUpgrade(helper *up.Helper) {
@ -163,7 +163,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")

View File

@ -25,10 +25,10 @@ import (
"sync"
"time"
"go.mau.fi/util/dbutil"
log "maunium.net/go/maulogger/v2"
"maunium.net/go/mautrix/id"
"maunium.net/go/mautrix/util/dbutil"
)
type BackfillType int

View File

@ -23,10 +23,10 @@ import (
"github.com/lib/pq"
_ "github.com/mattn/go-sqlite3"
"go.mau.fi/util/dbutil"
"go.mau.fi/whatsmeow/store"
"go.mau.fi/whatsmeow/store/sqlstore"
"maunium.net/go/maulogger/v2"
"maunium.net/go/mautrix/util/dbutil"
"maunium.net/go/mautrix-whatsapp/database/upgrades"
)

View File

@ -21,10 +21,10 @@ import (
"errors"
"time"
"go.mau.fi/util/dbutil"
log "maunium.net/go/maulogger/v2"
"maunium.net/go/mautrix/id"
"maunium.net/go/mautrix/util/dbutil"
)
type DisappearingMessageQuery struct {

View File

@ -22,15 +22,13 @@ import (
"fmt"
"time"
"google.golang.org/protobuf/proto"
waProto "go.mau.fi/whatsmeow/binary/proto"
_ "github.com/mattn/go-sqlite3"
"go.mau.fi/util/dbutil"
waProto "go.mau.fi/whatsmeow/binary/proto"
"google.golang.org/protobuf/proto"
log "maunium.net/go/maulogger/v2"
"maunium.net/go/mautrix/id"
"maunium.net/go/mautrix/util/dbutil"
)
type HistorySyncQuery struct {

View File

@ -21,10 +21,10 @@ import (
"errors"
_ "github.com/mattn/go-sqlite3"
"go.mau.fi/util/dbutil"
log "maunium.net/go/maulogger/v2"
"maunium.net/go/mautrix/id"
"maunium.net/go/mautrix/util/dbutil"
)
type MediaBackfillRequestStatus int

View File

@ -22,12 +22,11 @@ import (
"strings"
"time"
"go.mau.fi/util/dbutil"
"go.mau.fi/whatsmeow/types"
log "maunium.net/go/maulogger/v2"
"maunium.net/go/mautrix/id"
"maunium.net/go/mautrix/util/dbutil"
"go.mau.fi/whatsmeow/types"
)
type MessageQuery struct {

View File

@ -21,7 +21,7 @@ import (
"strings"
"github.com/lib/pq"
"maunium.net/go/mautrix/util/dbutil"
"go.mau.fi/util/dbutil"
)
func scanPollOptionMapping(rows dbutil.Rows) (id string, hashArr [32]byte, err error) {

View File

@ -21,12 +21,11 @@ import (
"fmt"
"time"
"go.mau.fi/util/dbutil"
"go.mau.fi/whatsmeow/types"
log "maunium.net/go/maulogger/v2"
"maunium.net/go/mautrix/id"
"maunium.net/go/mautrix/util/dbutil"
"go.mau.fi/whatsmeow/types"
)
type PortalKey struct {

View File

@ -20,12 +20,11 @@ import (
"database/sql"
"time"
"go.mau.fi/util/dbutil"
"go.mau.fi/whatsmeow/types"
log "maunium.net/go/maulogger/v2"
"maunium.net/go/mautrix/id"
"maunium.net/go/mautrix/util/dbutil"
"go.mau.fi/whatsmeow/types"
)
type PuppetQuery struct {

View File

@ -20,12 +20,11 @@ import (
"database/sql"
"errors"
"go.mau.fi/util/dbutil"
"go.mau.fi/whatsmeow/types"
log "maunium.net/go/maulogger/v2"
"maunium.net/go/mautrix/id"
"maunium.net/go/mautrix/util/dbutil"
"go.mau.fi/whatsmeow/types"
)
type ReactionQuery struct {

View File

@ -20,7 +20,7 @@ import (
"embed"
"errors"
"maunium.net/go/mautrix/util/dbutil"
"go.mau.fi/util/dbutil"
)
var Table dbutil.UpgradeTable

View File

@ -21,12 +21,11 @@ import (
"sync"
"time"
"go.mau.fi/util/dbutil"
"go.mau.fi/whatsmeow/types"
log "maunium.net/go/maulogger/v2"
"maunium.net/go/mautrix/id"
"maunium.net/go/mautrix/util/dbutil"
"go.mau.fi/whatsmeow/types"
)
type UserQuery struct {

View File

@ -20,9 +20,10 @@ import (
"fmt"
"time"
"go.mau.fi/util/dbutil"
"maunium.net/go/mautrix"
"maunium.net/go/mautrix/id"
"maunium.net/go/mautrix/util/dbutil"
"maunium.net/go/mautrix-whatsapp/database"
)

5
go.mod
View File

@ -9,16 +9,17 @@ require (
github.com/lib/pq v1.10.9
github.com/mattn/go-sqlite3 v1.14.17
github.com/prometheus/client_golang v1.16.0
github.com/rs/zerolog v1.29.1
github.com/rs/zerolog v1.30.0
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
github.com/tidwall/gjson v1.14.4
go.mau.fi/util v0.0.0-20230805161919-cf42c11d39c3
go.mau.fi/whatsmeow v0.0.0-20230804210635-04e4e3a38f73
golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1
golang.org/x/image v0.9.0
golang.org/x/net v0.12.0
google.golang.org/protobuf v1.31.0
maunium.net/go/maulogger/v2 v2.4.1
maunium.net/go/mautrix v0.15.5-0.20230729114956-ff77fa8ec663
maunium.net/go/mautrix v0.15.5-0.20230805162445-fd1cdd8c9457
)
require (

12
go.sum
View File

@ -48,9 +48,9 @@ github.com/prometheus/procfs v0.10.1 h1:kYK1Va/YMlutzCGazswoHKo//tZVlFpKYh+Pymzi
github.com/prometheus/procfs v0.10.1/go.mod h1:nwNm2aOCAYw8uTR/9bWRREkZFxAUcWzPHWJq+XBB/FM=
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.29.1 h1:cO+d60CHkknCbvzEWxP0S9K6KqyTjrCNUy1LdQLCGPc=
github.com/rs/zerolog v1.29.1/go.mod h1:Le6ESbR7hc+DP6Lt1THiV8CQSdkkNrd3R0XbEgp3ZBU=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.30.0 h1:SymVODrcRsaRaSInD9yQtKbtWqwsfoPcRff/oRXLj4c=
github.com/rs/zerolog v1.30.0/go.mod h1:/tk+P47gFdPXq4QYjvCmT5/Gsug2nagsFWBWhAiSi1w=
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0=
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
@ -68,6 +68,8 @@ github.com/yuin/goldmark v1.5.4 h1:2uY/xC0roWy8IBEGLgB1ywIoEJFGmRrX21YQcvGZzjU=
github.com/yuin/goldmark v1.5.4/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.mau.fi/libsignal v0.1.0 h1:vAKI/nJ5tMhdzke4cTK1fb0idJzz1JuEIpmjprueC+c=
go.mau.fi/libsignal v0.1.0/go.mod h1:R8ovrTezxtUNzCQE5PH30StOQWWeBskBsWE55vMfY9I=
go.mau.fi/util v0.0.0-20230805161919-cf42c11d39c3 h1:r3Hrayw0CfmkrDhse7SbClYzq0e7/5P3iKpyV+gW16w=
go.mau.fi/util v0.0.0-20230805161919-cf42c11d39c3/go.mod h1:tNxQ2KpD+QhP2MlMfJvFSGSJfDjg4OhIwP7bIK43X/I=
go.mau.fi/whatsmeow v0.0.0-20230804210635-04e4e3a38f73 h1:JK9z+AWKvWXINSqz6wqfF67L/uUMEMJ+Mfw4sVMFnQg=
go.mau.fi/whatsmeow v0.0.0-20230804210635-04e4e3a38f73/go.mod h1:+ObGpFE6cbbY4hKc1FmQH9MVfqaemmlXGXSnwDvCOyE=
go.mau.fi/zeroconfig v0.1.2 h1:DKOydWnhPMn65GbXZOafgkPm11BvFashZWLct0dGFto=
@ -131,5 +133,5 @@ maunium.net/go/mauflag v1.0.0 h1:YiaRc0tEI3toYtJMRIfjP+jklH45uDHtT80nUamyD4M=
maunium.net/go/mauflag v1.0.0/go.mod h1:nLivPOpTpHnpzEh8jEdSL9UqO9+/KBJFmNRlwKfkPeA=
maunium.net/go/maulogger/v2 v2.4.1 h1:N7zSdd0mZkB2m2JtFUsiGTQQAdP0YeFWT7YMc80yAL8=
maunium.net/go/maulogger/v2 v2.4.1/go.mod h1:omPuYwYBILeVQobz8uO3XC8DIRuEb5rXYlQSuqrbCho=
maunium.net/go/mautrix v0.15.5-0.20230729114956-ff77fa8ec663 h1:tsXiuaWnBe9Xa/ms8tUhsJ4x7tPbQJ94fugqBIC0vsw=
maunium.net/go/mautrix v0.15.5-0.20230729114956-ff77fa8ec663/go.mod h1:dBaDmsnOOBM4a+gKcgefXH73pHGXm+MCJzCs1dXFgrw=
maunium.net/go/mautrix v0.15.5-0.20230805162445-fd1cdd8c9457 h1:VBKrYpAojLXdvR0RKi6uLqUmmfQLAf96SRdHv1G9occ=
maunium.net/go/mautrix v0.15.5-0.20230805162445-fd1cdd8c9457/go.mod h1:gpOJUT7EgK7vZTbewOrhWzNNjjJqwVahGRfTVg3BQko=

View File

@ -23,8 +23,8 @@ import (
"time"
"github.com/rs/zerolog"
"maunium.net/go/mautrix/util/variationselector"
"go.mau.fi/util/dbutil"
"go.mau.fi/util/variationselector"
waProto "go.mau.fi/whatsmeow/binary/proto"
"go.mau.fi/whatsmeow/types"
@ -32,7 +32,6 @@ import (
"maunium.net/go/mautrix/appservice"
"maunium.net/go/mautrix/event"
"maunium.net/go/mautrix/id"
"maunium.net/go/mautrix/util/dbutil"
"maunium.net/go/mautrix-whatsapp/config"
"maunium.net/go/mautrix-whatsapp/database"

View File

@ -27,6 +27,7 @@ import (
"google.golang.org/protobuf/proto"
"go.mau.fi/util/configupgrade"
"go.mau.fi/whatsmeow"
waProto "go.mau.fi/whatsmeow/binary/proto"
"go.mau.fi/whatsmeow/store"
@ -38,7 +39,6 @@ import (
"maunium.net/go/mautrix/bridge/status"
"maunium.net/go/mautrix/event"
"maunium.net/go/mautrix/id"
"maunium.net/go/mautrix/util/configupgrade"
"maunium.net/go/mautrix-whatsapp/config"
"maunium.net/go/mautrix-whatsapp/database"

View File

@ -44,12 +44,20 @@ import (
"github.com/chai2010/webp"
"github.com/rs/zerolog"
"github.com/tidwall/gjson"
"go.mau.fi/util/dbutil"
"go.mau.fi/util/exerrors"
"go.mau.fi/util/exmime"
"go.mau.fi/util/ffmpeg"
"go.mau.fi/util/random"
"go.mau.fi/util/variationselector"
"go.mau.fi/whatsmeow"
waProto "go.mau.fi/whatsmeow/binary/proto"
"go.mau.fi/whatsmeow/types"
"go.mau.fi/whatsmeow/types/events"
"golang.org/x/exp/slices"
"golang.org/x/image/draw"
"google.golang.org/protobuf/proto"
log "maunium.net/go/maulogger/v2"
"maunium.net/go/mautrix"
"maunium.net/go/mautrix/appservice"
"maunium.net/go/mautrix/bridge"
@ -58,15 +66,6 @@ import (
"maunium.net/go/mautrix/event"
"maunium.net/go/mautrix/format"
"maunium.net/go/mautrix/id"
"maunium.net/go/mautrix/util"
"maunium.net/go/mautrix/util/dbutil"
"maunium.net/go/mautrix/util/ffmpeg"
"maunium.net/go/mautrix/util/variationselector"
"go.mau.fi/whatsmeow"
waProto "go.mau.fi/whatsmeow/binary/proto"
"go.mau.fi/whatsmeow/types"
"go.mau.fi/whatsmeow/types/events"
"maunium.net/go/mautrix-whatsapp/database"
)
@ -2335,7 +2334,7 @@ func (portal *Portal) convertListMessage(intent *appservice.IntentAPI, source *U
body = fmt.Sprintf("%s\n\n%s", msg.GetTitle(), body)
}
}
randomID := util.RandomString(64)
randomID := random.String(64)
body = fmt.Sprintf("%s\n%s", body, randomID)
if msg.GetFooterText() != "" {
body = fmt.Sprintf("%s\n\n%s", body, msg.GetFooterText())
@ -2943,7 +2942,7 @@ func (portal *Portal) convertMediaMessageContent(intent *appservice.IntentAPI, m
content.Body = mimeClass
}
content.Body += util.ExtensionFromMimetype(msg.GetMimetype())
content.Body += exmime.ExtensionFromMimetype(msg.GetMimetype())
}
msgWithDuration, ok := msg.(MediaMessageWithDuration)
@ -3495,12 +3494,12 @@ func (portal *Portal) preprocessMatrixMedia(ctx context.Context, sender *User, r
}
data, err := portal.MainIntent().DownloadBytesContext(ctx, mxc)
if err != nil {
return nil, util.NewDualError(errMediaDownloadFailed, err)
return nil, exerrors.NewDualError(errMediaDownloadFailed, err)
}
if file != nil {
err = file.DecryptInPlace(data)
if err != nil {
return nil, util.NewDualError(errMediaDecryptFailed, err)
return nil, exerrors.NewDualError(errMediaDecryptFailed, err)
}
}
mimeType := content.GetInfo().MimeType
@ -3555,7 +3554,7 @@ func (portal *Portal) preprocessMatrixMedia(ctx context.Context, sender *User, r
}
if convertErr != nil {
if content.Info.MimeType != mimeType || data == nil {
return nil, util.NewDualError(fmt.Errorf("%w (%s to %s)", errMediaConvertFailed, mimeType, content.Info.MimeType), convertErr)
return nil, exerrors.NewDualError(fmt.Errorf("%w (%s to %s)", errMediaConvertFailed, mimeType, content.Info.MimeType), convertErr)
} else {
// If the mime type didn't change and the errored conversion function returned the original data, just log a warning and continue
portal.log.Warnfln("Failed to re-encode %s media: %v, continuing with original file", mimeType, convertErr)
@ -3563,7 +3562,7 @@ func (portal *Portal) preprocessMatrixMedia(ctx context.Context, sender *User, r
}
uploadResp, err := sender.Client.Upload(ctx, data, mediaType)
if err != nil {
return nil, util.NewDualError(errMediaWhatsAppUploadFailed, err)
return nil, exerrors.NewDualError(errMediaWhatsAppUploadFailed, err)
}
// Audio doesn't have thumbnails