Update conversations tab

This commit is contained in:
Pierre HUBERT 2021-03-08 17:08:00 +01:00
parent 9f98a2efd9
commit 349b66939c
3 changed files with 90 additions and 25 deletions

View File

@ -119,6 +119,10 @@ h1 {
margin-top: 10px; margin-top: 10px;
} }
#conversations-target .conversation .conversation-logo {
max-height: 200px;
}
#conversations-target .conversation .conversation-metadata { #conversations-target .conversation .conversation-metadata {
font-size: 90%; font-size: 90%;
font-style: italic; font-style: italic;

View File

@ -15,15 +15,15 @@ function GetConversationTitle(conversation){
let count = 0; let count = 0;
let name = ""; let name = "";
conversation.members.forEach(member_id => { conversation.members.forEach(member => {
//We only needs information about three members //We only needs information about three members
if(count > 3) return; if(count > 3) return;
//We skip current user ID //We skip current user ID
if(member_id == userID()) return; if(member.user_id == userID()) return;
let memberInfo = getUserInfo(member_id); let memberInfo = getUserInfo(member.user_id);
if(name.length > 0) if(name.length > 0)
name += ", "; name += ", ";
@ -65,6 +65,17 @@ function ApplyConversations(){
innerHTML: conversationInfo.name ? conversationInfo.name : GetConversationTitle(conversationInfo) innerHTML: conversationInfo.name ? conversationInfo.name : GetConversationTitle(conversationInfo)
}); });
// Conversation logo
if (conversationInfo.logo)
{
let logo = createElem2({
appendTo: conversationCardContent,
class: "conversation-logo",
type: "img",
});
applyURLToImage(logo, conversationInfo.logo);
}
//Conversation metadata //Conversation metadata
let metadataContainer = createElem2({ let metadataContainer = createElem2({
appendTo: conversationCardContent, appendTo: conversationCardContent,
@ -73,18 +84,17 @@ function ApplyConversations(){
}); });
function addMetadata(data){ function addMetadata(data){
createElem2({ return createElem2({
appendTo: metadataContainer, appendTo: metadataContainer,
type: "div", type: "div",
innerHTML: data innerHTML: data
}) })
} }
addMetadata("ID: " + conversationInfo.ID); addMetadata("ID: " + conversationInfo.id);
addMetadata("Owner: " + getUserInfo(conversationInfo.ID_owner).full_name); if (conversationInfo.color)
addMetadata("Last activity: " + timeToStr(conversationInfo.last_active)); addMetadata("Color: #" + conversationInfo.color).style.color = "#" + conversationInfo.color;
addMetadata("Following: " + (conversationInfo.following == 1? "Yes" : "No")); addMetadata("Last activity: " + timeToStr(conversationInfo.last_activity));
addMetadata("Saw last message: " + (conversationInfo.saw_last_message == 1? "Yes" : "No"));
//Process members list //Process members list
let conversationMembers = createElem2({ let conversationMembers = createElem2({
@ -100,8 +110,16 @@ function ApplyConversations(){
type: "div" type: "div"
}); });
fillElWithUserInfo(memberContainer, member); fillElWithUserInfo(memberContainer, member.user_id);
const addInfo = (str) => createElem2({
appendTo: memberContainer,
type: "span",
innerHTML: " <i>" + str + "</i> "
})
addInfo(member.is_admin ? "Admin" : "");
addInfo(member.following ? "Following" : "");
}); });
//Process conversation messages //Process conversation messages
@ -111,7 +129,7 @@ function ApplyConversations(){
class: "conversation-messages" class: "conversation-messages"
}); });
data.conversations_messages[conversationInfo.ID].forEach(message => { data.conversations_messages[conversationInfo.id].forEach(message => {
let messageContainer = createElem2({ let messageContainer = createElem2({
appendTo: conversationMessage, appendTo: conversationMessage,
@ -119,13 +137,19 @@ function ApplyConversations(){
class: "message" class: "message"
}); });
// Handle server messages
if(!message.user_id) {
messageContainer.innerHTML = "<i>Server message:" + JSON.stringify(message.server_message) + "</i>";
return;
}
//Message author //Message author
let messageAuthor = createElem2({ let messageAuthor = createElem2({
appendTo: messageContainer, appendTo: messageContainer,
type: "div", type: "div",
class: "user-info" class: "user-info"
}); });
fillElWithUserInfo(messageAuthor, message.ID_user); fillElWithUserInfo(messageAuthor, message.user_id);
//Message content //Message content
createElem2({ createElem2({
@ -135,19 +159,46 @@ function ApplyConversations(){
innerHTML: message.message innerHTML: message.message
}); });
//Message image //Message file
if(message.image_path != null){ if(message.file != null){
let messageImageContainer = createElem2({ if (message.file.type.startsWith("image/"))
appendTo: messageContainer, {
type: "div", let messageImageContainer = createElem2({
}); appendTo: messageContainer,
type: "a",
href: getFilePathFromURL(message.file.url),
});
messageImageContainer.target = "_blank"
let messageImage = createElem2({
appendTo: messageImageContainer,
type: "img",
class: "message-image"
});
applyURLToImage(messageImage, message.file.url);
}
let messageImage = createElem2({ else {
appendTo: messageImageContainer, let messageFileContainer = createElem2({
type: "img", appendTo: messageContainer,
class: "message-image" type: "div",
}); class: "message-file"
applyURLToImage(messageImage, message.image_path); });
messageFileContainer.innerHTML =
"Size: "+ fileSizeToHuman(message.file.size) + "<br />" +
"Type: " + message.file.type + "<br />" +
"URL: <a target='_blank' href='" + getFilePathFromURL(message.file.url) + "'>"+message.file.url+"</a><br />";
if (message.file.thumbnail) {
let thumb = createElem2({
appendTo: messageFileContainer,
type: "img",
class: "message-file-thumb"
});
applyURLToImage(thumb, message.file.thumbnail)
}
}
} }
//Message date //Message date
@ -155,7 +206,7 @@ function ApplyConversations(){
appendTo: messageContainer, appendTo: messageContainer,
type: "div", type: "div",
class: "message-date", class: "message-date",
innerHTML: timeToStr(message.time_insert) innerHTML: timeToStr(message.time_sent)
}) })
}); });

View File

@ -231,3 +231,13 @@ function fillElWithUserInfo(el, id){
function userID() { function userID() {
return data.advanced_info.userID; return data.advanced_info.userID;
} }
/**
* Format file size to human readable format
*
* @param {number} size The size to format
*/
function fileSizeToHuman(size) {
return Math.round(size/(1000*1000)*1000)/1000 + "MB";
}