66 lines
2.4 KiB
TypeScript
Raw Normal View History

2023-05-05 21:27:40 +08:00
import * as vscode from 'vscode';
2023-05-09 10:34:33 +08:00
import { MessageHandler } from './messageHandler';
2023-05-10 17:56:56 +08:00
import { regInMessage, regOutMessage } from '../util/reg_messages';
import { stopDevChatBase, sendMessageBase, deleteChatMessageBase } from './sendMessageBase';
import { UiUtilWrapper } from '../util/uiUtil';
2023-05-10 17:56:56 +08:00
2023-05-05 21:27:40 +08:00
let _lastMessage: any = undefined;
2023-05-10 17:56:56 +08:00
regInMessage({command: 'sendMessage', text: '', hash: undefined});
regOutMessage({ command: 'receiveMessage', text: 'xxxx', hash: 'xxx', user: 'xxx', date: 'xxx'});
regOutMessage({ command: 'receiveMessagePartial', text: 'xxxx', user: 'xxx', date: 'xxx'});
// message: { command: 'sendMessage', text: 'xxx', hash: 'xxx'}
// return message:
// { command: 'receiveMessage', text: 'xxxx', hash: 'xxx', user: 'xxx', date: 'xxx'}
// { command: 'receiveMessagePartial', text: 'xxxx', user: 'xxx', date: 'xxx'}
2023-05-16 14:35:01 +08:00
export async function sendMessage(message: any, panel: vscode.WebviewPanel|vscode.WebviewView): Promise<void> {
2023-05-23 11:16:48 +08:00
_lastMessage = message;
const responseMessage = await sendMessageBase(message, (data: { command: string, text: string, user: string, date: string}) => {
2023-05-31 16:10:53 +08:00
MessageHandler.sendMessage(panel, data, false);
});
if (responseMessage) {
MessageHandler.sendMessage(panel, responseMessage);
}
2023-05-05 21:27:40 +08:00
}
2023-05-23 11:16:48 +08:00
// regeneration last message again
regInMessage({command: 'regeneration'});
export async function regeneration(message: any, panel: vscode.WebviewPanel|vscode.WebviewView): Promise<void> {
// call sendMessage to send last message again
if (_lastMessage) {
sendMessage(_lastMessage, panel);
}
}
2023-05-10 17:56:56 +08:00
regInMessage({command: 'stopDevChat'});
2023-05-16 14:35:01 +08:00
export async function stopDevChat(message: any, panel: vscode.WebviewPanel|vscode.WebviewView): Promise<void> {
stopDevChatBase(message);
}
regInMessage({command: 'deleteChatMessage', hash: 'xxx'});
regOutMessage({ command: 'deletedChatMessage', hash: 'xxxx'});
export async function deleteChatMessage(message: any, panel: vscode.WebviewPanel|vscode.WebviewView): Promise<void> {
// prompt user to confirm
const confirm = await vscode.window.showWarningMessage(
`Are you sure to delete this message?`,
{ modal: true },
'Delete'
);
if (confirm !== 'Delete') {
return;
}
const deleted = deleteChatMessageBase(message);
if (!deleted) {
MessageHandler.sendMessage(panel, { command: 'deletedChatMessage', hash: message.hash });
} else {
UiUtilWrapper.showErrorMessage('Delete message failed!');
}
}
2023-05-08 12:09:52 +08:00
2023-05-05 21:27:40 +08:00