Skip to content

Commit

Permalink
スタンプの削除を実装
Browse files Browse the repository at this point in the history
  • Loading branch information
kamecha committed Oct 27, 2024
1 parent de30e5a commit 7bc6b69
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
2 changes: 1 addition & 1 deletion autoload/traqvim/command.vim
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ function traqvim#command#stamp(args) abort
if a:args[0] ==# 'add'
call denops#request('traqvim', 'messageAddStamps', [bufnr(), traqvim#message#get_message(), a:args[1:]])
elseif a:args[0] ==# 'remove'
call denops#request('traqvim', 'removeStamps', [bufnr(), traqvim#message#get_message(), a:args[1:]])
call denops#request('traqvim', 'messageRemoveStamps', [bufnr(), traqvim#message#get_message(), a:args[1:]])
endif
endfunction

Expand Down
48 changes: 48 additions & 0 deletions denops/traqvim/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
deleteMessage,
editMessage,
getMessageStamps,
removeMessageStamp,
removePin,
} from "./model.ts";
import { isMessage } from "./type_check.ts";
Expand Down Expand Up @@ -321,3 +322,50 @@ export const actionAddMessageStamp = async (
editedTimeline.find((m) => m.id === message.id),
);
}

export const actionRemoveMessageStamp = async (
denops: Denops,
message: Message,
stamp: string,
bufNum: number,
): Promise<void> => {
try {
await removeMessageStamp(message.id, stamp);
} catch (e) {
console.error(e);
return;
}
// 既存メッセージの取得
const timeline = await vars.buffers.get(denops, "channelTimeline");
assert(timeline, is.ArrayOf(isMessage));
// 一旦対象メッセージを削除する
await vars.buffers.set(
denops,
"channelTimeline",
timeline.filter((m) => m.id !== message.id),
);
await denops.call("traqvim#view#draw_delete_message", bufNum, message);
// 更新されたメッセージにあるスタンプを取得
const updatedMessage = await getMessageStamps(message.id);
const editedTimeline = timeline.map((m) => {
if (m.id === message.id) {
return {
...m,
stamps: updatedMessage,
};
} else {
return m;
}
});
// 編集したものをセット
await vars.buffers.set(
denops,
"channelTimeline",
editedTimeline,
);
await denops.call(
"traqvim#view#draw_append_message",
bufNum,
editedTimeline.find((m) => m.id === message.id),
);
};
20 changes: 20 additions & 0 deletions denops/traqvim/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
actionForwardChannelMessage,
actionOpenActivity,
actionOpenChannel,
actionRemoveMessageStamp,
actionRemovePin,
actionYankMessageLink,
actionYankMessageMarkdown,
Expand Down Expand Up @@ -425,6 +426,25 @@ export async function main(denops: Denops) {
}
return;
},
async messageRemoveStamps(
bufNum: unknown,
message: unknown,
stampNames: unknown,
): Promise<unknown> {
assert(bufNum, is.Number);
assert(message, isMessage);
assert(stampNames, is.ArrayOf(is.String));
for (const stampName of stampNames) {
const stampId = await getStampId(stampName);
if (stampId === undefined) {
helper.echo(denops, `Stamp not found: ${stampName}`);
continue;
}
const stamp = await getStamp(stampId);
await actionRemoveMessageStamp(denops, message, stamp.id, bufNum);
}
return;
},
async createPin(
bufNum: unknown,
message: unknown,
Expand Down

0 comments on commit 7bc6b69

Please sign in to comment.