Update to latest APIs

This commit is contained in:
Paul Frazee 2022-10-26 14:34:47 -05:00
parent 349cfe7177
commit 1983512fef
74 changed files with 2334 additions and 525 deletions

View file

@ -4,6 +4,7 @@ import {BottomSheetTextInput} from '@gorhom/bottom-sheet'
import LinearGradient from 'react-native-linear-gradient'
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
import * as GetUserFollows from '../../../third-party/api/src/types/app/bsky/getUserFollows'
import * as Post from '../../../third-party/api/src/types/app/bsky/post'
import {Autocomplete} from './composer/Autocomplete'
import Toast from '../util/Toast'
import ProgressCircle from '../util/ProgressCircle'
@ -20,7 +21,7 @@ export function Component({
replyTo,
onPost,
}: {
replyTo?: string
replyTo?: Post.PostRef
onPost?: () => void
}) {
const store = useStores()

View file

@ -1,7 +1,7 @@
import React, {useMemo} from 'react'
import {observer} from 'mobx-react-lite'
import {Image, StyleSheet, Text, View} from 'react-native'
import {AdxUri} from '../../../third-party/uri'
import {AtUri} from '../../../third-party/uri'
import {FontAwesomeIcon, Props} from '@fortawesome/react-native-fontawesome'
import {NotificationsViewItemModel} from '../../../state/models/notifications-view'
import {s, colors} from '../../lib/styles'
@ -20,13 +20,13 @@ export const FeedItem = observer(function FeedItem({
}) {
const itemHref = useMemo(() => {
if (item.isLike || item.isRepost) {
const urip = new AdxUri(item.subjectUri)
return `/profile/${urip.host}/post/${urip.recordKey}`
const urip = new AtUri(item.subjectUri)
return `/profile/${urip.host}/post/${urip.rkey}`
} else if (item.isFollow) {
return `/profile/${item.author.name}`
} else if (item.isReply) {
const urip = new AdxUri(item.uri)
return `/profile/${urip.host}/post/${urip.recordKey}`
const urip = new AtUri(item.uri)
return `/profile/${urip.host}/post/${urip.rkey}`
}
return ''
}, [item])

View file

@ -2,7 +2,7 @@ import React, {useMemo} from 'react'
import {observer} from 'mobx-react-lite'
import {Image, StyleSheet, Text, TouchableOpacity, View} from 'react-native'
import Svg, {Line} from 'react-native-svg'
import {AdxUri} from '../../../third-party/uri'
import {AtUri} from '../../../third-party/uri'
import * as PostType from '../../../third-party/api/src/types/app/bsky/post'
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
import {PostThreadViewPostModel} from '../../../state/models/post-thread-view'
@ -31,26 +31,29 @@ export const PostThreadItem = observer(function PostThreadItem({
const hasEngagement = item.likeCount || item.repostCount
const itemHref = useMemo(() => {
const urip = new AdxUri(item.uri)
return `/profile/${item.author.name}/post/${urip.recordKey}`
const urip = new AtUri(item.uri)
return `/profile/${item.author.name}/post/${urip.rkey}`
}, [item.uri, item.author.name])
const itemTitle = `Post by ${item.author.name}`
const authorHref = `/profile/${item.author.name}`
const authorTitle = item.author.name
const likesHref = useMemo(() => {
const urip = new AdxUri(item.uri)
return `/profile/${item.author.name}/post/${urip.recordKey}/liked-by`
const urip = new AtUri(item.uri)
return `/profile/${item.author.name}/post/${urip.rkey}/liked-by`
}, [item.uri, item.author.name])
const likesTitle = 'Likes on this post'
const repostsHref = useMemo(() => {
const urip = new AdxUri(item.uri)
return `/profile/${item.author.name}/post/${urip.recordKey}/reposted-by`
const urip = new AtUri(item.uri)
return `/profile/${item.author.name}/post/${urip.rkey}/reposted-by`
}, [item.uri, item.author.name])
const repostsTitle = 'Reposts of this post'
const onPressReply = () => {
store.shell.openModal(
new ComposePostModel({replyTo: item.uri, onPost: onPostReply}),
new ComposePostModel({
replyTo: {uri: item.uri, cid: item.cid},
onPost: onPostReply,
}),
)
}
const onPressToggleRepost = () => {

View file

@ -1,6 +1,6 @@
import React, {useState, useEffect, useMemo} from 'react'
import {observer} from 'mobx-react-lite'
import {AdxUri} from '../../../third-party/uri'
import {AtUri} from '../../../third-party/uri'
import * as PostType from '../../../third-party/api/src/types/app/bsky/post'
import {
ActivityIndicator,
@ -59,20 +59,22 @@ export const Post = observer(function Post({uri}: {uri: string}) {
const item = view.thread
const record = view.thread?.record as unknown as PostType.Record
const itemUrip = new AdxUri(item.uri)
const itemHref = `/profile/${item.author.name}/post/${itemUrip.recordKey}`
const itemUrip = new AtUri(item.uri)
const itemHref = `/profile/${item.author.name}/post/${itemUrip.rkey}`
const itemTitle = `Post by ${item.author.name}`
const authorHref = `/profile/${item.author.name}`
const authorTitle = item.author.name
let replyAuthorDid = ''
let replyHref = ''
if (record.reply) {
const urip = new AdxUri(record.reply.parent || record.reply.root)
const urip = new AtUri(record.reply.parent?.uri || record.reply.root.uri)
replyAuthorDid = urip.hostname
replyHref = `/profile/${urip.hostname}/post/${urip.recordKey}`
replyHref = `/profile/${urip.hostname}/post/${urip.rkey}`
}
const onPressReply = () => {
store.shell.openModal(new ComposePostModel({replyTo: item.uri}))
store.shell.openModal(
new ComposePostModel({replyTo: {uri: item.uri, cid: item.cid}}),
)
}
const onPressToggleRepost = () => {
item

View file

@ -1,7 +1,7 @@
import React, {useMemo} from 'react'
import {observer} from 'mobx-react-lite'
import {Image, StyleSheet, Text, TouchableOpacity, View} from 'react-native'
import {AdxUri} from '../../../third-party/uri'
import {AtUri} from '../../../third-party/uri'
import * as PostType from '../../../third-party/api/src/types/app/bsky/post'
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
import {FeedViewItemModel} from '../../../state/models/feed-view'
@ -23,24 +23,26 @@ export const FeedItem = observer(function FeedItem({
const store = useStores()
const record = item.record as unknown as PostType.Record
const itemHref = useMemo(() => {
const urip = new AdxUri(item.uri)
return `/profile/${item.author.name}/post/${urip.recordKey}`
const urip = new AtUri(item.uri)
return `/profile/${item.author.name}/post/${urip.rkey}`
}, [item.uri, item.author.name])
const itemTitle = `Post by ${item.author.name}`
const authorHref = `/profile/${item.author.name}`
const replyAuthorDid = useMemo(() => {
if (!record.reply) return ''
const urip = new AdxUri(record.reply.parent || record.reply.root)
const urip = new AtUri(record.reply.parent?.uri || record.reply.root.uri)
return urip.hostname
}, [record.reply])
const replyHref = useMemo(() => {
if (!record.reply) return ''
const urip = new AdxUri(record.reply.parent || record.reply.root)
return `/profile/${urip.hostname}/post/${urip.recordKey}`
const urip = new AtUri(record.reply.parent?.uri || record.reply.root.uri)
return `/profile/${urip.hostname}/post/${urip.rkey}`
}, [record.reply])
const onPressReply = () => {
store.shell.openModal(new ComposePostModel({replyTo: item.uri}))
store.shell.openModal(
new ComposePostModel({replyTo: {uri: item.uri, cid: item.cid}}),
)
}
const onPressToggleRepost = () => {
item

View file

@ -1,4 +1,4 @@
import {AdxUri} from '../../third-party/uri'
import {AtUri} from '../../third-party/uri'
import {Entity as Entities} from '../../third-party/api/src/types/app/bsky/post'
type Entity = Entities[0]
@ -16,12 +16,12 @@ export function pluralize(n: number, base: string, plural?: string): string {
export function makeRecordUri(
didOrName: string,
collection: string,
recordKey: string,
rkey: string,
) {
const urip = new AdxUri(`adx://host/`)
const urip = new AtUri(`at://host/`)
urip.host = didOrName
urip.collection = collection
urip.recordKey = recordKey
urip.rkey = rkey
return urip.toString()
}

View file

@ -39,17 +39,17 @@ export const routes: Route[] = [
[
PostThread,
['far', 'message'],
r('/profile/(?<name>[^/]+)/post/(?<recordKey>[^/]+)'),
r('/profile/(?<name>[^/]+)/post/(?<rkey>[^/]+)'),
],
[
PostLikedBy,
'heart',
r('/profile/(?<name>[^/]+)/post/(?<recordKey>[^/]+)/liked-by'),
r('/profile/(?<name>[^/]+)/post/(?<rkey>[^/]+)/liked-by'),
],
[
PostRepostedBy,
'retweet',
r('/profile/(?<name>[^/]+)/post/(?<recordKey>[^/]+)/reposted-by'),
r('/profile/(?<name>[^/]+)/post/(?<rkey>[^/]+)/reposted-by'),
],
]

View file

@ -6,8 +6,8 @@ import {useStores} from '../../state'
export const PostLikedBy = ({visible, params}: ScreenParams) => {
const store = useStores()
const {name, recordKey} = params
const uri = makeRecordUri(name, 'app.bsky.post', recordKey)
const {name, rkey} = params
const uri = makeRecordUri(name, 'app.bsky.post', rkey)
useEffect(() => {
if (visible) {

View file

@ -6,8 +6,8 @@ import {useStores} from '../../state'
export const PostRepostedBy = ({visible, params}: ScreenParams) => {
const store = useStores()
const {name, recordKey} = params
const uri = makeRecordUri(name, 'app.bsky.post', recordKey)
const {name, rkey} = params
const uri = makeRecordUri(name, 'app.bsky.post', rkey)
useEffect(() => {
if (visible) {

View file

@ -6,8 +6,8 @@ import {useStores} from '../../state'
export const PostThread = ({visible, params}: ScreenParams) => {
const store = useStores()
const {name, recordKey} = params
const uri = makeRecordUri(name, 'app.bsky.post', recordKey)
const {name, rkey} = params
const uri = makeRecordUri(name, 'app.bsky.post', rkey)
useEffect(() => {
if (visible) {