Skip to content
This repository has been archived by the owner on Oct 4, 2023. It is now read-only.

Commit

Permalink
Update social features to use entity manager (#1853)
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacsolo committed Sep 12, 2022
1 parent 99952d1 commit ebbb561
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
84 changes: 84 additions & 0 deletions packages/common/src/services/audius-backend/AudiusBackend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,13 @@ export const audiusBackend = ({

async function repostTrack(trackId: ID) {
try {
const socialFeatureEntityManagerEnabled =
(await getFeatureEnabled(
FeatureFlags.SOCIAL_FEATURE_ENTITY_MANAGER_ENABLED
)) ?? false
if (socialFeatureEntityManagerEnabled) {
return await audiusLibs.EntityManager.repostTrack(trackId)
}
return audiusLibs.Track.addTrackRepost(trackId)
} catch (err) {
console.error(getErrorMessage(err))
Expand All @@ -1165,6 +1172,14 @@ export const audiusBackend = ({

async function undoRepostTrack(trackId: ID) {
try {
const socialFeatureEntityManagerEnabled =
(await getFeatureEnabled(
FeatureFlags.SOCIAL_FEATURE_ENTITY_MANAGER_ENABLED
)) ?? false

if (socialFeatureEntityManagerEnabled) {
return await audiusLibs.EntityManager.unrepostTrack(trackId)
}
return audiusLibs.Track.deleteTrackRepost(trackId)
} catch (err) {
console.error(getErrorMessage(err))
Expand All @@ -1174,6 +1189,15 @@ export const audiusBackend = ({

async function repostCollection(playlistId: ID) {
try {
const socialFeatureEntityManagerEnabled =
(await getFeatureEnabled(
FeatureFlags.SOCIAL_FEATURE_ENTITY_MANAGER_ENABLED
)) ?? false

if (socialFeatureEntityManagerEnabled) {
return audiusLibs.EntityManager.repostPlaylist(playlistId)
}

return audiusLibs.Playlist.addPlaylistRepost(playlistId)
} catch (err) {
console.error(getErrorMessage(err))
Expand All @@ -1183,6 +1207,14 @@ export const audiusBackend = ({

async function undoRepostCollection(playlistId: ID) {
try {
const socialFeatureEntityManagerEnabled =
(await getFeatureEnabled(
FeatureFlags.SOCIAL_FEATURE_ENTITY_MANAGER_ENABLED
)) ?? false

if (socialFeatureEntityManagerEnabled) {
return audiusLibs.EntityManager.unrepostPlaylist(playlistId)
}
return audiusLibs.Playlist.deletePlaylistRepost(playlistId)
} catch (err) {
console.error(getErrorMessage(err))
Expand Down Expand Up @@ -1493,6 +1525,15 @@ export const audiusBackend = ({

async function followUser(followeeUserId: ID) {
try {
const socialFeatureEntityManagerEnabled =
(await getFeatureEnabled(
FeatureFlags.SOCIAL_FEATURE_ENTITY_MANAGER_ENABLED
)) ?? false

if (socialFeatureEntityManagerEnabled) {
return await audiusLibs.EntityManager.followUser(followeeUserId)
}

return await audiusLibs.User.addUserFollow(followeeUserId)
} catch (err) {
console.log(getErrorMessage(err))
Expand All @@ -1502,6 +1543,15 @@ export const audiusBackend = ({

async function unfollowUser(followeeUserId: ID) {
try {
const socialFeatureEntityManagerEnabled =
(await getFeatureEnabled(
FeatureFlags.SOCIAL_FEATURE_ENTITY_MANAGER_ENABLED
)) ?? false

if (socialFeatureEntityManagerEnabled) {
return await audiusLibs.EntityManager.unfollowUser(followeeUserId)
}

return await audiusLibs.User.deleteUserFollow(followeeUserId)
} catch (err) {
console.log(getErrorMessage(err))
Expand Down Expand Up @@ -1951,6 +2001,15 @@ export const audiusBackend = ({
// Favoriting a track
async function saveTrack(trackId: ID) {
try {
const socialFeatureEntityManagerEnabled =
(await getFeatureEnabled(
FeatureFlags.SOCIAL_FEATURE_ENTITY_MANAGER_ENABLED
)) ?? false

if (socialFeatureEntityManagerEnabled) {
return await audiusLibs.EntityManager.saveTrack(trackId)
}

return await audiusLibs.Track.addTrackSave(trackId)
} catch (err) {
console.log(getErrorMessage(err))
Expand All @@ -1974,6 +2033,14 @@ export const audiusBackend = ({
// Favorite a playlist
async function saveCollection(playlistId: ID) {
try {
const socialFeatureEntityManagerEnabled =
(await getFeatureEnabled(
FeatureFlags.SOCIAL_FEATURE_ENTITY_MANAGER_ENABLED
)) ?? false

if (socialFeatureEntityManagerEnabled) {
return await audiusLibs.EntityManager.savePlaylist(playlistId)
}
return await audiusLibs.Playlist.addPlaylistSave(playlistId)
} catch (err) {
console.log(getErrorMessage(err))
Expand All @@ -1984,6 +2051,15 @@ export const audiusBackend = ({
// Unfavoriting a track
async function unsaveTrack(trackId: ID) {
try {
const socialFeatureEntityManagerEnabled =
(await getFeatureEnabled(
FeatureFlags.SOCIAL_FEATURE_ENTITY_MANAGER_ENABLED
)) ?? false

if (socialFeatureEntityManagerEnabled) {
return await audiusLibs.EntityManager.unsaveTrack(trackId)
}

return await audiusLibs.Track.deleteTrackSave(trackId)
} catch (err) {
console.log(getErrorMessage(err))
Expand All @@ -1994,6 +2070,14 @@ export const audiusBackend = ({
// Unfavorite a playlist
async function unsaveCollection(playlistId: ID) {
try {
const socialFeatureEntityManagerEnabled =
(await getFeatureEnabled(
FeatureFlags.SOCIAL_FEATURE_ENTITY_MANAGER_ENABLED
)) ?? false

if (socialFeatureEntityManagerEnabled) {
return await audiusLibs.EntityManager.unsavePlaylist(playlistId)
}
return await audiusLibs.Playlist.deletePlaylistSave(playlistId)
} catch (err) {
console.log(getErrorMessage(err))
Expand Down
2 changes: 2 additions & 0 deletions packages/common/src/services/remote-config/feature-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export enum FeatureFlags {
EARLY_ACCESS = 'early_access',
SUPPORTER_DETHRONED_ENABLED = 'supporter_dethroned_enabled',
PLAYLIST_ENTITY_MANAGER_ENABLED = 'playlist_entity_manager_enabled',
SOCIAL_FEATURE_ENTITY_MANAGER_ENABLED = 'social_feature_entity_manager_enabled',
NEW_TABLES = 'new_tables',
BUY_AUDIO_ENABLED = 'buy_audio_enabled'
}
Expand All @@ -40,6 +41,7 @@ export const flagDefaults: { [key in FeatureFlags]: boolean } = {
[FeatureFlags.EARLY_ACCESS]: false,
[FeatureFlags.SUPPORTER_DETHRONED_ENABLED]: false,
[FeatureFlags.PLAYLIST_ENTITY_MANAGER_ENABLED]: false,
[FeatureFlags.SOCIAL_FEATURE_ENTITY_MANAGER_ENABLED]: false,
[FeatureFlags.NEW_TABLES]: false,
[FeatureFlags.BUY_AUDIO_ENABLED]: false
}

0 comments on commit ebbb561

Please sign in to comment.