backend: improve documentation of pin/update functions

This commit is contained in:
Norm 2022-10-16 18:06:22 -04:00
parent f17485d8a2
commit f2f547172e
Signed by untrusted user: norm
GPG key ID: 7123E30E441E80DE
2 changed files with 21 additions and 11 deletions

View file

@ -12,11 +12,11 @@ import { deliverToFollowers } from '@/remote/activitypub/deliver-manager.js';
import { deliverToRelays } from '../relay.js'; import { deliverToRelays } from '../relay.js';
/** /**
* 稿 * Pin a given post to a user profile.
* @param user * @param user the user to pin the note to
* @param noteId * @param noteId ID of note to pin
*/ */
export async function addPinned(user: { id: User['id']; host: User['host']; }, noteId: Note['id']) { export async function addPinned(user: { id: User['id']; host: User['host']; }, noteId: Note['id']): Promise<void> {
// Fetch pinee // Fetch pinee
const note = await Notes.findOneBy({ const note = await Notes.findOneBy({
id: noteId, id: noteId,
@ -51,11 +51,11 @@ export async function addPinned(user: { id: User['id']; host: User['host']; }, n
} }
/** /**
* 稿 * Unpin a given post from a user profile.
* @param user * @param user the user to unpin a note from
* @param noteId * @param noteId ID of note to unpin
*/ */
export async function removePinned(user: { id: User['id']; host: User['host']; }, noteId: Note['id']) { export async function removePinned(user: { id: User['id']; host: User['host']; }, noteId: Note['id']): Promise<void> {
// Fetch unpinee // Fetch unpinee
const note = await Notes.findOneBy({ const note = await Notes.findOneBy({
id: noteId, id: noteId,
@ -77,7 +77,13 @@ export async function removePinned(user: { id: User['id']; host: User['host']; }
} }
} }
export async function deliverPinnedChange(userId: User['id'], noteId: Note['id'], isAddition: boolean) { /**
* Notify followers and relays when a note is pinned/unpinned.
* @param userId ID of user
* @param noteId ID of note
* @param isAddition whether the note was pinned or unpinned
*/
export async function deliverPinnedChange(userId: User['id'], noteId: Note['id'], isAddition: boolean): Promise<void> {
const user = await Users.findOneBy({ id: userId }); const user = await Users.findOneBy({ id: userId });
if (user == null) throw new Error('user not found'); if (user == null) throw new Error('user not found');

View file

@ -6,11 +6,15 @@ import { renderPerson } from '@/remote/activitypub/renderer/person.js';
import { deliverToFollowers } from '@/remote/activitypub/deliver-manager.js'; import { deliverToFollowers } from '@/remote/activitypub/deliver-manager.js';
import { deliverToRelays } from '../relay.js'; import { deliverToRelays } from '../relay.js';
export async function publishToFollowers(userId: User['id']) { /**
* Send an Update activity to a user's followers.
* @param userId ID of user
*/
export async function publishToFollowers(userId: User['id']): Promise<void> {
const user = await Users.findOneBy({ id: userId }); const user = await Users.findOneBy({ id: userId });
if (user == null) throw new Error('user not found'); if (user == null) throw new Error('user not found');
// フォロワーがリモートユーザーかつ投稿者がローカルユーザーならUpdateを配信 // Deliver Update if the follower is a remote user and the poster is a local user
if (Users.isLocalUser(user)) { if (Users.isLocalUser(user)) {
const content = renderActivity(renderUpdate(await renderPerson(user), user)); const content = renderActivity(renderUpdate(await renderPerson(user), user));
deliverToFollowers(user, content); deliverToFollowers(user, content);