+1
-1
cmd/handlers.go
+1
-1
cmd/handlers.go
···
425
425
426
426
// Submit to PDS as feed.play record
427
427
if user.ATProtoDID != nil && atprotoService != nil {
428
-
if err := atprotoservice.SubmitPlayToPDS(r.Context(), *user.ATProtoDID, &track, atprotoService); err != nil {
428
+
if err := atprotoservice.SubmitPlayToPDS(r.Context(), *user.ATProtoDID, *user.MostRecentAtProtoSessionID, &track, atprotoService); err != nil {
429
429
log.Printf("apiSubmitListensHandler: Error submitting play to PDS for user %d: %v", userID, err)
430
430
// Don't fail the request, just log the error
431
431
}
+6
-21
service/atproto/submission.go
+6
-21
service/atproto/submission.go
···
6
6
"log"
7
7
"time"
8
8
9
-
"github.com/bluesky-social/indigo/api/atproto"
9
+
comatproto "github.com/bluesky-social/indigo/api/atproto"
10
10
lexutil "github.com/bluesky-social/indigo/lex/util"
11
-
"github.com/bluesky-social/indigo/xrpc"
12
11
"github.com/spf13/viper"
13
12
"github.com/teal-fm/piper/api/teal"
14
-
"github.com/teal-fm/piper/db"
15
13
"github.com/teal-fm/piper/models"
16
14
atprotoauth "github.com/teal-fm/piper/oauth/atproto"
17
15
)
18
16
19
17
// SubmitPlayToPDS submits a track play to the ATProto PDS as a feed.play record
20
-
func SubmitPlayToPDS(ctx context.Context, did string, track *models.Track, atprotoService *atprotoauth.ATprotoAuthService) error {
18
+
func SubmitPlayToPDS(ctx context.Context, did string, mostRecentAtProtoSessionID string, track *models.Track, atprotoService *atprotoauth.ATprotoAuthService) error {
21
19
if did == "" {
22
20
return fmt.Errorf("DID cannot be empty")
23
21
}
24
22
25
23
// Get ATProto client
26
-
client, err := atprotoService.GetATProtoClient()
24
+
client, err := atprotoService.GetATProtoClient(did, mostRecentAtProtoSessionID, ctx)
27
25
if err != nil || client == nil {
28
26
return fmt.Errorf("failed to get ATProto client: %w", err)
29
27
}
30
28
31
-
xrpcClient := atprotoService.GetXrpcClient()
32
-
if xrpcClient == nil {
33
-
return fmt.Errorf("xrpc client is not available")
34
-
}
35
-
36
-
// Get user session
37
-
sess, err := atprotoService.DB.GetAtprotoSession(did, ctx, *client)
38
-
if err != nil {
39
-
return fmt.Errorf("couldn't get Atproto session for DID %s: %w", did, err)
40
-
}
41
-
42
29
// Convert track to feed.play record
43
30
playRecord, err := TrackToPlayRecord(track)
44
31
if err != nil {
···
46
33
}
47
34
48
35
// Create the record
49
-
input := atproto.RepoCreateRecord_Input{
36
+
input := comatproto.RepoCreateRecord_Input{
50
37
Collection: "fm.teal.alpha.feed.play",
51
-
Repo: sess.DID,
38
+
Repo: client.AccountDID.String(),
52
39
Record: &lexutil.LexiconTypeDecoder{Val: playRecord},
53
40
}
54
41
55
-
authArgs := db.AtpSessionToAuthArgs(sess)
56
-
var out atproto.RepoCreateRecord_Output
57
-
if err := xrpcClient.Do(ctx, authArgs, xrpc.Procedure, "application/json", "com.atproto.repo.createRecord", nil, input, &out); err != nil {
42
+
if _, err := comatproto.RepoCreateRecord(ctx, client, &input); err != nil {
58
43
return fmt.Errorf("failed to create play record for DID %s: %w", did, err)
59
44
}
60
45
+2
-2
service/lastfm/lastfm.go
+2
-2
service/lastfm/lastfm.go
···
413
413
return nil
414
414
}
415
415
416
-
func (l *LastFMService) SubmitTrackToPDS(did string, track *models.Track, ctx context.Context) error {
416
+
func (l *LastFMService) SubmitTrackToPDS(did string, mostRecentAtProtoSessionID string, track *models.Track, ctx context.Context) error {
417
417
// Use shared atproto service for submission
418
-
return atprotoservice.SubmitPlayToPDS(ctx, did, track, l.atprotoService)
418
+
return atprotoservice.SubmitPlayToPDS(ctx, did, mostRecentAtProtoSessionID, track, l.atprotoService)
419
419
}
420
420
421
421
// convertLastFMTrackToModelsTrack converts a Last.fm Track to models.Track format
+2
-2
service/spotify/spotify.go
+2
-2
service/spotify/spotify.go
···
59
59
}
60
60
}
61
61
62
-
func (s *SpotifyService) SubmitTrackToPDS(did string, track *models.Track, ctx context.Context) error {
62
+
func (s *SpotifyService) SubmitTrackToPDS(did string, mostRecentAtProtoSessionID string, track *models.Track, ctx context.Context) error {
63
63
//Had a empty feed.play get submitted not sure why. Tracking here
64
64
if track.Name == "" {
65
65
s.logger.Println("Track name is empty. Skipping submission. Please record the logs before and send to the teal.fm Discord")
···
67
67
}
68
68
69
69
// Use shared atproto service for submission
70
-
return atprotoservice.SubmitPlayToPDS(ctx, did, track, s.atprotoService)
70
+
return atprotoservice.SubmitPlayToPDS(ctx, did, mostRecentAtProtoSessionID, track, s.atprotoService)
71
71
}
72
72
73
73
func (s *SpotifyService) SetAccessToken(token string, refreshToken string, userId int64, hasSession bool) (int64, error) {