Upgrade user memberships pane

This commit is contained in:
Pierre HUBERT 2021-03-05 15:26:45 +01:00
parent f3c3e9420d
commit 136db55703
7 changed files with 45 additions and 34 deletions

View File

@ -17,19 +17,19 @@ class CallsController {
* @param {Conversation} conv Information about the target conversation * @param {Conversation} conv Information about the target conversation
*/ */
static Open(conv) { static Open(conv) {
if(OpenCalls.has(conv.ID) && OpenCalls.get(conv.ID).isOpen) if(OpenCalls.has(conv.id) && OpenCalls.get(conv.id).isOpen)
return; return;
console.info("Open call for conversation " + conv.ID); console.info("Open call for conversation " + conv.id);
// Create a new window for the conversation // Create a new window for the conversation
const window = new CallWindow(conv); const window = new CallWindow(conv);
OpenCalls.set(conv.ID, window) OpenCalls.set(conv.id, window)
this.AddToLocalStorage(conv.ID); this.AddToLocalStorage(conv.id);
window.on("close", () => { window.on("close", () => {
OpenCalls.delete(conv.ID) OpenCalls.delete(conv.id)
this.RemoveFromLocalStorage(conv.ID) this.RemoveFromLocalStorage(conv.id)
}) })
} }

View File

@ -177,7 +177,7 @@ const ConversationsInterface = {
} }
//Else, perform an API request //Else, perform an API request
var apiURI = "conversations/getInfosOne"; var apiURI = "conversations/get_single";
var params = { var params = {
conversationID: conversationID, conversationID: conversationID,
}; };

View File

