tangled
alpha
login
or
join now
stream.place
/
streamplace
74
fork
atom
Live video on the AT Protocol
74
fork
atom
overview
issues
1
pulls
pipelines
add GetUserFollowingUser
10xcrazy.horse
10 months ago
495dcbd0
84d012d4
+22
-22
3 changed files
expand all
collapse all
unified
split
pkg
model
follow.go
model.go
spxrpc
graph.go
+9
pkg/model/follow.go
···
49
49
var follows []Follow
50
50
return follows, m.DB.Where("subject_did = ?", userDID).Find(&follows).Error
51
51
}
52
52
+
53
53
+
func (m *DBModel) GetUserFollowingUser(ctx context.Context, userDID, subjectDID string) (*Follow, error) {
54
54
+
var follow Follow
55
55
+
result := m.DB.Where("user_did = ? AND subject_did = ?", userDID, subjectDID).First(&follow)
56
56
+
if result.RowsAffected == 0 {
57
57
+
return nil, nil
58
58
+
}
59
59
+
return &follow, result.Error
60
60
+
}
+1
pkg/model/model.go
···
54
54
CreateFollow(ctx context.Context, userDID, rev string, follow *bsky.GraphFollow) error
55
55
GetUserFollowing(ctx context.Context, userDID string) ([]Follow, error)
56
56
GetUserFollowers(ctx context.Context, userDID string) ([]Follow, error)
57
57
+
GetUserFollowingUser(ctx context.Context, userDID, subjectDID string) (*Follow, error)
57
58
DeleteFollow(ctx context.Context, userDID, rev string) error
58
59
GetFollowersNotificationTokens(userDID string) ([]string, error)
59
60
+12
-22
pkg/spxrpc/graph.go
···
5
5
"fmt"
6
6
7
7
"github.com/bluesky-social/indigo/api/atproto"
8
8
+
"github.com/bluesky-social/indigo/atproto/syntax"
8
9
"go.opentelemetry.io/otel"
9
9
-
"stream.place/streamplace/pkg/log"
10
10
placestreamtypes "stream.place/streamplace/pkg/streamplace"
11
11
)
12
12
···
14
14
ctx, span := otel.Tracer("server").Start(ctx, "handlePlaceStreamGraphGetFollowingUser")
15
15
defer span.End()
16
16
17
17
-
if userDID == "" || !isValidDID(userDID) {
18
18
-
log.Error(ctx, "Missing or invalid user DID")
19
19
-
return &placestreamtypes.GraphGetFollowingUser_Output{}, nil
17
17
+
_, didErr := syntax.ParseDID(userDID)
18
18
+
if userDID == "" || didErr != nil {
19
19
+
return nil, fmt.Errorf("Missing or invalid user DID")
20
20
}
21
21
22
22
-
follows, err := s.model.GetUserFollowing(ctx, userDID)
22
22
+
follow, err := s.model.GetUserFollowingUser(ctx, userDID, subjectDID)
23
23
if err != nil {
24
24
-
log.Error(ctx, "Failed to get user following", "error", err)
25
25
-
return &placestreamtypes.GraphGetFollowingUser_Output{}, nil
24
24
+
return nil, fmt.Errorf("Failed to get user following: %w", err)
26
25
}
27
26
28
28
-
for _, follow := range follows {
29
29
-
if follow.SubjectDID == subjectDID {
30
30
-
// User is following the subject, return the follow reference
31
31
-
return &placestreamtypes.GraphGetFollowingUser_Output{
32
32
-
Follow: &atproto.RepoStrongRef{
33
33
-
Cid: "", // We don't store CID in our model
34
34
-
Uri: fmt.Sprintf("at://%s/app.bsky.graph.follow/%s", userDID, follow.RKey),
35
35
-
},
36
36
-
}, nil
27
27
+
output := &placestreamtypes.GraphGetFollowingUser_Output{}
28
28
+
if follow != nil {
29
29
+
output.Follow = &atproto.RepoStrongRef{
30
30
+
Cid: "", // We don't store CID in our model
31
31
+
Uri: fmt.Sprintf("at://%s/app.bsky.graph.follow/%s", userDID, follow.RKey),
37
32
}
38
33
}
39
34
40
40
-
// User is not following the subject
41
41
-
return &placestreamtypes.GraphGetFollowingUser_Output{}, nil
42
42
-
}
43
43
-
44
44
-
func isValidDID(did string) bool {
45
45
-
return len(did) > 0 && (did[:7] == "did:plc" || did[:7] == "did:web")
35
35
+
return output, nil
46
36
}