Skip to content

Commit 7452785

Browse files
committed
small updates
1 parent bd6b0d5 commit 7452785

File tree

4 files changed

+58
-34
lines changed

4 files changed

+58
-34
lines changed

packages/common/src/api/tan-query/comments.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ export const useReportComment = () => {
941941
replies: prevData.replies?.filter(
942942
(reply: ReplyComment) => reply.id !== commentId
943943
),
944-
replyCount: prevData.replyCount - 1
944+
replyCount: prevData.replyCount ? prevData.replyCount - 1 : 0
945945
} as Comment
946946
}
947947
)
@@ -1047,7 +1047,7 @@ export const useMuteUser = () => {
10471047
// Subtract how many replies were removed from total reply count
10481048
// NOTE: remember that not all replies by the user may be showing due to pagination
10491049
rootComment.replyCount =
1050-
rootComment.replyCount -
1050+
(rootComment.replyCount ?? 0) -
10511051
(prevReplyCount - rootComment.replies.length)
10521052
}
10531053

packages/discovery-provider/src/api/v1/users.py

+33-4
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
track_activity_full_model,
6565
track_activity_model,
6666
)
67-
from src.api.v1.models.comments import base_comment_model
67+
from src.api.v1.models.comments import comment_mention, reply_comment_model
6868
from src.api.v1.models.common import favorite
6969
from src.api.v1.models.developer_apps import authorized_app, developer_app
7070
from src.api.v1.models.extensions.fields import NestedOneOf
@@ -3196,8 +3196,31 @@ def get(self, receiving_user_id, grantor_user_id):
31963196

31973197

31983198
# Comments
3199+
user_comment_model = ns.model(
3200+
"comment",
3201+
{
3202+
"id": fields.String(required=True),
3203+
"user_id": fields.String(required=False),
3204+
"message": fields.String(required=True),
3205+
"mentions": fields.List(
3206+
fields.Nested(comment_mention),
3207+
required=False,
3208+
),
3209+
"track_timestamp_s": fields.Integer(required=False),
3210+
"react_count": fields.Integer(required=True),
3211+
"is_edited": fields.Boolean(required=True),
3212+
"is_current_user_reacted": fields.Boolean(required=False),
3213+
"is_artist_reacted": fields.Boolean(required=False),
3214+
"is_tombstone": fields.Boolean(required=False),
3215+
"is_muted": fields.Boolean(required=False),
3216+
"created_at": fields.String(required=True),
3217+
"updated_at": fields.String(required=False),
3218+
"reply_count": fields.Integer(required=False),
3219+
"replies": fields.List(fields.Nested(reply_comment_model), require=False),
3220+
},
3221+
)
31993222
user_comments_response = make_response(
3200-
"user_comments_response", ns, fields.List(fields.Nested(base_comment_model))
3223+
"user_comments_response", ns, fields.List(fields.Nested(user_comment_model))
32013224
)
32023225

32033226

@@ -3220,6 +3243,12 @@ class UserComments(Resource):
32203243
def get(self, id):
32213244
args = pagination_with_current_user_parser.parse_args()
32223245
decoded_id = decode_with_abort(id, ns)
3223-
current_user_id = args.get("user_id")
3224-
user_comments = get_user_comments(args, decoded_id, current_user_id)
3246+
current_user_id = get_current_user_id(args)
3247+
args = {
3248+
**args,
3249+
"target_user_id": decoded_id,
3250+
"current_user_id": current_user_id,
3251+
}
3252+
user_comments = get_user_comments(args)
3253+
32253254
return success_response(user_comments)

packages/discovery-provider/src/queries/get_comments.py

+15-19
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import logging # pylint: disable=C0302
1+
import logging
2+
from typing import TypedDict
23

34
from sqlalchemy import and_, asc, desc, func, or_
45
from sqlalchemy.orm import aliased
@@ -397,11 +398,22 @@ def filter_mentions(mention):
397398
return track_comment_res
398399

399400

400-
def get_user_comments(args, user_id, current_user_id):
401+
class GetUserCommentsArgs(TypedDict):
402+
sort_method: str
403+
offset: int
404+
limit: int
405+
target_user_id: int
406+
current_user_id: int
407+
408+
409+
def get_user_comments(args: GetUserCommentsArgs):
401410
offset, limit = format_offset(args), format_limit(
402411
args, default_limit=COMMENT_ROOT_DEFAULT_LIMIT
403412
)
404413

414+
user_id = args["target_user_id"]
415+
current_user_id = args["current_user_id"]
416+
405417
user_comments = []
406418
db = get_db_read_replica()
407419

@@ -444,11 +456,6 @@ def get_user_comments(args, user_id, current_user_id):
444456
mentioned_users.c.is_delete,
445457
)
446458
).label("mentions"),
447-
Track.owner_id.label("artist_id"),
448-
)
449-
.outerjoin(
450-
Track,
451-
Comment.entity_id == Track.track_id,
452459
)
453460
.outerjoin(
454461
mentioned_users,
@@ -467,7 +474,6 @@ def get_user_comments(args, user_id, current_user_id):
467474
Comment.comment_id,
468475
react_count_subquery.c.react_count,
469476
CommentNotificationSetting.is_muted,
470-
Track.owner_id,
471477
)
472478
.filter(
473479
Comment.user_id == user_id,
@@ -481,14 +487,7 @@ def get_user_comments(args, user_id, current_user_id):
481487
).all()
482488

