Skip to content

Commit

Permalink
[C-5562] Migrate follows-you to api (#10774)
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanjeffers authored Dec 18, 2024
1 parent 22420a9 commit 06c2678
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 35 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 @@ -34,6 +34,7 @@ export type UserMetadata = {
current_user_followee_follow_count: number
does_current_user_follow: boolean
does_current_user_subscribe?: boolean
does_follow_current_user: boolean
erc_wallet: WalletAddress
followee_count: number
follower_count: number
Expand Down
1 change: 1 addition & 0 deletions packages/discovery-provider/src/api/v1/models/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
"current_user_followee_follow_count": fields.Integer(required=True),
"does_current_user_follow": fields.Boolean(required=True),
"does_current_user_subscribe": fields.Boolean(required=True),
"does_follow_current_user": fields.Boolean(required=True),
"handle_lc": fields.String(required=True),
"updated_at": fields.String(required=True),
"cover_photo_sizes": fields.String,
Expand Down
19 changes: 19 additions & 0 deletions packages/discovery-provider/src/queries/query_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ def populate_user_metadata(
current_user_followed_user_ids = {}
current_user_subscribed_user_ids = {}
current_user_followee_follow_count_dict = {}
queried_user_follows_current_user_dict = {}
if current_user_id:
# does current user follow any of requested user ids
current_user_follow_rows = (
Expand All @@ -260,6 +261,20 @@ def populate_user_metadata(
for [following_id] in current_user_follow_rows:
current_user_followed_user_ids[following_id] = True

# does queried user follow current user
queried_user_follows_current_user_rows = (
session.query(Follow.follower_user_id)
.filter(
Follow.is_current == True,
Follow.is_delete == False,
Follow.follower_user_id.in_(user_ids),
Follow.followee_user_id == current_user_id,
)
.all()
)
for [follower_id] in queried_user_follows_current_user_rows:
queried_user_follows_current_user_dict[follower_id] = True

# collect all outgoing subscription edges for current user
current_user_subscribed_rows = (
session.query(Subscription)
Expand Down Expand Up @@ -341,9 +356,13 @@ def populate_user_metadata(
user[
response_name_constants.does_current_user_follow
] = current_user_followed_user_ids.get(user_id, False)
user[
response_name_constants.does_follow_current_user
] = queried_user_follows_current_user_dict.get(user_id, False)
user[
response_name_constants.does_current_user_subscribe
] = current_user_subscribed_user_ids.get(user_id, False)

user[
response_name_constants.current_user_followee_follow_count
] = current_user_followee_follow_count_dict.get(user_id, 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
does_current_user_follow = "does_current_user_follow"
# boolean - does current user subscribe to given user
does_current_user_subscribe = "does_current_user_subscribe"
# boolean - does given user follow current user
does_follow_current_user = "does_follow_current_user"
# integer - number of followees of current user that also follow given user
current_user_followee_follow_count = "current_user_followee_follow_count"
# boolean - has current user tipped given user
Expand Down
17 changes: 3 additions & 14 deletions packages/mobile/src/components/user/FollowsYouBadge.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { useGetUserById } from '@audius/common/api'
import type { ID } from '@audius/common/models'
import { trpc } from '@audius/common/services'
import { accountSelectors } from '@audius/common/store'
import { useSelector } from 'react-redux'

import { MusicBadge } from '@audius/harmony-native'

Expand All @@ -15,17 +13,8 @@ type FollowsYouBadgeProps = {

export const FollowsYouBadge = (props: FollowsYouBadgeProps) => {
const { userId } = props
const currentUserId = useSelector(accountSelectors.getUserId)
const { data } = trpc.me.userRelationship.useQuery(
{
theirId: userId.toString()
},
{
enabled: !!currentUserId
}
)

if (!data?.followsMe) return null
const { data: user } = useGetUserById({ id: userId })
if (!user?.does_follow_current_user) return null

return <MusicBadge size='s'>{messages.followsYou}</MusicBadge>
}
12 changes: 1 addition & 11 deletions packages/mobile/src/screens/chat-screen/ChatUserListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useCallback } from 'react'

import { trpc } from '@audius/common/services'
import {
accountSelectors,
cacheUsersSelectors,
Expand Down Expand Up @@ -161,15 +160,6 @@ export const ChatUserListItem = ({
)
const { onOpen: openInboxUnavailableDrawer } = useInboxUnavailableModal()

const { data: relationship } = trpc.me.userRelationship.useQuery(
{
theirId: userId.toString()
},
{
enabled: !!currentUserId
}
)

const handlePress = useCallback(() => {
if (user?.user_id) {
Keyboard.dismiss()
Expand Down Expand Up @@ -265,7 +255,7 @@ export const ChatUserListItem = ({
</View>
)}
</View>
{relationship?.followsMe && canCreateChat ? (
{user?.does_follow_current_user && canCreateChat ? (
<Text
fontSize='xxs'
weight='heavy'
Expand Down
9 changes: 9 additions & 0 deletions packages/sdk/src/sdk/api/generated/full/models/UserFull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,12 @@ export interface UserFull {
* @memberof UserFull
*/
doesCurrentUserSubscribe: boolean;
/**
*
* @type {boolean}
* @memberof UserFull
*/
doesFollowCurrentUser: boolean;
/**
*
* @type {string}
Expand Down Expand Up @@ -426,6 +432,7 @@ export function instanceOfUserFull(value: object): value is UserFull {
isInstance = isInstance && "currentUserFolloweeFollowCount" in value && value["currentUserFolloweeFollowCount"] !== undefined;
isInstance = isInstance && "doesCurrentUserFollow" in value && value["doesCurrentUserFollow"] !== undefined;
isInstance = isInstance && "doesCurrentUserSubscribe" in value && value["doesCurrentUserSubscribe"] !== undefined;
isInstance = isInstance && "doesFollowCurrentUser" in value && value["doesFollowCurrentUser"] !== undefined;
isInstance = isInstance && "handleLc" in value && value["handleLc"] !== undefined;
isInstance = isInstance && "updatedAt" in value && value["updatedAt"] !== undefined;
isInstance = isInstance && "hasCollectibles" in value && value["hasCollectibles"] !== undefined;
Expand Down Expand Up @@ -488,6 +495,7 @@ export function UserFullFromJSONTyped(json: any, ignoreDiscriminator: boolean):
'currentUserFolloweeFollowCount': json['current_user_followee_follow_count'],
'doesCurrentUserFollow': json['does_current_user_follow'],
'doesCurrentUserSubscribe': json['does_current_user_subscribe'],
'doesFollowCurrentUser': json['does_follow_current_user'],
'handleLc': json['handle_lc'],
'updatedAt': json['updated_at'],
'coverPhotoSizes': !exists(json, 'cover_photo_sizes') ? undefined : json['cover_photo_sizes'],
Expand Down Expand Up @@ -556,6 +564,7 @@ export function UserFullToJSON(value?: UserFull | null): any {
'current_user_followee_follow_count': value.currentUserFolloweeFollowCount,
'does_current_user_follow': value.doesCurrentUserFollow,
'does_current_user_subscribe': value.doesCurrentUserSubscribe,
'does_follow_current_user': value.doesFollowCurrentUser,
'handle_lc': value.handleLc,
'updated_at': value.updatedAt,
'cover_photo_sizes': value.coverPhotoSizes,
Expand Down
16 changes: 6 additions & 10 deletions packages/web/src/components/user-badges/FollowsYouBadge.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useGetUserById } from '@audius/common/api'
import { ID } from '@audius/common/models'
import { trpc } from '@audius/common/services'
import { accountSelectors } from '@audius/common/store'
import { useSelector } from 'react-redux'

Expand All @@ -23,18 +23,14 @@ const FollowsYouBadge = ({
className = '',
variant = 'standard'
}: FollowsYouBadgeProps) => {
const wm = useWithMobileStyle(styles.mobile)
const currentUserId = useSelector(accountSelectors.getUserId)
const { data } = trpc.me.userRelationship.useQuery(
{
theirId: userId.toString()
},
{
enabled: !!currentUserId
}
const { data: user } = useGetUserById(
{ id: userId },
{ disabled: !currentUserId }
)
const wm = useWithMobileStyle(styles.mobile)

if (!data?.followsMe) return null
if (!user?.does_follow_current_user) return null

return (
<div
Expand Down

0 comments on commit 06c2678

Please sign in to comment.