-
Notifications
You must be signed in to change notification settings - Fork 133
[PE-6132] Artist-side remix contest ended notification #12044
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@audius/sdk": patch | ||
| --- | ||
|
|
||
| Artist remix contest ended notification |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...iscovery-provider/integration_tests/tasks/test_artist_remix_contest_ended_notification.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import logging | ||
| from datetime import datetime, timedelta | ||
|
|
||
| from integration_tests.utils import populate_mock_db | ||
| from src.models.notifications.notification import Notification | ||
| from src.tasks.remix_contest_notifications.artist_remix_contest_ended import ( | ||
| create_artist_remix_contest_ended_notifications, | ||
| ) | ||
| from src.utils.db_session import get_db | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| TEST_EVENT_CREATOR_ID = 1 | ||
| TEST_TRACK_ID = 100 | ||
|
|
||
|
|
||
| def test_artist_remix_contest_ended_notification(app): | ||
| """Test that artist remix contest ended notification is created for the contest creator when the contest ends""" | ||
| with app.app_context(): | ||
| db = get_db() | ||
|
|
||
| now = datetime.now() | ||
| end_date = now - timedelta(hours=1) | ||
|
|
||
| entities = { | ||
| "users": [ | ||
| { | ||
| "user_id": TEST_EVENT_CREATOR_ID, | ||
| "is_current": True, | ||
| "created_at": now, | ||
| "updated_at": now, | ||
| } | ||
| ], | ||
| "tracks": [ | ||
| { | ||
| "track_id": TEST_TRACK_ID, | ||
| "owner_id": TEST_EVENT_CREATOR_ID, | ||
| "is_current": True, | ||
| "is_delete": False, | ||
| "created_at": now, | ||
| "updated_at": now, | ||
| } | ||
| ], | ||
| "events": [ | ||
| { | ||
| "event_id": 1, | ||
| "event_type": "remix_contest", | ||
| "user_id": TEST_EVENT_CREATOR_ID, | ||
| "entity_id": TEST_TRACK_ID, | ||
| "entity_type": "track", | ||
| "is_deleted": False, | ||
| "created_at": now, | ||
| "updated_at": now, | ||
| "end_date": end_date, | ||
| } | ||
| ], | ||
| } | ||
| populate_mock_db(db, entities) | ||
|
|
||
| with db.scoped_session() as session: | ||
| create_artist_remix_contest_ended_notifications(session, now=now) | ||
| notifications = ( | ||
| session.query(Notification) | ||
| .filter(Notification.type == "artist_remix_contest_ended") | ||
| .all() | ||
| ) | ||
| assert len(notifications) == 1 | ||
| notification = notifications[0] | ||
| assert notification.user_ids == [TEST_EVENT_CREATOR_ID] | ||
| assert notification.data["entity_id"] == TEST_TRACK_ID |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...es/discovery-provider/src/tasks/remix_contest_notifications/artist_remix_contest_ended.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| from datetime import datetime, timedelta | ||
|
|
||
| from src.models.events.event import Event, EventType | ||
| from src.models.notifications.notification import Notification | ||
| from src.utils.structured_logger import StructuredLogger | ||
|
|
||
| ARTIST_REMIX_CONTEST_ENDED = "artist_remix_contest_ended" | ||
| REMIX_CONTEST_ENDED_WINDOW_HOURS = 24 | ||
|
|
||
| logger = StructuredLogger(__name__) | ||
|
|
||
|
|
||
| def get_artist_remix_contest_ended_group_id(event_id): | ||
| return f"{ARTIST_REMIX_CONTEST_ENDED}:{event_id}" | ||
|
|
||
|
|
||
| def create_artist_remix_contest_ended_notifications(session, now=None): | ||
| now = now or datetime.now() | ||
| window_start = now - timedelta(hours=REMIX_CONTEST_ENDED_WINDOW_HOURS) | ||
| window_end = now | ||
|
|
||
| ended_contests = ( | ||
| session.query(Event) | ||
| .filter( | ||
| Event.event_type == EventType.remix_contest, | ||
| Event.is_deleted == False, | ||
| Event.end_date != None, | ||
| Event.end_date.between(window_start, window_end), | ||
| ) | ||
| .all() | ||
| ) | ||
|
|
||
| new_notifications = [] | ||
| for event in ended_contests: | ||
| group_id = get_artist_remix_contest_ended_group_id(event.event_id) | ||
| exists = ( | ||
| session.query(Notification) | ||
| .filter( | ||
| Notification.group_id == group_id, | ||
| Notification.type == ARTIST_REMIX_CONTEST_ENDED, | ||
| Notification.user_ids.any(event.user_id), | ||
| ) | ||
| .first() | ||
| ) | ||
| if not exists: | ||
| new_notification = Notification( | ||
| specifier=str(event.user_id), | ||
| group_id=group_id, | ||
| blocknumber=None, | ||
| user_ids=[event.user_id], | ||
| type=ARTIST_REMIX_CONTEST_ENDED, | ||
| data={ | ||
| "entity_id": event.entity_id, | ||
| }, | ||
| timestamp=now, | ||
| ) | ||
| new_notifications.append(new_notification) | ||
| logger.info( | ||
| f"Inserting {len(new_notifications)} artist remix contest ended notifications" | ||
| ) | ||
| session.add_all(new_notifications) | ||
| session.commit() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...le/src/screens/notifications-screen/Notifications/ArtistRemixContestEndedNotification.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import { useCallback } from 'react' | ||
|
|
||
| import { useTrack } from '@audius/common/api' | ||
| import type { ArtistRemixContestEndedNotification as ArtistRemixContestEndedNotificationType } from '@audius/common/store' | ||
|
|
||
| import { IconTrophy } from '@audius/harmony-native' | ||
| import { useNotificationNavigation } from 'app/hooks/useNotificationNavigation' | ||
|
|
||
| import { | ||
| NotificationHeader, | ||
| NotificationText, | ||
| NotificationTile, | ||
| NotificationTitle | ||
| } from '../Notification' | ||
|
|
||
| const messages = { | ||
| title: 'Your Remix Contest Ended', | ||
| description: | ||
| "Your remix contest has ended. Don't forget to contact your winners!" | ||
| } | ||
|
|
||
| type ArtistRemixContestEndedNotificationProps = { | ||
| notification: ArtistRemixContestEndedNotificationType | ||
| } | ||
|
|
||
| export const ArtistRemixContestEndedNotification = ( | ||
| props: ArtistRemixContestEndedNotificationProps | ||
| ) => { | ||
| const { notification } = props | ||
| const { entityId } = notification | ||
|
|
||
| const navigation = useNotificationNavigation() | ||
| const { data: track } = useTrack(entityId) | ||
|
|
||
| const handlePress = useCallback(() => { | ||
| if (track) { | ||
| navigation.navigate(notification) | ||
| } | ||
| }, [track, navigation, notification]) | ||
|
|
||
| if (!track) return null | ||
|
|
||
| return ( | ||
| <NotificationTile notification={notification} onPress={handlePress}> | ||
| <NotificationHeader icon={IconTrophy}> | ||
| <NotificationTitle>{messages.title}</NotificationTitle> | ||
| </NotificationHeader> | ||
| <NotificationText>{messages.description}</NotificationText> | ||
| </NotificationTile> | ||
| ) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are we using contact here under the 'pick your winners' milestone is in?