add filtered to Status

pull/171/head
Rasmus Lindroth 2022-12-30 11:03:08 +01:00
parent aa9c1859b5
commit e86f463667
3 changed files with 73 additions and 30 deletions

View File

@ -19,6 +19,18 @@ type Filter struct {
Irreversible bool `json:"irreversible"`
}
type FilterResult struct {
Filter struct {
ID string `json:"id"`
Title string `json:"title"`
Context []string `json:"context"`
ExpiresAt time.Time `json:"expires_at"`
FilterAction string `json:"filter_action"`
} `json:"filter"`
KeywordMatches []string `json:"keyword_matches"`
StatusMatches []string `json:"status_matches"`
}
// GetFilters returns all the filters on the current account.
func (c *Client) GetFilters(ctx context.Context) ([]*Filter, error) {
var filters []*Filter

View File

@ -15,35 +15,36 @@ import (
// Status is struct to hold status.
type Status struct {
ID ID `json:"id"`
URI string `json:"uri"`
URL string `json:"url"`
Account Account `json:"account"`
InReplyToID interface{} `json:"in_reply_to_id"`
InReplyToAccountID interface{} `json:"in_reply_to_account_id"`
Reblog *Status `json:"reblog"`
Content string `json:"content"`
CreatedAt time.Time `json:"created_at"`
EditedAt time.Time `json:"edited_at"`
Emojis []Emoji `json:"emojis"`
RepliesCount int64 `json:"replies_count"`
ReblogsCount int64 `json:"reblogs_count"`
FavouritesCount int64 `json:"favourites_count"`
Reblogged interface{} `json:"reblogged"`
Favourited interface{} `json:"favourited"`
Bookmarked interface{} `json:"bookmarked"`
Muted interface{} `json:"muted"`
Sensitive bool `json:"sensitive"`
SpoilerText string `json:"spoiler_text"`
Visibility string `json:"visibility"`
MediaAttachments []Attachment `json:"media_attachments"`
Mentions []Mention `json:"mentions"`
Tags []Tag `json:"tags"`
Card *Card `json:"card"`
Poll *Poll `json:"poll"`
Application Application `json:"application"`
Language string `json:"language"`
Pinned interface{} `json:"pinned"`
ID ID `json:"id"`
URI string `json:"uri"`
URL string `json:"url"`
Account Account `json:"account"`
InReplyToID interface{} `json:"in_reply_to_id"`
InReplyToAccountID interface{} `json:"in_reply_to_account_id"`
Reblog *Status `json:"reblog"`
Content string `json:"content"`
CreatedAt time.Time `json:"created_at"`
EditedAt time.Time `json:"edited_at"`
Emojis []Emoji `json:"emojis"`
RepliesCount int64 `json:"replies_count"`
ReblogsCount int64 `json:"reblogs_count"`
FavouritesCount int64 `json:"favourites_count"`
Reblogged interface{} `json:"reblogged"`
Favourited interface{} `json:"favourited"`
Bookmarked interface{} `json:"bookmarked"`
Muted interface{} `json:"muted"`
Sensitive bool `json:"sensitive"`
SpoilerText string `json:"spoiler_text"`
Visibility string `json:"visibility"`
MediaAttachments []Attachment `json:"media_attachments"`
Mentions []Mention `json:"mentions"`
Tags []Tag `json:"tags"`
Card *Card `json:"card"`
Poll *Poll `json:"poll"`
Application Application `json:"application"`
Language string `json:"language"`
Pinned interface{} `json:"pinned"`
Filtered []FilterResult `json:"filtered"`
}
// StatusHistory is a struct to hold status history data.

View File

@ -70,7 +70,7 @@ func TestGetStatus(t *testing.T) {
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
return
}
fmt.Fprintln(w, `{"content": "zzz", "emojis":[{"shortcode":"💩", "url":"http://example.com", "static_url": "http://example.com/static"}]}`)
fmt.Fprintln(w, `{"content": "zzz", "emojis":[{"shortcode":"💩", "url":"http://example.com", "static_url": "http://example.com/static"}], "filtered": [{"filter": {"id": "3", "title": "Hide completely", "context": ["home"], "expires_at": "2022-09-20T17:27:39.296Z", "filter_action": "hide"}, "keyword_matches": ["bad word"], "status_matches": ["109031743575371913"]}]}`)
}))
defer ts.Close()
@ -103,6 +103,36 @@ func TestGetStatus(t *testing.T) {
if status.Emojis[0].StaticURL != "http://example.com/static" {
t.Fatalf("want %q but %q", "https://example.com/static", status.Emojis[0].StaticURL)
}
if len(status.Filtered) != 1 {
t.Fatal("should have filtered")
}
if status.Filtered[0].Filter.ID != "3" {
t.Fatalf("want %q but %q", "3", status.Filtered[0].Filter.ID)
}
if status.Filtered[0].Filter.Title != "Hide completely" {
t.Fatalf("want %q but %q", "Hide completely", status.Filtered[0].Filter.Title)
}
if len(status.Filtered[0].Filter.Context) != 1 {
t.Fatal("should have one context")
}
if status.Filtered[0].Filter.Context[0] != "home" {
t.Fatalf("want %q but %q", "home", status.Filtered[0].Filter.Context[0])
}
if status.Filtered[0].Filter.FilterAction != "hide" {
t.Fatalf("want %q but %q", "hide", status.Filtered[0].Filter.FilterAction)
}
if len(status.Filtered[0].KeywordMatches) != 1 {
t.Fatal("should have one matching keyword")
}
if status.Filtered[0].KeywordMatches[0] != "bad word" {
t.Fatalf("want %q but %q", "bad word", status.Filtered[0].KeywordMatches[0])
}
if len(status.Filtered[0].StatusMatches) != 1 {
t.Fatal("should have one matching status")
}
if status.Filtered[0].StatusMatches[0] != "109031743575371913" {
t.Fatalf("want %q but %q", "109031743575371913", status.Filtered[0].StatusMatches[0])
}
}
func TestGetStatusCard(t *testing.T) {