Skip to content
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

Add request client #342

Merged
merged 11 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/status-js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ export { createClient } from './client/client'
export type { Community } from './client/community/community'
export type { Reaction, Reactions } from './client/community/get-reactions'
export type { Member } from './client/member'
export { createPreviewClient } from './preview-client/preview-client'
export { deserializePublicKey } from './utils/deserialize-public-key'
export { publicKeyToEmojiHash } from './utils/public-key-to-emoji-hash'
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { mapCommunityPreview } from './map-community-preview'

import type {
CommunityChat,
CommunityDescription,
} from '../protos/communities_pb'
import type { CommunityPreview } from './map-community-preview'

export type CommunityChatPreview = {
emoji?: string
displayName: string
description: string
appUrl: string
color: string
community: CommunityPreview
}

export function mapCommunityChatPreview(
communityChat: CommunityChat,
communityDescription: CommunityDescription,
communityPublicKey: string,
communityChatUuid: string
): CommunityChatPreview | undefined {
const community = mapCommunityPreview(
communityDescription,
communityPublicKey
)

if (!community) {
return
}

const { identity } = communityChat

if (!identity) {
return
}

const communityChatPreview: CommunityChatPreview = {
emoji: identity.emoji,
displayName: identity.displayName,
description: identity.description,
color: identity.color,
appUrl: `status-im://cc/${communityPublicKey}/${communityChatUuid}`,
felicio marked this conversation as resolved.
Show resolved Hide resolved
community,
}

return communityChatPreview
}
55 changes: 55 additions & 0 deletions packages/status-js/src/preview-client/map-community-preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// todo?: rename to map-commuinty-details and use in client.ts too
felicio marked this conversation as resolved.
Show resolved Hide resolved
import { tags as tagsMap } from './tags'

import type { CommunityDescription } from '../protos/communities_pb'

export type CommunityPreview = {
banner?: Uint8Array
photo?: Uint8Array
displayName: string
description: string
membersCount: number
appUrl: string
tags: Array<{
emoji: string
text: string
}>
color: string
}

export function mapCommunityPreview(
communityDescription: CommunityDescription,
communityPublicKey: string
): CommunityPreview | undefined {
const { identity, tags, members } = communityDescription

if (!identity) {
return
}

const communityPreview: CommunityPreview = {
banner: identity.images.banner?.payload,
photo: identity.images.thumbnail?.payload,
displayName: identity.displayName,
description: identity.description,
membersCount: Object.keys(members).length,
appUrl: `status-im://c/${communityPublicKey}`,
tags: tags.reduce<CommunityPreview['tags']>((tags, nextTag) => {
const emoji = tagsMap[nextTag as keyof typeof tagsMap]

if (!emoji) {
return tags
}

tags.push({
text: nextTag,
emoji,
})

return tags
}, []),
color: identity.color,
}

return communityPreview
}
40 changes: 40 additions & 0 deletions packages/status-js/src/preview-client/map-user-preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { publicKeyToEmojiHash } from '../utils/public-key-to-emoji-hash'

import type { ContactCodeAdvertisement } from '../protos/push-notifications_pb'

export type UserPreview = {
photo?: Uint8Array
displayName: string
description?: string
emojiHash: string
socialUrls: Array<{
url: string
// todo?: map fixed (e.g. telegram) and custom
felicio marked this conversation as resolved.
Show resolved Hide resolved
text: string
}>
appUrl: string
// todo: currently not in protobuf nor in product
// color: string
}

export function mapUserPreview(
contactCodeAdvertisement: ContactCodeAdvertisement,
userPublicKey: string
): UserPreview | undefined {
const { chatIdentity: identity } = contactCodeAdvertisement

if (!identity) {
return
}

const userPreview: UserPreview = {
photo: identity.images.thumbnail?.payload,
displayName: identity.displayName,
description: identity.description,
emojiHash: publicKeyToEmojiHash(userPublicKey),
socialUrls: identity.socialLinks,
appUrl: `status-im://u/${userPublicKey}`,
}

return userPreview
}
Loading