aboutsummaryrefslogtreecommitdiff
path: root/mastodon
diff options
context:
space:
mode:
authorr <r@freesoftwareextremist.com>2022-01-27 12:05:15 +0000
committerr <r@freesoftwareextremist.com>2022-01-27 12:05:15 +0000
commitb8c0133bcd5e7f1d4063ad992949cc19d18e7aad (patch)
tree5322b83d194c9ffcb498627bdd16175f9508d87d /mastodon
parent54c42455f393c5ae8ebdb19884d40ebd9a18f755 (diff)
parent4ef5e0daf285f41850c9ac53b0322d85fbf5eaec (diff)
downloadbloat-b8c0133bcd5e7f1d4063ad992949cc19d18e7aad.tar.gz
bloat-b8c0133bcd5e7f1d4063ad992949cc19d18e7aad.zip
Merge branch 'master' into absolute_fluoride
Diffstat (limited to 'mastodon')
-rw-r--r--mastodon/accounts.go8
-rw-r--r--mastodon/helper.go23
-rw-r--r--mastodon/notification.go5
-rw-r--r--mastodon/status.go15
4 files changed, 45 insertions, 6 deletions
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
}
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,
+ }
}
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)
}
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"`