Skip to content

Commit d900b2b

Browse files
committed
Start work on replies
1 parent c87067a commit d900b2b

4 files changed

Lines changed: 95 additions & 38 deletions

File tree

bluesky/blueskyapi.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@ type AuthRequest struct {
2626
}
2727

2828
type User struct {
29-
DID string `json:"did"`
30-
Handle string `json:"handle"`
31-
DisplayName string `json:"displayName"`
32-
Description string `json:"description"`
33-
Avatar string `json:"avatar"`
34-
Banner string `json:"banner"`
35-
FollowersCount int `json:"followersCount"`
36-
FollowsCount int `json:"followsCount"`
37-
PostsCount int `json:"postsCount"`
38-
IndexedAt string `json:"indexedAt"`
39-
CreatedAt string `json:"createdAt"`
29+
DID string `json:"did"`
30+
Handle string `json:"handle"`
31+
DisplayName string `json:"displayName"`
32+
Description string `json:"description"`
33+
Avatar string `json:"avatar"`
34+
Banner string `json:"banner"`
35+
FollowersCount int `json:"followersCount"`
36+
FollowsCount int `json:"followsCount"`
37+
PostsCount int `json:"postsCount"`
38+
IndexedAt time.Time `json:"indexedAt"`
39+
CreatedAt time.Time `json:"createdAt"`
4040
Associated struct {
4141
Lists int `json:"lists"`
4242
FeedGens int `json:"feedgens"`
@@ -125,7 +125,7 @@ type Post struct {
125125
RepostCount int `json:"repostCount"`
126126
LikeCount int `json:"likeCount"`
127127
QuoteCount int `json:"quoteCount"`
128-
IndexedAt string `json:"indexedAt"`
128+
IndexedAt time.Time `json:"indexedAt"`
129129
Viewer PostViewer `json:"viewer"`
130130
}
131131

@@ -145,10 +145,10 @@ type Timeline struct {
145145
}
146146

147147
type Thread struct {
148-
Type string `json:"$type"`
149-
Post Post `json:"post"`
150-
Parent Post `json:"parent"`
151-
Replies []Post `json:"replies"`
148+
Type string `json:"$type"`
149+
Post Post `json:"post"`
150+
Parent *Post `json:"parent"`
151+
Replies *[]Thread `json:"replies"`
152152
}
153153

154154
// This is solely for the purpose of unmarshalling the response from the API
@@ -358,7 +358,7 @@ func AuthorTTB(author User) *bridge.TwitterUser {
358358
}(),
359359
ProfileSidebarBorderColor: "87bc44",
360360
ProfileBackgroundTile: false,
361-
CreatedAt: author.CreatedAt,
361+
CreatedAt: bridge.TwitterTimeConverter(author.CreatedAt),
362362
ProfileImageURL: "http://10.0.0.77:3000/cdn/img/?url=" + url.QueryEscape(author.Avatar) + ":thumb",
363363
Location: "",
364364
ProfileLinkColor: "0000ff",

bridge/bridge.go

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,48 @@ import (
1010
"time"
1111
)
1212

13+
type RelatedResultsQuery struct {
14+
Annotations interface{} `json:"annotations"` // TODO
15+
ResultType string `json:"resultType"`
16+
Score float64 `json:"score"`
17+
GroupName string `json:"groupName"`
18+
Results []Results `json:"results"`
19+
}
20+
21+
type Results struct {
22+
Kind string `json:"kind"`
23+
Score float64 `json:"score"`
24+
Annotations interface{} `json:"annotations"` // TODO
25+
Value Tweet `json:"results"`
26+
}
27+
1328
type Retweet struct {
1429
Tweet
1530
RetweetedStatus Tweet `json:"retweeted_status"`
1631
}
1732

1833
type Tweet struct {
19-
Coordinates interface{} `json:"coordinates"`
20-
Favourited bool `json:"favorited"`
21-
CreatedAt string `json:"created_at"`
22-
Truncated bool `json:"truncated"`
23-
Entities Entities `json:"entities"`
24-
Text string `json:"text"`
25-
Annotations interface{} `json:"annotations"`
26-
Contributors interface{} `json:"contributors"`
27-
ID big.Int `json:"id"`
28-
IDStr string `json:"id_str"`
29-
Geo interface{} `json:"geo"`
30-
Place interface{} `json:"place"`
31-
InReplyToUserID *big.Int `json:"in_reply_to_user_id"`
32-
InReplyToUserIDStr *string `json:"in_reply_to_user_id_str"`
33-
User TwitterUser `json:"user,omitempty"`
34-
Source string `json:"source"`
35-
InReplyToStatusID *big.Int `json:"in_reply_to_status_id"`
36-
InReplyToStatusIDStr *string `json:"in_reply_to_status_id_str"`
37-
InReplyToScreenName *string `json:"in_reply_to_screen_name"`
34+
Coordinates interface{} `json:"coordinates"`
35+
Favourited bool `json:"favorited"`
36+
CreatedAt string `json:"created_at"`
37+
Truncated bool `json:"truncated"`
38+
Entities Entities `json:"entities"`
39+
Text string `json:"text"`
40+
Annotations interface{} `json:"annotations"`
41+
Contributors interface{} `json:"contributors"`
42+
ID big.Int `json:"id"`
43+
IDStr string `json:"id_str"`
44+
Geo interface{} `json:"geo"`
45+
Place interface{} `json:"place"`
46+
User TwitterUser `json:"user,omitempty"`
47+
Source string `json:"source"`
48+
49+
// Reply stuff
50+
InReplyToUserID *big.Int `json:"in_reply_to_user_id"`
51+
InReplyToUserIDStr *string `json:"in_reply_to_user_id_str"`
52+
InReplyToStatusID *big.Int `json:"in_reply_to_status_id"`
53+
InReplyToStatusIDStr *string `json:"in_reply_to_status_id_str"`
54+
InReplyToScreenName *string `json:"in_reply_to_screen_name"`
3855

3956
// The following aren't found in home_timeline, but can be found when directly fetching a tweet.
4057

twitterv1/post_viewing.go

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,45 @@ func home_timeline(c *fiber.Ctx) error {
8989

9090
}
9191

92+
func RelatedResults(c *fiber.Ctx) error {
93+
encodedId := c.Params("id")
94+
idBigInt, ok := new(big.Int).SetString(encodedId, 10)
95+
if !ok {
96+
return c.Status(fiber.StatusBadRequest).SendString("Invalid ID format")
97+
}
98+
uri, _, _ := bridge.TwitterMsgIdToBluesky(idBigInt)
99+
100+
_, _, oauthToken, err := GetAuthFromReq(c)
101+
if err != nil {
102+
return c.Status(fiber.StatusUnauthorized).SendString("OAuth token not found in Authorization header")
103+
}
104+
105+
err, thread := blueskyapi.GetPost(*oauthToken, uri, 1, 0)
106+
107+
if err != nil {
108+
return err
109+
}
110+
111+
postAuthor := bridge.BlueSkyToTwitterID(thread.Thread.Post.Author.DID)
112+
113+
twitterReplies := bridge.RelatedResultsQuery{
114+
Annotations: nil,
115+
ResultType: "Tweet",
116+
Score: 1.0,
117+
GroupName: "TweetsWithConversation",
118+
Results: []bridge.Results{},
119+
}
120+
for _, reply := range *thread.Thread.Replies {
121+
twitterReplies.Results = append(twitterReplies.Results, bridge.Results{
122+
Kind: "Tweet",
123+
Score: 1.0,
124+
Value: TranslatePostToTweet(reply.Post, uri, postAuthor.String(), &thread.Thread.Post.Record.CreatedAt, nil),
125+
})
126+
}
127+
128+
return c.JSON([]bridge.RelatedResultsQuery{twitterReplies})
129+
}
130+
92131
// https://web.archive.org/web/20120708204036/https://dev.twitter.com/docs/api/1/get/statuses/show/%3Aid
93132
func GetStatusFromId(c *fiber.Ctx) error {
94133
encodedId := c.Params("id")
@@ -349,8 +388,8 @@ func TweetInfo(c *fiber.Ctx) error {
349388
favourites := []big.Int{}
350389
retweeters := []big.Int{}
351390

352-
for _, reply := range thread.Thread.Replies {
353-
repliers = append(repliers, *bridge.BlueSkyToTwitterID(reply.Author.DID))
391+
for _, reply := range *thread.Thread.Replies {
392+
repliers = append(repliers, *bridge.BlueSkyToTwitterID(reply.Post.Author.DID))
354393
}
355394
for _, like := range likes.Likes {
356395
favourites = append(favourites, *bridge.BlueSkyToTwitterID(like.Actor.DID))

twitterv1/twitterv1.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func InitServer() {
3838
app.Get("/1/statuses/home_timeline.json", home_timeline)
3939
app.Get("/1/statuses/show/:id.json", GetStatusFromId)
4040
app.Get("/i/statuses/:id/activity/summary.json", TweetInfo)
41+
app.Get("/1/related_results/show/:id.json", RelatedResults)
4142

4243
// Users
4344
app.Get("/1/users/show.xml", user_info)

0 commit comments

Comments
 (0)