From 7d389d22581cc785005a42d655eb7f9c32aac3ec Mon Sep 17 00:00:00 2001 From: r Date: Sat, 23 Oct 2021 13:41:41 +0000 Subject: Show signin button in case of an auth error --- mastodon/helper.go | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'mastodon') diff --git a/mastodon/helper.go b/mastodon/helper.go index 05af20f..cb0013d 100644 --- a/mastodon/helper.go +++ b/mastodon/helper.go @@ -3,12 +3,28 @@ package mastodon import ( "encoding/base64" "encoding/json" - "errors" "fmt" "net/http" "os" ) +type Error struct { + code int + err string +} + +func (e Error) Error() string { + return e.err +} + +func (e Error) IsAuthError() bool { + switch e.code { + case http.StatusForbidden, http.StatusUnauthorized: + return true + } + return false +} + // Base64EncodeFileName returns the base64 data URI format string of the file with the file name. func Base64EncodeFileName(filename string) (string, error) { file, err := os.Open(filename) @@ -51,5 +67,8 @@ func parseAPIError(prefix string, resp *http.Response) error { errMsg = fmt.Sprintf("%s: %s", errMsg, e.Error) } - return errors.New(errMsg) + return Error{ + code: resp.StatusCode, + err: errMsg, + } } -- cgit v1.2.3 From 4d68062f2d0525a9d2a40e50d60ea9b25daae9ad Mon Sep 17 00:00:00 2001 From: r Date: Fri, 29 Oct 2021 14:20:15 +0000 Subject: Add "mute (keep notifications)" button --- mastodon/accounts.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'mastodon') diff --git a/mastodon/accounts.go b/mastodon/accounts.go index 694e672..df0a3b7 100644 --- a/mastodon/accounts.go +++ b/mastodon/accounts.go @@ -243,9 +243,13 @@ func (c *Client) AccountUnblock(ctx context.Context, id string) (*Relationship, } // AccountMute mute the account. -func (c *Client) AccountMute(ctx context.Context, id string) (*Relationship, error) { +func (c *Client) AccountMute(ctx context.Context, id string, notifications *bool) (*Relationship, error) { + params := url.Values{} + if notifications != nil { + params.Set("notifications", strconv.FormatBool(*notifications)) + } var relationship Relationship - err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/accounts/%s/mute", url.PathEscape(string(id))), nil, &relationship, nil) + err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/accounts/%s/mute", url.PathEscape(string(id))), params, &relationship, nil) if err != nil { return nil, err } -- cgit v1.2.3 From 1c8c661abb4beda77edefe421fba1a52cf933956 Mon Sep 17 00:00:00 2001 From: r Date: Mon, 22 Nov 2021 06:40:15 +0000 Subject: Fix time parsing for empty string --- mastodon/status.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'mastodon') diff --git a/mastodon/status.go b/mastodon/status.go index 80e7e0e..8b148b3 100644 --- a/mastodon/status.go +++ b/mastodon/status.go @@ -19,6 +19,19 @@ type ReplyInfo struct { Number int `json:"number"` } +type CreatedAt struct { + time.Time +} + +func (t *CreatedAt) UnmarshalJSON(d []byte) error { + // Special case to handle retweets from GNU Social + // which returns empty string ("") in created_at + if len(d) == 2 && string(d) == `""` { + return nil + } + return t.Time.UnmarshalJSON(d) +} + // Status is struct to hold status. type Status struct { ID string `json:"id"` @@ -29,7 +42,7 @@ type Status struct { InReplyToAccountID interface{} `json:"in_reply_to_account_id"` Reblog *Status `json:"reblog"` Content string `json:"content"` - CreatedAt time.Time `json:"created_at"` + CreatedAt CreatedAt `json:"created_at"` Emojis []Emoji `json:"emojis"` RepliesCount int64 `json:"replies_count"` ReblogsCount int64 `json:"reblogs_count"` -- cgit v1.2.3 From db29c3d87404677c9c02f62097d8a0307cd8d5da Mon Sep 17 00:00:00 2001 From: r Date: Mon, 13 Dec 2021 13:58:15 +0000 Subject: Add an option to hide unsupported notifications --- mastodon/notification.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'mastodon') diff --git a/mastodon/notification.go b/mastodon/notification.go index 656e6a1..e94f901 100644 --- a/mastodon/notification.go +++ b/mastodon/notification.go @@ -23,9 +23,12 @@ type Notification struct { } // GetNotifications return notifications. -func (c *Client) GetNotifications(ctx context.Context, pg *Pagination, excludes []string) ([]*Notification, error) { +func (c *Client) GetNotifications(ctx context.Context, pg *Pagination, includes, excludes []string) ([]*Notification, error) { var notifications []*Notification params := url.Values{} + for _, include := range includes { + params.Add("include_types[]", include) + } for _, exclude := range excludes { params.Add("exclude_types[]", exclude) } -- cgit v1.2.3