Skip to content

Commit 8a46027

Browse files
committed
fix: ids not properly encoding
1 parent 16a7e75 commit 8a46027

5 files changed

Lines changed: 46 additions & 42 deletions

File tree

bluesky/blueskyapi.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ func AuthorTTB(author User) *bridge.TwitterUser {
486486
ContributorsEnabled: false,
487487
URL: "",
488488
UtcOffset: nil,
489-
ID: *bridge.BlueSkyToTwitterID(author.DID),
489+
ID: bridge.BlueSkyToTwitterID(author.DID),
490490
ProfileUseBackgroundImage: false,
491491
ListedCount: 0,
492492
ProfileTextColor: "000000",

bridge/bridge.go

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ type Tweet struct {
4646
Text string `json:"text"`
4747
Annotations interface{} `json:"annotations"`
4848
Contributors interface{} `json:"contributors"`
49-
ID big.Int `json:"id"`
49+
ID *big.Int `json:"id"`
5050
IDStr string `json:"id_str"`
5151
Geo interface{} `json:"geo"`
5252
Place interface{} `json:"place"`
@@ -73,8 +73,8 @@ type Tweet struct {
7373
CurrentUserRetweet *CurrentUserRetweet `json:"current_user_retweet,omitempty"`
7474
}
7575
type CurrentUserRetweet struct {
76-
ID big.Int `json:"id"`
77-
IDStr string `json:"id_str"`
76+
ID *big.Int `json:"id"`
77+
IDStr string `json:"id_str"`
7878
}
7979

8080
type TwitterUser struct {
@@ -85,14 +85,14 @@ type TwitterUser struct {
8585
CreatedAt string `json:"created_at" xml:"created_at"`
8686
ProfileImageURL string `json:"profile_image_url" xml:"profile_image_url"`
8787
// ProfileImageURLHttps string `json:"profile_image_url_https" xml:"profile_image_url_https"`
88-
Location string `json:"location" xml:"location"`
89-
ProfileLinkColor string `json:"profile_link_color" xml:"profile_link_color"`
90-
FollowRequestSent bool `json:"follow_request_sent" xml:"follow_request_sent"`
91-
URL string `json:"url" xml:"url"`
92-
FavouritesCount int `json:"favourites_count" xml:"favourites_count"`
93-
ContributorsEnabled bool `json:"contributors_enabled" xml:"contributors_enabled"`
94-
UtcOffset *int `json:"utc_offset" xml:"utc_offset"`
95-
ID big.Int `json:"id" xml:"id"`
88+
Location string `json:"location" xml:"location"`
89+
ProfileLinkColor string `json:"profile_link_color" xml:"profile_link_color"`
90+
FollowRequestSent bool `json:"follow_request_sent" xml:"follow_request_sent"`
91+
URL string `json:"url" xml:"url"`
92+
FavouritesCount int `json:"favourites_count" xml:"favourites_count"`
93+
ContributorsEnabled bool `json:"contributors_enabled" xml:"contributors_enabled"`
94+
UtcOffset *int `json:"utc_offset" xml:"utc_offset"`
95+
ID *big.Int `json:"id" xml:"id"`
9696
// IDStr string `json:"id_str" xml:"id_str"`
9797
ProfileUseBackgroundImage bool `json:"profile_use_background_image" xml:"profile_use_background_image"`
9898
ProfileTextColor string `json:"profile_text_color" xml:"profile_text_color"`
@@ -135,7 +135,7 @@ type MediaSize struct {
135135
}
136136

137137
type Media struct {
138-
ID big.Int `json:"id"`
138+
ID *big.Int `json:"id"`
139139
IDStr string `json:"id_str"`
140140
MediaURL string `json:"media_url"`
141141
MediaURLHttps string `json:"media_url_https"`
@@ -167,11 +167,11 @@ type Hashtag struct {
167167
}
168168

169169
type UserMention struct {
170-
Name string `json:"name"`
171-
ID big.Int `json:"id"`
172-
IDStr string `json:"id_str"`
173-
Indices []int `json:"indices"`
174-
ScreenName string `json:"screen_name"`
170+
Name string `json:"name"`
171+
ID *big.Int `json:"id"`
172+
IDStr string `json:"id_str"`
173+
Indices []int `json:"indices"`
174+
ScreenName string `json:"screen_name"`
175175
}
176176

177177
type SleepTime struct {
@@ -214,7 +214,7 @@ type Config struct {
214214
type UsersRelationship struct {
215215
Name string `json:"name" xml:"name"`
216216
IDStr string `json:"id_str" xml:"id_str"`
217-
ID big.Int `json:"id" xml:"id"`
217+
ID *big.Int `json:"id" xml:"id"`
218218
Connections Connections `json:"connections" xml:"connections"`
219219
ScreenName string `json:"screen_name" xml:"screen_name"`
220220
}
@@ -236,17 +236,17 @@ type UserRelationships struct {
236236
// https://web.archive.org/web/20120516154953/https://dev.twitter.com/docs/api/1/get/friendships/show
237237
// used in the /friendships/show endpoint
238238
type UserFriendship struct {
239-
ID big.Int `json:"id" xml:"id"`
240-
IDStr string `json:"id_str" xml:"id_str"`
241-
ScreenName string `json:"screen_name" xml:"screen_name"`
242-
Following bool `json:"following" xml:"following"`
243-
FollowedBy bool `json:"followed_by" xml:"followed_by"`
244-
NotificationsEnabled *bool `json:"notifications_enabled" xml:"notifications_enabled"` // unknown
245-
CanDM *bool `json:"can_dm,omitempty" xml:"can_dm,omitempty"`
246-
Blocking *bool `json:"blocking" xml:"blocking"` // unknown
247-
WantRetweets *bool `json:"want_retweets" xml:"want_retweets"` // unknown
248-
MarkedSpam *bool `json:"marked_spam" xml:"marked_spam"` // unknown
249-
AllReplies *bool `json:"all_replies" xml:"all_replies"` // unknown
239+
ID *big.Int `json:"id" xml:"id"`
240+
IDStr string `json:"id_str" xml:"id_str"`
241+
ScreenName string `json:"screen_name" xml:"screen_name"`
242+
Following bool `json:"following" xml:"following"`
243+
FollowedBy bool `json:"followed_by" xml:"followed_by"`
244+
NotificationsEnabled *bool `json:"notifications_enabled" xml:"notifications_enabled"` // unknown
245+
CanDM *bool `json:"can_dm,omitempty" xml:"can_dm,omitempty"`
246+
Blocking *bool `json:"blocking" xml:"blocking"` // unknown
247+
WantRetweets *bool `json:"want_retweets" xml:"want_retweets"` // unknown
248+
MarkedSpam *bool `json:"marked_spam" xml:"marked_spam"` // unknown
249+
AllReplies *bool `json:"all_replies" xml:"all_replies"` // unknown
250250
}
251251

252252
type SourceTargetFriendship struct {

twitterv1/interaction.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ func retweet(c *fiber.Ctx) error {
8080
}
8181
retweet.Retweeted = true
8282
now := time.Now() // pain, also fix this to use the proper timestamp according to the server.
83-
retweet.ID = bridge.BskyMsgToTwitterID(*retweetPostURI, &now, user_did)
83+
retweetId := bridge.BskyMsgToTwitterID(*retweetPostURI, &now, user_did)
84+
retweet.ID = &retweetId
8485
retweet.IDStr = retweet.ID.String()
8586

8687
return c.JSON(bridge.Retweet{

twitterv1/post_viewing.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ func GetStatusFromId(c *fiber.Ctx) error {
170170
_, pds, _, oauthToken, err := GetAuthFromReq(c)
171171

172172
if err != nil {
173-
return c.Status(fiber.StatusUnauthorized).SendString("OAuth token not found in Authorization header")
173+
emptyString := ""
174+
oauthToken = &emptyString
174175
}
175176

176177
err, thread := blueskyapi.GetPost(*pds, *oauthToken, uri, 0, 1)
@@ -200,7 +201,7 @@ func TranslatePostToTweet(tweet blueskyapi.Post, replyMsgBskyURI string, replyUs
200201
// Process each image
201202
// fmt.Println("Image:", "http://10.0.0.77:3000/cdn/img/?url="+url.QueryEscape("https://cdn.bsky.app/img/feed_thumbnail/plain/did:plc:"+item.Post.Author.DID+"/"+image.Image.Ref.Link+"/@jpeg"))
202203
tweetEntities.Media = append(tweetEntities.Media, bridge.Media{
203-
ID: *big.NewInt(int64(id)),
204+
ID: big.NewInt(int64(id)),
204205
IDStr: strconv.Itoa(id),
205206
MediaURL: "http://10.0.0.77:3000/cdn/img/?url=" + url.QueryEscape("https://cdn.bsky.app/img/feed_thumbnail/plain/"+tweet.Author.DID+"/"+image.Image.Ref.Link+"/@jpeg"),
206207
// MediaURLHttps: "https://10.0.0.77:3000/cdn/img/?url=" + url.QueryEscape("https://cdn.bsky.app/img/feed_thumbnail/plain/did:plc:"+image.Image.Ref.Link+"@jpeg"),
@@ -225,7 +226,7 @@ func TranslatePostToTweet(tweet blueskyapi.Post, replyMsgBskyURI string, replyUs
225226
Name: tweet.Record.Text[faucet.Index.ByteStart+1 : faucet.Index.ByteEnd],
226227
//ScreenName: "test",
227228
ScreenName: tweet.Record.Text[faucet.Index.ByteStart+1 : faucet.Index.ByteEnd],
228-
ID: *bridge.BlueSkyToTwitterID(faucet.Features[0].Did),
229+
ID: bridge.BlueSkyToTwitterID(faucet.Features[0].Did),
229230
Indices: []int{
230231
faucet.Index.ByteStart,
231232
faucet.Index.ByteEnd,
@@ -282,12 +283,14 @@ func TranslatePostToTweet(tweet blueskyapi.Post, replyMsgBskyURI string, replyUs
282283
Entities: tweetEntities,
283284
Annotations: nil, // I am curious what annotations are
284285
Contributors: nil,
285-
ID: func() big.Int {
286+
ID: func() *big.Int {
286287
// we have to use psudo ids because of https://github.com/bluesky-social/atproto/issues/1811
287288
if isRetweet {
288-
return bridge.BskyMsgToTwitterID(tweet.URI, &postReason.IndexedAt, &postReason.By.DID)
289+
id := bridge.BskyMsgToTwitterID(tweet.URI, &postReason.IndexedAt, &postReason.By.DID)
290+
return &id
289291
}
290-
return bridge.BskyMsgToTwitterID(tweet.URI, &tweet.Record.CreatedAt, nil)
292+
id := bridge.BskyMsgToTwitterID(tweet.URI, &tweet.Record.CreatedAt, nil)
293+
return &id
291294
}(),
292295
IDStr: func() string {
293296
if isRetweet {
@@ -355,7 +358,7 @@ func TranslatePostToTweet(tweet blueskyapi.Post, replyMsgBskyURI string, replyUs
355358
_, my_did, _ := blueskyapi.GetURIComponents(*tweet.Viewer.Repost)
356359
retweetId := bridge.BskyMsgToTwitterID(tweet.URI, &RepostRecord.Value.CreatedAt, &my_did)
357360
return &bridge.CurrentUserRetweet{
358-
ID: retweetId,
361+
ID: &retweetId,
359362
IDStr: retweetId.String(),
360363
}
361364
}
@@ -388,7 +391,7 @@ func GetUserInfoFromTweetData(tweet blueskyapi.Post) bridge.TwitterUser {
388391
ContributorsEnabled: false,
389392
UtcOffset: nil,
390393
IsTranslator: false,
391-
ID: *bridge.BlueSkyToTwitterID(tweet.URI),
394+
ID: bridge.BlueSkyToTwitterID(tweet.URI),
392395
// IDStr: bridge.BlueSkyToTwitterID(tweet.URI).String(),
393396
ProfileUseBackgroundImage: false,
394397
ProfileTextColor: "333333",

twitterv1/user.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ func UserRelationships(c *fiber.Ctx) error {
165165
return user.DisplayName
166166
}(),
167167
ScreenName: user.Handle,
168-
ID: encodedUserId,
168+
ID: &encodedUserId,
169169
IDStr: encodedUserId.String(),
170170
Connections: connections,
171171
})
@@ -239,8 +239,8 @@ func GetUsersRelationship(c *fiber.Ctx) error {
239239
return c.Status(fiber.StatusBadRequest).SendString("Failed to fetch source user")
240240
}
241241

242-
targetDID := bridge.TwitterIDToBlueSky(targetUser.ID) // not the most efficient way to do this, but it works
243-
sourceDID := bridge.TwitterIDToBlueSky(sourceUser.ID)
242+
targetDID := bridge.TwitterIDToBlueSky(*targetUser.ID) // not the most efficient way to do this, but it works
243+
sourceDID := bridge.TwitterIDToBlueSky(*sourceUser.ID)
244244

245245
relationship, err := blueskyapi.GetRelationships(*pds, *oauthToken, sourceDID, []string{targetDID})
246246
if err != nil {

0 commit comments

Comments
 (0)