Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions browser/websocket/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand All @@ -15,7 +15,9 @@ export interface JoinPageRoomResult {
*
* @param update 書き換え後の本文を作成する函数。引数には現在の本文が渡される
*/
patch: (update: (before: Line[]) => string[]) => Promise<void>;
patch: (
update: (before: Line[], metadata?: HeadData) => string[],
) => Promise<void>;
/** ページの更新情報を購読する */
listenPageUpdate: () => AsyncGenerator<CommitNotification, void, unknown>;
/** ページの操作を終了する。これを呼び出すと他のmethodsは使えなくなる
Expand Down Expand Up @@ -62,10 +64,15 @@ export async function joinPageRoom(
})();

return {
patch: async (update: (before: Line[]) => string[] | Promise<string[]>) => {
patch: async (
update: (
before: Line[],
metadata?: HeadData,
) => string[] | Promise<string[]>,
) => {
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,
Expand Down
6 changes: 3 additions & 3 deletions browser/websocket/shortcuts.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -55,7 +55,7 @@ export async function deletePage(
export async function patch(
project: string,
title: string,
update: (lines: Line[]) => string[] | Promise<string[]>,
update: (lines: Line[], metadata?: HeadData) => string[] | Promise<string[]>,
): Promise<void> {
const [
head_,
Expand All @@ -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 });

Expand Down