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

61
static/js/services/buddylist.js

@ -200,19 +200,25 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text! @@ -200,19 +200,25 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text!
Buddylist.prototype.onBuddyScopeCreated = function(scope, data) {
scope.element = null;
scope.contact = null;
scope.display = {};
scope.session = buddySession.create(data);
scope.doDefault = function() {
var id = scope.session.Id;
if (scope.status.isMixer) {
return scope.doAudioConference(id);
}
//if (scope.status.isMixer) {
// return scope.doAudioConference(id);
//}
return scope.doCall(id);
};
scope.doDefaultContact = function() {
var id = scope.session.Id;
return scope.doContact(id);
var contact = scope.contact;
if (contact) {
return scope.doContactRemove(contact.Userid);
} else {
var id = scope.session.Id;
return scope.doContactRequest(id);
}
};
scope.$on("$destroy", function() {
scope.element = null;
@ -472,7 +478,7 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text! @@ -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);
var id = data.Id;
@ -488,7 +494,7 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text! @@ -488,7 +494,7 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text!
this.tree.remove(id);
// Remove session.
var session = scope.session;
if (session.remove(id)) {
if ((session.remove(id) && scope.contact === null) || force) {
// No session left. Cleanup.
if (scope.element) {
this.lefts[id] = scope.element;
@ -500,9 +506,12 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text! @@ -500,9 +506,12 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text!
}
delete this.actionElements[id];
} 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();
this.updateDisplay(sessionData.Id, scope, sessionData, "status");
if (sessionData) {
this.updateDisplay(sessionData.Id, scope, sessionData, "status");
}
scope.$apply();
}
@ -528,13 +537,37 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text! @@ -528,13 +537,37 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text!
var scope = buddyData.get(userid);
if (scope) {
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", data);
console.log("onContactRemoved", contact);
var userid = contact.Userid;
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! @@ -563,9 +596,9 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text!
} else {
var scope = buddyData.get(id);
var template = buddyActions;
if (scope.status.autoCalls && _.indexOf(scope.status.autoCalls, "conference") !== -1) {
template = buddyActionsForAudioMixer;
}
//if (scope.status.autoCalls && _.indexOf(scope.status.autoCalls, "conference") !== -1) {
// template = buddyActionsForAudioMixer;
//}
//console.log("scope", scope, id);
template(scope, _.bind(function(clonedElement, $scope) {
actionElements[id] = clonedElement;

23
static/js/services/buddysession.js

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

5
static/js/services/contactdata.js

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

11
static/js/services/contacts.js

@ -34,6 +34,17 @@ define(['underscore', 'jquery'], function(underscore, $) { @@ -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();
}];

2
static/partials/buddy.html

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
<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="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>

Loading…
Cancel
Save