1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-12-26 05:28:50 +00:00

Create a view to get conversations info

This commit is contained in:
Pierre HUBERT 2021-03-02 17:16:43 +01:00
parent e41c647e6f
commit 4ecf14a32c
2 changed files with 75 additions and 1 deletions

View File

@ -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;

View File

@ -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;
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;