diff --git a/browser/websocket/room.ts b/browser/websocket/room.ts index 6873cfb..1d8e9fc 100644 --- a/browser/websocket/room.ts +++ b/browser/websocket/room.ts @@ -2,7 +2,7 @@ import { CommitNotification, socketIO, wrap } from "../../deps/socket.ts"; import { getProjectId, getUserId } from "./id.ts"; import { applyCommit } from "./applyCommit.ts"; import { makeChanges } from "./makeChanges.ts"; -import { pull } from "./pull.ts"; +import { HeadData, pull } from "./pull.ts"; import type { Line } from "../../deps/scrapbox.ts"; import { pushCommit } from "./_fetch.ts"; export type { CommitNotification }; @@ -15,7 +15,9 @@ export interface JoinPageRoomResult { * * @param update 書き換え後の本文を作成する函数。引数には現在の本文が渡される */ - patch: (update: (before: Line[]) => string[]) => Promise; + patch: ( + update: (before: Line[], metadata?: HeadData) => string[], + ) => Promise; /** ページの更新情報を購読する */ listenPageUpdate: () => AsyncGenerator; /** ページの操作を終了する。これを呼び出すと他のmethodsは使えなくなる @@ -62,10 +64,15 @@ export async function joinPageRoom( })(); return { - patch: async (update: (before: Line[]) => string[] | Promise) => { + patch: async ( + update: ( + before: Line[], + metadata?: HeadData, + ) => string[] | Promise, + ) => { for (let i = 0; i < 3; i++) { try { - const pending = update(head.lines); + const pending = update(head.lines, head); const newLines = pending instanceof Promise ? await pending : pending; const changes = makeChanges(head.lines, newLines, { userId, diff --git a/browser/websocket/shortcuts.ts b/browser/websocket/shortcuts.ts index ab2c4bd..679cf96 100644 --- a/browser/websocket/shortcuts.ts +++ b/browser/websocket/shortcuts.ts @@ -1,7 +1,7 @@ import { socketIO, wrap } from "../../deps/socket.ts"; import { getProjectId, getUserId } from "./id.ts"; import { makeChanges } from "./makeChanges.ts"; -import { pull } from "./pull.ts"; +import { HeadData, pull } from "./pull.ts"; import { pinNumber } from "./pin.ts"; import type { Line } from "../../deps/scrapbox.ts"; import { pushCommit, pushWithRetry } from "./_fetch.ts"; @@ -55,7 +55,7 @@ export async function deletePage( export async function patch( project: string, title: string, - update: (lines: Line[]) => string[] | Promise, + update: (lines: Line[], metadata?: HeadData) => string[] | Promise, ): Promise { const [ head_, @@ -76,7 +76,7 @@ export async function patch( // 3回retryする for (let i = 0; i < 3; i++) { try { - const pending = update(head.lines); + const pending = update(head.lines, head); const newLines = pending instanceof Promise ? await pending : pending; const changes = makeChanges(head.lines, newLines, { userId, head });