Skip to content

Commit 70dbc44

Browse files
authored
Add coin-gated text posts (#742)
1 parent bff2ecc commit 70dbc44

8 files changed

Lines changed: 921 additions & 26 deletions

File tree

api/dbv1/access.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ func (q *Queries) GetBulkTrackAccess(
323323
var mint string
324324
var balance int64
325325
if err := rows.Scan(&mint, &balance); err == nil {
326-
walletTokenBalances[mint] = balance
326+
walletTokenBalances[mint] += balance
327327
}
328328
}
329329
return rows.Err()

api/dbv1/full_comments.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ type FullComment struct {
4040
Replies []FullComment `json:"replies"`
4141
ParentCommentId pgtype.Int4 `json:"parent_comment_id"`
4242

43-
// this should be omitted
4443
ReplyIds []int32 `db:"reply_ids" json:"-"`
4544
}
4645

@@ -51,12 +50,12 @@ func (q *Queries) FullCommentsKeyed(ctx context.Context, arg GetCommentsParams)
5150

5251
sql := `
5352
SELECT
54-
comment_id as id,
55-
parent_comment_id,
56-
entity_type,
57-
entity_id,
58-
user_id,
59-
text as message,
53+
comments.comment_id AS id,
54+
comment_threads.parent_comment_id,
55+
comments.entity_type,
56+
comments.entity_id,
57+
comments.user_id,
58+
comments.text AS message,
6059
6160
(
6261
SELECT json_agg(
@@ -72,7 +71,7 @@ func (q *Queries) FullCommentsKeyed(ctx context.Context, arg GetCommentsParams)
7271
) m
7372
)::jsonb as mentions,
7473
75-
track_timestamp_s,
74+
comments.track_timestamp_s,
7675
7776
(
7877
SELECT count(*)
@@ -90,7 +89,7 @@ func (q *Queries) FullCommentsKeyed(ctx context.Context, arg GetCommentsParams)
9089
AND cc.is_delete = false
9190
) as reply_ids,
9291
93-
is_edited,
92+
comments.is_edited,
9493
9594
EXISTS (
9695
SELECT 1
@@ -104,7 +103,7 @@ func (q *Queries) FullCommentsKeyed(ctx context.Context, arg GetCommentsParams)
104103
SELECT 1
105104
FROM comment_reactions
106105
WHERE comment_id = comments.comment_id
107-
AND user_id = tracks.owner_id
106+
AND user_id = COALESCE(tracks.owner_id, comments.entity_id)
108107
AND is_delete = false
109108
) AS is_artist_reacted,
110109
@@ -115,19 +114,22 @@ func (q *Queries) FullCommentsKeyed(ctx context.Context, arg GetCommentsParams)
115114
FROM comment_notification_settings mutes
116115
WHERE @my_id > 0
117116
AND mutes.user_id = @my_id
118-
AND mutes.entity_type = entity_type
119-
AND mutes.entity_id = entity_id
117+
AND mutes.entity_type = comments.entity_type
118+
AND mutes.entity_id = comments.entity_id
120119
LIMIT 1
121120
), false) as is_muted,
122121
123122
comments.created_at,
124123
comments.updated_at
125124
126125
FROM comments
127-
JOIN tracks ON entity_id = track_id
126+
LEFT JOIN tracks ON comments.entity_type = 'Track' AND comments.entity_id = tracks.track_id
128127
LEFT JOIN comment_threads USING (comment_id)
129-
WHERE comment_id = ANY(@ids::int[])
130-
AND (@include_unlisted = true OR tracks.is_unlisted = false)
128+
WHERE comments.comment_id = ANY(@ids::int[])
129+
AND (
130+
(comments.entity_type = 'Track' AND (@include_unlisted = true OR COALESCE(tracks.is_unlisted, false) = false))
131+
OR comments.entity_type = 'FanClub'
132+
)
131133
ORDER BY comments.created_at DESC
132134
`
133135

@@ -150,7 +152,6 @@ func (q *Queries) FullCommentsKeyed(ctx context.Context, arg GetCommentsParams)
150152
commentMap[int32(comment.Id)] = comment
151153
}
152154

153-
// fetch replies
154155
replyIds := []int32{}
155156
for _, comment := range comments {
156157
replyIds = append(replyIds, comment.ReplyIds...)
@@ -170,7 +171,6 @@ func (q *Queries) FullCommentsKeyed(ctx context.Context, arg GetCommentsParams)
170171
comment.Replies = append(comment.Replies, reply)
171172
}
172173
}
173-
// todo: sort replies?
174174
comment.ReplyCount = len(comment.Replies)
175175

