Skip to content

Commit

Permalink
pre-commit: add staticcheck and goimports
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Jul 31, 2024
1 parent 3865645 commit 7fb80e7
Show file tree
Hide file tree
Showing 26 changed files with 115 additions and 173 deletions.
15 changes: 13 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: trailing-whitespace
exclude_types: [markdown]
Expand All @@ -11,5 +11,16 @@ repos:
- repo: https://github.com/tekwizely/pre-commit-golang
rev: v1.0.0-rc.1
hooks:
# - id: go-imports-repo
- id: go-imports-repo
args:
- "-local"
- "go.mau.fi/mautrix-gmessages"
- "-w"
- id: go-vet-repo-mod
- id: go-staticcheck-repo-mod

- repo: https://github.com/beeper/pre-commit-go
rev: v0.3.1
hooks:
- id: zerolog-ban-msgf
- id: zerolog-use-stringer
5 changes: 0 additions & 5 deletions libgm/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,6 @@ func (c *Client) diffVersionFormat(curr *gmproto.ConfigVersion, latest *gmproto.
return fmt.Sprintf("%d.%d.%d -> %d.%d.%d", curr.Year, curr.Month, curr.Day, latest.Year, latest.Month, latest.Day)
}

func (c *Client) updateWebEncryptionKey(key []byte) {
c.Logger.Debug().Msg("Updated WebEncryptionKey")
c.AuthData.WebEncryptionKey = key
}

func (c *Client) updateTachyonAuthToken(data *gmproto.TokenData) {
c.AuthData.TachyonAuthToken = data.GetTachyonAuthToken()
validForDuration := time.Duration(data.GetTTL()) * time.Microsecond
Expand Down
9 changes: 5 additions & 4 deletions libgm/gmproto/authentication.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions libgm/gmproto/client.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions libgm/gmproto/config.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions libgm/gmproto/conversations.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions libgm/gmproto/events.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions libgm/gmproto/pblite.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions libgm/gmproto/rpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions libgm/gmproto/settings.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions libgm/gmproto/ukey.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions libgm/gmproto/util.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions libgm/pair_google.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func (c *Client) baseSignInGaiaPayload() *gmproto.SignInGaiaRequest {
}
}

