Message deleting

main
Talon 2024-08-30 17:22:59 +02:00
parent 4ab828ea2b
commit e384b6fcc3
3 changed files with 23 additions and 6 deletions

View File

@ -40,7 +40,7 @@ export const deleteMessage = async (messageId: string) => {
// Remove from FTS table if enabled
if (FTS5Enabled) {
const query2 = db.prepare(`DELETE FROM messages_fts WHERE rowid = $rowId`);
const result2 = query.run({ rowId: messageId });
const result2 = query2.run({ rowId: messageId });
}
events.emit('message-deleted', messageId);
return result;

View File

@ -4,7 +4,8 @@ import { Button, Container, TextInput} from "../ui";
import { Dialog } from "../ui/dialog";
import { Text } from "../ui";
import { MultilineInput } from "../ui/multiline-input";
export class MessageDialog extends Dialog<void> {
import { state } from "../state";
export class MessageDialog extends Dialog<IMessage | null> {
private message: IMessage;
private messageText: MultilineInput;
private deleteButton: Button;
@ -19,10 +20,12 @@ export class MessageDialog extends Dialog<void> {
this.deleteButton = new Button("Delete");
this.deleteButton.setPosition(10, 90, 80, 10);
this.deleteButton.onClick(() => {
return;
this.deleteButton.onClick(async () => {
await API.deleteMessage(state.currentChannel!.id.toString(), this.message.id.toString());
this.choose(null);
});
this.add(this.messageText);
this.add(this.deleteButton);
if (this.message.fileId !== null) {
this.fileInfoContainer = new Container("File info");
this.fileInfoContainer.setPosition(10, 50, 30, 80);

View File

@ -226,7 +226,7 @@ export class MainView extends View {
const itm = new ListItem(`${message.content}; ${this.convertIsoTimeStringToFriendly(message.createdAt)}`);
itm.setUserData(message.id);
itm.onClick(() => {
new MessageDialog(message).open();
this.openMessageDialog(message);
})
return itm;
}
@ -581,7 +581,6 @@ export class MainView extends View {
}
private handleHotkey(e: KeyboardEvent) {
if (e.ctrlKey && e.shiftKey) {
const action = this.hotkeyMap.get(e.key.toLowerCase());
if (action) {
@ -590,4 +589,19 @@ export class MainView extends View {
}
}
}
private async openMessageDialog(message: IMessage) {
const d = new MessageDialog(message);
const msg = await d.open();
console.log(msg);
if (!msg || msg === null) {
state.currentChannel?.removeMessage(message.id);
const node = this.messageElementMap.get(message.id);
if (node) {
this.messageList.remove(node);
this.messageElementMap.delete(message.id);
}
state.save();
}
}
}