display mail in iframe, add design for thread and unseen
This commit is contained in:
@@ -41,11 +41,12 @@ async function getRooms(mailboxId) {
|
||||
INNER JOIN message
|
||||
INNER JOIN mailbox_message
|
||||
INNER JOIN address
|
||||
WHERE
|
||||
message.message_id = app_room.message_id AND
|
||||
mailbox_message.mailbox_id = ? AND
|
||||
mailbox_message.message_id = message.message_id AND
|
||||
address.address_id = app_room.owner_id
|
||||
WHERE
|
||||
message.message_id = app_room.message_id AND
|
||||
mailbox_message.mailbox_id = ? AND
|
||||
mailbox_message.message_id = message.message_id AND
|
||||
address.address_id = app_room.owner_id
|
||||
ORDER BY app_room.lastUpdate DESC
|
||||
`;
|
||||
const values = [mailboxId];
|
||||
return await execQueryAsync(query, values);
|
||||
|
||||
@@ -12,13 +12,6 @@ async function getAddresseId(email, name) {
|
||||
return await execQueryAsyncWithId(query, values);
|
||||
}
|
||||
|
||||
function getMailboxId(email) {
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve(0)
|
||||
});
|
||||
// todo
|
||||
}
|
||||
|
||||
async function getFieldId(field) {
|
||||
const query = `INSERT INTO field_name (field_name) VALUES (?) ON DUPLICATE KEY UPDATE field_id=LAST_INSERT_ID(field_id)`;
|
||||
const values = [field]
|
||||
@@ -33,7 +26,6 @@ async function findRoomByOwner(ownerId) {
|
||||
|
||||
module.exports = {
|
||||
getAddresseId,
|
||||
getMailboxId,
|
||||
getFieldId,
|
||||
findRoomByOwner,
|
||||
};
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
const { transformEmojis } = require("../utils/string.js");
|
||||
const { db, execQuery, execQueryAsync, execQueryAsyncWithId } = require("./db.js");
|
||||
const DEBUG = require("../utils/debug").DEBUG;
|
||||
|
||||
@@ -30,12 +31,14 @@ function registerBodypart(messageId, part, bodypartId, bytes, nbLines) {
|
||||
}
|
||||
|
||||
async function saveBodypart(bytes, hash, text, data) {
|
||||
text = transformEmojis(text);
|
||||
const query = `INSERT IGNORE INTO bodypart (bytes, hash, text, data) VALUES (?, ?, ?, ?)`;
|
||||
const values = [bytes, hash, text, data];
|
||||
return await execQueryAsyncWithId(query, values);
|
||||
}
|
||||
|
||||
async function saveHeader_fields(messageId, fieldId, bodypartId, part, value) {
|
||||
value = transformEmojis(value);
|
||||
const query = `
|
||||
INSERT IGNORE INTO header_field
|
||||
(message_id, field_id, bodypart_id, part, value) VALUES (?, ?, ?, ?, ?)
|
||||
@@ -54,7 +57,7 @@ async function saveAddress_fields(messageId, fieldId, addressId, number) {
|
||||
}
|
||||
|
||||
function saveSource(messageId, content) {
|
||||
content = Buffer.from(content);
|
||||
content = transformEmojis(content);
|
||||
const query = `
|
||||
INSERT INTO source (message_id, content) VALUES (?, ?)
|
||||
ON DUPLICATE KEY UPDATE content = ?
|
||||
|
||||
@@ -1,28 +1,32 @@
|
||||
const { db, execQueryAsync, execQueryAsyncWithId } = require("./db.js");
|
||||
const { transformEmojis } = require("../utils/string.js");
|
||||
const { db, execQueryAsync, execQueryAsyncWithId, execQuery } = require("./db.js");
|
||||
const { queryFromId, queryToId, queryCcId } = require("./utils/addressQueries.js");
|
||||
const DEBUG = require("../utils/debug").DEBUG;
|
||||
|
||||
async function createRoom(roomName, ownerId, messageId) {
|
||||
roomName = transformEmojis(roomName);
|
||||
const query = `INSERT INTO app_room (room_name, owner_id, message_id) VALUES (?, ?, ?)`;
|
||||
const values = [roomName.substring(0, 255), ownerId, messageId];
|
||||
return await execQueryAsyncWithId(query, values);
|
||||
// todo add members
|
||||
}
|
||||
|
||||
async function registerMessageInRoom(messageId, roomId, isSeen) {
|
||||
async function registerMessageInRoom(messageId, roomId, isSeen, idate) {
|
||||
const query = `INSERT IGNORE INTO app_room_message (message_id, room_id) VALUES (?, ?)`;
|
||||
const values = [messageId, roomId];
|
||||
await execQueryAsync(query, values);
|
||||
|
||||
updateLastUpdateRoom(roomId);
|
||||
updateLastUpdateRoom(roomId, idate);
|
||||
|
||||
if (!isSeen) {
|
||||
incrementNotSeenRoom(roomId);
|
||||
}
|
||||
}
|
||||
|
||||
function updateLastUpdateRoom(roomId) {
|
||||
// todo
|
||||
function updateLastUpdateRoom(roomId, idate) {
|
||||
const query = `UPDATE app_room SET lastUpdate = ? WHERE room_id = ?`;
|
||||
const values = [idate, roomId];
|
||||
execQuery(query, values);
|
||||
}
|
||||
|
||||
function incrementNotSeenRoom(roomId) {
|
||||
@@ -41,18 +45,10 @@ async function createThread(threadName, ownerId, messageId, parentRoomId, isDm)
|
||||
async function registerMessageInThread(messageId, threadId, isSeen) {
|
||||
// todo check if it is still a thread or should be a room
|
||||
// todo isdm
|
||||
const query = `INSERT IGNORE INTO app_space_message
|
||||
(message_id, thread_id) VALUES (?, ?)`;
|
||||
const values = [messageId, threadId];
|
||||
await execQueryAsync(query, values);
|
||||
updateLastUpdateThread(threadId);
|
||||
|
||||
if (!isSeen) {
|
||||
incrementNotSeenThread(threadId);
|
||||
}
|
||||
console.log("register message in thread")
|
||||
}
|
||||
|
||||
function updateLastUpdateRoom(threadId) {
|
||||
function updateLastUpdateThread(threadId) {
|
||||
// todo
|
||||
// check for parent
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ CREATE TABLE bodypart (
|
||||
bodypart_id INT AUTO_INCREMENT,
|
||||
bytes INT NOT NULL,
|
||||
hash TEXT NOT NULL,
|
||||
text TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
|
||||
text TEXT,
|
||||
data BINARY,
|
||||
PRIMARY KEY (bodypart_id)
|
||||
);
|
||||
@@ -75,10 +75,10 @@ CREATE TABLE bodypart (
|
||||
-- 7
|
||||
CREATE TABLE source (
|
||||
message_id INT NOT NULL,
|
||||
content BLOB NOT NULL,
|
||||
content TEXT NOT NULL,
|
||||
PRIMARY KEY (message_id),
|
||||
FOREIGN KEY (message_id) REFERENCES message(message_id) ON DELETE CASCADE
|
||||
)
|
||||
);
|
||||
|
||||
-- 8
|
||||
CREATE TABLE field_name (
|
||||
@@ -94,7 +94,7 @@ CREATE TABLE header_field (
|
||||
field_id INT NOT NULL,
|
||||
bodypart_id INT,
|
||||
part VARCHAR(128),
|
||||
value TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
|
||||
value TEXT,
|
||||
UNIQUE KEY (message_id, field_id, bodypart_id),
|
||||
UNIQUE KEY (message_id, field_id, part),
|
||||
FOREIGN KEY (message_id) REFERENCES message(message_id) ON DELETE CASCADE,
|
||||
|
||||
Reference in New Issue
Block a user