aboutsummaryrefslogtreecommitdiff
path: root/mastodon
diff options
context:
space:
mode:
authorr <r@freesoftwareextremist.com>2021-11-22 06:40:15 +0000
committerr <r@freesoftwareextremist.com>2021-11-22 06:40:15 +0000
commit1c8c661abb4beda77edefe421fba1a52cf933956 (patch)
tree66487ac51307b10bd5259074d171590004c0a3b1 /mastodon
parentb2a9e44db1a703fe0150c5aef7097020a9e1550d (diff)
downloadbloat-1c8c661abb4beda77edefe421fba1a52cf933956.tar.gz
bloat-1c8c661abb4beda77edefe421fba1a52cf933956.zip
Fix time parsing for empty string
Diffstat (limited to 'mastodon')
-rw-r--r--mastodon/status.go15
1 files changed, 14 insertions, 1 deletions
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"`