Skip to content

Commit be18604

Browse files
dylanjefferssamgutentag
authored andcommitted
[C-5203] Fix comment unpin (#10102)
1 parent 919317b commit be18604

File tree

10 files changed

+85
-12
lines changed

10 files changed

+85
-12
lines changed

packages/common/src/adapters/track.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ export const userTrackMetadataFromSDK = (
147147
rights_controller: input.rightsController
148148
? (snakecaseKeys(input.rightsController) as RightsController)
149149
: null,
150-
save_count: input.favoriteCount
150+
save_count: input.favoriteCount,
151+
pinned_comment_id: input.pinnedCommentId ?? null
151152
}
152153

153154
return newTrack

packages/discovery-provider/integration_tests/tasks/entity_manager/test_comment.py

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def test_comment_pin(app, mocker):
194194
{"user_id": 1, "handle": "user-1", "wallet": "user1wallet"},
195195
{"user_id": 2, "handle": "user-2", "wallet": "user2wallet"},
196196
],
197-
"tracks": [{"track_id": 1, "owner_id": 1, "pinned_comment_id": 2}],
197+
"tracks": [{"track_id": 1, "owner_id": 1}],
198198
"comments": [{"comment_id": 1, "user_id": 2}, {"comment_id": 2, "user_id": 2}],
199199
}
200200

@@ -237,8 +237,8 @@ def test_comment_unpin(app, mocker):
237237
{"user_id": 1, "handle": "user-1", "wallet": "user1wallet"},
238238
{"user_id": 2, "handle": "user-2", "wallet": "user2wallet"},
239239
],
240-
"tracks": [{"track_id": 1, "owner_id": 1}],
241-
"comments": [{"comment_id": 1, "user_id": 2, "is_pinned": True}],
240+
"tracks": [{"track_id": 1, "owner_id": 1, "pinned_comment_id": 1}],
241+
"comments": [{"comment_id": 1, "user_id": 2}],
242242
}
243243

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

276276

277+
def test_comment_repin(app, mocker):
278+
entities = {
279+
"users": [
280+
{"user_id": 1, "handle": "user-1", "wallet": "user1wallet"},
281+
],
282+
"tracks": [{"track_id": 1, "owner_id": 1, "pinned_comment_id": 2}],
283+
"comments": [{"comment_id": 1, "user_id": 2}, {"comment_id": 2, "user_id": 2}],
284+
}
285+
286+
tx_receipts = {
287+
"PinComment": [
288+
{
289+
"args": AttributeDict(
290+
{
291+
"_entityId": 1,
292+
"_entityType": "Comment",
293+
"_userId": 1,
294+
"_action": "Pin",
295+
"_metadata": f'{{"cid": "", "data": {json.dumps({"entity_id": 1})}}}',
296+
"_signer": "user1wallet",
297+
}
298+
)
299+
},
300+
],
301+
}
302+
303+
entity_manager_txs, db, update_task = setup_test(app, mocker, entities, tx_receipts)
304+
305+
with db.scoped_session() as session:
306+
entity_manager_update(
307+
update_task,
308+
session,
309+
entity_manager_txs,
310+
block_number=0,
311+
block_timestamp=1585336422,
312+
block_hash=hex(0),
313+
)
314+
315+
tracks = session.query(Track).filter(Track.track_id == 1).all()
316+
assert tracks[0].pinned_comment_id == 1
317+
318+
277319
def test_dupe_pin(app, mocker):
278320
entities = {
279321
"users": [

packages/discovery-provider/plugins/notifications/src/types/dn.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,7 @@ export interface TrackRow {
659659
musical_key?: string | null
660660
is_custom_musical_key?: boolean | null
661661
audio_analysis_error_count?: number
662+
pinned_comment_id?: number | null
662663
}
663664
export interface TrendingParamRow {
664665
genre?: string | null
@@ -837,7 +838,6 @@ export interface CommentRow {
837838
text: string
838839
is_delete: boolean
839840
is_visible: boolean
840-
is_pinned: boolean
841841
is_edited: boolean
842842
txhash?: string
843843
}

packages/discovery-provider/src/api/v1/models/tracks.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
"is_streamable": fields.Boolean,
109109
"ddex_app": fields.String(allow_null=True),
110110
"playlists_containing_track": fields.List(fields.Integer),
111+
"pinned_comment_id": fields.Integer(allow_null=True),
111112
},
112113
)
113114

@@ -206,6 +207,7 @@
206207
"download_conditions": NestedOneOf(
207208
access_gate, allow_null=True, description="How to unlock the track download"
208209
),
210+
"pinned_comment_id": fields.Integer(allow_null=True),
209211
},
210212
)
211213

packages/discovery-provider/src/tasks/entity_manager/entities/comment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ def pin_comment(params: ManageEntityParameters):
328328

329329

330330
def unpin_comment(params: ManageEntityParameters):
331-
validate_pin_tx(params, True)
331+
validate_pin_tx(params, False)
332332
track_id = params.metadata["entity_id"]
333333
existing_track = params.existing_records[EntityType.TRACK.value][track_id]
334334

packages/harmony/src/components/icon-text/IconText.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Fragment } from 'react'
2+
13
import { Flex } from 'components/layout'
24
import { Text } from 'components/text'
35

