@@ -4,32 +4,14 @@ import {
44 socketIO ,
55 wrap ,
66} from "../../deps/socket.ts" ;
7- import { createNewLineId , getProjectId , getUserId } from "./id.ts" ;
7+ import { getProjectId , getUserId } from "./id.ts" ;
88import { diffToChanges } from "./patch.ts" ;
99import { applyCommit } from "./applyCommit.ts" ;
1010import type { Line } from "../../deps/scrapbox.ts" ;
11- import { ensureEditablePage , pushCommit , pushWithRetry } from "./_fetch.ts" ;
11+ import { ensureEditablePage , pushCommit } from "./_fetch.ts" ;
1212export type { CommitNotification } ;
1313
1414export interface JoinPageRoomResult {
15- /** 特定の位置にテキストを挿入する
16- *
17- * @param text - 挿入したいテキスト (複数行も可)
18- * @param beforeId - この行IDが指し示す行の上に挿入する。末尾に挿入する場合は`_end`を指定する
19- */
20- insert : ( text : string , beforeId : string ) => Promise < void > ;
21- /** 特定の行を削除する
22- *
23- * @param lineId 削除したい行の行ID
24- */
25- remove : ( lineId : string ) => Promise < void > ;
26- /** 特定の位置のテキストを書き換える
27- *
28- * @param text - 書き換え後のテキスト (改行は不可)
29- * @param lineId - 書き換えたい行の行ID
30- */
31- update : ( text : string , lineId : string ) => Promise < void > ;
32-
3315 /** ページ全体を書き換える
3416 *
3517 * `update()`で現在の本文から書き換え後の本文を作ってもらう。
@@ -86,49 +68,7 @@ export async function joinPageRoom(
8668 }
8769 } ) ( ) ;
8870
89- async function push ( changes : Change [ ] , retry = 3 ) {
90- // 変更後のlinesを計算する
91- const changedLines = applyCommit ( lines , changes , {
92- userId,
93- } ) ;
94- // タイトルの変更チェック
95- // 空ページの場合もタイトル変更commitを入れる
96- if ( lines [ 0 ] . text !== changedLines [ 0 ] . text || ! created ) {
97- changes . push ( { title : changedLines [ 0 ] . text } ) ;
98- }
99- // サムネイルの変更チェック
100- const oldDescriptions = lines . slice ( 1 , 6 ) . map ( ( line ) => line . text ) ;
101- const newDescriptions = changedLines . slice ( 1 , 6 ) . map ( ( lines ) => lines . text ) ;
102- if ( oldDescriptions . join ( "\n" ) !== newDescriptions . join ( "\n" ) ) {
103- changes . push ( { descriptions : newDescriptions } ) ;
104- }
105-
106- // serverにpushする
107- parentId = await pushWithRetry ( request , changes , {
108- parentId,
109- projectId,
110- pageId,
111- userId,
112- project,
113- title,
114- retry,
115- } ) ;
116- // pushに成功したら、localにも変更を反映する
117- created = true ;
118- lines = changedLines ;
119- }
120-
12171 return {
122- insert : async ( text : string , beforeId = "_end" ) => {
123- const changes = text . split ( / \n | \r \n / ) . map ( ( line ) => ( {
124- _insert : beforeId ,
125- lines : { text : line , id : createNewLineId ( userId ) } ,
126- } ) ) ;
127- await push ( changes ) ;
128- } ,
129- remove : ( lineId : string ) => push ( [ { _delete : lineId , lines : - 1 } ] ) ,
130- update : ( text : string , lineId : string ) =>
131- push ( [ { _update : lineId , lines : { text } } ] ) ,
13272 patch : async ( update : ( before : Line [ ] ) => string [ ] | Promise < string [ ] > ) => {
13373 const tryPush = async ( ) => {
13474 const pending = update ( lines ) ;
0 commit comments