diff --git a/docs/db_struct.sql b/docs/db_struct.sql index 006cfa1..d1006ee 100644 --- a/docs/db_struct.sql +++ b/docs/db_struct.sql @@ -245,3 +245,40 @@ CREATE TABLE `comunic_custom_emojis` ( `shortcut` VARCHAR(45) NULL, `path` VARCHAR(255) NULL, PRIMARY KEY (`id`)); + + +CREATE VIEW comunic_conversations_info AS + SELECT + l.id, + m.user_id, + l.name, + l.color, + l.background, + l.creation_time, + l.group_id, + l.can_everyone_add_members, + m.is_admin, + m.added_on AS user_added_on, + m.following, + m.last_message_seen, + msg.id AS last_msg_id, + msg.time_sent AS last_msg_time_sent, + msg.user_id AS last_msg_user_id, + msg.message AS last_msg_message, + msg.filepath AS last_msg_filepath, + msg.file_size AS last_msg_file_size, + msg.file_name AS last_msg_file_name, + msg.file_thumbnail AS last_msg_file_thumbnail, + msg.file_type AS last_msg_file_type + FROM + comunic_conversations_list l + JOIN + comunic_conversations_members m ON l.id = m.conv_id + JOIN + (SELECT + MAX(id) AS max_msg_id, conv_id + FROM + comunic_conversations_messages + GROUP BY conv_id) msg_id ON msg_id.conv_id = l.id + JOIN + comunic_conversations_messages msg ON msg.id = msg_id.max_msg_id; \ No newline at end of file diff --git a/docs/migration.sql b/docs/migration.sql index 4c70c2a..0faabd4 100644 --- a/docs/migration.sql +++ b/docs/migration.sql @@ -24,4 +24,41 @@ alter table comunic_conversations_list drop column last_active; alter table comunic_conversations_list add column color varchar(6), add column background varchar(255), - add group_id int; \ No newline at end of file + add group_id int; + +-- Conversations view +CREATE VIEW comunic_conversations_info AS + SELECT + l.id, + m.user_id, + l.name, + l.color, + l.background, + l.creation_time, + l.group_id, + l.can_everyone_add_members, + m.is_admin, + m.added_on AS user_added_on, + m.following, + m.last_message_seen, + msg.id AS last_msg_id, + msg.time_sent AS last_msg_time_sent, + msg.user_id AS last_msg_user_id, + msg.message AS last_msg_message, + msg.filepath AS last_msg_filepath, + msg.file_size AS last_msg_file_size, + msg.file_name AS last_msg_file_name, + msg.file_thumbnail AS last_msg_file_thumbnail, + msg.file_type AS last_msg_file_type + FROM + comunic_conversations_list l + JOIN + comunic_conversations_members m ON l.id = m.conv_id + JOIN + (SELECT + MAX(id) AS max_msg_id, conv_id + FROM + comunic_conversations_messages + GROUP BY conv_id) msg_id ON msg_id.conv_id = l.id + JOIN + comunic_conversations_messages msg ON msg.id = msg_id.max_msg_id; \ No newline at end of file