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