176176
if comment.IsDelete {

api/dbv1/parallel.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import (
77
)
88

99
type ParallelParams struct {
10-
UserIds []int32
11-
TrackIds []int32
12-
PlaylistIds []int32
13-
MyID int32
14-
AuthedWallet string
10+
UserIds []int32
11+
TrackIds []int32
12+
PlaylistIds []int32
13+
MyID int32
14+
AuthedWallet string
1515
}
1616

1717
type ParallelResult struct {

api/server.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,9 @@ func NewApiServer(config config.Config) *ApiServer {
507507
g.Post("/tracks/:trackId/downloads", app.requireAuthMiddleware, app.requireWriteScope, app.postV1TrackDownload)
508508
g.Put("/tracks/:trackId", app.requireAuthMiddleware, app.requireWriteScope, app.putV1Track)
509509
g.Delete("/tracks/:trackId", app.requireAuthMiddleware, app.requireWriteScope, app.deleteV1Track)
510+
g.Get("/fan_club/feed", app.v1FanClubFeed)
511+
g.Get("/fan-club/feed", app.v1FanClubFeed)
512+
510513
g.Get("/tracks/:trackId/comments", app.v1TrackComments)
511514
g.Get("/tracks/:trackId/comment_count", app.v1TrackCommentCount)
512515
g.Get("/tracks/:trackId/comment-count", app.v1TrackCommentCount)

api/swagger/swagger-v1.yaml

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,100 @@ paths:
611611
"500":
612612
description: Server error
613613
content: {}
614+
/fan_club/feed:
615+
get:
616+
tags:
617+
- fan_club
618+
description: Get the fan club feed for a given artist, including text posts and comments
619+
operationId: Get Fan Club Feed
620+
security:
621+
- {}
622+
- OAuth2:
623+
- read
624+
parameters:
625+
- name: mint
626+
in: query
627+
description: The mint address of the artist's fan club token
628+
required: true
629+
schema:
630+
type: string
631+
- name: user_id
632+
in: query
633+
description: The user ID of the user making the request
634+
schema:
635+
type: string
636+
- name: offset
637+
in: query
638+
description:
639+
The number of items to skip. Useful for pagination (page number
640+
* limit)
641+
schema:
642+
type: integer
643+
- name: limit
644+
in: query
645+
description: The number of items to fetch
646+
schema:
647+
type: integer
648+
responses:
649+
"200":
650+
description: Success
651+
content:
652+
application/json:
653+
schema:
654+
$ref: "#/components/schemas/track_comments_response"
655+
"400":
656+
description: Bad request
657+
content: {}
658+
"500":
659+
description: Server error
660+
content: {}
661+
/fan-club/feed:
662+
get:
663+
tags:
664+
- fan_club
665+
description: Get the fan club feed for a given artist (hyphenated alias), including text posts and comments
666+
operationId: Get Fan Club Feed Alias
667+
security:
668+
- {}
669+
- OAuth2:
670+
- read
671+
parameters:
672+
- name: mint
673+
in: query
674+
description: The mint address of the artist's fan club token
675+
required: true
676+
schema:
677+
type: string
678+
- name: user_id
679+
in: query
680+
description: The user ID of the user making the request
681+
schema:
682+
type: string
683+
- name: offset
684+
in: query
685+
description:
686+
The number of items to skip. Useful for pagination (page number
687+
* limit)
688+
schema:
689+
type: integer
690+
- name: limit
691+
in: query
692+
description: The number of items to fetch
693+
schema:
694+
type: integer
695+
responses:
696+
"200":
697+
description: Success
698+
content:
699+
application/json:
700+
schema:
701+
$ref: "#/components/schemas/track_comments_response"
702+
"400":
703+
description: Bad request
704+
content: {}
705+
"500":
706+
description: Server error
707+
content: {}
614708
/developer-apps:
615709
post:
616710
tags:
@@ -14682,6 +14776,7 @@ components:
1468214776
description: Type of entity that can be commented on
1468314777
enum:
1468414778
- Track
14779+
- Coin
1468514780
top_listener:
1468614781
type: object
1468714782
properties:

0 commit comments

Comments
 (0)