diff --git a/static/js/controllers/contactsmanagercontroller.js b/static/js/controllers/contactsmanagercontroller.js index 2384bb1f..fe948ea5 100644 --- a/static/js/controllers/contactsmanagercontroller.js +++ b/static/js/controllers/contactsmanagercontroller.js @@ -22,43 +22,47 @@ define([], function() { // ContactsmanagerController return ["$scope", "$modalInstance", "contactData", "data", "contacts", 'buddySession', function($scope, $modalInstance, contactData, data, contacts, buddySession) { - $scope.header = data.header; $scope.contacts = []; $scope.search = {}; - $scope.tmp = {}; - $scope.tmp.displayName = data.contact && data.contact.Status.displayName; - $scope.contact = data.contact; + $scope.contact = null; $scope.session = null; - if(data.contact) { + var tmp = { + displayName: data.contact ? data.contact.Status.displayName : null + }; + var setContactInfo = function(contact) { + contacts.update(contact.Userid, contact.Status); + }; + var updateContacts = function(async) { + if (async) { + $scope.$apply(function(scope) { + scope.contacts = contactData.getAll(); + }); + } else { + $scope.contacts = contactData.getAll(); + } + }; + updateContacts(); + contacts.e.on('contactadded', function() { + updateContacts(true); + }); + contacts.e.on('contactupdated', function() { + updateContacts(true); + }); + + // Values to check include 0, so check for number to get around incorrect 'false' type conversion + if(angular.isNumber(data.contactIndex)) { + $scope.contact = $scope.contacts[data.contactIndex]; var sessions = buddySession.sessions(); for (var id in sessions) { if (sessions.hasOwnProperty(id) && sessions[id].Userid === $scope.contact.Userid) { - $scope.session = sessions[id] && sessions[id].sessions[id]; + $scope.session = sessions[id] ? sessions[id].sessions[id] : null; //console.log('contact manager session', $scope.session); } } } - var totalUnnamed = 0; - $scope.unnamed = function() { - return totalUnnamed += 1; - }; - - var updateContacts = function() { - $scope.contacts = contactData.getAll(); - }; - updateContacts(); - contacts.e.on('contactadded', function() { - updateContacts(); - }); - - var setContactInfo = function(contact) { - contact.Status.displayName = $scope.tmp.displayName; - contacts.update({Id: contact.Id, Success: contact.Success, Token: contact.Token, Userid: contact.Userid}, contact.Status); - }; - $scope.removeContact = function() { contacts.remove($scope.contact.Userid); updateContacts(); @@ -66,22 +70,22 @@ define([], function() { }; $scope.syncContactInfo = function() { - $scope.tmp.displayName = $scope.session.Status.displayName; - }; - - $scope.edit = function(contact) { - $modalInstance.close(contact); + $scope.contact.Status.displayName = $scope.session.Status.displayName; }; $scope.save = function() { - setContactInfo(data.contact); + setContactInfo($scope.contact); $modalInstance.close(); }; $scope.cancel = function(contact) { + $scope.contact.Status.displayName = tmp.displayName; $modalInstance.dismiss(); }; + $scope.edit = function(index) { + $scope.$broadcast('openEditContact', index); + }; }]; }); diff --git a/static/js/controllers/controllers.js b/static/js/controllers/controllers.js index 26b18ddf..f85da201 100644 --- a/static/js/controllers/controllers.js +++ b/static/js/controllers/controllers.js @@ -26,7 +26,7 @@ define([ 'controllers/chatroomcontroller', 'controllers/roomchangecontroller', 'controllers/usersettingscontroller', - 'controllers/contactsmanagercontroller'], function(_, MediastreamController, StatusmessageController, ChatroomController, RoomchangeController, UsersettingsController, ContactsmanagerController) { + 'controllers/contactsmanagercontroller',], function(_, MediastreamController, StatusmessageController, ChatroomController, RoomchangeController, UsersettingsController, ContactsmanagerController) { var controllers = { MediastreamController: MediastreamController, diff --git a/static/js/directives/buddylist.js b/static/js/directives/buddylist.js index e3c71d5f..b458d768 100644 --- a/static/js/directives/buddylist.js +++ b/static/js/directives/buddylist.js @@ -84,6 +84,7 @@ define(['underscore', 'text!partials/buddylist.html'], function(_, template) { var onStatus = _.bind(buddylist.onStatus, buddylist); var onContactAdded = _.bind(buddylist.onContactAdded, buddylist); var onContactRemoved = _.bind(buddylist.onContactRemoved, buddylist); + var onContactUpdated = _.bind(buddylist.onContactUpdated, buddylist); mediaStream.api.e.on("received.userleftorjoined", function(event, dataType, data) { if (dataType === "Left") { onLeft(data); @@ -119,6 +120,9 @@ define(['underscore', 'text!partials/buddylist.html'], function(_, template) { contacts.e.on("contactremoved", function(event, data) { onContactRemoved(data); }); + contacts.e.on("contactupdated", function(event, data) { + onContactUpdated(data); + }); }]; diff --git a/static/js/directives/contactrequest.js b/static/js/directives/contactrequest.js index 9e9d5d3a..ef5358a7 100644 --- a/static/js/directives/contactrequest.js +++ b/static/js/directives/contactrequest.js @@ -53,7 +53,7 @@ define(['jquery', 'underscore'], function($, _) { var buddy = buddyData.lookup($scope.id); var status = {}; if (buddy) { - status = angular.isObject(buddy.status) ? angular.extend(status, buddy.status) : buddy.status; + $.extend(status, buddy.status); } $scope.addContact(request, status); } diff --git a/static/js/directives/contactsmanager.js b/static/js/directives/contactsmanager.js new file mode 100644 index 00000000..cc70ef1d --- /dev/null +++ b/static/js/directives/contactsmanager.js @@ -0,0 +1,54 @@ +/* + * Spreed WebRTC. + * Copyright (C) 2013-2014 struktur AG + * + * This file is part of Spreed WebRTC. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ +define(['underscore', 'jquery'], function(_, $) { + + // contactsmanager + return [function() { + + var controller = ['$scope', 'dialogs', 'translation', function($scope, dialogs, translation) { + + var editContactDialog = function(index) { + return dialogs.create( + "/contactsmanager/edit.html", + "ContactsmanagerController", + { + header: translation._("Edit Contact"), + contactIndex: index, + }, { + wc: "contactsmanager" + } + ); + }; + + $scope.$on('openEditContact', function(event, index) { + editContactDialog(index); + }); + }]; + + return { + scope: true, + restrict: "A", + controller: controller, + }; + + }]; + +}); diff --git a/static/js/directives/directives.js b/static/js/directives/directives.js index de5d0458..4aa68ea1 100644 --- a/static/js/directives/directives.js +++ b/static/js/directives/directives.js @@ -42,7 +42,8 @@ define([ 'directives/pdfcanvas', 'directives/odfcanvas', 'directives/presentation', - 'directives/youtubevideo',], function(_, onEnter, onEscape, statusMessage, buddyList, buddyPictureCapture, buddyPictureUpload, settings, chat, audioVideo, usability, audioLevel, fileInfo, screenshare, roomBar, socialShare, page, contactRequest, defaultDialog, pdfcanvas, odfcanvas, presentation, youtubevideo) { + 'directives/youtubevideo', + 'directives/contactsmanager',], function(_, onEnter, onEscape, statusMessage, buddyList, buddyPictureCapture, buddyPictureUpload, settings, chat, audioVideo, usability, audioLevel, fileInfo, screenshare, roomBar, socialShare, page, contactRequest, defaultDialog, pdfcanvas, odfcanvas, presentation, youtubevideo, contactsmanager) { var directives = { onEnter: onEnter, @@ -66,7 +67,8 @@ define([ pdfcanvas: pdfcanvas, odfcanvas: odfcanvas, presentation: presentation, - youtubevideo: youtubevideo + youtubevideo: youtubevideo, + contactsmanager: contactsmanager }; var initialize = function(angModule) { diff --git a/static/js/directives/settings.js b/static/js/directives/settings.js index 503bbb5a..80e5fc53 100644 --- a/static/js/directives/settings.js +++ b/static/js/directives/settings.js @@ -51,6 +51,17 @@ define(['jquery', 'underscore', 'text!partials/settings.html'], function($, _, t } }); + $scope.openContactsManager = function() { + return dialogs.create( + "/contactsmanager/main.html", + "ContactsmanagerController", + { + header: translation._("Contacts Manager") + }, { + wc: "contactsmanager" + } + ); + }; $scope.saveSettings = function() { var form = $scope.settingsform; if (form.$valid && form.$dirty) { diff --git a/static/js/filters/displayname.js b/static/js/filters/displayname.js index a3a7a27f..85b8f677 100644 --- a/static/js/filters/displayname.js +++ b/static/js/filters/displayname.js @@ -29,6 +29,7 @@ define([], function() { var user_text = translation._("User"); var someone_text = translation._("Someone"); var me_text = translation._("Me"); + var contact_text = translation._("Unnamed Contact"); return function(id, me_ok) { if (id === group_chat_id) { return ""; @@ -38,6 +39,9 @@ define([], function() { if (scope.display.displayName) { return scope.display.displayName; } + if(me_ok === "contactsmanager") { + return contact_text + " " + scope.buddyIndex; + } return user_text + " " + scope.buddyIndex; } else { var data = appData.get(); diff --git a/static/js/services/buddylist.js b/static/js/services/buddylist.js index ffd5cfd0..1a8a99fc 100644 --- a/static/js/services/buddylist.js +++ b/static/js/services/buddylist.js @@ -129,7 +129,7 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text! }; // buddyList - return ["$window", "$compile", "playSound", "buddyData", "buddySession", "buddyPicture", "fastScroll", "mediaStream", "animationFrame", "$q", '$timeout', function($window, $compile, playSound, buddyData, buddySession, buddyPicture, fastScroll, mediaStream, animationFrame, $q, $timeout) { + return ["$window", "$compile", "playSound", "buddyData", "buddySession", "buddyPicture", "fastScroll", "mediaStream", "animationFrame", "$q", function($window, $compile, playSound, buddyData, buddySession, buddyPicture, fastScroll, mediaStream, animationFrame, $q) { var buddyTemplate = $compile(templateBuddy); var buddyActions = $compile(templateBuddyActions); @@ -450,6 +450,15 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text! }; + Buddylist.prototype.onContactUpdated = function(data) { + var scope = buddyData.get(data.Userid); + if (scope && scope.contact) { + scope.contact.Status = angular.extend(scope.contact.Status, data.Status); + } + this.updateDisplay(data.Id, scope, data, "status"); + //console.log("onContactUpdated", 'data', data, 'scope', scope); + }; + Buddylist.prototype.onStatus = function(data) { //console.log("onStatus", data); @@ -585,7 +594,7 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text! scope.contact = contact; var sessionData = scope.session.get(); if (sessionData) { - if (angular.isString(contact.Status) && sessionData.Status) { + if (contact.Status === null && sessionData.Status) { // Update contact status with session.Status var status = contact.Status = _.extend({}, sessionData.Status); // Remove status message. @@ -602,10 +611,7 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text! console.log("Injected status into contact", contact); } this.updateDisplay(sessionData.Id, scope, contact, "status"); - // keep asyc nature but eliminate $apply conflicts - $timeout(function() { - scope.$apply(); - }, 0, false); + scope.$apply(); } } else { // Create new scope for contact. diff --git a/static/js/services/contactdata.js b/static/js/services/contactdata.js index 94fd425e..5f6074af 100644 --- a/static/js/services/contactdata.js +++ b/static/js/services/contactdata.js @@ -54,8 +54,8 @@ define(['underscore', 'jquery'], function(underscore, $) { Id: "contact-"+id, Userid: userid, Token: token, - Status: status - }; + Status: null + } return contact; }, addByData: function(data) { diff --git a/static/js/services/contacts.js b/static/js/services/contacts.js index d6b06951..258df360 100644 --- a/static/js/services/contacts.js +++ b/static/js/services/contacts.js @@ -18,7 +18,7 @@ * along with this program. If not, see . * */ -define(['underscore', 'jquery', 'modernizr', 'sjcl', 'text!partials/contactsmanager.html', 'text!partials/contactsmanageredit.html'], function(underscore, $, Modernizr, sjcl, templateContactsManager, templateContactsManagerEdit) { +define(['underscore', 'jquery', 'modernizr', 'sjcl', 'text!partials/contactsmanager.html', 'text!partials/contactsmanageredit.html'], function(_, $, Modernizr, sjcl, templateContactsManager, templateContactsManagerEdit) { var Database = function(name) { this.version = 3; @@ -36,6 +36,7 @@ define(['underscore', 'jquery', 'modernizr', 'sjcl', 'text!partials/contactsmana console.info("Created contacts database.") }; request.onsuccess = _.bind(that.onsuccess, that); + request.onerror = _.bind(that.onerror, that); }; Database.prototype.init = function(db) { var createOrUpdateStore = function(name, obj) { @@ -156,6 +157,13 @@ define(['underscore', 'jquery', 'modernizr', 'sjcl', 'text!partials/contactsmana }; + Contacts.prototype.put = function(contact) { + this.database.put("contacts", { + id: this.id(contact.Userid), + contact: this.encrypt(contact) + }); + } + Contacts.prototype.open = function(userid, suserid) { if (this.database && (!userid || this.userid !== userid)) { @@ -243,10 +251,7 @@ define(['underscore', 'jquery', 'modernizr', 'sjcl', 'text!partials/contactsmana var contact = contactData.addByRequest(request, status); this.e.triggerHandler("contactadded", contact); if (this.database) { - this.database.put("contacts", { - id: this.id(contact.Userid), - contact: this.encrypt(contact) - }) + this.put(contact); } }; @@ -262,10 +267,23 @@ define(['underscore', 'jquery', 'modernizr', 'sjcl', 'text!partials/contactsmana } }; - Contacts.prototype.update = function(request, status) { - console.log("contact update", status); - this.remove(request.Userid); - this.add(request, status); + Contacts.prototype.update = function(userid, status) { + var updateContact = _.bind(function(contact) { + contact.Status = angular.extend(contact.Status, status); + this.e.triggerHandler("contactupdated", contact); + this.put(contact); + //console.log("contact update", contact); + }, this); + this.database.all("contacts", _.bind(function(data) { + var d = this.decrypt(data.contact); + if (d) { + var contact = contactData.addByData(d); + if (contact.Userid == userid) { + //console.log('found contact in database', contact); + updateContact(contact); + } + } + }, this)); }; return new Contacts(); diff --git a/static/partials/contactsmanager.html b/static/partials/contactsmanager.html index c5d8c267..e65233ce 100644 --- a/static/partials/contactsmanager.html +++ b/static/partials/contactsmanager.html @@ -1,4 +1,4 @@ -
+

{{_('You have no contacts.')}}

@@ -14,12 +14,10 @@
- {{contact.Status.displayName}} - Unnamed Contact {{i}} + {{contact.Userid|displayName:'contactsmanager'}} - - + diff --git a/static/partials/contactsmanageredit.html b/static/partials/contactsmanageredit.html index c50fc366..a5986dd0 100644 --- a/static/partials/contactsmanageredit.html +++ b/static/partials/contactsmanageredit.html @@ -3,13 +3,13 @@
-