mirror of
https://github.com/pierre42100/ComunicWeb
synced 2024-11-26 13:59:23 +00:00
Update unread conversations dropdown
This commit is contained in:
parent
98352c1c50
commit
f3c3e9420d
@ -319,16 +319,10 @@ const ConversationsInterface = {
|
|||||||
/**
|
/**
|
||||||
* Get the list of unread conversations
|
* Get the list of unread conversations
|
||||||
*
|
*
|
||||||
* @param {function} callback
|
* @returns {Promise<UnreadConversation[]>}
|
||||||
*/
|
*/
|
||||||
getUnreadConversations: function(callback){
|
getUnreadConversations: async function() {
|
||||||
|
return await api("conversations/get_list_unread", null, true);
|
||||||
//Perform a request on the API
|
|
||||||
var apiURI = "conversations/get_list_unread";
|
|
||||||
var params = {};
|
|
||||||
|
|
||||||
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback);
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -99,67 +99,49 @@ ComunicWeb.components.conversations.unreadDropdown = {
|
|||||||
*
|
*
|
||||||
* @param {HTMLElement} target The target to display the conversations
|
* @param {HTMLElement} target The target to display the conversations
|
||||||
*/
|
*/
|
||||||
refresh_list_conversations: function(target){
|
refresh_list_conversations: async function(target) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
//Perform a request through the interface
|
//Perform a request through the interface
|
||||||
ComunicWeb.components.conversations.interface.getUnreadConversations(function(conversations){
|
const list = await ConversationsInterface.getUnreadConversations();
|
||||||
|
|
||||||
//Check for errors
|
|
||||||
if(conversations.error){
|
|
||||||
//Display an error
|
|
||||||
ComunicWeb.common.notificationSystem.showNotification(lang("conversations_dropdown_err_get_list"), "danger");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Get the list of users ID
|
//Get the list of users ID
|
||||||
var usersID = [];
|
let usersID = new Set();
|
||||||
|
|
||||||
//Process the list of conversations
|
//Process the list of conversations
|
||||||
for (var index = 0; index < conversations.length; index++) {
|
for (let entry of list) {
|
||||||
const entry = conversations[index];
|
ConversationsUtils.getUsersIDForMessage(entry.message).forEach(id => usersID.add(id))
|
||||||
|
|
||||||
var userID = entry.userID;
|
|
||||||
if(!usersID.includes(userID))
|
|
||||||
usersID.push(userID);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Get informations about the users
|
const users = await getUsers([...usersID]);
|
||||||
ComunicWeb.user.userInfos.getMultipleUsersInfo(usersID, function(usersInfos){
|
|
||||||
|
|
||||||
//Check for errors
|
this._display_list(target, list, users);
|
||||||
if(usersInfos.error){
|
|
||||||
//Display an error
|
|
||||||
ComunicWeb.common.notificationSystem.showNotification(lang("conversations_dropdown_err_get_user_info"), "danger");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Display the list of conversations
|
catch(e) {
|
||||||
ComunicWeb.components.conversations.unreadDropdown._display_list(target, conversations, usersInfos);
|
console.error(e);
|
||||||
});
|
ComunicWeb.common.notificationSystem.showNotification(lang("conversations_dropdown_err_get_list"), "danger");
|
||||||
});
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display the list of conversations
|
* Display the list of conversations
|
||||||
*
|
*
|
||||||
* @param {HTMLElement} target The target for the fields
|
* @param {HTMLElement} target The target for the fields
|
||||||
* @param {array} conversations The list of conversations
|
* @param {UnreadConversation[]} conversations The list of conversations
|
||||||
* @param {object} usersInfos Informations about related users
|
* @param {UsersList} usersInfo Information about related users
|
||||||
*/
|
*/
|
||||||
_display_list: function(target, conversations, usersInfos){
|
_display_list: function(target, conversations, usersInfo){
|
||||||
|
|
||||||
//Empty the target
|
//Empty the target
|
||||||
target.innerHTML = "";
|
target.innerHTML = "";
|
||||||
|
|
||||||
//Process each conversation
|
//Process each conversation
|
||||||
for (var index = 0; index < conversations.length; index++) {
|
for (let conversation of conversations) {
|
||||||
|
|
||||||
//Get the conversation
|
|
||||||
const conversation = conversations[index];
|
|
||||||
|
|
||||||
//Get informations about the user
|
//Get informations about the user
|
||||||
const userInfos = usersInfos["user-" + conversation.userID];
|
const user = usersInfo.get(ConversationsUtils.getMainUserForMessage(conversation.message))
|
||||||
|
|
||||||
//Create list element
|
//Create list element
|
||||||
var convLi = createElem2({
|
var convLi = createElem2({
|
||||||
@ -170,10 +152,9 @@ ComunicWeb.components.conversations.unreadDropdown = {
|
|||||||
//Create the conversation link element
|
//Create the conversation link element
|
||||||
var convLink = createElem2({
|
var convLink = createElem2({
|
||||||
appendTo: convLi,
|
appendTo: convLi,
|
||||||
type: "a",
|
type: "a"
|
||||||
href: "#"
|
|
||||||
});
|
});
|
||||||
convLink.setAttribute("data-conversation-id", conversation.id);
|
convLink.setAttribute("data-conversation-id", conversation.conv.id);
|
||||||
|
|
||||||
//Add left elements
|
//Add left elements
|
||||||
var leftElems = createElem2({
|
var leftElems = createElem2({
|
||||||
@ -187,14 +168,14 @@ ComunicWeb.components.conversations.unreadDropdown = {
|
|||||||
appendTo: leftElems,
|
appendTo: leftElems,
|
||||||
type: "img",
|
type: "img",
|
||||||
class: "img-circle",
|
class: "img-circle",
|
||||||
src: userInfos.accountImage
|
src: conversation.conv.logo ? conversation.conv.logo : user.image
|
||||||
});
|
});
|
||||||
|
|
||||||
//Add item top informations
|
//Add item top informations
|
||||||
var liTop = createElem2({
|
var liTop = createElem2({
|
||||||
appendTo: convLink,
|
appendTo: convLink,
|
||||||
type: "h4",
|
type: "h4",
|
||||||
innerHTML: userFullName(userInfos)
|
innerHTML: user.fullName
|
||||||
});
|
});
|
||||||
|
|
||||||
//Add item top small informations
|
//Add item top small informations
|
||||||
@ -204,30 +185,42 @@ ComunicWeb.components.conversations.unreadDropdown = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
//Add the message post time
|
//Add the message post time
|
||||||
var conversationLastActive = createElem2({
|
createElem2({
|
||||||
appendTo: liTopSmall,
|
appendTo: liTopSmall,
|
||||||
type: "span",
|
type: "span",
|
||||||
innerHTML: '<i class="fa fa-clock-o"></i> ' + ComunicWeb.common.date.timeDiffToStr(conversation.last_active) + " ago"
|
innerHTML: '<i class="fa fa-clock-o"></i> ' + ComunicWeb.common.date.timeDiffToStr(conversation.conv.last_activity) + " ago"
|
||||||
});
|
});
|
||||||
|
|
||||||
//Add conversation name (if available)
|
//Add conversation name (if available)
|
||||||
if(conversation.conv_name != ""){
|
if(conversation.conv.name != "" && conversation.conv.name != null){
|
||||||
|
|
||||||
var targetConversation = createElem2({
|
createElem2({
|
||||||
appendTo: convLink,
|
appendTo: convLink,
|
||||||
type: "p",
|
type: "p",
|
||||||
innerHTML: conversation.conv_name,
|
innerHTML: conversation.conv.name,
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Add the message
|
// Add the message
|
||||||
var conversationMessage = createElem2({
|
if (conversation.message.message) {
|
||||||
|
createElem2({
|
||||||
appendTo: convLink,
|
appendTo: convLink,
|
||||||
type: "p",
|
type: "p",
|
||||||
class: "message-content",
|
class: "message-content",
|
||||||
innerHTML: removeHtmlTags(conversation.message)
|
innerHTML: removeHtmlTags(conversation.message.message)
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// In case of server message
|
||||||
|
if (conversation.message.server_message) {
|
||||||
|
createElem2({
|
||||||
|
appendTo: convLink,
|
||||||
|
type: "p",
|
||||||
|
class: "message-content",
|
||||||
|
innerHTML: ConversationsUtils.getServerMessage(conversation.message, usersInfo)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
//Make the conversation link lives
|
//Make the conversation link lives
|
||||||
convLink.onclick = function(){
|
convLink.onclick = function(){
|
||||||
|
@ -136,6 +136,85 @@ const ConversationsUtils = {
|
|||||||
//Return result
|
//Return result
|
||||||
return form;
|
return form;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the ID of the users for a message
|
||||||
|
*
|
||||||
|
* @param {ConversationMessage} msg
|
||||||
|
*/
|
||||||
|
getUsersIDForMessage: function(msg) {
|
||||||
|
if (msg.user_id != null && msg.user_id > 0)
|
||||||
|
return [msg.user_id];
|
||||||
|
|
||||||
|
switch (msg.server_message.type) {
|
||||||
|
case "user_created_conv":
|
||||||
|
case "user_left":
|
||||||
|
return [msg.server_message.user_id];
|
||||||
|
|
||||||
|
case "user_added_another":
|
||||||
|
return [msg.server_message.user_who_added, msg.server_message.user_added];
|
||||||
|
|
||||||
|
case "user_removed_another":
|
||||||
|
return [msg.server_message.user_who_removed, msg.server_message.user_removed];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the ID of the main user for a given message
|
||||||
|
*
|
||||||
|
* @param {ConversationMessage} msg
|
||||||
|
*/
|
||||||
|
getMainUserForMessage: function(msg) {
|
||||||
|
if (msg.user_id != null && msg.user_id > 0)
|
||||||
|
return msg.user_id;
|
||||||
|
|
||||||
|
switch (msg.server_message.type) {
|
||||||
|
case "user_created_conv":
|
||||||
|
case "user_left":
|
||||||
|
return msg.server_message.user_id;
|
||||||
|
|
||||||
|
case "user_added_another":
|
||||||
|
return msg.server_message.user_who_added;
|
||||||
|
|
||||||
|
case "user_removed_another":
|
||||||
|
return msg.server_message.user_who_removed;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a message of the server
|
||||||
|
*
|
||||||
|
* @param {ConversationMessage} msg
|
||||||
|
* @param {UsersList} users
|
||||||
|
*/
|
||||||
|
getServerMessage: function(msg, users) {
|
||||||
|
if (msg.server_message == null)
|
||||||
|
return "";
|
||||||
|
|
||||||
|
switch (msg.server_message.type) {
|
||||||
|
case "user_created_conv":
|
||||||
|
return tr("%1% created the conversation", {
|
||||||
|
"1": users.get(msg.server_message.user_id).fullName
|
||||||
|
});
|
||||||
|
|
||||||
|
case "user_added_another":
|
||||||
|
return tr("%1% added %2% to the conversation", {
|
||||||
|
"1": users.get(msg.server_message.user_who_added).fullName,
|
||||||
|
"2": users.get(msg.server_message.user_added).fullName
|
||||||
|
})
|
||||||
|
|
||||||
|
case "user_left":
|
||||||
|
return tr("%1% left the conversation", {
|
||||||
|
"1": users.get(msg.server_message.user_id).fullName
|
||||||
|
});
|
||||||
|
|
||||||
|
case "user_removed_another":
|
||||||
|
return tr("%1% removed %2% from the conversation", {
|
||||||
|
"1": users.get(msg.server_message.user_who_removed).fullName,
|
||||||
|
"2": users.get(msg.server_message.user_removed).fullName
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ComunicWeb.components.conversations.utils = ConversationsUtils;
|
ComunicWeb.components.conversations.utils = ConversationsUtils;
|
||||||
|
@ -130,7 +130,6 @@ ComunicWeb.common.langs.en = {
|
|||||||
//Conversations - unread dropdown
|
//Conversations - unread dropdown
|
||||||
conversations_dropdown_header: "Unread conversations",
|
conversations_dropdown_header: "Unread conversations",
|
||||||
conversations_dropdown_err_get_list: "Could not retrieve the list of unread conversations !",
|
conversations_dropdown_err_get_list: "Could not retrieve the list of unread conversations !",
|
||||||
conversations_dropdown_err_get_user_info: "Could not get informations about some users !",
|
|
||||||
conversations_dropdown_no_unread_notice: "You do not have any unread messages in the conversations you are following...",
|
conversations_dropdown_no_unread_notice: "You do not have any unread messages in the conversations you are following...",
|
||||||
|
|
||||||
|
|
||||||
|
@ -130,7 +130,6 @@ ComunicWeb.common.langs.fr = {
|
|||||||
//Conversations - unread dropdown
|
//Conversations - unread dropdown
|
||||||
conversations_dropdown_header: "Conversations non lues",
|
conversations_dropdown_header: "Conversations non lues",
|
||||||
conversations_dropdown_err_get_list: "Une erreur a survenue lors de la récupération des conversations non lues !",
|
conversations_dropdown_err_get_list: "Une erreur a survenue lors de la récupération des conversations non lues !",
|
||||||
conversations_dropdown_err_get_user_info: "Une erreur a survenue lors de la récupération d'informations de certains utilisateurs !",
|
|
||||||
conversations_dropdown_no_unread_notice: "Vous n'avez aucun message non lu dans les conversations que vous suivez...",
|
conversations_dropdown_no_unread_notice: "Vous n'avez aucun message non lu dans les conversations que vous suivez...",
|
||||||
|
|
||||||
//Notifications - dropdown
|
//Notifications - dropdown
|
||||||
|
53
assets/js/typings/Conversations.d.ts
vendored
53
assets/js/typings/Conversations.d.ts
vendored
@ -11,3 +11,56 @@ declare interface ConversationSettingsFormElements {
|
|||||||
allowEveryoneToAddMembers: HTMLElement,
|
allowEveryoneToAddMembers: HTMLElement,
|
||||||
followConversationInput: HTMLElement,
|
followConversationInput: HTMLElement,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
declare interface ConversationMember {
|
||||||
|
user_id: number,
|
||||||
|
last_message_seen: number,
|
||||||
|
following: boolean,
|
||||||
|
is_admin: boolean,
|
||||||
|
}
|
||||||
|
|
||||||
|
declare interface Conversation {
|
||||||
|
id: number,
|
||||||
|
last_activity: number,
|
||||||
|
name: string,
|
||||||
|
color?: string,
|
||||||
|
logo?: string,
|
||||||
|
group_id?: number,
|
||||||
|
members: ConversationMember[],
|
||||||
|
can_everyone_add_members: boolean,
|
||||||
|
can_have_call: boolean,
|
||||||
|
can_have_video_call: boolean,
|
||||||
|
has_call_now: boolean,
|
||||||
|
}
|
||||||
|
|
||||||
|
declare interface ConversationServerMessage {
|
||||||
|
type: "user_created_conv"|"user_added_another"|"user_left"|"user_removed_another",
|
||||||
|
user_id?: number,
|
||||||
|
user_who_added?: number,
|
||||||
|
user_added?: number,
|
||||||
|
user_who_removed?: number,
|
||||||
|
user_removed?: number,
|
||||||
|
}
|
||||||
|
|
||||||
|
declare interface ConversationMessageFile {
|
||||||
|
url: string,
|
||||||
|
size: number,
|
||||||
|
name: string,
|
||||||
|
thumbnail?: string,
|
||||||
|
type: string
|
||||||
|
}
|
||||||
|
|
||||||
|
declare interface ConversationMessage {
|
||||||
|
id: number,
|
||||||
|
conv_id: number,
|
||||||
|
user_id: number,
|
||||||
|
time_sent: number,
|
||||||
|
message?: string,
|
||||||
|
file?: ConversationMessageFile,
|
||||||
|
server_message?: ConversationServerMessage,
|
||||||
|
}
|
||||||
|
|
||||||
|
declare interface UnreadConversation {
|
||||||
|
conv: Conversation,
|
||||||
|
message: ConversationMessage
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user