Skip to content

Commit 5a2c4b7

Browse files
committed
fix: friendship lookup on JSON
1 parent 67abe8d commit 5a2c4b7

2 files changed

Lines changed: 24 additions & 13 deletions

File tree

bridge/bridge.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,13 @@ type Config struct {
247247

248248
// Used in the /friends/lookup endpoint
249249
type UsersRelationship struct {
250-
XMLName xml.Name `xml:"relationship" json:"-"`
251-
Name string `json:"name" xml:"name"`
252-
IDStr string `json:"id_str" xml:"id_str"`
253-
ID int64 `json:"id" xml:"id"`
254-
Connections Connections `json:"connections" xml:"connections"`
255-
ScreenName string `json:"screen_name" xml:"screen_name"`
250+
XMLName xml.Name `xml:"relationship" json:"-"`
251+
Name string `json:"name" xml:"name"`
252+
IDStr string `json:"id_str" xml:"id_str"`
253+
ID int64 `json:"id" xml:"id"`
254+
Connections []string `json:"connections" xml:"-"` // JSON representation
255+
ConnectionsXML Connections `json:"-" xml:"connections"` // XML representation
256+
ScreenName string `json:"screen_name" xml:"screen_name"`
256257
}
257258

258259
type Connection struct {

twitterv1/user.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,18 +153,23 @@ func UserRelationships(c *fiber.Ctx) error {
153153
}
154154

155155
connections := bridge.Connections{}
156+
connectionJSON := []string{}
156157

157158
if user.Viewer.Following != nil {
158159
connections.Connection = append(connections.Connection, bridge.Connection{Value: "following"})
160+
connectionJSON = append(connectionJSON, "following")
159161
}
160162
if user.Viewer.FollowedBy != nil {
161163
connections.Connection = append(connections.Connection, bridge.Connection{Value: "followed_by"})
164+
connectionJSON = append(connectionJSON, "followed_by")
162165
}
163166
if user.Viewer.Blocking != nil {
164167
connections.Connection = append(connections.Connection, bridge.Connection{Value: "blocked"})
168+
connectionJSON = append(connectionJSON, "blocking")
165169
}
166170
if user.Viewer.BlockedBy {
167171
connections.Connection = append(connections.Connection, bridge.Connection{Value: "blocked_by"}) // Complete guess
172+
connectionJSON = append(connectionJSON, "blocked_by")
168173
}
169174

170175
relationships = append(relationships, bridge.UsersRelationship{
@@ -174,18 +179,23 @@ func UserRelationships(c *fiber.Ctx) error {
174179
}
175180
return user.DisplayName
176181
}(),
177-
ScreenName: user.Handle,
178-
ID: *encodedUserId,
179-
IDStr: strconv.FormatInt(*encodedUserId, 10),
180-
Connections: connections,
182+
ScreenName: user.Handle,
183+
ID: *encodedUserId,
184+
IDStr: strconv.FormatInt(*encodedUserId, 10),
185+
ConnectionsXML: connections,
186+
Connections: connectionJSON,
181187
})
182188
}
183189

184-
root := bridge.UserRelationships{
185-
Relationships: relationships,
190+
if c.Params("filetype") == "xml" {
191+
root := bridge.UserRelationships{
192+
Relationships: relationships,
193+
}
194+
return EncodeAndSend(c, root)
195+
} else {
196+
return EncodeAndSend(c, relationships)
186197
}
187198

188-
return EncodeAndSend(c, root)
189199
}
190200

191201
// Gets the relationship between two users

0 commit comments

Comments
 (0)