Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[C-5203] Fix comment unpin #10102

Merged
merged 2 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/common/src/adapters/track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ export const userTrackMetadataFromSDK = (
rights_controller: input.rightsController
? (snakecaseKeys(input.rightsController) as RightsController)
: null,
save_count: input.favoriteCount
save_count: input.favoriteCount,
pinned_comment_id: input.pinnedCommentId ?? null
}

return newTrack
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def test_comment_pin(app, mocker):
{"user_id": 1, "handle": "user-1", "wallet": "user1wallet"},
{"user_id": 2, "handle": "user-2", "wallet": "user2wallet"},
],
"tracks": [{"track_id": 1, "owner_id": 1, "pinned_comment_id": 2}],
"tracks": [{"track_id": 1, "owner_id": 1}],
"comments": [{"comment_id": 1, "user_id": 2}, {"comment_id": 2, "user_id": 2}],
}

Expand Down Expand Up @@ -237,8 +237,8 @@ def test_comment_unpin(app, mocker):
{"user_id": 1, "handle": "user-1", "wallet": "user1wallet"},
{"user_id": 2, "handle": "user-2", "wallet": "user2wallet"},
],
"tracks": [{"track_id": 1, "owner_id": 1}],
"comments": [{"comment_id": 1, "user_id": 2, "is_pinned": True}],
"tracks": [{"track_id": 1, "owner_id": 1, "pinned_comment_id": 1}],
"comments": [{"comment_id": 1, "user_id": 2}],
}

tx_receipts = {
Expand Down Expand Up @@ -274,6 +274,48 @@ def test_comment_unpin(app, mocker):
assert tracks[0].pinned_comment_id == None


def test_comment_repin(app, mocker):
entities = {
"users": [
{"user_id": 1, "handle": "user-1", "wallet": "user1wallet"},
],
"tracks": [{"track_id": 1, "owner_id": 1, "pinned_comment_id": 2}],
"comments": [{"comment_id": 1, "user_id": 2}, {"comment_id": 2, "user_id": 2}],
}

tx_receipts = {
"PinComment": [
{
"args": AttributeDict(
{
"_entityId": 1,
"_entityType": "Comment",
"_userId": 1,
"_action": "Pin",
"_metadata": f'{{"cid": "", "data": {json.dumps({"entity_id": 1})}}}',
"_signer": "user1wallet",
}
)
},
],
}

entity_manager_txs, db, update_task = setup_test(app, mocker, entities, tx_receipts)

with db.scoped_session() as session:
entity_manager_update(
update_task,
session,
entity_manager_txs,
block_number=0,
block_timestamp=1585336422,
block_hash=hex(0),
)

tracks = session.query(Track).filter(Track.track_id == 1).all()
assert tracks[0].pinned_comment_id == 1


def test_dupe_pin(app, mocker):
entities = {
"users": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,7 @@ export interface TrackRow {
musical_key?: string | null
is_custom_musical_key?: boolean | null
audio_analysis_error_count?: number
pinned_comment_id?: number | null
}
export interface TrendingParamRow {
genre?: string | null
Expand Down Expand Up @@ -837,7 +838,6 @@ export interface CommentRow {
text: string
is_delete: boolean
is_visible: boolean
is_pinned: boolean
is_edited: boolean
txhash?: string
}
Expand Down
2 changes: 2 additions & 0 deletions packages/discovery-provider/src/api/v1/models/tracks.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
"is_streamable": fields.Boolean,
"ddex_app": fields.String(allow_null=True),
"playlists_containing_track": fields.List(fields.Integer),
"pinned_comment_id": fields.Integer(allow_null=True),
},
)

Expand Down Expand Up @@ -206,6 +207,7 @@
"download_conditions": NestedOneOf(
access_gate, allow_null=True, description="How to unlock the track download"
),
"pinned_comment_id": fields.Integer(allow_null=True),
},
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def pin_comment(params: ManageEntityParameters):


def unpin_comment(params: ManageEntityParameters):
validate_pin_tx(params, True)
validate_pin_tx(params, False)
track_id = params.metadata["entity_id"]
existing_track = params.existing_records[EntityType.TRACK.value][track_id]

Expand Down
8 changes: 5 additions & 3 deletions packages/harmony/src/components/icon-text/IconText.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Fragment } from 'react'

import { Flex } from 'components/layout'
import { Text } from 'components/text'