@@ -17,10 +19,10 @@ export const IconText = ({
1719
return (
1820
<Flex h='l' gap='xs' alignItems='center'>
1921
{icons.map(({ icon: Icon, color: iconColor = 'default' }, index) => (
20-
<>
22+
<Fragment key={`icon${index}`}>
2123
{index > 0 ? separator : null}
22-
<Icon key={`icon${index}`} size='2xs' color={iconColor} />
23-
</>
24+
<Icon size='2xs' color={iconColor} />
25+
</Fragment>
2426
))}
2527
<Text variant='body' size='xs' color={color}>
2628
{children}

packages/mobile/src/harmony-native/components/IconText/IconText.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Fragment } from 'react'
2+
13
import { Flex, Text } from '../..'
24

35
import type { IconTextProps } from './types'
@@ -20,10 +22,10 @@ export const IconText = ({
2022
return (
2123
<Flex direction='row' h='l' gap='xs' alignItems='center'>
2224
{icons.map(({ icon: Icon, color: iconColor = 'default' }, index) => (
23-
<>
25+
<Fragment key={`icon${index}`}>
2426
{index > 0 ? separator : null}
25-
<Icon key={`icon${index}`} size='2xs' color={iconColor} />
26-
</>
27+
<Icon size='2xs' color={iconColor} />
28+
</Fragment>
2729
))}
2830
<Text variant='body' size='xs' color={color}>
2931
{children}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,12 @@ export interface Track {
189189
* @memberof Track
190190
*/
191191
playlistsContainingTrack?: Array<number>;
192+
/**
193+
*
194+
* @type {number}
195+
* @memberof Track
196+
*/
197+
pinnedCommentId?: number;
192198
}
193199

194200
/**
@@ -248,6 +254,7 @@ export function TrackFromJSONTyped(json: any, ignoreDiscriminator: boolean): Tra
248254
'isStreamable': !exists(json, 'is_streamable') ? undefined : json['is_streamable'],
249255
'ddexApp': !exists(json, 'ddex_app') ? undefined : json['ddex_app'],
250256
'playlistsContainingTrack': !exists(json, 'playlists_containing_track') ? undefined : json['playlists_containing_track'],
257+
'pinnedCommentId': !exists(json, 'pinned_comment_id') ? undefined : json['pinned_comment_id'],
251258
};
252259
}
253260

@@ -285,6 +292,7 @@ export function TrackToJSON(value?: Track | null): any {
285292
'is_streamable': value.isStreamable,
286293
'ddex_app': value.ddexApp,
287294
'playlists_containing_track': value.playlistsContainingTrack,
295+
'pinned_comment_id': value.pinnedCommentId,
288296
};
289297
}
290298

packages/sdk/src/sdk/api/generated/full/models/SearchTrackFull.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,12 @@ export interface SearchTrackFull {
237237
* @memberof SearchTrackFull
238238
*/
239239
playlistsContainingTrack?: Array<number>;
240+
/**
241+
*
242+
* @type {number}
243+
* @memberof SearchTrackFull
244+
*/
245+
pinnedCommentId?: number;
240246
/**
241247
* Describes what access the given user has
242248
* @type {Access}
@@ -596,6 +602,7 @@ export function SearchTrackFullFromJSONTyped(json: any, ignoreDiscriminator: boo
596602
'isStreamable': !exists(json, 'is_streamable') ? undefined : json['is_streamable'],
597603
'ddexApp': !exists(json, 'ddex_app') ? undefined : json['ddex_app'],
598604
'playlistsContainingTrack': !exists(json, 'playlists_containing_track') ? undefined : json['playlists_containing_track'],
605+
'pinnedCommentId': !exists(json, 'pinned_comment_id') ? undefined : json['pinned_comment_id'],
599606
'access': AccessFromJSON(json['access']),
600607
'blocknumber': json['blocknumber'],
601608
'createDate': !exists(json, 'create_date') ? undefined : json['create_date'],
@@ -680,6 +687,7 @@ export function SearchTrackFullToJSON(value?: SearchTrackFull | null): any {
680687
'is_streamable': value.isStreamable,
681688
'ddex_app': value.ddexApp,
682689
'playlists_containing_track': value.playlistsContainingTrack,
690+
'pinned_comment_id': value.pinnedCommentId,
683691
'access': AccessToJSON(value.access),
684692
'blocknumber': value.blocknumber,
685693
'create_date': value.createDate,

packages/sdk/src/sdk/api/generated/full/models/TrackFull.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,12 @@ export interface TrackFull {
237237
* @memberof TrackFull
238238
*/
239239
playlistsContainingTrack?: Array<number>;
240+
/**
241+
*
242+
* @type {number}
243+
* @memberof TrackFull
244+
*/
245+
pinnedCommentId?: number;
240246
/**
241247
* Describes what access the given user has
242248
* @type {Access}
@@ -598,6 +604,7 @@ export function TrackFullFromJSONTyped(json: any, ignoreDiscriminator: boolean):
598604
'isStreamable': !exists(json, 'is_streamable') ? undefined : json['is_streamable'],
599605
'ddexApp': !exists(json, 'ddex_app') ? undefined : json['ddex_app'],
600606
'playlistsContainingTrack': !exists(json, 'playlists_containing_track') ? undefined : json['playlists_containing_track'],
607+
'pinnedCommentId': !exists(json, 'pinned_comment_id') ? undefined : json['pinned_comment_id'],
601608
'access': AccessFromJSON(json['access']),
602609
'blocknumber': json['blocknumber'],
603610
'createDate': !exists(json, 'create_date') ? undefined : json['create_date'],
@@ -682,6 +689,7 @@ export function TrackFullToJSON(value?: TrackFull | null): any {
682689
'is_streamable': value.isStreamable,
683690
'ddex_app': value.ddexApp,
684691
'playlists_containing_track': value.playlistsContainingTrack,
692+
'pinned_comment_id': value.pinnedCommentId,
685693
'access': AccessToJSON(value.access),
686694
'blocknumber': value.blocknumber,
687695
'create_date': value.createDate,

0 commit comments

Comments
 (0)