@ -9,32 +9,28 @@ const ConversationsUtils = {
/** /**
* Given conversation informations, returns its name * Given conversation informations, returns its name
* *
* @param {Object} infos Conversation informations * @param {Conversation} info Conversation information
* @param {Function} afterName What to do once we got conversation name * @param {Function} afterName What to do once we got conversation name
* @return {Boolean} True for a success * @return {Boolean} True for a success
*/ */
getName: function(infos, afterName){ getName: function(info, afterName){
//Check if the conversation has a name or not //Check if the conversation has a name or not
if(infos.name) if(info.name && info.name.length > 0)
afterName(infos.name); afterName(info.name);
else { else {
//Get informations about the first two members //Get informations about the first two members
var firstMembers = []; var firstMembers = [];
//Retrieve IDs //Retrieve IDs
for(o in infos.members){ for(o in info.members){
//Limit number to 2 //Limit number to 2
if(firstMembers.length < 2){ if(firstMembers.length < 2){
//Exclude current user ID
if(info.members[o].user_id != userID())
firstMembers.push(info.members[o].user_id);
//Check this is a valid entry
if(infos.members[o]){
//Exclude current user ID
if(infos.members[o] != userID())
firstMembers.push(infos.members[o]);
}
} }
} }
@ -42,7 +38,7 @@ const ConversationsUtils = {
ComunicWeb.user.userInfos.getNames(firstMembers, function(usersName){ ComunicWeb.user.userInfos.getNames(firstMembers, function(usersName){
//For conversations with many members (more than 3 - we musn't forget current user) //For conversations with many members (more than 3 - we musn't forget current user)
if(infos.members.length > 3) if(info.members.length > 3)
usersName += ", ..."; usersName += ", ...";
//Peform next action now //Peform next action now

View File

@ -309,7 +309,7 @@ const SidebarMain = {
* @param {HTMLElement} target * @param {HTMLElement} target
*/ */
refreshMemberships: function(target){ refreshMemberships: function(target){
ComunicWeb.components.webApp.interface.getMemberships( WebAppInterface.getMemberships(
() => notify("Could not refresh your memberships!", "error"), () => notify("Could not refresh your memberships!", "error"),
(m, u, g, c) => this.applyMemberships(target, m, u, g, c) (m, u, g, c) => this.applyMemberships(target, m, u, g, c)
); );
@ -319,14 +319,14 @@ const SidebarMain = {
* Apply memberships * Apply memberships
* *
* @param {HTMLElement} target * @param {HTMLElement} target
* @param {*} memberships * @param {UserMembership[]} memberships
* @param {*} users * @param {UsersList} users
* @param {*} groups * @param {*} groups
* @param {Map<number, String>} convs * @param {Map<number, String>} convs
*/ */
applyMemberships: function(target, memberships, users, groups, convs) { applyMemberships: function(target, memberships, users, groups, convs) {
// Empty liste // Empty list
target.innerHTML = ""; target.innerHTML = "";
let friendsTarget = createElem2({ let friendsTarget = createElem2({
@ -344,7 +344,7 @@ const SidebarMain = {
this.applyGroup(friendsTarget, groups.get(e.id), e.last_activity); this.applyGroup(friendsTarget, groups.get(e.id), e.last_activity);
if(e.type == "conversation") if(e.type == "conversation")
this.applyConversation(friendsTarget, e.conv, convs.get(e.conv.ID)); this.applyConversation(friendsTarget, e.conv, convs.get(e.conv.id));
}); });
createElem2({ createElem2({
@ -532,7 +532,7 @@ const SidebarMain = {
* Apply a conversation * Apply a conversation
* *
* @param {HTMLElement} target * @param {HTMLElement} target
* @param {Array<any>} conv * @param {Conversation} conv
* @param {String} name * @param {String} name
*/ */
applyConversation: function(target, conv, name) { applyConversation: function(target, conv, name) {
@ -542,17 +542,17 @@ const SidebarMain = {
type: "li", type: "li",
class: "conversation_memberhsip" class: "conversation_memberhsip"
}); });
li.setAttribute("data-membership-conv-id", conv.ID) li.setAttribute("data-membership-conv-id", conv.id)
// Check for unread messages // Check for unread messages
if(!conv.saw_last_message) { if(!conv.last_activity > conv.members.find(m => m.user_id == userID()).last_access) {
li.classList.add("has-unread-msg"); li.classList.add("has-unread-msg");
} }
let a = createElem2({ let a = createElem2({
appendTo: li, appendTo: li,
type: "a", type: "a",
onclick: () => openConversation(conv.ID, true) onclick: () => openConversation(conv.id, true)
}); });
// Icon // Icon
@ -573,7 +573,7 @@ const SidebarMain = {
appendTo: a, appendTo: a,
type: "div", type: "div",
class: "subinfo", class: "subinfo",
innerHTML: timeDiffToStr(conv.last_active) innerHTML: timeDiffToStr(conv.last_activity)
}); });

View File

@ -4,13 +4,13 @@
* @author Pierre HUBERT * @author Pierre HUBERT
*/ */
ComunicWeb.components.webApp.interface = { const WebAppInterface = {
/** /**
* Get all the membership of the user * Get all the membership of the user
* *
* @param {Function} err Function called in case of errors * @param {Function} err Function called in case of errors
* @param {Function(memberships, usersInfo, groupsInfo, convNames) : void} success Function called in case of success * @param {(UserMembership[], UsersList, groupsInfo, convNames) => void} success Function called in case of success
*/ */
getMemberships: async function(err, success) { getMemberships: async function(err, success) {
@ -26,6 +26,7 @@ ComunicWeb.components.webApp.interface = {
memberships.forEach(el => { memberships.forEach(el => {
if(el.type == "friend") if(el.type == "friend")
usersID.push(el.friend.ID_friend); usersID.push(el.friend.ID_friend);
else if(el.type == "group") else if(el.type == "group")
groupsID.push(el.id); groupsID.push(el.id);
}); });
@ -36,7 +37,7 @@ ComunicWeb.components.webApp.interface = {
// Get conversations name // Get conversations name
const convNames = new Map() const convNames = new Map()
for(const el of memberships.filter(el => el.type == "conversation")) for(const el of memberships.filter(el => el.type == "conversation"))
convNames.set(el.conv.ID, await getConvName(el.conv)) convNames.set(el.conv.id, await getConvName(el.conv))
success(memberships, usersInfo, groupsInfo, convNames); success(memberships, usersInfo, groupsInfo, convNames);

View File

@ -15,6 +15,7 @@ declare interface ConversationSettingsFormElements {
declare interface ConversationMember { declare interface ConversationMember {
user_id: number, user_id: number,
last_message_seen: number, last_message_seen: number,
last_access: number,
following: boolean, following: boolean,
is_admin: boolean, is_admin: boolean,
} }

13
assets/js/typings/UserMembreship.d.ts vendored Normal file
View File

@ -0,0 +1,13 @@
/**
* User membreship typings
*
* @author Pierre Hubert
*/
declare interface UserMembership {
type: "group"|"friend"|"conversation",
id ?: number,
friend ?: Friend,
last_activity ?: number,
conv ?: Conversation
}