From 12db32cc80d743c386b4fda0b1b110e99f12e802 Mon Sep 17 00:00:00 2001 From: Evan Theurer Date: Thu, 30 Jul 2015 15:05:12 +0200 Subject: [PATCH] Improve handling of user states. Add functionality to disable contact button when the person cannot be added as a contact. --- static/js/directives/chat.js | 15 +++++++++++---- static/partials/chatroom.html | 4 ++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/static/js/directives/chat.js b/static/js/directives/chat.js index 2ccfb1d4..37ba46af 100644 --- a/static/js/directives/chat.js +++ b/static/js/directives/chat.js @@ -205,6 +205,7 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro } subscope = controller.rooms[id] = scope.$new(); translation.inject(subscope); + subscope.contact = {}; subscope.id = id; subscope.isgroupchat = !!settings.group; subscope.index = index; @@ -217,9 +218,15 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro subscope.p2pstate = false; subscope.active = false; subscope.pending = 0; - subscope.isUser = !!(buddy && buddy.session && buddy.session.Userid); - subscope.isContact = !!(buddy && buddy.contact); - subscope.canAddContact = !subscope.isgroupchat && subscope.isUser; + var handleContactFunctionality = function() { + var buddyId = buddy && buddy.session && buddy.session.Userid; + var myId = appData.get().userid; + var isAnotherUser = buddyId && myId !== buddyId; + subscope.contact.isContact = !!(buddy && buddy.contact); + subscope.contact.disableContact = !myId || !isAnotherUser; + subscope.contact.showContact = !subscope.isgroupchat && buddyId; + }; + handleContactFunctionality(); if (!subscope.isgroupchat) { buddyData.push(id); } @@ -349,7 +356,7 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro if (userid !== data.Userid) { return; } - subscope.isContact = event.type === "contactadded"; + subscope.contact.isContact = event.type === "contactadded"; safeApply(subscope); }; contacts.e.on("contactadded", subscope.updateContactStatus); diff --git a/static/partials/chatroom.html b/static/partials/chatroom.html index d6c3819b..a33aaff2 100644 --- a/static/partials/chatroom.html +++ b/static/partials/chatroom.html @@ -5,8 +5,8 @@ - - + +