Message deleting
parent
4ab828ea2b
commit
e384b6fcc3
|
@ -40,7 +40,7 @@ export const deleteMessage = async (messageId: string) => {
|
||||||
// Remove from FTS table if enabled
|
// Remove from FTS table if enabled
|
||||||
if (FTS5Enabled) {
|
if (FTS5Enabled) {
|
||||||
const query2 = db.prepare(`DELETE FROM messages_fts WHERE rowid = $rowId`);
|
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);
|
events.emit('message-deleted', messageId);
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -4,7 +4,8 @@ import { Button, Container, TextInput} from "../ui";
|
||||||
import { Dialog } from "../ui/dialog";
|
import { Dialog } from "../ui/dialog";
|
||||||
import { Text } from "../ui";
|
import { Text } from "../ui";
|
||||||
import { MultilineInput } from "../ui/multiline-input";
|
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 message: IMessage;
|
||||||
private messageText: MultilineInput;
|
private messageText: MultilineInput;
|
||||||
private deleteButton: Button;
|
private deleteButton: Button;
|
||||||
|
@ -19,10 +20,12 @@ export class MessageDialog extends Dialog<void> {
|
||||||
|
|
||||||
this.deleteButton = new Button("Delete");
|
this.deleteButton = new Button("Delete");
|
||||||
this.deleteButton.setPosition(10, 90, 80, 10);
|
this.deleteButton.setPosition(10, 90, 80, 10);
|
||||||
this.deleteButton.onClick(() => {
|
this.deleteButton.onClick(async () => {
|
||||||
return;
|
await API.deleteMessage(state.currentChannel!.id.toString(), this.message.id.toString());
|
||||||
|
this.choose(null);
|
||||||
});
|
});
|
||||||
this.add(this.messageText);
|
this.add(this.messageText);
|
||||||
|
this.add(this.deleteButton);
|
||||||
if (this.message.fileId !== null) {
|
if (this.message.fileId !== null) {
|
||||||
this.fileInfoContainer = new Container("File info");
|
this.fileInfoContainer = new Container("File info");
|
||||||
this.fileInfoContainer.setPosition(10, 50, 30, 80);
|
this.fileInfoContainer.setPosition(10, 50, 30, 80);
|
||||||
|
|
|
@ -226,7 +226,7 @@ export class MainView extends View {
|
||||||
const itm = new ListItem(`${message.content}; ${this.convertIsoTimeStringToFriendly(message.createdAt)}`);
|
const itm = new ListItem(`${message.content}; ${this.convertIsoTimeStringToFriendly(message.createdAt)}`);
|
||||||
itm.setUserData(message.id);
|
itm.setUserData(message.id);
|
||||||
itm.onClick(() => {
|
itm.onClick(() => {
|
||||||
new MessageDialog(message).open();
|
this.openMessageDialog(message);
|
||||||
})
|
})
|
||||||
return itm;
|
return itm;
|
||||||
}
|
}
|
||||||
|
@ -581,7 +581,6 @@ export class MainView extends View {
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleHotkey(e: KeyboardEvent) {
|
private handleHotkey(e: KeyboardEvent) {
|
||||||
|
|
||||||
if (e.ctrlKey && e.shiftKey) {
|
if (e.ctrlKey && e.shiftKey) {
|
||||||
const action = this.hotkeyMap.get(e.key.toLowerCase());
|
const action = this.hotkeyMap.get(e.key.toLowerCase());
|
||||||
if (action) {
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue