From 45e5290f0c51dfecb737c9325329b8f69ba07c5d Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sat, 5 Aug 2023 18:59:17 +0300 Subject: [PATCH] Update mautrix-go to move stuff to util --- config/upgrade.go | 6 +++--- database/backfill.go | 2 +- database/database.go | 2 +- database/disappearingmessage.go | 2 +- database/historysync.go | 8 +++----- database/mediabackfillrequest.go | 2 +- database/message.go | 5 ++--- database/polloption.go | 2 +- database/portal.go | 5 ++--- database/puppet.go | 5 ++--- database/reaction.go | 5 ++--- database/upgrades/upgrades.go | 2 +- database/user.go | 5 ++--- disappear.go | 3 ++- go.mod | 5 +++-- go.sum | 12 +++++++----- historysync.go | 5 ++--- main.go | 2 +- portal.go | 33 ++++++++++++++++---------------- 19 files changed, 53 insertions(+), 58 deletions(-) diff --git a/config/upgrade.go b/config/upgrade.go index e4023e3..02ae8fe 100644 --- a/config/upgrade.go +++ b/config/upgrade.go @@ -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") diff --git a/database/backfill.go b/database/backfill.go index 6925382..273370b 100644 --- a/database/backfill.go +++ b/database/backfill.go @@ -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 diff --git a/database/database.go b/database/database.go index 7f519e7..4bc749a 100644 --- a/database/database.go +++ b/database/database.go @@ -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" ) diff --git a/database/disappearingmessage.go b/database/disappearingmessage.go index 7489381..bae11e0 100644 --- a/database/disappearingmessage.go +++ b/database/disappearingmessage.go @@ -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 { diff --git a/database/historysync.go b/database/historysync.go index 5727a9a..2f88139 100644 --- a/database/historysync.go +++ b/database/historysync.go @@ -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 { diff --git a/database/mediabackfillrequest.go b/database/mediabackfillrequest.go index c206796..e71b986 100644 --- a/database/mediabackfillrequest.go +++ b/database/mediabackfillrequest.go @@ -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 diff --git a/database/message.go b/database/message.go index ffe33c1..8f35de8 100644 --- a/database/message.go +++ b/database/message.go @@ -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 { diff --git a/database/polloption.go b/database/polloption.go index aedcd53..4af576f 100644 --- a/database/polloption.go +++ b/database/polloption.go @@ -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) { diff --git a/database/portal.go b/database/portal.go index 304d535..b9d4a66 100644 --- a/database/portal.go +++ b/database/portal.go @@ -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 { diff --git a/database/puppet.go b/database/puppet.go index 17d7996..c490e7e 100644 --- a/database/puppet.go +++ b/database/puppet.go @@ -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 { diff --git a/database/reaction.go b/database/reaction.go index f30f263..1769358 100644 --- a/database/reaction.go +++ b/database/reaction.go @@ -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 { diff --git a/database/upgrades/upgrades.go b/database/upgrades/upgrades.go index 00ac6bc..990f496 100644 --- a/database/upgrades/upgrades.go +++ b/database/upgrades/upgrades.go @@ -20,7 +20,7 @@ import ( "embed" "errors" - "maunium.net/go/mautrix/util/dbutil" + "go.mau.fi/util/dbutil" ) var Table dbutil.UpgradeTable diff --git a/database/user.go b/database/user.go index 8b77850..088e998 100644 --- a/database/user.go +++ b/database/user.go @@ -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 { diff --git a/disappear.go b/disappear.go index c90fc05..c315bc2 100644 --- a/disappear.go +++ b/disappear.go @@ -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" ) diff --git a/go.mod b/go.mod index 08a0943..245154e 100644 --- a/go.mod +++ b/go.mod @@ -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 ( diff --git a/go.sum b/go.sum index b74872b..368bc93 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/historysync.go b/historysync.go index aba3646..175746e 100644 --- a/historysync.go +++ b/historysync.go @@ -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" diff --git a/main.go b/main.go index 71f98f1..04675bc 100644 --- a/main.go +++ b/main.go @@ -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" diff --git a/portal.go b/portal.go index 93cc53f..d9ad3f0 100644 --- a/portal.go +++ b/portal.go @@ -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