@@ -4,7 +4,7 @@ import { applyCommit } from "./applyCommit.ts";
4
4
import { makeChanges } from "./makeChanges.ts" ;
5
5
import { HeadData , pull } from "./pull.ts" ;
6
6
import type { Line } from "../../deps/scrapbox.ts" ;
7
- import { pushCommit } from "./_fetch.ts" ;
7
+ import { pushCommit , pushWithRetry } from "./_fetch.ts" ;
8
8
export type { CommitNotification } ;
9
9
10
10
export interface JoinPageRoomResult {
@@ -13,7 +13,7 @@ export interface JoinPageRoomResult {
13
13
* `update()`で現在の本文から書き換え後の本文を作ってもらう。
14
14
* serverには書き換え前後の差分だけを送信する
15
15
*
16
- * @param update 書き換え後の本文を作成する函数。引数には現在の本文が渡される
16
+ * @param update 書き換え後の本文を作成する函数。引数には現在の本文が渡される。空配列を返すとページが削除される
17
17
*/
18
18
patch : (
19
19
update : ( before : Line [ ] , metadata : HeadData ) => string [ ] ,
@@ -74,11 +74,22 @@ export async function joinPageRoom(
74
74
try {
75
75
const pending = update ( head . lines , head ) ;
76
76
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
+
77
89
const changes = makeChanges ( head . lines , newLines , {
78
90
userId,
79
91
head,
80
92
} ) ;
81
-
82
93
const { commitId } = await pushCommit ( request , changes , {
83
94
parentId : head . commitId ,
84
95
projectId,
0 commit comments