//lint:ignore U1000 -
func (c *Client) signInGaiaInitial(ctx context.Context) (*gmproto.SignInGaiaResponse, error) {
payload := c.baseSignInGaiaPayload()
payload.UnknownInt3 = 1
Expand Down
5 changes: 1 addition & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ type GMBridge struct {

usersByMXID map[id.UserID]*User
usersLock sync.Mutex
spaceRooms map[id.RoomID]*User
spaceRoomsLock sync.Mutex
managementRooms map[id.RoomID]*User
managementRoomsLock sync.Mutex
portalsByMXID map[id.RoomID]*Portal
Expand Down Expand Up @@ -141,7 +139,7 @@ func (br *GMBridge) Stop() {
if user.Client == nil {
continue
}
br.ZLog.Debug().Str("user_id", user.MXID.String()).Msg("Disconnecting user")
br.ZLog.Debug().Stringer("user_id", user.MXID).Msg("Disconnecting user")
user.Client.Disconnect()
}
}
Expand All @@ -161,7 +159,6 @@ func (br *GMBridge) GetConfigPtr() interface{} {
func main() {
br := &GMBridge{
usersByMXID: make(map[id.UserID]*User),
spaceRooms: make(map[id.RoomID]*User),
managementRooms: make(map[id.RoomID]*User),
portalsByMXID: make(map[id.RoomID]*Portal),
portalsByKey: make(map[database.Key]*Portal),
Expand Down
12 changes: 6 additions & 6 deletions messagetracking.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (portal *Portal) sendErrorMessage(ctx context.Context, evt *event.Event, er
}
msg := fmt.Sprintf("\u26a0 Your %s %s bridged: %v", msgType, certainty, err)
if errors.Is(err, errEchoTimeout) {
msg = fmt.Sprintf("\u26a0 Your phone has not echoed the message, it may have been lost")
msg = "\u26a0 Your phone has not echoed the message, it may have been lost"
}
content := &event.MessageEventContent{
MsgType: event.MsgNotice,
Expand All @@ -137,7 +137,7 @@ func (portal *Portal) sendErrorMessage(ctx context.Context, evt *event.Event, er
}
resp, err := portal.sendMainIntentMessage(ctx, content)
if err != nil {
portal.zlog.Warn().Err(err).Str("event_id", evt.ID.String()).Msg("Failed to send bridging error message")
portal.zlog.Warn().Err(err).Stringer("event_id", evt.ID).Msg("Failed to send bridging error message")
return ""
}
return resp.EventID
Expand Down Expand Up @@ -189,19 +189,19 @@ func (portal *Portal) sendStatusEvent(ctx context.Context, evtID, lastRetry id.E
content.Status = event.MessageStatusSuccess
} else {
content.Reason, content.Status, _, _, content.Message = errorToStatusReason(err)
content.Error = err.Error()
content.InternalError = err.Error()
}
_, err = intent.SendMessageEvent(ctx, portal.MXID, event.BeeperMessageStatus, &content)
if err != nil {
portal.zlog.Warn().Err(err).Str("event_id", evtID.String()).Msg("Failed to send message status event")
portal.zlog.Warn().Err(err).Stringer("event_id", evtID).Msg("Failed to send message status event")
}
}

func (portal *Portal) sendDeliveryReceipt(ctx context.Context, eventID id.EventID) {
if portal.bridge.Config.Bridge.DeliveryReceipts {
err := portal.bridge.Bot.SendReceipt(ctx, portal.MXID, eventID, event.ReceiptTypeRead, nil)
if err != nil {
portal.zlog.Warn().Err(err).Str("event_id", eventID.String()).Msg("Failed to send delivery receipt")
portal.zlog.Warn().Err(err).Stringer("event_id", eventID).Msg("Failed to send delivery receipt")
}
}
}
Expand Down Expand Up @@ -262,7 +262,7 @@ func (portal *Portal) sendMessageMetrics(ctx context.Context, user *User, evt *e
}
}
if ms != nil {
portal.zlog.Debug().EmbedObject(ms.timings).Str("event_id", evt.ID.String()).Msg("Timings for Matrix event")
portal.zlog.Debug().EmbedObject(ms.timings).Stringer("event_id", evt.ID).Msg("Timings for Matrix event")
}
}

Expand Down
1 change: 0 additions & 1 deletion pkg/connector/chatinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/rs/zerolog"
"go.mau.fi/util/jsontime"
"go.mau.fi/util/ptr"

"maunium.net/go/mautrix/bridgev2"
"maunium.net/go/mautrix/bridgev2/database"
"maunium.net/go/mautrix/bridgev2/networkid"
Expand Down
10 changes: 5 additions & 5 deletions pkg/connector/chatsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import (

"github.com/rs/zerolog"
"google.golang.org/protobuf/proto"

"go.mau.fi/mautrix-gmessages/libgm/gmproto"
"maunium.net/go/mautrix/bridgev2"
"maunium.net/go/mautrix/bridgev2/database"
"maunium.net/go/mautrix/bridgev2/networkid"

"go.mau.fi/mautrix-gmessages/libgm/gmproto"
)

func (gc *GMClient) SyncConversations(ctx context.Context, lastDataReceived time.Time, minimalSync bool) {
Expand Down Expand Up @@ -157,16 +157,16 @@ func (evt *GMChatResync) ShouldCreatePortal() bool {
if evt.OnlyBackfill {
return false
}
if evt.Conv.Participants == nil {
return false
}
switch evt.Conv.GetStatus() {
case gmproto.ConversationStatus_ACTIVE, gmproto.ConversationStatus_ARCHIVED:
// continue to other checks
default:
// Don't create portal for keep_archived/spam/blocked/deleted
return false
}
if evt.Conv.Participants == nil {
return false
}
return true
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/connector/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@ import (

"github.com/rs/zerolog"
"go.mau.fi/util/exsync"

"go.mau.fi/mautrix-gmessages/libgm/gmproto"
"maunium.net/go/mautrix/bridge/status"
"maunium.net/go/mautrix/bridgev2"
"maunium.net/go/mautrix/bridgev2/networkid"

"go.mau.fi/mautrix-gmessages/libgm"
"go.mau.fi/mautrix-gmessages/libgm/gmproto"
)

type conversationMeta struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/connector/dbmeta.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import (
"sync"

"go.mau.fi/util/jsontime"
"maunium.net/go/mautrix/bridgev2/database"

"go.mau.fi/mautrix-gmessages/libgm"
"go.mau.fi/mautrix-gmessages/libgm/gmproto"
"maunium.net/go/mautrix/bridgev2/database"
)

func (gc *GMConnector) GetDBMetaTypes() database.MetaTypes {
Expand Down
Loading

0 comments on commit 7fb80e7

Please sign in to comment.