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