implement createReblog function to reduce reblog code duplication

pull/151/head
Dario Piotrowicz 2023-01-23 12:11:54 +00:00
rodzic c7978d4ea5
commit 96c9242298
6 zmienionych plików z 22 dodań i 24 usunięć

Wyświetl plik

@ -10,9 +10,9 @@ import {
sendMentionNotification,
sendLikeNotification,
sendFollowNotification,
sendReblogNotification,
createNotification,
insertFollowNotification,
sendReblogNotification,
} from 'wildebeest/backend/src/mastodon/notification'
import { type Object, updateObject } from 'wildebeest/backend/src/activitypub/objects'
import { parseHandle } from 'wildebeest/backend/src/utils/parse'
@ -21,7 +21,7 @@ import { addFollowing, acceptFollowing } from 'wildebeest/backend/src/mastodon/f
import { deliverToActor } from 'wildebeest/backend/src/activitypub/deliver'
import { getSigningKey } from 'wildebeest/backend/src/mastodon/account'
import { insertLike } from 'wildebeest/backend/src/mastodon/like'
import { insertReblog } from 'wildebeest/backend/src/mastodon/reblog'
import { createReblog } from 'wildebeest/backend/src/mastodon/reblog'
import { insertReply } from 'wildebeest/backend/src/mastodon/reply'
import type { Activity } from 'wildebeest/backend/src/activitypub/activities'
@ -288,15 +288,10 @@ export async function handle(
const notifId = await createNotification(db, 'reblog', targetActor, fromActor, obj)
await Promise.all([
// Add the object in the originating actor's outbox, allowing other
// actors on this instance to see the note in their timelines.
addObjectInOutbox(db, fromActor, obj, activity.published),
// Store the reblog for counting
insertReblog(db, fromActor, obj),
createReblog(db, fromActor, obj),
sendReblogNotification(db, fromActor, targetActor, notifId, adminEmail, vapidKeys),
])
break
}

Wyświetl plik

@ -3,6 +3,18 @@
import type { Object } from 'wildebeest/backend/src/activitypub/objects'
import type { Actor } from 'wildebeest/backend/src/activitypub/actors'
import { getResultsField } from './utils'
import { addObjectInOutbox } from '../activitypub/actors/outbox'
/**
* Creates a reblog and inserts it in the reblog author's outbox
*
* @param db D1Database
* @param actor Reblogger
* @param obj Object to reblog
*/
export async function createReblog(db: D1Database, actor: Actor, obj: Object) {
await Promise.all([addObjectInOutbox(db, actor, obj), insertReblog(db, actor, obj)])
}
export async function insertReblog(db: D1Database, actor: Actor, obj: Object) {
const id = crypto.randomUUID()

Wyświetl plik

@ -5,7 +5,7 @@ import * as oauth_token from 'wildebeest/functions/oauth/token'
import { isUrlValid, makeDB, assertCORS, assertJSON, createTestClient } from '../utils'
import { TEST_JWT, ACCESS_CERTS } from '../test-data'
import { strict as assert } from 'node:assert/strict'
import { Actor } from 'wildebeest/backend/src/activitypub/actors'
import type { Actor } from 'wildebeest/backend/src/activitypub/actors'
const userKEK = 'test_kek3'
const accessDomain = 'access.com'

Wyświetl plik

@ -2,7 +2,7 @@ import { strict as assert } from 'node:assert/strict'
import { insertReply } from 'wildebeest/backend/src/mastodon/reply'
import { getMentions } from 'wildebeest/backend/src/mastodon/status'
import { addObjectInOutbox } from 'wildebeest/backend/src/activitypub/actors/outbox'
import { createPublicNote, Note } from 'wildebeest/backend/src/activitypub/objects/note'
import { createPublicNote, type Note } from 'wildebeest/backend/src/activitypub/objects/note'
import { createImage } from 'wildebeest/backend/src/activitypub/objects/image'
import * as statuses from 'wildebeest/functions/api/v1/statuses'
import * as statuses_get from 'wildebeest/functions/api/v1/statuses/[id]'

Wyświetl plik

@ -3,7 +3,7 @@ import { replies, statuses } from 'wildebeest/frontend/src/dummyData'
import type { Account, MastodonStatus } from 'wildebeest/frontend/src/types'
import { createPublicNote, Note } from 'wildebeest/backend/src/activitypub/objects/note'
import { addObjectInOutbox } from 'wildebeest/backend/src/activitypub/actors/outbox'
import { insertReblog } from 'wildebeest/backend/src/mastodon/reblog'
import { createReblog } from 'wildebeest/backend/src/mastodon/reblog'
import { insertReply } from 'wildebeest/backend/src/mastodon/reply'
/**
@ -18,7 +18,7 @@ export async function init(domain: string, db: D1Database) {
}
const { reblogger, noteToReblog } = await pickReblogDetails(loadedStatuses, domain, db)
reblogNote(db, reblogger, noteToReblog)
await createReblog(db, reblogger, noteToReblog)
for (const reply of replies) {
await createReply(domain, db, reply, loadedStatuses)
@ -34,14 +34,6 @@ async function createStatus(domain: string, db: D1Database, actor: Person, conte
return note
}
/**
* Reblogs a note (representing a status)
*/
async function reblogNote(db: D1Database, reblogger: Person, noteToReblog: Note) {
await addObjectInOutbox(db, reblogger, noteToReblog)
await insertReblog(db, reblogger, noteToReblog)
}
/**
* Creates a reply for a note (representing a status)
*/

Wyświetl plik

@ -2,8 +2,7 @@
import type { Queue, DeliverMessageBody } from 'wildebeest/backend/src/types/queue'
import { cors } from 'wildebeest/backend/src/utils/cors'
import type { Env } from 'wildebeest/backend/src/types/env'
import { addObjectInOutbox } from 'wildebeest/backend/src/activitypub/actors/outbox'
import { insertReblog } from 'wildebeest/backend/src/mastodon/reblog'
import { createReblog } from 'wildebeest/backend/src/mastodon/reblog'
import { getSigningKey } from 'wildebeest/backend/src/mastodon/account'
import { deliverToActor, deliverFollowers } from 'wildebeest/backend/src/activitypub/deliver'
import type { Person } from 'wildebeest/backend/src/activitypub/actors'
@ -56,7 +55,7 @@ export async function handleRequest(
])
}
await Promise.all([addObjectInOutbox(db, connectedActor, obj), insertReblog(db, connectedActor, obj)])
await createReblog(db, connectedActor, obj)
status.reblogged = true
const headers = {