Expand All @@ -17,10 +19,10 @@ export const IconText = ({
return (
<Flex h='l' gap='xs' alignItems='center'>
{icons.map(({ icon: Icon, color: iconColor = 'default' }, index) => (
<>
<Fragment key={`icon${index}`}>
{index > 0 ? separator : null}
<Icon key={`icon${index}`} size='2xs' color={iconColor} />
</>
<Icon size='2xs' color={iconColor} />
</Fragment>
))}
<Text variant='body' size='xs' color={color}>
{children}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Fragment } from 'react'

import { Flex, Text } from '../..'

import type { IconTextProps } from './types'
Expand All @@ -20,10 +22,10 @@ export const IconText = ({
return (
<Flex direction='row' h='l' gap='xs' alignItems='center'>
{icons.map(({ icon: Icon, color: iconColor = 'default' }, index) => (
<>
<Fragment key={`icon${index}`}>
{index > 0 ? separator : null}
<Icon key={`icon${index}`} size='2xs' color={iconColor} />
</>
<Icon size='2xs' color={iconColor} />
</Fragment>
))}
<Text variant='body' size='xs' color={color}>
{children}
Expand Down
8 changes: 8 additions & 0 deletions packages/sdk/src/sdk/api/generated/default/models/Track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,12 @@ export interface Track {
* @memberof Track
*/
playlistsContainingTrack?: Array<number>;
/**
*
* @type {number}
* @memberof Track
*/
pinnedCommentId?: number;
}

/**
Expand Down Expand Up @@ -248,6 +254,7 @@ export function TrackFromJSONTyped(json: any, ignoreDiscriminator: boolean): Tra
'isStreamable': !exists(json, 'is_streamable') ? undefined : json['is_streamable'],
'ddexApp': !exists(json, 'ddex_app') ? undefined : json['ddex_app'],
'playlistsContainingTrack': !exists(json, 'playlists_containing_track') ? undefined : json['playlists_containing_track'],
'pinnedCommentId': !exists(json, 'pinned_comment_id') ? undefined : json['pinned_comment_id'],
};
}

Expand Down Expand Up @@ -285,6 +292,7 @@ export function TrackToJSON(value?: Track | null): any {
'is_streamable': value.isStreamable,
'ddex_app': value.ddexApp,
'playlists_containing_track': value.playlistsContainingTrack,
'pinned_comment_id': value.pinnedCommentId,
};
}

Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,12 @@ export interface SearchTrackFull {
* @memberof SearchTrackFull
*/
playlistsContainingTrack?: Array<number>;
/**
*
* @type {number}
* @memberof SearchTrackFull
*/
pinnedCommentId?: number;
/**
* Describes what access the given user has
* @type {Access}
Expand Down Expand Up @@ -596,6 +602,7 @@ export function SearchTrackFullFromJSONTyped(json: any, ignoreDiscriminator: boo
'isStreamable': !exists(json, 'is_streamable') ? undefined : json['is_streamable'],
'ddexApp': !exists(json, 'ddex_app') ? undefined : json['ddex_app'],
'playlistsContainingTrack': !exists(json, 'playlists_containing_track') ? undefined : json['playlists_containing_track'],
'pinnedCommentId': !exists(json, 'pinned_comment_id') ? undefined : json['pinned_comment_id'],
'access': AccessFromJSON(json['access']),
'blocknumber': json['blocknumber'],
'createDate': !exists(json, 'create_date') ? undefined : json['create_date'],
Expand Down Expand Up @@ -680,6 +687,7 @@ export function SearchTrackFullToJSON(value?: SearchTrackFull | null): any {
'is_streamable': value.isStreamable,
'ddex_app': value.ddexApp,
'playlists_containing_track': value.playlistsContainingTrack,
'pinned_comment_id': value.pinnedCommentId,
'access': AccessToJSON(value.access),
'blocknumber': value.blocknumber,
'create_date': value.createDate,
Expand Down
8 changes: 8 additions & 0 deletions packages/sdk/src/sdk/api/generated/full/models/TrackFull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,12 @@ export interface TrackFull {
* @memberof TrackFull
*/
playlistsContainingTrack?: Array<number>;
/**
*
* @type {number}
* @memberof TrackFull
*/
pinnedCommentId?: number;
/**
* Describes what access the given user has
* @type {Access}
Expand Down Expand Up @@ -598,6 +604,7 @@ export function TrackFullFromJSONTyped(json: any, ignoreDiscriminator: boolean):
'isStreamable': !exists(json, 'is_streamable') ? undefined : json['is_streamable'],
'ddexApp': !exists(json, 'ddex_app') ? undefined : json['ddex_app'],
'playlistsContainingTrack': !exists(json, 'playlists_containing_track') ? undefined : json['playlists_containing_track'],
'pinnedCommentId': !exists(json, 'pinned_comment_id') ? undefined : json['pinned_comment_id'],
'access': AccessFromJSON(json['access']),
'blocknumber': json['blocknumber'],
'createDate': !exists(json, 'create_date') ? undefined : json['create_date'],
Expand Down Expand Up @@ -682,6 +689,7 @@ export function TrackFullToJSON(value?: TrackFull | null): any {
'is_streamable': value.isStreamable,
'ddex_app': value.ddexApp,
'playlists_containing_track': value.playlistsContainingTrack,
'pinned_comment_id': value.pinnedCommentId,
'access': AccessToJSON(value.access),
'blocknumber': value.blocknumber,
'create_date': value.createDate,
Expand Down