diff --git a/src/styles/components/_buddylist.scss b/src/styles/components/_buddylist.scss index d7f7d6fc..73a3352f 100644 --- a/src/styles/components/_buddylist.scss +++ b/src/styles/components/_buddylist.scss @@ -135,6 +135,12 @@ &.hovered .buddyactions { right: 0; } + & .fa.contact:before { + content: "\f006"; + } + &.contact .fa.contact:before { + content: "\f005"; + } .buddyPicture { background: $actioncolor1; border-radius: 2px; diff --git a/static/js/directives/buddylist.js b/static/js/directives/buddylist.js index 191ab81a..5fdb7e25 100644 --- a/static/js/directives/buddylist.js +++ b/static/js/directives/buddylist.js @@ -21,7 +21,7 @@ define(['underscore', 'text!partials/buddylist.html'], function(_, template) { // buddyList - return ["$compile", "buddyList", "mediaStream", function($compile, buddyList, mediaStream) { + return ["$compile", "buddyList", "mediaStream", "contacts", function($compile, buddyList, mediaStream, contacts) { //console.log("buddyList directive"); @@ -84,6 +84,7 @@ define(['underscore', 'text!partials/buddylist.html'], function(_, template) { var onJoined = _.bind(buddylist.onJoined, buddylist); var onLeft = _.bind(buddylist.onLeft, buddylist); var onStatus = _.bind(buddylist.onStatus, buddylist); + var onContactAdded = _.bind(buddylist.onContactAdded, buddylist); mediaStream.api.e.on("received.userleftorjoined", function(event, dataType, data) { if (dataType === "Left") { onLeft(data); @@ -108,11 +109,14 @@ define(['underscore', 'text!partials/buddylist.html'], function(_, template) { $scope.setRoomStatus(false); buddylist.onClosed(); }); - - // Request user list whenever the connection comes ready. + // Request user list whenever the connection comes ready. mediaStream.connector.ready(function() { mediaStream.api.requestUsers(); }); + // Contacts. + contacts.e.on("contactadded", function(event, data) { + onContactAdded(data); + }); }]; diff --git a/static/js/directives/contactrequest.js b/static/js/directives/contactrequest.js index 89c3fd08..3889d13b 100644 --- a/static/js/directives/contactrequest.js +++ b/static/js/directives/contactrequest.js @@ -20,7 +20,7 @@ */ define(['jquery', 'underscore'], function($, _) { - return ["translation", function(translation) { + return ["translation", "buddyData", "contacts", function(translation, buddyData, contacts) { var controller = ['$scope', '$element', '$attrs', function($scope, $element, $attrs) { @@ -43,14 +43,14 @@ define(['jquery', 'underscore'], function($, _) { }); }; - $scope.addContact = function(request) { - console.log("AAAAAAAA", request); + $scope.addContact = function(request, status) { + contacts.add(request, status) }; // Add support for contacts on controller creation. var request = $scope.request; if (request.Success && request.Userid && request.Token) { - $scope.addContact(request); + $scope.addContact(request, buddyData.lookup($scope.id).status || null); } }]; diff --git a/static/js/services/buddydata.js b/static/js/services/buddydata.js index 16a2447e..fc0e110e 100644 --- a/static/js/services/buddydata.js +++ b/static/js/services/buddydata.js @@ -21,7 +21,7 @@ define(['underscore'], function(underscore) { // buddyData - return [function() { + return ["contactData", function(contactData) { var scopes = {}; var brain = {}; @@ -61,7 +61,7 @@ define(['underscore'], function(underscore) { } return 0; }, - get: function(id, createInParent, afterCreateCallback) { + get: function(id, createInParent, afterCreateCallback, userid) { if (scopes.hasOwnProperty(id)) { return scopes[id]; } else if (!createInParent && pushed.hasOwnProperty(id)) { @@ -71,6 +71,11 @@ define(['underscore'], function(underscore) { // If we have a parent we can create a new scope. var scope = scopes[id] = createInParent.$new(); scope.buddyIndex = ++count; + if (userid) { + scope.contact = contactData.get(userid); + } else { + scope.contact = null; + } scope.buddyIndexSortable = ("0000000" + scope.buddyIndex).slice(-7); if (pushed.hasOwnProperty(id)) { // Refresh pushed scope reference. diff --git a/static/js/services/buddylist.js b/static/js/services/buddylist.js index 1bcedd03..5bbd4aab 100644 --- a/static/js/services/buddylist.js +++ b/static/js/services/buddylist.js @@ -102,6 +102,12 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text! }; + BuddyTree.prototype.traverse = function(cb) { + + return this.tree.inOrderTraverse(cb); + + }; + BuddyTree.prototype.clear = function() { this.tree.clear(); @@ -144,7 +150,7 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text! var buddyElement = $(event.currentTarget); buddyElement.scope().doDefault(); }, this)); - $element.on("click", ".fa-star-o", _.bind(function(event) { + $element.on("click", ".fa.contact", _.bind(function(event) { event.stopPropagation(); var buddyElement = $(event.currentTarget); buddyElement.scope().doDefaultContact(); @@ -348,7 +354,7 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text! //console.log("onStatus", status); var id = data.Id; - var scope = buddyData.get(id, this.$scope, _.bind(this.onBuddyScope, this)); + var scope = buddyData.get(id, this.$scope, _.bind(this.onBuddyScope, this), data.Userid); // Update session. scope.session.Userid = data.Userid; scope.session.Rev = data.Rev; @@ -377,7 +383,7 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text! //console.log("Joined", data); var id = data.Id; - var scope = buddyData.get(id, this.$scope, _.bind(this.onBuddyScope, this)); + var scope = buddyData.get(id, this.$scope, _.bind(this.onBuddyScope, this), data.Userid); // Create session. scope.session = { Id: data.Id, @@ -405,6 +411,27 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text! }; + Buddylist.prototype.onContactAdded = function(contact) { + + console.log("onContactAdded", contact); + var userid = contact.Userid; + // TODO(longsleep): Traversing the whole tree is stupid. Implement key/value map for this. + this.tree.traverse(function(record) { + var scope = buddyData.lookup(record.id, true); + var sessionUserid = scope.session.Userid; + if (sessionUserid === userid) { + scope.contact = contact; + } + }); + + }; + + Buddylist.prototype.onContactRemoved = function(data) { + + console.log("onContactRemoved", data); + + }; + Buddylist.prototype.onLeft = function(data) { //console.log("Left", session); diff --git a/static/js/services/contactdata.js b/static/js/services/contactdata.js new file mode 100644 index 00000000..2becce40 --- /dev/null +++ b/static/js/services/contactdata.js @@ -0,0 +1,73 @@ +/* + * 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(underscore, $) { + + // contactData + return [function() { + + var contacts = {}; + var users = {}; + var count = 0; + + var contactData = { + addByRequest: function(request, status) { + console.log("addByRequest", request, status); + var userid = request.Userid; + var token = request.Token; + var id; + if (users.hasOwnProperty(userid)) { + // Existing contact. Replace it. + id = users[userid]; + } else { + id = String(count++); + users[userid] = id; + } + var contact = contacts[id] = { + Id: "contact-"+id, + Userid: userid, + Token: token, + Status: $.extend({}, status) + } + // TODO(longsleep): Trigger this to somewhere. + return contact; + }, + get: function(userid) { + if (users.hasOwnProperty(userid)) { + var id = users[userid]; + return contacts[id]; + } + return null; + }, + getById: function(id) { + if (id.indexOf("contact-") === 0) { + id = id.substr(8) + } + if (contacts.hasOwnProperty(id)) { + return contacts[id]; + } + return null + } + }; + return contactData; + + }]; + +}); diff --git a/static/js/services/contacts.js b/static/js/services/contacts.js new file mode 100644 index 00000000..94714d72 --- /dev/null +++ b/static/js/services/contacts.js @@ -0,0 +1,41 @@ +/* + * 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(underscore, $) { + + // contacts + return ["contactData", function(contactData) { + + var Contacts = function() { + this.e = $({}); + }; + + Contacts.prototype.add = function(request, status) { + + var contact = contactData.addByRequest(request, status); + this.e.triggerHandler("contactadded", contact); + + }; + + return new Contacts(); + + }]; + +}); diff --git a/static/js/services/services.js b/static/js/services/services.js index 2a9e0bc1..a15f3dba 100644 --- a/static/js/services/services.js +++ b/static/js/services/services.js @@ -43,7 +43,9 @@ define([ 'services/randomgen', 'services/fastscroll', 'services/videowaiter', - 'services/videolayout'], function(_, + 'services/videolayout', + 'services/contactdata', + 'services/contacts'], function(_, desktopNotify, playSound, safeApply, @@ -66,7 +68,9 @@ safeDisplayName, randomGen, fastScroll, videoWaiter, -videoLayout) { +videoLayout, +contactData, +contacts) { var services = { desktopNotify: desktopNotify, @@ -91,7 +95,9 @@ videoLayout) { randomGen: randomGen, fastScroll: fastScroll, videoWaiter: videoWaiter, - videoLayout: videoLayout + videoLayout: videoLayout, + contactData: contactData, + contacts: contacts }; var initialize = function(angModule) { diff --git a/static/partials/buddy.html b/static/partials/buddy.html index 0f94e185..26b59bdd 100644 --- a/static/partials/buddy.html +++ b/static/partials/buddy.html @@ -1,5 +1,5 @@ -
+
{{session.Id|displayName}}
-
{{session.Ua}}
+
{{session.Ua}}