Skip to content

Commit

Permalink
Use does_current_user_subscribe API field (#3943)
Browse files Browse the repository at this point in the history
  • Loading branch information
michellebrier committed Aug 25, 2023
1 parent 778a518 commit dd30c09
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/common/src/models/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type UserMetadata = {
creator_node_endpoint: Nullable<string>
current_user_followee_follow_count: number
does_current_user_follow: boolean
does_current_user_subscribe?: boolean
followee_count: number
follower_count: number
supporter_count: number
Expand Down
2 changes: 2 additions & 0 deletions packages/common/src/services/audius-api-client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export type APIUser = {
creator_node_endpoint: Nullable<string>
current_user_followee_follow_count: number
does_current_user_follow: boolean
does_current_user_subscribe?: boolean
handle_lc: string
updated_at: string
cover_photo_sizes: Nullable<CID>
Expand All @@ -73,6 +74,7 @@ export type APISearchUser = Omit<
| 'track_count'
| 'current_user_followee_follow_count'
| 'does_current_user_follow'
| 'does_current_user_subscribe'
>

export type APIRepost = {
Expand Down
11 changes: 7 additions & 4 deletions packages/web/src/common/store/profile/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,13 @@ function* fetchProfileAsync(action) {
yield fork(fetchSolanaCollectibles, user)

// Get current user notification & subscription status
const isSubscribed = yield call(
audiusBackendInstance.getUserSubscribed,
user.user_id
)
// TODO(michelle) simply use user.does_current_user_subscribe after all DNs
// are running >v0.4.6
const isSubscribed =
'does_current_user_subscribe' in user
? user.does_current_user_subscribe
: yield call(audiusBackendInstance.getUserSubscribed, user.user_id)

yield put(
profileActions.setNotificationSubscription(
user.user_id,
Expand Down
41 changes: 41 additions & 0 deletions packages/web/src/common/store/social/users/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,17 @@ export function* subscribeToUserAsync(userId: ID) {
return
}

yield* put(
cacheActions.update(Kind.USERS, [
{
id: userId,
metadata: {
does_current_user_subscribe: true
}
}
])
)

yield* call(confirmSubscribeToUser, userId, accountId)
}

Expand Down Expand Up @@ -306,6 +317,16 @@ export function* confirmSubscribeToUser(userId: ID, accountId: ID) {
timeout ? 'Timeout' : message
)
)
yield* put(
cacheActions.update(Kind.USERS, [
{
id: userId,
metadata: {
does_current_user_subscribe: false
}
}
])
)
}
)
)
Expand All @@ -319,6 +340,16 @@ export function* unsubscribeFromUserAsync(userId: ID) {
return
}

yield* put(
cacheActions.update(Kind.USERS, [
{
id: userId,
metadata: {
does_current_user_subscribe: false
}
}
])
)
yield* call(confirmUnsubscribeFromUser, userId, accountId)
}

Expand Down Expand Up @@ -352,6 +383,16 @@ export function* confirmUnsubscribeFromUser(userId: ID, accountId: ID) {
timeout ? 'Timeout' : message
)
)
yield* put(
cacheActions.update(Kind.USERS, [
{
id: userId,
metadata: {
does_current_user_subscribe: true
}
}
])
)
}
)
)
Expand Down

0 comments on commit dd30c09

Please sign in to comment.