Add embedded urls attribute to live thread updates
Signed-off-by: Vartan Benohanian <vartanbeno@gmail.com>
This commit is contained in:
parent
e73b89f0b8
commit
1eb75d163c
3 changed files with 52 additions and 7 deletions
|
@ -36,7 +36,7 @@ type LiveThread struct {
|
||||||
ViewerCount int `json:"viewer_count"`
|
ViewerCount int `json:"viewer_count"`
|
||||||
ViewerCountFuzzed bool `json:"viewer_count_fuzzed"`
|
ViewerCountFuzzed bool `json:"viewer_count_fuzzed"`
|
||||||
|
|
||||||
// Empty when a list thread has ended.
|
// Empty when a live thread has ended.
|
||||||
WebSocketURL string `json:"websocket_url,omitempty"`
|
WebSocketURL string `json:"websocket_url,omitempty"`
|
||||||
|
|
||||||
Announcement bool `json:"is_announcement"`
|
Announcement bool `json:"is_announcement"`
|
||||||
|
@ -50,10 +50,44 @@ type LiveThreadUpdate struct {
|
||||||
Author string `json:"author,omitempty"`
|
Author string `json:"author,omitempty"`
|
||||||
Created *Timestamp `json:"created_utc,omitempty"`
|
Created *Timestamp `json:"created_utc,omitempty"`
|
||||||
|
|
||||||
Body string `json:"body,omitempty"`
|
Body string `json:"body,omitempty"`
|
||||||
// todo: add "embeds" field?
|
EmbeddedURLs []string `json:"embeds,omitempty"`
|
||||||
|
Stricken bool `json:"stricken"`
|
||||||
|
}
|
||||||
|
|
||||||
Stricken bool `json:"stricken"`
|
// UnmarshalJSON implements the json.Unmarshaler interface.
|
||||||
|
func (u *LiveThreadUpdate) UnmarshalJSON(b []byte) error {
|
||||||
|
root := new(struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
FullID string `json:"name"`
|
||||||
|
Author string `json:"author"`
|
||||||
|
Created *Timestamp `json:"created_utc"`
|
||||||
|
|
||||||
|
Body string `json:"body"`
|
||||||
|
EmbeddedURLs []struct {
|
||||||
|
URL string `json:"url"`
|
||||||
|
} `json:"embeds"`
|
||||||
|
Stricken bool `json:"stricken"`
|
||||||
|
})
|
||||||
|
|
||||||
|
err := json.Unmarshal(b, root)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
u.ID = root.ID
|
||||||
|
u.FullID = root.FullID
|
||||||
|
u.Author = root.Author
|
||||||
|
u.Created = root.Created
|
||||||
|
|
||||||
|
u.Body = root.Body
|
||||||
|
u.Stricken = root.Stricken
|
||||||
|
|
||||||
|
for _, eu := range root.EmbeddedURLs {
|
||||||
|
u.EmbeddedURLs = append(u.EmbeddedURLs, eu.URL)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// LiveThreadCreateOrUpdateRequest represents a request to create/update a live thread.
|
// LiveThreadCreateOrUpdateRequest represents a request to create/update a live thread.
|
||||||
|
@ -432,7 +466,6 @@ func (s *LiveThreadService) Accept(ctx context.Context, id string) (*Response, e
|
||||||
}
|
}
|
||||||
|
|
||||||
// Leave the live thread by abdicating your status as contributor.
|
// Leave the live thread by abdicating your status as contributor.
|
||||||
// todo: test as the author who leaves the thread.
|
|
||||||
func (s *LiveThreadService) Leave(ctx context.Context, id string) (*Response, error) {
|
func (s *LiveThreadService) Leave(ctx context.Context, id string) (*Response, error) {
|
||||||
form := url.Values{}
|
form := url.Values{}
|
||||||
form.Set("api_type", "json")
|
form.Set("api_type", "json")
|
||||||
|
|
|
@ -75,7 +75,8 @@ var expectedLiveThreadUpdates = []*LiveThreadUpdate{
|
||||||
Author: "testuser1",
|
Author: "testuser1",
|
||||||
Created: &Timestamp{time.Date(2020, 9, 18, 4, 35, 24, 0, time.UTC)},
|
Created: &Timestamp{time.Date(2020, 9, 18, 4, 35, 24, 0, time.UTC)},
|
||||||
|
|
||||||
Body: "test 2",
|
Body: "test 2",
|
||||||
|
EmbeddedURLs: []string{"https://example.com", "https://reddit.com"},
|
||||||
|
|
||||||
Stricken: true,
|
Stricken: true,
|
||||||
},
|
},
|
||||||
|
|
13
testdata/live-thread/updates.json
vendored
13
testdata/live-thread/updates.json
vendored
|
@ -11,7 +11,18 @@
|
||||||
"name": "LiveUpdate_5e46cd94-f968-11ea-9a6a-0e1933241e7d",
|
"name": "LiveUpdate_5e46cd94-f968-11ea-9a6a-0e1933241e7d",
|
||||||
"mobile_embeds": [],
|
"mobile_embeds": [],
|
||||||
"author": "testuser1",
|
"author": "testuser1",
|
||||||
"embeds": [],
|
"embeds": [
|
||||||
|
{
|
||||||
|
"url": "https://example.com",
|
||||||
|
"width": 485,
|
||||||
|
"height": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://reddit.com",
|
||||||
|
"width": 485,
|
||||||
|
"height": 0
|
||||||
|
}
|
||||||
|
],
|
||||||
"created": 1600432524.0,
|
"created": 1600432524.0,
|
||||||
"created_utc": 1600403724.0,
|
"created_utc": 1600403724.0,
|
||||||
"body_html": "<div class=\"md\"><p>test 2</p>\n</div>",
|
"body_html": "<div class=\"md\"><p>test 2</p>\n</div>",
|
||||||
|
|
Loading…
Reference in a new issue