Compare commits
No commits in common. "843659b4959b193a6520e040d74ba74ff95b4bf0" and "b821c89e201e8fa06af413a4374c628bed1fed40" have entirely different histories.
843659b495
...
b821c89e20
@ -4,7 +4,6 @@ import { getMessageUid, getUserOfMailbox } from "../db/utils/mail";
|
|||||||
import emailManager from "../mails/EmailManager";
|
import emailManager from "../mails/EmailManager";
|
||||||
import { deleteMessage } from "../db/message/updateMessage-db";
|
import { deleteMessage } from "../db/message/updateMessage-db";
|
||||||
import logger from "../system/Logger";
|
import logger from "../system/Logger";
|
||||||
import { deleteRoom, getRoomNbMessage, getRoomOnMessageId } from "../db/Room-db";
|
|
||||||
|
|
||||||
export default class Message {
|
export default class Message {
|
||||||
static async addFlag(body, res: Response) {
|
static async addFlag(body, res: Response) {
|
||||||
@ -69,8 +68,7 @@ export default class Message {
|
|||||||
const mailbox = emailManager.getImap(user).getMailbox(mailboxId);
|
const mailbox = emailManager.getImap(user).getMailbox(mailboxId);
|
||||||
|
|
||||||
// add flag for deletion
|
// add flag for deletion
|
||||||
mailbox
|
mailbox.addFlag(uid.toString(), ["\\Deleted"])
|
||||||
.addFlag(uid.toString(), ["\\Deleted"])
|
|
||||||
.then(() => {
|
.then(() => {
|
||||||
// move message to trash
|
// move message to trash
|
||||||
mailbox.moveToTrash(uid.toString(), (err) => {
|
mailbox.moveToTrash(uid.toString(), (err) => {
|
||||||
@ -86,6 +84,7 @@ export default class Message {
|
|||||||
logger.log(err);
|
logger.log(err);
|
||||||
res.status(statusCode.METHOD_FAILURE).send({ error: err });
|
res.status(statusCode.METHOD_FAILURE).send({ error: err });
|
||||||
});
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static async deleteEverywhere(body, res: Response) {
|
static async deleteEverywhere(body, res: Response) {
|
||||||
@ -93,37 +92,26 @@ export default class Message {
|
|||||||
const uid = (await getMessageUid(messageId))[0]?.uid;
|
const uid = (await getMessageUid(messageId))[0]?.uid;
|
||||||
if (!uid) {
|
if (!uid) {
|
||||||
res.status(statusCode.NOT_FOUND).send({ error: "Message uid not found." });
|
res.status(statusCode.NOT_FOUND).send({ error: "Message uid not found." });
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const user = (await getUserOfMailbox(mailboxId))[0]?.user;
|
const user = (await getUserOfMailbox(mailboxId))[0]?.user;
|
||||||
if (!user) {
|
if (!user) {
|
||||||
res.status(statusCode.NOT_FOUND).send({ error: "Not account for this mailbox." });
|
res.status(statusCode.NOT_FOUND).send({ error: "Not account for this mailbox." });
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const roomId = (await getRoomOnMessageId(messageId))[0]?.room_id;
|
|
||||||
|
|
||||||
emailManager
|
emailManager
|
||||||
.getImap(user)
|
.getImap(user)
|
||||||
.getMailbox(mailboxId)
|
.getMailbox(mailboxId)
|
||||||
.removeFlag(uid.toString(), ["\\Deleted"])
|
.removeFlag(uid.toString(), ["\\Deleted"])
|
||||||
.then(async () => {
|
.then(() => {
|
||||||
try {
|
deleteMessage(messageId)
|
||||||
await deleteMessage(messageId);
|
.then((result) => {
|
||||||
if (roomId) {
|
// todo check if room is empty
|
||||||
const nbMessage = (await getRoomNbMessage(roomId))[0].nbMessage;
|
res.status(statusCode.OK).send();
|
||||||
if (nbMessage > 0) {
|
})
|
||||||
res.status(statusCode.OK).send();
|
.catch((err) => {
|
||||||
} else {
|
res.status(statusCode.METHOD_FAILURE).send({ error: err });
|
||||||
await deleteRoom(roomId);
|
console.log(err);
|
||||||
res.status(statusCode.OK).json({ deleteRoom: true }).send();
|
});
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
res.status(statusCode.METHOD_FAILURE).send({ error: err });
|
|
||||||
console.log(err);
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
|
@ -31,6 +31,8 @@ export default class Room {
|
|||||||
res.status(statusCode.OK).send();
|
res.status(statusCode.OK).send();
|
||||||
} else if (roomType === RoomType.GROUP || roomType === RoomType.THREAD) {
|
} else if (roomType === RoomType.GROUP || roomType === RoomType.THREAD) {
|
||||||
const lastMsgData = (await getLastMsgData(roomId))[0];
|
const lastMsgData = (await getLastMsgData(roomId))[0];
|
||||||
|
console.log(lastMsgData);
|
||||||
|
|
||||||
const mailBuilder = new MailBuilder();
|
const mailBuilder = new MailBuilder();
|
||||||
mailBuilder.inReplySubject(lastMsgData.subject).inReplyTo(lastMsgData.messageID).text(text).html(html);
|
mailBuilder.inReplySubject(lastMsgData.subject).inReplyTo(lastMsgData.messageID).text(text).html(html);
|
||||||
|
|
||||||
|
@ -12,10 +12,8 @@ export async function getRoomOwner(roomId: number) {
|
|||||||
return await execQueryAsync(query, values);
|
return await execQueryAsync(query, values);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* get all the data needed to reply to a message in a room
|
|
||||||
*/
|
|
||||||
export async function getLastMsgData(roomId: number) {
|
export async function getLastMsgData(roomId: number) {
|
||||||
|
|
||||||
const query = `
|
const query = `
|
||||||
SELECT
|
SELECT
|
||||||
msg.message_id AS id,
|
msg.message_id AS id,
|
||||||
@ -61,21 +59,3 @@ export async function getLastMsgData(roomId: number) {
|
|||||||
const values = [roomId];
|
const values = [roomId];
|
||||||
return await execQueryAsync(query, values);
|
return await execQueryAsync(query, values);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getRoomOnMessageId(messageId: number) {
|
|
||||||
const query = `SELECT room_id FROM app_room_message WHERE message_id = ?`;
|
|
||||||
const values = [messageId];
|
|
||||||
return await execQueryAsync(query, values);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getRoomNbMessage(roomId: number) {
|
|
||||||
const query = `SELECT COUNT(room_id) AS nbMessage FROM app_room_message WHERE room_id = ?`;
|
|
||||||
const values = [roomId];
|
|
||||||
return await execQueryAsync(query, values);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function deleteRoom(roomId: number) {
|
|
||||||
const query = `DELETE FROM app_room WHERE room_id = ?`;
|
|
||||||
const values = [roomId];
|
|
||||||
return await execQueryAsync(query, values);
|
|
||||||
}
|
|
||||||
|
@ -121,7 +121,7 @@ CREATE TABLE app_room (
|
|||||||
room_id INT AUTO_INCREMENT,
|
room_id INT AUTO_INCREMENT,
|
||||||
room_name VARCHAR(255) NOT NULL,
|
room_name VARCHAR(255) NOT NULL,
|
||||||
owner_id INT NOT NULL,
|
owner_id INT NOT NULL,
|
||||||
message_id INT,
|
message_id INT NOT NULL,
|
||||||
room_type INT NOT NULL DEFAULT 0,
|
room_type INT NOT NULL DEFAULT 0,
|
||||||
lastUpdate TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP(),
|
lastUpdate TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP(),
|
||||||
PRIMARY KEY (room_id),
|
PRIMARY KEY (room_id),
|
||||||
|
@ -35,6 +35,7 @@ export async function getMailbox(mailboxId: number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function updateMailbox(mailboxId: number, uidnext: number) {
|
export function updateMailbox(mailboxId: number, uidnext: number) {
|
||||||
|
console.log("updateMailbox", mailboxId, uidnext);
|
||||||
const query = `UPDATE mailbox SET uidnext = ? WHERE mailbox_id = ?`;
|
const query = `UPDATE mailbox SET uidnext = ? WHERE mailbox_id = ?`;
|
||||||
const values = [uidnext, mailboxId];
|
const values = [uidnext, mailboxId];
|
||||||
execQuery(query, values);
|
execQuery(query, values);
|
||||||
|
@ -137,7 +137,7 @@ export default class Mailbox {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.err("Failed to sync message " + error);
|
logger.err("Failed to sync message " + error);
|
||||||
}
|
}
|
||||||
logger.log(`Saved messages in uids ${i + STEP > nbMessageToSync ? nbMessageToSync : i + STEP}/${nbMessageToSync}`);
|
logger.log(`Saved messages ${i + STEP > nbMessageToSync ? nbMessageToSync : i + STEP}/${nbMessageToSync}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if has receive new msg during last sync then start a new sync
|
// if has receive new msg during last sync then start a new sync
|
||||||
|
@ -35,7 +35,7 @@ if (shouldReset) {
|
|||||||
if (table.table_name == "mailbox") return;
|
if (table.table_name == "mailbox") return;
|
||||||
console.log(table.table_name);
|
console.log(table.table_name);
|
||||||
execQuery("DELETE FROM " + table.table_name, []);
|
execQuery("DELETE FROM " + table.table_name, []);
|
||||||
// execQuery("DROP TABLE " + table.table_name, []);
|
// execQuery("DROP TABLE " + table.table_name);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -50,11 +50,7 @@ const deleteEverywhere = () => {
|
|||||||
deletionLoading.value = true;
|
deletionLoading.value = true;
|
||||||
API.deleteEverywhere({ mailboxId: room.value?.mailboxId, messageId: props.msg?.id })
|
API.deleteEverywhere({ mailboxId: room.value?.mailboxId, messageId: props.msg?.id })
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
// delete even if we delete the room after because the transition between room is not clean (todo)
|
|
||||||
store.commit("removeMsg", { roomId: room.value?.id, messageId: props.msg?.id });
|
store.commit("removeMsg", { roomId: room.value?.id, messageId: props.msg?.id });
|
||||||
if (res.data?.deleteRoom) {
|
|
||||||
store.commit("removeRoom", { roomId: room.value?.id });
|
|
||||||
}
|
|
||||||
deletionLoading.value = false;
|
deletionLoading.value = false;
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
|
@ -132,14 +132,6 @@ const store = createStore<State>({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
removeRoom(state, payload) {
|
|
||||||
const roomMessageIndex = state.roomMessages.findIndex((roomM) => roomM.roomId === payload.roomId);
|
|
||||||
state.roomMessages.splice(roomMessageIndex, 1);
|
|
||||||
const roomIndex = state.rooms.findIndex((room) => room.id === payload.roomId);
|
|
||||||
state.rooms.splice(roomIndex, 1);
|
|
||||||
// state.activeRoom = state.rooms[0].id;
|
|
||||||
// router.push(`/${state.activeRoom}`);
|
|
||||||
},
|
|
||||||
addMessages(state, payload) {
|
addMessages(state, payload) {
|
||||||
// todo add if not exist
|
// todo add if not exist
|
||||||
const room = roomOnId(state, payload.roomId);
|
const room = roomOnId(state, payload.roomId);
|
||||||
@ -182,12 +174,6 @@ const store = createStore<State>({
|
|||||||
const msgs = msgOnRoomId(state, payload.roomId);
|
const msgs = msgOnRoomId(state, payload.roomId);
|
||||||
const msgIndex = msgs?.messages.findIndex((msg) => msg.id == payload.messageId) ?? -1;
|
const msgIndex = msgs?.messages.findIndex((msg) => msg.id == payload.messageId) ?? -1;
|
||||||
if (msgs && msgIndex != -1) {
|
if (msgs && msgIndex != -1) {
|
||||||
if (!isSeenFc(msgs.messages[msgIndex].flags)) {
|
|
||||||
const room = roomOnId(state, payload.roomId);
|
|
||||||
if (room) {
|
|
||||||
room.notSeen = room.notSeen - 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
msgs.messages.splice(msgIndex, 1);
|
msgs.messages.splice(msgIndex, 1);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -51,7 +51,6 @@ function openMessageView(messageId) {
|
|||||||
|
|
||||||
const shouldBeCompact = (index) => {
|
const shouldBeCompact = (index) => {
|
||||||
// show last three messages
|
// show last three messages
|
||||||
// todo fix not changing three displayed when deleting
|
|
||||||
if (messages.value?.length - 4 < index) return false;
|
if (messages.value?.length - 4 < index) return false;
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
@ -1,8 +1,3 @@
|
|||||||
<script lang="ts" setup>
|
|
||||||
import Accounts from "./accounts/Accounts.vue";
|
|
||||||
import Rooms from "./rooms/Rooms.vue";
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<Accounts class="accounts" />
|
<Accounts class="accounts" />
|
||||||
@ -10,6 +5,19 @@ import Rooms from "./rooms/Rooms.vue";
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import Accounts from "./accounts/Accounts";
|
||||||
|
import Rooms from "./rooms/Rooms.vue";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: "Sidebar",
|
||||||
|
components: {
|
||||||
|
Accounts,
|
||||||
|
Rooms,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
div {
|
div {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
Loading…
Reference in New Issue
Block a user