Fix to auth of mutation ops
parent
c7d7e152a0
commit
2058505bf1
|
@ -7,22 +7,21 @@
|
||||||
import AdxApi from '../../third-party/api'
|
import AdxApi from '../../third-party/api'
|
||||||
import {ServiceClient} from '../../third-party/api/src/index'
|
import {ServiceClient} from '../../third-party/api/src/index'
|
||||||
import {AdxUri} from '../../third-party/uri'
|
import {AdxUri} from '../../third-party/uri'
|
||||||
import * as storage from './storage'
|
import {RootStoreModel} from '../models/root-store'
|
||||||
|
|
||||||
export function doPolyfill() {
|
export function doPolyfill() {
|
||||||
AdxApi.xrpc.fetch = fetchHandler
|
AdxApi.xrpc.fetch = fetchHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function post(
|
export async function post(
|
||||||
adx: ServiceClient,
|
store: RootStoreModel,
|
||||||
user: string,
|
|
||||||
text: string,
|
text: string,
|
||||||
replyToUri?: string,
|
replyToUri?: string,
|
||||||
) {
|
) {
|
||||||
let reply
|
let reply
|
||||||
if (replyToUri) {
|
if (replyToUri) {
|
||||||
const replyToUrip = new AdxUri(replyToUri)
|
const replyToUrip = new AdxUri(replyToUri)
|
||||||
const parentPost = await adx.todo.social.post.get({
|
const parentPost = await store.api.todo.social.post.get({
|
||||||
nameOrDid: replyToUrip.host,
|
nameOrDid: replyToUrip.host,
|
||||||
tid: replyToUrip.recordKey,
|
tid: replyToUrip.recordKey,
|
||||||
})
|
})
|
||||||
|
@ -33,8 +32,8 @@ export async function post(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return await adx.todo.social.post.create(
|
return await store.api.todo.social.post.create(
|
||||||
{did: user},
|
{did: store.me.did || ''},
|
||||||
{
|
{
|
||||||
text,
|
text,
|
||||||
reply,
|
reply,
|
||||||
|
@ -43,9 +42,9 @@ export async function post(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function like(adx: ServiceClient, user: string, uri: string) {
|
export async function like(store: RootStoreModel, uri: string) {
|
||||||
return await adx.todo.social.like.create(
|
return await store.api.todo.social.like.create(
|
||||||
{did: user},
|
{did: store.me.did || ''},
|
||||||
{
|
{
|
||||||
subject: uri,
|
subject: uri,
|
||||||
createdAt: new Date().toISOString(),
|
createdAt: new Date().toISOString(),
|
||||||
|
@ -53,17 +52,17 @@ export async function like(adx: ServiceClient, user: string, uri: string) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function unlike(adx: ServiceClient, likeUri: string) {
|
export async function unlike(store: RootStoreModel, likeUri: string) {
|
||||||
const likeUrip = new AdxUri(likeUri)
|
const likeUrip = new AdxUri(likeUri)
|
||||||
return await adx.todo.social.like.delete({
|
return await store.api.todo.social.like.delete({
|
||||||
did: likeUrip.hostname,
|
did: likeUrip.hostname,
|
||||||
tid: likeUrip.recordKey,
|
tid: likeUrip.recordKey,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function repost(adx: ServiceClient, user: string, uri: string) {
|
export async function repost(store: RootStoreModel, uri: string) {
|
||||||
return await adx.todo.social.repost.create(
|
return await store.api.todo.social.repost.create(
|
||||||
{did: user},
|
{did: store.me.did || ''},
|
||||||
{
|
{
|
||||||
subject: uri,
|
subject: uri,
|
||||||
createdAt: new Date().toISOString(),
|
createdAt: new Date().toISOString(),
|
||||||
|
@ -71,21 +70,17 @@ export async function repost(adx: ServiceClient, user: string, uri: string) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function unrepost(adx: ServiceClient, repostUri: string) {
|
export async function unrepost(store: RootStoreModel, repostUri: string) {
|
||||||
const repostUrip = new AdxUri(repostUri)
|
const repostUrip = new AdxUri(repostUri)
|
||||||
return await adx.todo.social.repost.delete({
|
return await store.api.todo.social.repost.delete({
|
||||||
did: repostUrip.hostname,
|
did: repostUrip.hostname,
|
||||||
tid: repostUrip.recordKey,
|
tid: repostUrip.recordKey,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function follow(
|
export async function follow(store: RootStoreModel, subject: string) {
|
||||||
adx: ServiceClient,
|
return await store.api.todo.social.follow.create(
|
||||||
user: string,
|
{did: store.me.did || ''},
|
||||||
subject: string,
|
|
||||||
) {
|
|
||||||
return await adx.todo.social.follow.create(
|
|
||||||
{did: user},
|
|
||||||
{
|
{
|
||||||
subject,
|
subject,
|
||||||
createdAt: new Date().toISOString(),
|
createdAt: new Date().toISOString(),
|
||||||
|
@ -93,9 +88,9 @@ export async function follow(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function unfollow(adx: ServiceClient, followUri: string) {
|
export async function unfollow(store: RootStoreModel, followUri: string) {
|
||||||
const followUrip = new AdxUri(followUri)
|
const followUrip = new AdxUri(followUri)
|
||||||
return await adx.todo.social.follow.delete({
|
return await store.api.todo.social.follow.delete({
|
||||||
did: followUrip.hostname,
|
did: followUrip.hostname,
|
||||||
tid: followUrip.recordKey,
|
tid: followUrip.recordKey,
|
||||||
})
|
})
|
||||||
|
|
|
@ -61,17 +61,13 @@ export class FeedViewItemModel implements GetFeedView.FeedItem {
|
||||||
|
|
||||||
async toggleLike() {
|
async toggleLike() {
|
||||||
if (this.myState.like) {
|
if (this.myState.like) {
|
||||||
await apilib.unlike(this.rootStore.api, this.myState.like)
|
await apilib.unlike(this.rootStore, this.myState.like)
|
||||||
runInAction(() => {
|
runInAction(() => {
|
||||||
this.likeCount--
|
this.likeCount--
|
||||||
this.myState.like = undefined
|
this.myState.like = undefined
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
const res = await apilib.like(
|
const res = await apilib.like(this.rootStore, this.uri)
|
||||||
this.rootStore.api,
|
|
||||||
'did:test:alice',
|
|
||||||
this.uri,
|
|
||||||
)
|
|
||||||
runInAction(() => {
|
runInAction(() => {
|
||||||
this.likeCount++
|
this.likeCount++
|
||||||
this.myState.like = res.uri
|
this.myState.like = res.uri
|
||||||
|
@ -81,17 +77,13 @@ export class FeedViewItemModel implements GetFeedView.FeedItem {
|
||||||
|
|
||||||
async toggleRepost() {
|
async toggleRepost() {
|
||||||
if (this.myState.repost) {
|
if (this.myState.repost) {
|
||||||
await apilib.unrepost(this.rootStore.api, this.myState.repost)
|
await apilib.unrepost(this.rootStore, this.myState.repost)
|
||||||
runInAction(() => {
|
runInAction(() => {
|
||||||
this.repostCount--
|
this.repostCount--
|
||||||
this.myState.repost = undefined
|
this.myState.repost = undefined
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
const res = await apilib.repost(
|
const res = await apilib.repost(this.rootStore, this.uri)
|
||||||
this.rootStore.api,
|
|
||||||
'did:test:alice',
|
|
||||||
this.uri,
|
|
||||||
)
|
|
||||||
runInAction(() => {
|
runInAction(() => {
|
||||||
this.repostCount++
|
this.repostCount++
|
||||||
this.myState.repost = res.uri
|
this.myState.repost = res.uri
|
||||||
|
|
|
@ -106,17 +106,13 @@ export class PostThreadViewPostModel implements GetPostThread.Post {
|
||||||
|
|
||||||
async toggleLike() {
|
async toggleLike() {
|
||||||
if (this.myState.like) {
|
if (this.myState.like) {
|
||||||
await apilib.unlike(this.rootStore.api, this.myState.like)
|
await apilib.unlike(this.rootStore, this.myState.like)
|
||||||
runInAction(() => {
|
runInAction(() => {
|
||||||
this.likeCount--
|
this.likeCount--
|
||||||
this.myState.like = undefined
|
this.myState.like = undefined
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
const res = await apilib.like(
|
const res = await apilib.like(this.rootStore, this.uri)
|
||||||
this.rootStore.api,
|
|
||||||
'did:test:alice',
|
|
||||||
this.uri,
|
|
||||||
)
|
|
||||||
runInAction(() => {
|
runInAction(() => {
|
||||||
this.likeCount++
|
this.likeCount++
|
||||||
this.myState.like = res.uri
|
this.myState.like = res.uri
|
||||||
|
@ -126,17 +122,13 @@ export class PostThreadViewPostModel implements GetPostThread.Post {
|
||||||
|
|
||||||
async toggleRepost() {
|
async toggleRepost() {
|
||||||
if (this.myState.repost) {
|
if (this.myState.repost) {
|
||||||
await apilib.unrepost(this.rootStore.api, this.myState.repost)
|
await apilib.unrepost(this.rootStore, this.myState.repost)
|
||||||
runInAction(() => {
|
runInAction(() => {
|
||||||
this.repostCount--
|
this.repostCount--
|
||||||
this.myState.repost = undefined
|
this.myState.repost = undefined
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
const res = await apilib.repost(
|
const res = await apilib.repost(this.rootStore, this.uri)
|
||||||
this.rootStore.api,
|
|
||||||
'did:test:alice',
|
|
||||||
this.uri,
|
|
||||||
)
|
|
||||||
runInAction(() => {
|
runInAction(() => {
|
||||||
this.repostCount++
|
this.repostCount++
|
||||||
this.myState.repost = res.uri
|
this.myState.repost = res.uri
|
||||||
|
|
|
@ -74,17 +74,13 @@ 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.myState.follow)
|
await apilib.unfollow(this.rootStore, this.myState.follow)
|
||||||
runInAction(() => {
|
runInAction(() => {
|
||||||
this.followersCount--
|
this.followersCount--
|
||||||
this.myState.follow = undefined
|
this.myState.follow = undefined
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
const res = await apilib.follow(
|
const res = await apilib.follow(this.rootStore, this.did)
|
||||||
this.rootStore.api,
|
|
||||||
this.rootStore.me.did,
|
|
||||||
this.did,
|
|
||||||
)
|
|
||||||
runInAction(() => {
|
runInAction(() => {
|
||||||
this.followersCount++
|
this.followersCount++
|
||||||
this.myState.follow = res.uri
|
this.myState.follow = res.uri
|
||||||
|
|
|
@ -48,7 +48,7 @@ export function Component({replyTo}: {replyTo?: string}) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await apilib.post(store.api, 'did:test:alice', text, replyTo)
|
await apilib.post(store, 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(
|
||||||
|
@ -103,7 +103,7 @@ export function Component({replyTo}: {replyTo?: string}) {
|
||||||
start={{x: 0, y: 0}}
|
start={{x: 0, y: 0}}
|
||||||
end={{x: 1, y: 1}}
|
end={{x: 1, y: 1}}
|
||||||
style={styles.postBtn}>
|
style={styles.postBtn}>
|
||||||
<Text style={[s.white, s.f16, s.semiBold]}>Post</Text>
|
<Text style={[s.white, s.f16, s.bold]}>Post</Text>
|
||||||
</LinearGradient>
|
</LinearGradient>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
</View>
|
</View>
|
||||||
|
|
Loading…
Reference in New Issue