Implement unfollow, unlike, unrepost
parent
aabde2b401
commit
a8c8286b88
|
@ -53,8 +53,12 @@ export async function like(adx: ServiceClient, user: string, uri: string) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function unlike(adx: ServiceClient, user: string, uri: string) {
|
export async function unlike(adx: ServiceClient, likeUri: string) {
|
||||||
throw new Error('TODO')
|
const likeUrip = new AdxUri(likeUri)
|
||||||
|
return await adx.todo.social.like.delete({
|
||||||
|
did: likeUrip.hostname,
|
||||||
|
tid: likeUrip.recordKey,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function repost(adx: ServiceClient, user: string, uri: string) {
|
export async function repost(adx: ServiceClient, user: string, uri: string) {
|
||||||
|
@ -67,8 +71,12 @@ export async function repost(adx: ServiceClient, user: string, uri: string) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function unrepost(adx: ServiceClient, user: string, uri: string) {
|
export async function unrepost(adx: ServiceClient, repostUri: string) {
|
||||||
throw new Error('TODO')
|
const repostUrip = new AdxUri(repostUri)
|
||||||
|
return await adx.todo.social.repost.delete({
|
||||||
|
did: repostUrip.hostname,
|
||||||
|
tid: repostUrip.recordKey,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function follow(
|
export async function follow(
|
||||||
|
@ -85,12 +93,12 @@ export async function follow(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function unfollow(
|
export async function unfollow(adx: ServiceClient, followUri: string) {
|
||||||
adx: ServiceClient,
|
const followUrip = new AdxUri(followUri)
|
||||||
user: string,
|
return await adx.todo.social.follow.delete({
|
||||||
subject: {did: string},
|
did: followUrip.hostname,
|
||||||
) {
|
tid: followUrip.recordKey,
|
||||||
throw new Error('TODO')
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function updateProfile(
|
export async function updateProfile(
|
||||||
|
@ -108,36 +116,42 @@ interface FetchHandlerResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchHandler(
|
async function fetchHandler(
|
||||||
httpUri: string,
|
reqUri: string,
|
||||||
httpMethod: string,
|
reqMethod: string,
|
||||||
httpHeaders: Record<string, string>,
|
reqHeaders: Record<string, string>,
|
||||||
httpReqBody: any,
|
reqBody: any,
|
||||||
): Promise<FetchHandlerResponse> {
|
): Promise<FetchHandlerResponse> {
|
||||||
httpHeaders['Authorization'] = 'did:test:alice' // DEBUG
|
reqHeaders['Authorization'] = 'did:test:alice' // DEBUG
|
||||||
|
|
||||||
|
const reqMimeType = reqHeaders['Content-Type'] || reqHeaders['content-type']
|
||||||
|
if (reqMimeType && reqMimeType.startsWith('application/json')) {
|
||||||
|
reqBody = JSON.stringify(reqBody)
|
||||||
|
}
|
||||||
|
|
||||||
const res = await RNFetchBlob.fetch(
|
const res = await RNFetchBlob.fetch(
|
||||||
/** @ts-ignore method coersion, it's fine -prf */
|
/** @ts-ignore method coersion, it's fine -prf */
|
||||||
httpMethod,
|
reqMethod,
|
||||||
httpUri,
|
reqUri,
|
||||||
httpHeaders,
|
reqHeaders,
|
||||||
httpReqBody,
|
reqBody,
|
||||||
)
|
)
|
||||||
|
|
||||||
const status = res.info().status
|
const resStatus = res.info().status
|
||||||
const headers = (res.info().headers || {}) as Record<string, string>
|
const resHeaders = (res.info().headers || {}) as Record<string, string>
|
||||||
const mimeType = headers['Content-Type'] || headers['content-type']
|
const resMimeType = resHeaders['Content-Type'] || resHeaders['content-type']
|
||||||
let resBody
|
let resBody
|
||||||
if (mimeType) {
|
if (resMimeType) {
|
||||||
if (mimeType.startsWith('application/json')) {
|
if (resMimeType.startsWith('application/json')) {
|
||||||
resBody = res.json()
|
resBody = res.json()
|
||||||
} else if (mimeType.startsWith('text/')) {
|
} else if (resMimeType.startsWith('text/')) {
|
||||||
resBody = res.text()
|
resBody = res.text()
|
||||||
} else {
|
} else {
|
||||||
resBody = res.base64()
|
resBody = res.base64()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
status,
|
status: resStatus,
|
||||||
headers,
|
headers: resHeaders,
|
||||||
body: resBody,
|
body: resBody,
|
||||||
}
|
}
|
||||||
// const res = await fetch(httpUri, {
|
// const res = await fetch(httpUri, {
|
||||||
|
|
|
@ -59,13 +59,17 @@ export class FeedViewItemModel implements GetFeedView.FeedItem {
|
||||||
|
|
||||||
async toggleLike() {
|
async toggleLike() {
|
||||||
if (this.myState.like) {
|
if (this.myState.like) {
|
||||||
await apilib.unlike(this.rootStore.api, 'alice.test', this.uri)
|
await apilib.unlike(this.rootStore.api, this.myState.like)
|
||||||
runInAction(() => {
|
runInAction(() => {
|
||||||
this.likeCount--
|
this.likeCount--
|
||||||
this.myState.like = undefined
|
this.myState.like = undefined
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
const res = await apilib.like(this.rootStore.api, 'alice.test', this.uri)
|
const res = await apilib.like(
|
||||||
|
this.rootStore.api,
|
||||||
|
'did:test:alice',
|
||||||
|
this.uri,
|
||||||
|
)
|
||||||
runInAction(() => {
|
runInAction(() => {
|
||||||
this.likeCount++
|
this.likeCount++
|
||||||
this.myState.like = res.uri
|
this.myState.like = res.uri
|
||||||
|
@ -75,7 +79,7 @@ export class FeedViewItemModel implements GetFeedView.FeedItem {
|
||||||
|
|
||||||
async toggleRepost() {
|
async toggleRepost() {
|
||||||
if (this.myState.repost) {
|
if (this.myState.repost) {
|
||||||
await apilib.unrepost(this.rootStore.api, 'alice.test', this.uri)
|
await apilib.unrepost(this.rootStore.api, this.myState.repost)
|
||||||
runInAction(() => {
|
runInAction(() => {
|
||||||
this.repostCount--
|
this.repostCount--
|
||||||
this.myState.repost = undefined
|
this.myState.repost = undefined
|
||||||
|
@ -83,7 +87,7 @@ export class FeedViewItemModel implements GetFeedView.FeedItem {
|
||||||
} else {
|
} else {
|
||||||
const res = await apilib.repost(
|
const res = await apilib.repost(
|
||||||
this.rootStore.api,
|
this.rootStore.api,
|
||||||
'alice.test',
|
'did:test:alice',
|
||||||
this.uri,
|
this.uri,
|
||||||
)
|
)
|
||||||
runInAction(() => {
|
runInAction(() => {
|
||||||
|
|
|
@ -95,13 +95,17 @@ export class PostThreadViewPostModel implements GetPostThread.Post {
|
||||||
|
|
||||||
async toggleLike() {
|
async toggleLike() {
|
||||||
if (this.myState.like) {
|
if (this.myState.like) {
|
||||||
await apilib.unlike(this.rootStore.api, 'alice.test', this.uri)
|
await apilib.unlike(this.rootStore.api, this.myState.like)
|
||||||
runInAction(() => {
|
runInAction(() => {
|
||||||
this.likeCount--
|
this.likeCount--
|
||||||
this.myState.like = undefined
|
this.myState.like = undefined
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
const res = await apilib.like(this.rootStore.api, 'alice.test', this.uri)
|
const res = await apilib.like(
|
||||||
|
this.rootStore.api,
|
||||||
|
'did:test:alice',
|
||||||
|
this.uri,
|
||||||
|
)
|
||||||
runInAction(() => {
|
runInAction(() => {
|
||||||
this.likeCount++
|
this.likeCount++
|
||||||
this.myState.like = res.uri
|
this.myState.like = res.uri
|
||||||
|
@ -111,7 +115,7 @@ export class PostThreadViewPostModel implements GetPostThread.Post {
|
||||||
|
|
||||||
async toggleRepost() {
|
async toggleRepost() {
|
||||||
if (this.myState.repost) {
|
if (this.myState.repost) {
|
||||||
await apilib.unrepost(this.rootStore.api, 'alice.test', this.uri)
|
await apilib.unrepost(this.rootStore.api, this.myState.repost)
|
||||||
runInAction(() => {
|
runInAction(() => {
|
||||||
this.repostCount--
|
this.repostCount--
|
||||||
this.myState.repost = undefined
|
this.myState.repost = undefined
|
||||||
|
@ -119,7 +123,7 @@ export class PostThreadViewPostModel implements GetPostThread.Post {
|
||||||
} else {
|
} else {
|
||||||
const res = await apilib.repost(
|
const res = await apilib.repost(
|
||||||
this.rootStore.api,
|
this.rootStore.api,
|
||||||
'alice.test',
|
'did:test:alice',
|
||||||
this.uri,
|
this.uri,
|
||||||
)
|
)
|
||||||
runInAction(() => {
|
runInAction(() => {
|
||||||
|
|
|
@ -74,9 +74,7 @@ export class ProfileViewModel {
|
||||||
throw new Error('Not logged in')
|
throw new Error('Not logged in')
|
||||||
}
|
}
|
||||||
if (this.myState.follow) {
|
if (this.myState.follow) {
|
||||||
await apilib.unfollow(this.rootStore.api, this.rootStore.me.did, {
|
await apilib.unfollow(this.rootStore.api, this.myState.follow)
|
||||||
did: this.did,
|
|
||||||
})
|
|
||||||
runInAction(() => {
|
runInAction(() => {
|
||||||
this.followersCount--
|
this.followersCount--
|
||||||
this.myState.follow = undefined
|
this.myState.follow = undefined
|
||||||
|
|
|
@ -48,7 +48,7 @@ export function Component({replyTo}: {replyTo?: string}) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await apilib.post(store.api, 'alice.test', text, replyTo)
|
await apilib.post(store.api, 'did:test:alice', text, replyTo)
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(`Failed to create post: ${e.toString()}`)
|
console.error(`Failed to create post: ${e.toString()}`)
|
||||||
setError(
|
setError(
|
||||||
|
|
|
@ -30,7 +30,7 @@ export const ProfileHeader = observer(function ProfileHeader({
|
||||||
view?.toggleFollowing().then(
|
view?.toggleFollowing().then(
|
||||||
() => {
|
() => {
|
||||||
Toast.show(
|
Toast.show(
|
||||||
`${view.myState.hasFollowed ? 'Following' : 'No longer following'} ${
|
`${view.myState.follow ? 'Following' : 'No longer following'} ${
|
||||||
view.displayName || view.name
|
view.displayName || view.name
|
||||||
}`,
|
}`,
|
||||||
{
|
{
|
||||||
|
@ -104,7 +104,7 @@ export const ProfileHeader = observer(function ProfileHeader({
|
||||||
style={[styles.mainBtn, styles.btn]}>
|
style={[styles.mainBtn, styles.btn]}>
|
||||||
<Text style={[s.fw400, s.f14]}>Edit Profile</Text>
|
<Text style={[s.fw400, s.f14]}>Edit Profile</Text>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
) : view.myState.hasFollowed ? (
|
) : view.myState.follow ? (
|
||||||
<TouchableOpacity
|
<TouchableOpacity
|
||||||
onPress={onPressToggleFollow}
|
onPress={onPressToggleFollow}
|
||||||
style={[styles.mainBtn, styles.btn]}>
|
style={[styles.mainBtn, styles.btn]}>
|
||||||
|
|
Loading…
Reference in New Issue