mirror of
				https://github.com/pierre42100/ComunicWeb
				synced 2025-11-04 12:14:12 +00:00 
			
		
		
		
	Upgrade user memberships pane
This commit is contained in:
		@@ -17,19 +17,19 @@ class CallsController {
 | 
			
		||||
	 * @param {Conversation} conv Information about the target conversation
 | 
			
		||||
	 */
 | 
			
		||||
	static Open(conv) {
 | 
			
		||||
		if(OpenCalls.has(conv.ID) && OpenCalls.get(conv.ID).isOpen)
 | 
			
		||||
		if(OpenCalls.has(conv.id) && OpenCalls.get(conv.id).isOpen)
 | 
			
		||||
			return;
 | 
			
		||||
		
 | 
			
		||||
		console.info("Open call for conversation " + conv.ID);
 | 
			
		||||
		console.info("Open call for conversation " + conv.id);
 | 
			
		||||
		
 | 
			
		||||
		// Create a new window for the conversation
 | 
			
		||||
		const window = new CallWindow(conv);
 | 
			
		||||
		OpenCalls.set(conv.ID, window)
 | 
			
		||||
		this.AddToLocalStorage(conv.ID);
 | 
			
		||||
		OpenCalls.set(conv.id, window)
 | 
			
		||||
		this.AddToLocalStorage(conv.id);
 | 
			
		||||
 | 
			
		||||
		window.on("close", () => {
 | 
			
		||||
			OpenCalls.delete(conv.ID)
 | 
			
		||||
			this.RemoveFromLocalStorage(conv.ID)
 | 
			
		||||
			OpenCalls.delete(conv.id)
 | 
			
		||||
			this.RemoveFromLocalStorage(conv.id)
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -177,7 +177,7 @@ const ConversationsInterface = {
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Else, perform an API request
 | 
			
		||||
		var apiURI = "conversations/getInfosOne";
 | 
			
		||||
		var apiURI = "conversations/get_single";
 | 
			
		||||
		var params = {
 | 
			
		||||
			conversationID: conversationID,
 | 
			
		||||
		};
 | 
			
		||||
 
 | 
			
		||||
@@ -9,32 +9,28 @@ const ConversationsUtils = {
 | 
			
		||||
	/**
 | 
			
		||||
	 * 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
 | 
			
		||||
	 * @return {Boolean} True for a success
 | 
			
		||||
	 */
 | 
			
		||||
	getName: function(infos, afterName){
 | 
			
		||||
	getName: function(info, afterName){
 | 
			
		||||
 | 
			
		||||
		//Check if the conversation has a name or not
 | 
			
		||||
		if(infos.name)
 | 
			
		||||
			afterName(infos.name);
 | 
			
		||||
		if(info.name && info.name.length > 0)
 | 
			
		||||
			afterName(info.name);
 | 
			
		||||
		else {
 | 
			
		||||
 | 
			
		||||
			//Get informations about the first two members
 | 
			
		||||
			var firstMembers = [];
 | 
			
		||||
 | 
			
		||||
			//Retrieve IDs
 | 
			
		||||
			for(o in infos.members){
 | 
			
		||||
			for(o in info.members){
 | 
			
		||||
				//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){
 | 
			
		||||
 | 
			
		||||
				//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 += ", ...";
 | 
			
		||||
 | 
			
		||||
				//Peform next action now
 | 
			
		||||
 
 | 
			
		||||
@@ -309,7 +309,7 @@ const SidebarMain = {
 | 
			
		||||
	 * @param {HTMLElement} target 
 | 
			
		||||
	 */
 | 
			
		||||
	refreshMemberships: function(target){
 | 
			
		||||
		ComunicWeb.components.webApp.interface.getMemberships(
 | 
			
		||||
		WebAppInterface.getMemberships(
 | 
			
		||||
			() => notify("Could not refresh your memberships!", "error"), 
 | 
			
		||||
			(m, u, g, c) => this.applyMemberships(target, m, u, g, c)
 | 
			
		||||
		);
 | 
			
		||||
@@ -319,14 +319,14 @@ const SidebarMain = {
 | 
			
		||||
	 * Apply memberships
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param {HTMLElement} target
 | 
			
		||||
	 * @param {*} memberships 
 | 
			
		||||
	 * @param {*} users 
 | 
			
		||||
	 * @param {UserMembership[]} memberships 
 | 
			
		||||
	 * @param {UsersList} users 
 | 
			
		||||
	 * @param {*} groups 
 | 
			
		||||
	 * @param {Map<number, String>} convs
 | 
			
		||||
	 */
 | 
			
		||||
	applyMemberships: function(target, memberships, users, groups, convs) {
 | 
			
		||||
 | 
			
		||||
		// Empty liste
 | 
			
		||||
		// Empty list
 | 
			
		||||
		target.innerHTML = "";
 | 
			
		||||
 | 
			
		||||
		let friendsTarget = createElem2({
 | 
			
		||||
@@ -344,7 +344,7 @@ const SidebarMain = {
 | 
			
		||||
				this.applyGroup(friendsTarget, groups.get(e.id), e.last_activity);
 | 
			
		||||
			
 | 
			
		||||
			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({
 | 
			
		||||
@@ -532,7 +532,7 @@ const SidebarMain = {
 | 
			
		||||
	 * Apply a conversation
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param {HTMLElement} target
 | 
			
		||||
	 * @param {Array<any>} conv
 | 
			
		||||
	 * @param {Conversation} conv
 | 
			
		||||
	 * @param {String} name
 | 
			
		||||
	 */
 | 
			
		||||
	applyConversation: function(target, conv, name) {
 | 
			
		||||
@@ -542,17 +542,17 @@ const SidebarMain = {
 | 
			
		||||
			type: "li",
 | 
			
		||||
			class: "conversation_memberhsip"
 | 
			
		||||
		});
 | 
			
		||||
		li.setAttribute("data-membership-conv-id", conv.ID)
 | 
			
		||||
		li.setAttribute("data-membership-conv-id", conv.id)
 | 
			
		||||
 | 
			
		||||
		// 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");
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		let a = createElem2({
 | 
			
		||||
			appendTo: li,
 | 
			
		||||
			type: "a",
 | 
			
		||||
			onclick: () => openConversation(conv.ID, true)
 | 
			
		||||
			onclick: () => openConversation(conv.id, true)
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
		// Icon
 | 
			
		||||
@@ -573,7 +573,7 @@ const SidebarMain = {
 | 
			
		||||
			appendTo: a,
 | 
			
		||||
			type: "div",
 | 
			
		||||
			class: "subinfo",
 | 
			
		||||
			innerHTML: timeDiffToStr(conv.last_active)
 | 
			
		||||
			innerHTML: timeDiffToStr(conv.last_activity)
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -4,13 +4,13 @@
 | 
			
		||||
 * @author Pierre HUBERT
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
ComunicWeb.components.webApp.interface = {
 | 
			
		||||
const WebAppInterface = {
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Get all the membership of the user
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @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) {
 | 
			
		||||
 | 
			
		||||
@@ -26,6 +26,7 @@ ComunicWeb.components.webApp.interface = {
 | 
			
		||||
			memberships.forEach(el => {
 | 
			
		||||
				if(el.type == "friend")
 | 
			
		||||
					usersID.push(el.friend.ID_friend);
 | 
			
		||||
				
 | 
			
		||||
				else if(el.type == "group")
 | 
			
		||||
					groupsID.push(el.id);
 | 
			
		||||
			});
 | 
			
		||||
@@ -36,7 +37,7 @@ ComunicWeb.components.webApp.interface = {
 | 
			
		||||
			// Get conversations name
 | 
			
		||||
			const convNames = new Map()
 | 
			
		||||
			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);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user