kopia lustrzana https://github.com/cloudflare/wildebeest
Merge pull request #214 from cloudflare/sven/regen-timeline-delete
regenerate the home timeline after status deletionpull/215/head
commit
78d029c452
|
@ -815,7 +815,7 @@ describe('Mastodon APIs', () => {
|
||||||
const queue = makeQueue()
|
const queue = makeQueue()
|
||||||
const actor = await createPerson(domain, db, userKEK, 'sven@cloudflare.com')
|
const actor = await createPerson(domain, db, userKEK, 'sven@cloudflare.com')
|
||||||
const mastodonId = 'abcd'
|
const mastodonId = 'abcd'
|
||||||
const res = await statuses_id.handleRequestDelete(db, mastodonId, actor, domain, userKEK, queue)
|
const res = await statuses_id.handleRequestDelete(db, mastodonId, actor, domain, userKEK, queue, cache)
|
||||||
assert.equal(res.status, 404)
|
assert.equal(res.status, 404)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -826,7 +826,15 @@ describe('Mastodon APIs', () => {
|
||||||
const actor2 = await createPerson(domain, db, userKEK, 'sven2@cloudflare.com')
|
const actor2 = await createPerson(domain, db, userKEK, 'sven2@cloudflare.com')
|
||||||
const note = await createPublicNote(domain, db, 'note from actor2', actor2)
|
const note = await createPublicNote(domain, db, 'note from actor2', actor2)
|
||||||
|
|
||||||
const res = await statuses_id.handleRequestDelete(db, note[mastodonIdSymbol]!, actor, domain, userKEK, queue)
|
const res = await statuses_id.handleRequestDelete(
|
||||||
|
db,
|
||||||
|
note[mastodonIdSymbol]!,
|
||||||
|
actor,
|
||||||
|
domain,
|
||||||
|
userKEK,
|
||||||
|
queue,
|
||||||
|
cache
|
||||||
|
)
|
||||||
assert.equal(res.status, 404)
|
assert.equal(res.status, 404)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -837,7 +845,15 @@ describe('Mastodon APIs', () => {
|
||||||
const note = await createPublicNote(domain, db, 'note from actor', actor)
|
const note = await createPublicNote(domain, db, 'note from actor', actor)
|
||||||
await addObjectInOutbox(db, actor, note)
|
await addObjectInOutbox(db, actor, note)
|
||||||
|
|
||||||
const res = await statuses_id.handleRequestDelete(db, note[mastodonIdSymbol]!, actor, domain, userKEK, queue)
|
const res = await statuses_id.handleRequestDelete(
|
||||||
|
db,
|
||||||
|
note[mastodonIdSymbol]!,
|
||||||
|
actor,
|
||||||
|
domain,
|
||||||
|
userKEK,
|
||||||
|
queue,
|
||||||
|
cache
|
||||||
|
)
|
||||||
assert.equal(res.status, 200)
|
assert.equal(res.status, 200)
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -850,6 +866,35 @@ describe('Mastodon APIs', () => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('delete status regenerates the timeline', async () => {
|
||||||
|
const db = await makeDB()
|
||||||
|
const queue = makeQueue()
|
||||||
|
const cache = makeCache()
|
||||||
|
const actor = await createPerson(domain, db, userKEK, 'sven@cloudflare.com')
|
||||||
|
const note = await createPublicNote(domain, db, 'note from actor', actor)
|
||||||
|
await addObjectInOutbox(db, actor, note)
|
||||||
|
|
||||||
|
// Poison the timeline
|
||||||
|
await cache.put(actor.id.toString() + '/timeline/home', 'funny value')
|
||||||
|
|
||||||
|
const res = await statuses_id.handleRequestDelete(
|
||||||
|
db,
|
||||||
|
note[mastodonIdSymbol]!,
|
||||||
|
actor,
|
||||||
|
domain,
|
||||||
|
userKEK,
|
||||||
|
queue,
|
||||||
|
cache
|
||||||
|
)
|
||||||
|
assert.equal(res.status, 200)
|
||||||
|
|
||||||
|
// ensure that timeline has been regenerated after the deletion
|
||||||
|
// and that timeline is empty
|
||||||
|
const timeline = await cache.get<Array<any>>(actor.id.toString() + '/timeline/home')
|
||||||
|
assert(timeline)
|
||||||
|
assert.equal(timeline!.length, 0)
|
||||||
|
})
|
||||||
|
|
||||||
test('delete status sends to followers', async () => {
|
test('delete status sends to followers', async () => {
|
||||||
const db = await makeDB()
|
const db = await makeDB()
|
||||||
const queue = makeQueue()
|
const queue = makeQueue()
|
||||||
|
@ -863,7 +908,15 @@ describe('Mastodon APIs', () => {
|
||||||
await addFollowing(db, actor3, actor, 'not needed')
|
await addFollowing(db, actor3, actor, 'not needed')
|
||||||
await acceptFollowing(db, actor3, actor)
|
await acceptFollowing(db, actor3, actor)
|
||||||
|
|
||||||
const res = await statuses_id.handleRequestDelete(db, note[mastodonIdSymbol]!, actor, domain, userKEK, queue)
|
const res = await statuses_id.handleRequestDelete(
|
||||||
|
db,
|
||||||
|
note[mastodonIdSymbol]!,
|
||||||
|
actor,
|
||||||
|
domain,
|
||||||
|
userKEK,
|
||||||
|
queue,
|
||||||
|
cache
|
||||||
|
)
|
||||||
assert.equal(res.status, 200)
|
assert.equal(res.status, 200)
|
||||||
|
|
||||||
assert.equal(queue.messages.length, 2)
|
assert.equal(queue.messages.length, 2)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
// https://docs.joinmastodon.org/methods/statuses/#get
|
// https://docs.joinmastodon.org/methods/statuses/#get
|
||||||
|
|
||||||
|
import type { Cache } from 'wildebeest/backend/src/cache'
|
||||||
import { type Note } from 'wildebeest/backend/src/activitypub/objects/note'
|
import { type Note } from 'wildebeest/backend/src/activitypub/objects/note'
|
||||||
import * as activities from 'wildebeest/backend/src/activitypub/activities/delete'
|
import * as activities from 'wildebeest/backend/src/activitypub/activities/delete'
|
||||||
import { cors } from 'wildebeest/backend/src/utils/cors'
|
import { cors } from 'wildebeest/backend/src/utils/cors'
|
||||||
|
@ -13,6 +14,8 @@ import { getObjectByMastodonId } from 'wildebeest/backend/src/activitypub/object
|
||||||
import { urlToHandle } from 'wildebeest/backend/src/utils/handle'
|
import { urlToHandle } from 'wildebeest/backend/src/utils/handle'
|
||||||
import { deliverFollowers } from 'wildebeest/backend/src/activitypub/deliver'
|
import { deliverFollowers } from 'wildebeest/backend/src/activitypub/deliver'
|
||||||
import type { Queue, DeliverMessageBody } from 'wildebeest/backend/src/types/queue'
|
import type { Queue, DeliverMessageBody } from 'wildebeest/backend/src/types/queue'
|
||||||
|
import * as timeline from 'wildebeest/backend/src/mastodon/timeline'
|
||||||
|
import { cacheFromEnv } from 'wildebeest/backend/src/cache'
|
||||||
|
|
||||||
export const onRequestGet: PagesFunction<Env, any, ContextData> = async ({ params, env, request }) => {
|
export const onRequestGet: PagesFunction<Env, any, ContextData> = async ({ params, env, request }) => {
|
||||||
const domain = new URL(request.url).hostname
|
const domain = new URL(request.url).hostname
|
||||||
|
@ -21,7 +24,15 @@ export const onRequestGet: PagesFunction<Env, any, ContextData> = async ({ param
|
||||||
|
|
||||||
export const onRequestDelete: PagesFunction<Env, any, ContextData> = async ({ params, env, request, data }) => {
|
export const onRequestDelete: PagesFunction<Env, any, ContextData> = async ({ params, env, request, data }) => {
|
||||||
const domain = new URL(request.url).hostname
|
const domain = new URL(request.url).hostname
|
||||||
return handleRequestDelete(env.DATABASE, params.id as UUID, data.connectedActor, domain, env.userKEK, env.QUEUE)
|
return handleRequestDelete(
|
||||||
|
env.DATABASE,
|
||||||
|
params.id as UUID,
|
||||||
|
data.connectedActor,
|
||||||
|
domain,
|
||||||
|
env.userKEK,
|
||||||
|
env.QUEUE,
|
||||||
|
cacheFromEnv(env)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function handleRequestGet(db: D1Database, id: UUID, domain: string): Promise<Response> {
|
export async function handleRequestGet(db: D1Database, id: UUID, domain: string): Promise<Response> {
|
||||||
|
@ -68,7 +79,8 @@ export async function handleRequestDelete(
|
||||||
connectedActor: Person,
|
connectedActor: Person,
|
||||||
domain: string,
|
domain: string,
|
||||||
userKEK: string,
|
userKEK: string,
|
||||||
queue: Queue<DeliverMessageBody>
|
queue: Queue<DeliverMessageBody>,
|
||||||
|
cache: Cache
|
||||||
): Promise<Response> {
|
): Promise<Response> {
|
||||||
const obj = (await getObjectByMastodonId(db, id)) as Note
|
const obj = (await getObjectByMastodonId(db, id)) as Note
|
||||||
if (obj === null) {
|
if (obj === null) {
|
||||||
|
@ -89,6 +101,8 @@ export async function handleRequestDelete(
|
||||||
const activity = activities.create(domain, connectedActor, obj)
|
const activity = activities.create(domain, connectedActor, obj)
|
||||||
await deliverFollowers(db, userKEK, connectedActor, activity, queue)
|
await deliverFollowers(db, userKEK, connectedActor, activity, queue)
|
||||||
|
|
||||||
|
await timeline.pregenerateTimelines(domain, db, cache, connectedActor)
|
||||||
|
|
||||||
const headers = {
|
const headers = {
|
||||||
...cors(),
|
...cors(),
|
||||||
'content-type': 'application/json; charset=utf-8',
|
'content-type': 'application/json; charset=utf-8',
|
||||||
|
|
Ładowanie…
Reference in New Issue