Browse Source

Implemented contact add and remove with aggregated buddies.

pull/48/head
Simon Eisenmann 11 years ago
parent
commit
d50fb327b3
  1. 12
      static/js/directives/buddylist.js
  2. 57
      static/js/services/buddylist.js
  3. 23
      static/js/services/buddysession.js
  4. 5
      static/js/services/contactdata.js
  5. 11
      static/js/services/contacts.js
  6. 2
      static/partials/buddy.html

12
static/js/directives/buddylist.js

@ -46,7 +46,7 @@ define(['underscore', 'text!partials/buddylist.html'], function(_, template) {
}; };
$scope.doContact = function(id) { $scope.doContactRequest = function(id) {
//console.log("doContact", id); //console.log("doContact", id);
$scope.$emit("requestcontact", id, { $scope.$emit("requestcontact", id, {
@ -55,6 +55,12 @@ define(['underscore', 'text!partials/buddylist.html'], function(_, template) {
}; };
$scope.doContactRemove = function(userid) {
contacts.remove(userid);
};
$scope.doAudioConference = function(id) { $scope.doAudioConference = function(id) {
$scope.updateAutoAccept(id); $scope.updateAutoAccept(id);
@ -85,6 +91,7 @@ define(['underscore', 'text!partials/buddylist.html'], function(_, template) {
var onLeft = _.bind(buddylist.onLeft, buddylist); var onLeft = _.bind(buddylist.onLeft, buddylist);
var onStatus = _.bind(buddylist.onStatus, buddylist); var onStatus = _.bind(buddylist.onStatus, buddylist);
var onContactAdded = _.bind(buddylist.onContactAdded, buddylist); var onContactAdded = _.bind(buddylist.onContactAdded, buddylist);
var onContactRemoved = _.bind(buddylist.onContactRemoved, buddylist);
mediaStream.api.e.on("received.userleftorjoined", function(event, dataType, data) { mediaStream.api.e.on("received.userleftorjoined", function(event, dataType, data) {
if (dataType === "Left") { if (dataType === "Left") {
onLeft(data); onLeft(data);
@ -117,6 +124,9 @@ define(['underscore', 'text!partials/buddylist.html'], function(_, template) {
contacts.e.on("contactadded", function(event, data) { contacts.e.on("contactadded", function(event, data) {
onContactAdded(data); onContactAdded(data);
}); });
contacts.e.on("contactremoved", function(event, data) {
onContactRemoved(data);
});
}]; }];

57
static/js/services/buddylist.js

@ -200,19 +200,25 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text!
Buddylist.prototype.onBuddyScopeCreated = function(scope, data) { Buddylist.prototype.onBuddyScopeCreated = function(scope, data) {
scope.element = null; scope.element = null;
scope.contact = null;
scope.display = {}; scope.display = {};
scope.session = buddySession.create(data); scope.session = buddySession.create(data);
scope.doDefault = function() { scope.doDefault = function() {
var id = scope.session.Id; var id = scope.session.Id;
if (scope.status.isMixer) { //if (scope.status.isMixer) {
return scope.doAudioConference(id); // return scope.doAudioConference(id);
} //}
return scope.doCall(id); return scope.doCall(id);
}; };
scope.doDefaultContact = function() { scope.doDefaultContact = function() {
var contact = scope.contact;
if (contact) {
return scope.doContactRemove(contact.Userid);
} else {
var id = scope.session.Id; var id = scope.session.Id;
return scope.doContact(id); return scope.doContactRequest(id);
}
}; };
scope.$on("$destroy", function() { scope.$on("$destroy", function() {
scope.element = null; scope.element = null;
@ -472,7 +478,7 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text!
}; };
Buddylist.prototype.onLeft = function(data) { Buddylist.prototype.onLeft = function(data, force) {
//console.log("Left", data); //console.log("Left", data);
var id = data.Id; var id = data.Id;
@ -488,7 +494,7 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text!
this.tree.remove(id); this.tree.remove(id);
// Remove session. // Remove session.
var session = scope.session; var session = scope.session;
if (session.remove(id)) { if ((session.remove(id) && scope.contact === null) || force) {
// No session left. Cleanup. // No session left. Cleanup.
if (scope.element) { if (scope.element) {
this.lefts[id] = scope.element; this.lefts[id] = scope.element;
@ -500,9 +506,12 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text!
} }
delete this.actionElements[id]; delete this.actionElements[id];
} else { } else {
// Update display stuff if session left. // Update display stuff if session left. This can
// return no session in case when we got this as contact.
var sessionData = session.get(); var sessionData = session.get();
if (sessionData) {
this.updateDisplay(sessionData.Id, scope, sessionData, "status"); this.updateDisplay(sessionData.Id, scope, sessionData, "status");
}
scope.$apply(); scope.$apply();
} }
@ -528,13 +537,37 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text!
var scope = buddyData.get(userid); var scope = buddyData.get(userid);
if (scope) { if (scope) {
scope.contact = contact; scope.contact = contact;
var sessionData = scope.session.get();
if (sessionData) {
if (contact.Status === null && sessionData.Status) {
// Update contact status with session.Status
contact.Status = _.extend({}, sessionData.Status);
console.log("Injected status into contact", contact);
}
this.updateDisplay(sessionData.Id, scope, contact, "status");
}
} else {
// TODO(longsleep): Implement rendering of contacts without scope.
console.log("No scope for contact", userid);
} }
}; };
Buddylist.prototype.onContactRemoved = function(data) { Buddylist.prototype.onContactRemoved = function(contact) {
console.log("onContactRemoved", contact);
var userid = contact.Userid;
console.log("onContactRemoved", data); var scope = buddyData.get(userid);
if (scope) {
scope.contact = null;
// Remove with left when no session for this userid.
var sessionData = scope.session.get();
if (!sessionData) {
// Force left.
this.onLeft({Id: userid}, true);
}
}
}; };
@ -563,9 +596,9 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text!
} else { } else {
var scope = buddyData.get(id); var scope = buddyData.get(id);
var template = buddyActions; var template = buddyActions;
if (scope.status.autoCalls && _.indexOf(scope.status.autoCalls, "conference") !== -1) { //if (scope.status.autoCalls && _.indexOf(scope.status.autoCalls, "conference") !== -1) {
template = buddyActionsForAudioMixer; // template = buddyActionsForAudioMixer;
} //}
//console.log("scope", scope, id); //console.log("scope", scope, id);
template(scope, _.bind(function(clonedElement, $scope) { template(scope, _.bind(function(clonedElement, $scope) {
actionElements[id] = clonedElement; actionElements[id] = clonedElement;

23
static/js/services/buddysession.js

@ -28,7 +28,6 @@ define(["underscore"], function(_) {
this.count = 0; this.count = 0;
if (data.Id) { if (data.Id) {
this.add(data.Id, data); this.add(data.Id, data);
this.use(data);
this.Userid = data.Userid || null; this.Userid = data.Userid || null;
} else { } else {
this.set({}); this.set({});
@ -37,6 +36,9 @@ define(["underscore"], function(_) {
BuddySession.prototype.add = function(id, data) { BuddySession.prototype.add = function(id, data) {
this.sessions[id] = data; this.sessions[id] = data;
if (this.count === 0) {
this.use(id, data);
}
this.count++; this.count++;
return data; return data;
}; };
@ -53,9 +55,13 @@ define(["underscore"], function(_) {
return this.sessions[id]; return this.sessions[id];
}; };
BuddySession.prototype.use = function(data) { BuddySession.prototype.use = function(id, data) {
this.Id = data.Id || null; if (id) {
this.Ua = data.Ua || ""; this.Id = id;
} else {
this.Id = null;
}
console.log("Use session as default", id, data);
}; };
BuddySession.prototype.remove = function(id, onEmptyCallback) { BuddySession.prototype.remove = function(id, onEmptyCallback) {
@ -71,10 +77,15 @@ define(["underscore"], function(_) {
} }
} }
if (sessionData) { if (sessionData) {
//console.log("remove session", sessionData); this.use(sessionData.Id, sessionData);
this.use(sessionData);
} else { } else {
console.log("Last session removed", sessions); console.log("Last session removed", sessions);
if (this.Userid) {
console.log("Using userid as session id");
this.use(this.Userid);
} else {
this.use(null);
}
return true; return true;
} }
} }

5
static/js/services/contactdata.js

@ -44,7 +44,7 @@ define(['underscore', 'jquery'], function(underscore, $) {
Id: "contact-"+id, Id: "contact-"+id,
Userid: userid, Userid: userid,
Token: token, Token: token,
Status: $.extend({}, status) Status: null
} }
// TODO(longsleep): Trigger this to somewhere. // TODO(longsleep): Trigger this to somewhere.
return contact; return contact;
@ -56,6 +56,9 @@ define(['underscore', 'jquery'], function(underscore, $) {
} }
return null; return null;
}, },
remove: function(userid) {
delete users[userid];
},
getById: function(id) { getById: function(id) {
if (id.indexOf("contact-") === 0) { if (id.indexOf("contact-") === 0) {
id = id.substr(8) id = id.substr(8)

11
static/js/services/contacts.js

@ -34,6 +34,17 @@ define(['underscore', 'jquery'], function(underscore, $) {
}; };
Contacts.prototype.remove = function(userid) {
var contact = contactData.get(userid);
//console.log("contacts remove", userid, contact);
if (contact) {
contactData.remove(userid);
this.e.triggerHandler("contactremoved", contact);
}
};
return new Contacts(); return new Contacts();
}]; }];

2
static/partials/buddy.html

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

Loading…
Cancel
Save