From 0169f2140a3a180b2c190bd705b0de30de9ef3f4 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Wed, 9 Aug 2023 16:34:54 +0300 Subject: [PATCH] Enable go vet in pre-commit --- .pre-commit-config.yaml | 8 +-- gmtest/main.go | 2 +- libgm/conversation_builder.go | 94 ----------------------------------- 3 files changed, 5 insertions(+), 99 deletions(-) delete mode 100644 libgm/conversation_builder.go diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 34515be..67a78da 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,8 +8,8 @@ repos: - id: check-yaml - id: check-added-large-files -# - repo: https://github.com/tekwizely/pre-commit-golang -# rev: v1.0.0-rc.1 -# hooks: + - repo: https://github.com/tekwizely/pre-commit-golang + rev: v1.0.0-rc.1 + hooks: # - id: go-imports-repo -# - id: go-vet-repo-mod + - id: go-vet-repo-mod diff --git a/gmtest/main.go b/gmtest/main.go index 773094e..af4254b 100644 --- a/gmtest/main.go +++ b/gmtest/main.go @@ -71,7 +71,7 @@ func main() { must(cli.Connect()) } - c := make(chan os.Signal) + c := make(chan os.Signal, 1) input := make(chan string) signal.Notify(c, os.Interrupt, syscall.SIGTERM) go func() { diff --git a/libgm/conversation_builder.go b/libgm/conversation_builder.go deleted file mode 100644 index 7ca1298..0000000 --- a/libgm/conversation_builder.go +++ /dev/null @@ -1,94 +0,0 @@ -package libgm - -import ( - "fmt" - - "google.golang.org/protobuf/proto" - - "go.mau.fi/mautrix-gmessages/libgm/gmproto" -) - -type ConversationBuilderError struct { - errMsg string -} - -func (cbe *ConversationBuilderError) Error() string { - return fmt.Sprintf("Failed to build conversation builder: %s", cbe.errMsg) -} - -type ConversationBuilder struct { - conversationId string - - actionStatus gmproto.ConversationActionStatus - status gmproto.ConversationStatus - muteStatus *gmproto.ConversationMuteStatus -} - -func (cb *ConversationBuilder) SetConversationId(conversationId string) *ConversationBuilder { - cb.conversationId = conversationId - return cb -} - -// For block, unblock, block & report -func (cb *ConversationBuilder) SetConversationActionStatus(actionStatus gmproto.ConversationActionStatus) *ConversationBuilder { - cb.actionStatus = actionStatus - return cb -} - -// For archive, unarchive, delete -func (cb *ConversationBuilder) SetConversationStatus(status gmproto.ConversationStatus) *ConversationBuilder { - cb.status = status - return cb -} - -func (cb *ConversationBuilder) SetMuteStatus(muteStatus *gmproto.ConversationMuteStatus) *ConversationBuilder { - cb.muteStatus = muteStatus - return cb -} - -func (cb *ConversationBuilder) Build(protoMessage proto.Message) (proto.Message, error) { - if cb.conversationId == "" { - return nil, &ConversationBuilderError{errMsg: "conversationID can not be empty"} - } - - switch protoMessage.(type) { - case *gmproto.UpdateConversationRequest: - payload, failedBuild := cb.buildUpdateConversationPayload() - if failedBuild != nil { - return nil, failedBuild - } - return payload, nil - default: - panic("Invalid protoMessage conversation builder type") - } - return nil, &ConversationBuilderError{errMsg: "failed to build for unknown reasons"} -} - -func (cb *ConversationBuilder) buildUpdateConversationPayload() (*gmproto.UpdateConversationRequest, error) { - if cb.actionStatus == 0 && cb.status == 0 && cb.muteStatus == nil { - return nil, &ConversationBuilderError{errMsg: "actionStatus, status & muteStatus can not be empty when updating conversation, set atleast 1"} - } - - payload := &gmproto.UpdateConversationRequest{} - - if cb.actionStatus != 0 { - payload.Action = cb.actionStatus - payload.Action5 = &gmproto.ConversationAction5{ - Field2: true, - } - payload.ConversationID = cb.conversationId - } else if cb.status != 0 || cb.muteStatus != nil { - payload.Data = &gmproto.UpdateConversationData{ConversationID: cb.conversationId} - if cb.muteStatus != nil { - payload.Data.Data = &gmproto.UpdateConversationData_Mute{Mute: *cb.muteStatus} - } else if cb.status != 0 { - payload.Data.Data = &gmproto.UpdateConversationData_Status{Status: cb.status} - } - } - - return payload, nil -} - -func (c *Client) NewConversationBuilder() *ConversationBuilder { - return &ConversationBuilder{} -}