Browse Source

Implemented next bunch of contact services.

pull/48/head
Simon Eisenmann 12 years ago
parent
commit
8792ebac29
  1. 6
      src/styles/components/_buddylist.scss
  2. 10
      static/js/directives/buddylist.js
  3. 8
      static/js/directives/contactrequest.js
  4. 9
      static/js/services/buddydata.js
  5. 33
      static/js/services/buddylist.js
  6. 73
      static/js/services/contactdata.js
  7. 41
      static/js/services/contacts.js
  8. 12
      static/js/services/services.js
  9. 4
      static/partials/buddy.html

6
src/styles/components/_buddylist.scss

@ -135,6 +135,12 @@ @@ -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;

10
static/js/directives/buddylist.js

@ -21,7 +21,7 @@ @@ -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) { @@ -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) { @@ -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);
});
}];

8
static/js/directives/contactrequest.js

@ -20,7 +20,7 @@ @@ -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($, _) { @@ -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);
}
}];

9
static/js/services/buddydata.js

@ -21,7 +21,7 @@ @@ -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) { @@ -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) { @@ -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.

33
static/js/services/buddylist.js

@ -102,6 +102,12 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text! @@ -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! @@ -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! @@ -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! @@ -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! @@ -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);

73
static/js/services/contactdata.js

@ -0,0 +1,73 @@ @@ -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 <http://www.gnu.org/licenses/>.
*
*/
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;
}];
});

41
static/js/services/contacts.js

@ -0,0 +1,41 @@ @@ -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 <http://www.gnu.org/licenses/>.
*
*/
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();
}];
});

12
static/js/services/services.js

@ -43,7 +43,9 @@ define([ @@ -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, @@ -66,7 +68,9 @@ safeDisplayName,
randomGen,
fastScroll,
videoWaiter,
videoLayout) {
videoLayout,
contactData,
contacts) {
var services = {
desktopNotify: desktopNotify,
@ -91,7 +95,9 @@ videoLayout) { @@ -91,7 +95,9 @@ videoLayout) {
randomGen: randomGen,
fastScroll: fastScroll,
videoWaiter: videoWaiter,
videoLayout: videoLayout
videoLayout: videoLayout,
contactData: contactData,
contacts: contacts
};
var initialize = function(angModule) {

4
static/partials/buddy.html

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
<div class="buddy withSubline">
<div class="buddy withSubline" ng-class="{'contact': contact}">
<div class="buddyPicture"><i class="fa fa-user fa-3x"/><img ng-show="status.buddyPicture" alt ng-src="{{status.buddyPicture}}" width="46" height="46"/></div>
<div class="buddy1">{{session.Id|displayName}}</div>
<div class="buddy2"><i ng-show="session.Userid" class="fa fa-star-o"></i> {{session.Ua}}</div>
<div class="buddy2"><i ng-show="session.Userid" class="fa contact"></i> {{session.Ua}}</div>
</div>

Loading…
Cancel
Save