tangled
alpha
login
or
join now
whey.party
/
red-dwarf-server
13
fork
atom
collection of golang services under the Red Dwarf umbrella
server.reddwarf.app
bluesky
reddwarf
microcosm
appview
13
fork
atom
overview
issues
pulls
pipelines
ProfileView viewer for following and blocking state
whey.party
3 months ago
e98b8ef7
dd084c49
+129
-15
4 changed files
expand all
collapse all
unified
split
main.go
shims
lex
app
bsky
actor
defs
profileview.go
feed
defs
embed.go
postview.go
+39
-6
main.go
···
117
117
} else {
118
118
didtest = &didval
119
119
}
120
120
-
profiletest, _, _ := appbskyactordefs.ProfileViewBasic(ctx, *didtest, sl, BSKYIMAGECDN_URL)
120
120
+
profiletest, _, _ := appbskyactordefs.ProfileViewBasic(ctx, *didtest, sl, cs, BSKYIMAGECDN_URL, nil)
121
121
122
122
log.Println(*profiletest.DisplayName)
123
123
log.Println(*profiletest.Avatar)
···
164
164
165
165
bskyappdid, _ := utils.NewDID("did:plc:z72i7hdynmk6r22z27h6tvur")
166
166
167
167
-
profiletest2, _, _ := appbskyactordefs.ProfileViewDetailed(ctx, bskyappdid, sl, cs, BSKYIMAGECDN_URL)
167
167
+
profiletest2, _, _ := appbskyactordefs.ProfileViewDetailed(ctx, bskyappdid, sl, cs, BSKYIMAGECDN_URL, nil)
168
168
169
169
data, err := json.MarshalIndent(profiletest2, "", " ")
170
170
if err != nil {
···
176
176
func(c *gin.Context) {
177
177
actors := c.QueryArray("actors")
178
178
179
179
+
rawdid := c.GetString("user_did")
180
180
+
var viewer *utils.DID
181
181
+
didval, errdid := utils.NewDID(rawdid)
182
182
+
if errdid != nil {
183
183
+
viewer = nil
184
184
+
} else {
185
185
+
viewer = &didval
186
186
+
}
187
187
+
179
188
profiles := make([]*appbsky.ActorDefs_ProfileViewDetailed, 0, len(actors))
180
189
181
190
for _, v := range actors {
···
183
192
if err != nil {
184
193
continue
185
194
}
186
186
-
profile, _, _ := appbskyactordefs.ProfileViewDetailed(ctx, did, sl, cs, BSKYIMAGECDN_URL)
195
195
+
profile, _, _ := appbskyactordefs.ProfileViewDetailed(ctx, did, sl, cs, BSKYIMAGECDN_URL, viewer)
187
196
profiles = append(profiles, profile)
188
197
}
189
198
···
200
209
c.JSON(http.StatusBadRequest, nil)
201
210
return
202
211
}
203
203
-
profile, _, _ := appbskyactordefs.ProfileViewDetailed(ctx, did, sl, cs, BSKYIMAGECDN_URL)
212
212
+
rawdid := c.GetString("user_did")
213
213
+
var viewer *utils.DID
214
214
+
didval, errdid := utils.NewDID(rawdid)
215
215
+
if errdid != nil {
216
216
+
viewer = nil
217
217
+
} else {
218
218
+
viewer = &didval
219
219
+
}
220
220
+
profile, _, _ := appbskyactordefs.ProfileViewDetailed(ctx, did, sl, cs, BSKYIMAGECDN_URL, viewer)
204
221
c.JSON(http.StatusOK, profile)
205
222
})
206
223
···
226
243
if err != nil {
227
244
continue
228
245
}
229
229
-
labelerprofile, _, _ := appbskyactordefs.ProfileView(ctx, did, sl, BSKYIMAGECDN_URL)
246
246
+
rawdid := c.GetString("user_did")
247
247
+
var viewer *utils.DID
248
248
+
didval, errdid := utils.NewDID(rawdid)
249
249
+
if errdid != nil {
250
250
+
viewer = nil
251
251
+
} else {
252
252
+
viewer = &didval
253
253
+
}
254
254
+
labelerprofile, _, _ := appbskyactordefs.ProfileView(ctx, did, sl, cs, BSKYIMAGECDN_URL, viewer)
230
255
labelerserviceresponse, _ := agnostic.RepoGetRecord(ctx, sl, "", "app.bsky.labeler.service", string(did), "self")
231
256
var labelerservice appbsky.LabelerService
232
257
if labelerserviceresponse != nil {
···
329
354
if err != nil {
330
355
return
331
356
}
357
357
+
rawdid := c.GetString("user_did")
358
358
+
var viewer *utils.DID
359
359
+
didval, errdid := utils.NewDID(rawdid)
360
360
+
if errdid != nil {
361
361
+
viewer = nil
362
362
+
} else {
363
363
+
viewer = &didval
364
364
+
}
332
365
333
366
// fetch profile and record in parallel too (optional)
334
367
// but to keep it simple, do serial inside this goroutine
335
335
-
profile, _, _ := appbskyactordefs.ProfileView(ctx, repoDID, sl, BSKYIMAGECDN_URL)
368
368
+
profile, _, _ := appbskyactordefs.ProfileView(ctx, repoDID, sl, cs, BSKYIMAGECDN_URL, viewer)
336
369
337
370
rec, err := agnostic.RepoGetRecord(ctx, sl, "", collection, did, rkey)
338
371
if err != nil || rec.Value == nil {
+88
-7
shims/lex/app/bsky/actor/defs/profileview.go
···
3
3
import (
4
4
"context"
5
5
"encoding/json"
6
6
+
"log"
6
7
7
8
"github.com/bluesky-social/indigo/api/agnostic"
8
9
appbsky "github.com/bluesky-social/indigo/api/bsky"
10
10
+
"github.com/bluesky-social/indigo/atproto/syntax"
9
11
"tangled.org/whey.party/red-dwarf-server/microcosm"
10
12
"tangled.org/whey.party/red-dwarf-server/microcosm/constellation"
11
13
"tangled.org/whey.party/red-dwarf-server/microcosm/slingshot"
12
14
"tangled.org/whey.party/red-dwarf-server/shims/utils"
13
15
)
14
16
15
15
-
func ProfileViewBasic(ctx context.Context, did utils.DID, sl *microcosm.MicrocosmClient, imgcdn string) (*appbsky.ActorDefs_ProfileViewBasic, *appbsky.ActorProfile, error) {
16
16
-
profileview, profile, err := ProfileView(ctx, did, sl, imgcdn)
17
17
+
func ProfileViewBasic(ctx context.Context, did utils.DID, sl *microcosm.MicrocosmClient, cs *microcosm.MicrocosmClient, imgcdn string, viewer *utils.DID) (*appbsky.ActorDefs_ProfileViewBasic, *appbsky.ActorProfile, error) {
18
18
+
profileview, profile, err := ProfileView(ctx, did, sl, cs, imgcdn, viewer)
17
19
18
20
if err != nil {
19
21
return nil, nil, err
···
38
40
}, profile, err
39
41
}
40
42
41
41
-
func ProfileView(ctx context.Context, did utils.DID, sl *microcosm.MicrocosmClient, imgcdn string) (*appbsky.ActorDefs_ProfileView, *appbsky.ActorProfile, error) {
43
43
+
func ProfileView(ctx context.Context, did utils.DID, sl *microcosm.MicrocosmClient, cs *microcosm.MicrocosmClient, imgcdn string, viewer *utils.DID) (*appbsky.ActorDefs_ProfileView, *appbsky.ActorProfile, error) {
42
44
identity, err_i := slingshot.ResolveMiniDoc(ctx, sl, string(did))
43
45
if err_i != nil {
44
46
identity = nil
···
76
78
avatar = &url
77
79
}
78
80
81
81
+
var blocking *string
82
82
+
blockedBy := false
83
83
+
var following *string
84
84
+
var followedBy *string
85
85
+
86
86
+
viewerProfileDID := ""
87
87
+
if viewer != nil {
88
88
+
viewerProfileDID = string(*viewer)
89
89
+
}
90
90
+
targetProfileDID := string(did)
91
91
+
//viewerProfileURI, err_viewerProfileURI := syntax.ParseATURI("at://" + viewerProfileDID + "/app.bsky.actor.profile/self")
92
92
+
//targetProfileURI, err_targetProfileURI := syntax.ParseATURI("at://" + targetProfileDID + "/app.bsky.actor.profile/self")
93
93
+
94
94
+
log.Println("viewerProfileDID: " + viewerProfileDID + " and targetProfileDID: " + targetProfileDID)
95
95
+
96
96
+
if viewerProfileDID != "" && targetProfileDID != "" {
97
97
+
blockingBacklink, err_blockingBacklink := constellation.GetBacklinks(ctx, cs, targetProfileDID, "app.bsky.graph.block:subject", []string{viewerProfileDID}, nil, nil)
98
98
+
if err_blockingBacklink == nil && blockingBacklink.Records != nil && len(blockingBacklink.Records) > 0 && blockingBacklink.Total > 0 {
99
99
+
blockingATURI, err_blockingATURI := syntax.ParseATURI("at://" + blockingBacklink.Records[0].Did + "/app.bsky.graph.block/" + blockingBacklink.Records[0].Rkey)
100
100
+
if err_blockingATURI == nil {
101
101
+
blockingString := blockingATURI.String()
102
102
+
blocking = &blockingString
103
103
+
}
104
104
+
}
105
105
+
blockedByBacklink, err_blockedByBacklink := constellation.GetBacklinks(ctx, cs, viewerProfileDID, "app.bsky.graph.block:subject", []string{targetProfileDID}, nil, nil)
106
106
+
if err_blockedByBacklink == nil && blockedByBacklink.Records != nil && len(blockedByBacklink.Records) > 0 && blockedByBacklink.Total > 0 {
107
107
+
_, err_blockedByATURI := syntax.ParseATURI("at://" + blockedByBacklink.Records[0].Did + "/app.bsky.graph.block/" + blockedByBacklink.Records[0].Rkey)
108
108
+
if err_blockedByATURI == nil {
109
109
+
blockedBy = true
110
110
+
}
111
111
+
}
112
112
+
followingBacklink, err_followingBacklink := constellation.GetBacklinks(ctx, cs, targetProfileDID, "app.bsky.graph.follow:subject", []string{viewerProfileDID}, nil, nil)
113
113
+
if err_followingBacklink == nil && followingBacklink.Records != nil && len(followingBacklink.Records) > 0 && followingBacklink.Total > 0 {
114
114
+
followingATURI, err_followingATURI := syntax.ParseATURI("at://" + followingBacklink.Records[0].Did + "/app.bsky.graph.follow/" + followingBacklink.Records[0].Rkey)
115
115
+
if err_followingATURI == nil {
116
116
+
followingString := followingATURI.String()
117
117
+
following = &followingString
118
118
+
}
119
119
+
}
120
120
+
followedByBacklink, err_followedByBacklink := constellation.GetBacklinks(ctx, cs, viewerProfileDID, "app.bsky.graph.follow:subject", []string{targetProfileDID}, nil, nil)
121
121
+
if err_followedByBacklink == nil && followedByBacklink.Records != nil && len(followedByBacklink.Records) > 0 && followedByBacklink.Total > 0 {
122
122
+
followedByATURI, err_followedByATURI := syntax.ParseATURI("at://" + followedByBacklink.Records[0].Did + "/app.bsky.graph.follow/" + followedByBacklink.Records[0].Rkey)
123
123
+
if err_followedByATURI == nil {
124
124
+
followedByString := followedByATURI.String()
125
125
+
followedBy = &followedByString
126
126
+
}
127
127
+
}
128
128
+
129
129
+
}
130
130
+
131
131
+
// we dont know before hand, so to make it visible on the page, we must set it to be non zero
132
132
+
nonzeroassociated := int64(1)
133
133
+
79
134
return &appbsky.ActorDefs_ProfileView{
80
80
-
Associated: nil,
135
135
+
Associated: &appbsky.ActorDefs_ProfileAssociated{
136
136
+
// ActivitySubscription *ActorDefs_ProfileAssociatedActivitySubscription `json:"activitySubscription,omitempty" cborgen:"activitySubscription,omitempty"`
137
137
+
// Chat *ActorDefs_ProfileAssociatedChat `json:"chat,omitempty" cborgen:"chat,omitempty"`
138
138
+
// Feedgens *int64 `json:"feedgens,omitempty" cborgen:"feedgens,omitempty"`
139
139
+
Feedgens: &nonzeroassociated,
140
140
+
// Labeler *bool `json:"labeler,omitempty" cborgen:"labeler,omitempty"`
141
141
+
// Lists *int64 `json:"lists,omitempty" cborgen:"lists,omitempty"`
142
142
+
Lists: &nonzeroassociated,
143
143
+
// StarterPacks *int64 `json:"starterPacks,omitempty" cborgen:"starterPacks,omitempty"`
144
144
+
StarterPacks: &nonzeroassociated,
145
145
+
},
81
146
Avatar: avatar,
82
147
CreatedAt: profile.CreatedAt,
83
148
Debug: nil,
···
90
155
Pronouns: nil,
91
156
Status: nil,
92
157
Verification: nil,
93
93
-
Viewer: nil,
158
158
+
Viewer: &appbsky.ActorDefs_ViewerState{
159
159
+
// // activitySubscription: This property is present only in selected cases, as an optimization.
160
160
+
// ActivitySubscription *NotificationDefs_ActivitySubscription `json:"activitySubscription,omitempty" cborgen:"activitySubscription,omitempty"`
161
161
+
// BlockedBy *bool `json:"blockedBy,omitempty" cborgen:"blockedBy,omitempty"`
162
162
+
BlockedBy: &blockedBy,
163
163
+
// Blocking *string `json:"blocking,omitempty" cborgen:"blocking,omitempty"`
164
164
+
Blocking: blocking,
165
165
+
// BlockingByList *GraphDefs_ListViewBasic `json:"blockingByList,omitempty" cborgen:"blockingByList,omitempty"`
166
166
+
// FollowedBy *string `json:"followedBy,omitempty" cborgen:"followedBy,omitempty"`
167
167
+
FollowedBy: followedBy,
168
168
+
// Following *string `json:"following,omitempty" cborgen:"following,omitempty"`
169
169
+
Following: following,
170
170
+
// // knownFollowers: This property is present only in selected cases, as an optimization.
171
171
+
// KnownFollowers *ActorDefs_KnownFollowers `json:"knownFollowers,omitempty" cborgen:"knownFollowers,omitempty"`
172
172
+
// Muted *bool `json:"muted,omitempty" cborgen:"muted,omitempty"`
173
173
+
// MutedByList *GraphDefs_ListViewBasic `json:"mutedByList,omitempty" cborgen:"mutedByList,omitempty"`
174
174
+
},
94
175
}, &profile, nil
95
176
}
96
177
97
97
-
func ProfileViewDetailed(ctx context.Context, did utils.DID, sl *microcosm.MicrocosmClient, cs *microcosm.MicrocosmClient, imgcdn string) (*appbsky.ActorDefs_ProfileViewDetailed, *appbsky.ActorProfile, error) {
98
98
-
profileview, profile, err := ProfileView(ctx, did, sl, imgcdn)
178
178
+
func ProfileViewDetailed(ctx context.Context, did utils.DID, sl *microcosm.MicrocosmClient, cs *microcosm.MicrocosmClient, imgcdn string, viewer *utils.DID) (*appbsky.ActorDefs_ProfileViewDetailed, *appbsky.ActorProfile, error) {
179
179
+
profileview, profile, err := ProfileView(ctx, did, sl, cs, imgcdn, viewer)
99
180
if err != nil {
100
181
return nil, nil, err
101
182
}
+1
-1
shims/lex/app/bsky/feed/defs/embed.go
···
291
291
292
292
if collection == "app.bsky.feed.post" {
293
293
//t.EmbedRecord_ViewRecord.LexiconTypeID = "app.bsky.embed.record#viewRecord"
294
294
-
profileViewBasic, _, err := appbskyactordefs.ProfileViewBasic(ctx, utils.DID(aturi.Authority().String()), sl, imgcdn)
294
294
+
profileViewBasic, _, err := appbskyactordefs.ProfileViewBasic(ctx, utils.DID(aturi.Authority().String()), sl, cs, imgcdn, viewer)
295
295
if err != nil {
296
296
log.Println("[EmbedRecord_View_Record] profileviewbasic failed")
297
297
return notFoundRecordEmbed(aturi.String())
+1
-1
shims/lex/app/bsky/feed/defs/postview.go
···
49
49
}
50
50
//}
51
51
52
52
-
profile, _, err := appbskyactordefs.ProfileViewBasic(ctx, repoDID, sl, imgcdn)
52
52
+
profile, _, err := appbskyactordefs.ProfileViewBasic(ctx, repoDID, sl, cs, imgcdn, viewer)
53
53
if err != nil || profile == nil {
54
54
if profile == nil {
55
55
//log.Println("WHAT!! profile / author field is null?!?!?! whyyy")