483489
user_comments_res = []
484-
for [user_comment, react_count, is_muted, mentions, artist_id] in user_comments:
485-
replies = get_replies(
486-
session,
487-
user_comment.comment_id,
488-
current_user_id,
489-
artist_id,
490-
limit=None,
491-
)
490+
for [user_comment, react_count, is_muted, mentions] in user_comments:
492491

493492
def remove_delete(mention):
494493
del mention["is_delete"]
@@ -499,7 +498,6 @@ def filter_mentions(mention):
499498
mention["user_id"] is not None and mention["is_delete"] is not True
500499
)
501500

502-
reply_count = len(replies)
503501
user_comments_res.append(
504502
{
505503
"id": encode_int_id(user_comment.comment_id),
@@ -518,11 +516,9 @@ def filter_mentions(mention):
518516
"is_edited": user_comment.is_edited,
519517
"track_timestamp_s": user_comment.track_timestamp_s,
520518
"react_count": react_count,
521-
"reply_count": reply_count,
522519
"is_current_user_reacted": get_is_reacted(
523520
session, current_user_id, user_comment.comment_id
524521
),
525-
"replies": replies[:3],
526522
"created_at": str(user_comment.created_at),
527523
"updated_at": str(user_comment.updated_at),
528524
"is_muted": is_muted if is_muted is not None else False,

packages/sdk/src/sdk/api/generated/default/models/Comment.ts

+8-9
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,6 @@ export interface Comment {
6969
* @memberof Comment
7070
*/
7171
reactCount: number;
72-
/**
73-
*
74-
* @type {number}
75-
* @memberof Comment
76-
*/
77-
replyCount: number;
7872
/**
7973
*
8074
* @type {boolean}
@@ -117,6 +111,12 @@ export interface Comment {
117111
* @memberof Comment
118112
*/
119113
updatedAt?: string;
114+
/**
115+
*
116+
* @type {number}
117+
* @memberof Comment
118+
*/
119+
replyCount?: number;
120120
/**
121121
*
122122
* @type {Array<ReplyComment>}
@@ -133,7 +133,6 @@ export function instanceOfComment(value: object): value is Comment {
133133
isInstance = isInstance && "id" in value && value["id"] !== undefined;
134134
isInstance = isInstance && "message" in value && value["message"] !== undefined;
135135
isInstance = isInstance && "reactCount" in value && value["reactCount"] !== undefined;
136-
isInstance = isInstance && "replyCount" in value && value["replyCount"] !== undefined;
137136
isInstance = isInstance && "isEdited" in value && value["isEdited"] !== undefined;
138137
isInstance = isInstance && "createdAt" in value && value["createdAt"] !== undefined;
139138

@@ -156,14 +155,14 @@ export function CommentFromJSONTyped(json: any, ignoreDiscriminator: boolean): C
156155
'mentions': !exists(json, 'mentions') ? undefined : ((json['mentions'] as Array<any>).map(CommentMentionFromJSON)),
157156
'trackTimestampS': !exists(json, 'track_timestamp_s') ? undefined : json['track_timestamp_s'],
158157
'reactCount': json['react_count'],
159-
'replyCount': json['reply_count'],
160158
'isEdited': json['is_edited'],
161159
'isCurrentUserReacted': !exists(json, 'is_current_user_reacted') ? undefined : json['is_current_user_reacted'],
162160
'isArtistReacted': !exists(json, 'is_artist_reacted') ? undefined : json['is_artist_reacted'],
163161
'isTombstone': !exists(json, 'is_tombstone') ? undefined : json['is_tombstone'],
164162
'isMuted': !exists(json, 'is_muted') ? undefined : json['is_muted'],
165163
'createdAt': json['created_at'],
166164
'updatedAt': !exists(json, 'updated_at') ? undefined : json['updated_at'],
165+
'replyCount': !exists(json, 'reply_count') ? undefined : json['reply_count'],
167166
'replies': !exists(json, 'replies') ? undefined : ((json['replies'] as Array<any>).map(ReplyCommentFromJSON)),
168167
};
169168
}
@@ -183,14 +182,14 @@ export function CommentToJSON(value?: Comment | null): any {
183182
'mentions': value.mentions === undefined ? undefined : ((value.mentions as Array<any>).map(CommentMentionToJSON)),
184183
'track_timestamp_s': value.trackTimestampS,
185184
'react_count': value.reactCount,
186-
'reply_count': value.replyCount,
187185
'is_edited': value.isEdited,
188186
'is_current_user_reacted': value.isCurrentUserReacted,
189187
'is_artist_reacted': value.isArtistReacted,
190188
'is_tombstone': value.isTombstone,
191189
'is_muted': value.isMuted,
192190
'created_at': value.createdAt,
193191
'updated_at': value.updatedAt,
192+
'reply_count': value.replyCount,
194193
'replies': value.replies === undefined ? undefined : ((value.replies as Array<any>).map(ReplyCommentToJSON)),
195194
};
196195
}

0 commit comments

Comments
 (0)