|
|
|
@ -21,12 +21,13 @@
@@ -21,12 +21,13 @@
|
|
|
|
|
define(['underscore'], function(underscore) { |
|
|
|
|
|
|
|
|
|
// buddyData
|
|
|
|
|
return ["contactData", "mediaStream", function(contactData, mediaStream) { |
|
|
|
|
return ["contactData", "mediaStream", "$rootScope", function(contactData, mediaStream, $rootScope) { |
|
|
|
|
|
|
|
|
|
var scopes = {}; |
|
|
|
|
var brain = {}; |
|
|
|
|
var pushed = {}; |
|
|
|
|
var attestations = {}; |
|
|
|
|
var fakes = {}; |
|
|
|
|
var count = 0; |
|
|
|
|
|
|
|
|
|
var buddyData = { |
|
|
|
@ -40,10 +41,15 @@ define(['underscore'], function(underscore) {
@@ -40,10 +41,15 @@ define(['underscore'], function(underscore) {
|
|
|
|
|
push: function(id) { |
|
|
|
|
var entry = pushed[id]; |
|
|
|
|
if (!entry) { |
|
|
|
|
entry = pushed[id] = { |
|
|
|
|
count: 1, |
|
|
|
|
scope: scopes[id] |
|
|
|
|
}; |
|
|
|
|
var scope = scopes[id]; |
|
|
|
|
if (scope) { |
|
|
|
|
entry = pushed[id] = { |
|
|
|
|
count: 1, |
|
|
|
|
scope: scopes[id] |
|
|
|
|
}; |
|
|
|
|
} else { |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
entry.count++; |
|
|
|
|
} |
|
|
|
@ -105,18 +111,48 @@ define(['underscore'], function(underscore) {
@@ -105,18 +111,48 @@ define(['underscore'], function(underscore) {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
lookup: function(id, onlyactive) { |
|
|
|
|
var scope = null; |
|
|
|
|
lookup: function(id, onlyactive, withfakes) { |
|
|
|
|
if (!id) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (scopes.hasOwnProperty(id)) { |
|
|
|
|
scope = scopes[id]; |
|
|
|
|
return scopes[id]; |
|
|
|
|
} else if (!onlyactive) { |
|
|
|
|
if (brain.hasOwnProperty(id)) { |
|
|
|
|
scope = brain[id]; |
|
|
|
|
return brain[id]; |
|
|
|
|
} else if (pushed.hasOwnProperty(id)) { |
|
|
|
|
scope = pushed[id].scope; |
|
|
|
|
return pushed[id].scope; |
|
|
|
|
} |
|
|
|
|
if (withfakes) { |
|
|
|
|
var fake = fakes[id]; |
|
|
|
|
//console.log("check fake", id, fake);
|
|
|
|
|
if (fake) { |
|
|
|
|
//console.log("found fake", fake);
|
|
|
|
|
if (fake.display) { |
|
|
|
|
return fake; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
if (attestations.hasOwnProperty(id)) { |
|
|
|
|
// Fetch with help of session attestation token.
|
|
|
|
|
fake = fakes[id] = {}; |
|
|
|
|
var token = attestations[id].a; |
|
|
|
|
console.log("attestation request", id); |
|
|
|
|
mediaStream.api.sendSessions(token, "session", function(event, type, data) { |
|
|
|
|
console.log("attestation session response", id, type, data); |
|
|
|
|
if (data.Users && data.Users.length > 0) { |
|
|
|
|
var s = data.Users[0]; |
|
|
|
|
fake.display = { |
|
|
|
|
displayName: s.Status.displayName |
|
|
|
|
} |
|
|
|
|
// TODO(longsleep): Find a better way to apply this than digest on root scope.
|
|
|
|
|
$rootScope.$digest(); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return scope; |
|
|
|
|
return null; |
|
|
|
|
}, |
|
|
|
|
del: function(id, hard) { |
|
|
|
|
var scope = scopes[id]; |
|
|
|
@ -158,7 +194,7 @@ define(['underscore'], function(underscore) {
@@ -158,7 +194,7 @@ define(['underscore'], function(underscore) {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (create) { |
|
|
|
|
//console.log("Created attestation entry", from);
|
|
|
|
|
console.log("Created attestation entry", from); |
|
|
|
|
attestations[from] = { |
|
|
|
|
a: attestation, |
|
|
|
|
t: (new Date().getTime()) |
|
|
|
|