generated from well-known-components/template-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Get sent and received friendship requests optimizations (#38)
* chore: seq diag improvements * feat: Use the profile image url to create the full url * feat: Get Sent and Received Friendship Requests respond with profile data * chore: Remove unused imports * refactor: Try with filter boolean but doesn't work * refactor: Pick specific props from entity * chore: Use Avatar type from schemas
- Loading branch information
1 parent
746e8d2
commit 34da607
Showing
21 changed files
with
237 additions
and
152 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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
22 changes: 14 additions & 8 deletions
22
src/adapters/rpc-server/services/get-pending-friendship-requests.ts
This file contains 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
25 changes: 16 additions & 9 deletions
25
src/adapters/rpc-server/services/get-sent-friendship-requests.ts
This file contains 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 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 |
---|---|---|
@@ -1,17 +1,19 @@ | ||
import { User } from '@dcl/protocol/out-js/decentraland/social_service/v2/social_service_v2.gen' | ||
import { FriendProfile } from '@dcl/protocol/out-js/decentraland/social_service/v2/social_service_v2.gen' | ||
import { Entity } from '@dcl/schemas' | ||
import { getProfileAvatar, getProfilePictureUrl } from './profiles' | ||
import { normalizeAddress } from '../utils/address' | ||
|
||
export function parseProfilesToFriends(profiles: Entity[], contentServerUrl: string): User[] { | ||
return profiles.map((profile) => { | ||
const { userId, name, hasClaimedName } = getProfileAvatar(profile) | ||
export function parseProfileToFriend(profile: Entity, contentServerUrl: string): FriendProfile { | ||
const { userId, name, hasClaimedName } = getProfileAvatar(profile) | ||
|
||
return { | ||
address: normalizeAddress(userId), | ||
name, | ||
hasClaimedName, | ||
profilePictureUrl: getProfilePictureUrl(contentServerUrl, profile) | ||
} | ||
}) | ||
return { | ||
address: normalizeAddress(userId), | ||
name, | ||
hasClaimedName, | ||
profilePictureUrl: getProfilePictureUrl(contentServerUrl, profile) | ||
} | ||
} | ||
|
||
export function parseProfilesToFriends(profiles: Entity[], contentServerUrl: string): FriendProfile[] { | ||
return profiles.map((profile) => parseProfileToFriend(profile, contentServerUrl)) | ||
} |
This file contains 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 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 |
---|---|---|
@@ -1,29 +1,15 @@ | ||
import { Entity } from '@dcl/schemas' | ||
import { Entity, Avatar } from '@dcl/schemas' | ||
|
||
type Avatar = { | ||
userId: string | ||
name: string | ||
hasClaimedName: boolean | ||
snapshots: { | ||
face256: string | ||
} | ||
} | ||
|
||
export function getProfileAvatar(profile: Entity): Avatar { | ||
export function getProfileAvatar(profile: Pick<Entity, 'metadata'>): Avatar { | ||
const [avatar] = profile.metadata.avatars | ||
|
||
if (!avatar) throw new Error('Missing profile avatar') | ||
|
||
return avatar | ||
} | ||
|
||
export function getProfilePictureUrl(baseUrl: string, profile: Entity): string { | ||
export function getProfilePictureUrl(baseUrl: string, { id }: Pick<Entity, 'id'>): string { | ||
if (!baseUrl) throw new Error('Missing baseUrl for profile picture') | ||
|
||
const avatar = getProfileAvatar(profile) | ||
const hash = avatar?.snapshots.face256 | ||
|
||
if (!hash) throw new Error('Missing snapshot hash for profile picture') | ||
|
||
return `${baseUrl}/contents/${hash}` | ||
return `${baseUrl}/entities/${id}/face.png` | ||
} |
This file contains 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 |
---|---|---|
@@ -1,14 +1,16 @@ | ||
import { Entity } from '@dcl/schemas' | ||
import { Friend } from '../../src/types' | ||
import { getProfileAvatar } from '../../src/logic/profiles' | ||
|
||
export const createMockFriend = (address: string): Friend => ({ | ||
address | ||
}) | ||
|
||
export function parseExpectedFriends(contentServerUrl: string) { | ||
return (address: string) => ({ | ||
address, | ||
name: `Profile name ${address}`, | ||
export function parseExpectedFriends(profileImagesUrl: string) { | ||
return (profile: Entity) => ({ | ||
address: getProfileAvatar(profile).userId, | ||
name: getProfileAvatar(profile).name, | ||
hasClaimedName: true, | ||
profilePictureUrl: `${contentServerUrl}/contents/bafybeiasdfqwer` | ||
profilePictureUrl: `${profileImagesUrl}/entities/${profile.id}/face.png` | ||
}) | ||
} |
Oops, something went wrong.