@@ -4,7 +4,7 @@ import { applyCommit } from "./applyCommit.ts";
44import { makeChanges } from "./makeChanges.ts" ;
55import { HeadData , pull } from "./pull.ts" ;
66import type { Line } from "../../deps/scrapbox.ts" ;
7- import { pushCommit } from "./_fetch.ts" ;
7+ import { pushCommit , pushWithRetry } from "./_fetch.ts" ;
88export type { CommitNotification } ;
99
1010export interface JoinPageRoomResult {
@@ -13,7 +13,7 @@ export interface JoinPageRoomResult {
1313 * `update()`で現在の本文から書き換え後の本文を作ってもらう。
1414 * serverには書き換え前後の差分だけを送信する
1515 *
16- * @param update 書き換え後の本文を作成する函数。引数には現在の本文が渡される
16+ * @param update 書き換え後の本文を作成する函数。引数には現在の本文が渡される。空配列を返すとページが削除される
1717 */
1818 patch : (
1919 update : ( before : Line [ ] , metadata : HeadData ) => string [ ] ,
@@ -74,11 +74,22 @@ export async function joinPageRoom(
7474 try {
7575 const pending = update ( head . lines , head ) ;
7676 const newLines = pending instanceof Promise ? await pending : pending ;
77+
78+ if ( newLines . length === 0 ) {
79+ await pushWithRetry ( request , [ { deleted : true } ] , {
80+ projectId,
81+ pageId : head . pageId ,
82+ parentId : head . commitId ,
83+ userId,
84+ project,
85+ title,
86+ } ) ;
87+ }
88+
7789 const changes = makeChanges ( head . lines , newLines , {
7890 userId,
7991 head,
8092 } ) ;
81-
8293 const { commitId } = await pushCommit ( request , changes , {
8394 parentId : head . commitId ,
8495 projectId,
0 commit comments