Bug 1102806: LoopCalls.jsm introduction forgot to include contacts blocking logic. r=Standard8

This commit is contained in:
Mike de Boer
2014-11-21 11:55:32 +01:00
parent 55124993eb
commit f146423bb1
2 changed files with 34 additions and 3 deletions

View File

@@ -11,12 +11,17 @@ Cu.import("resource://gre/modules/XPCOMUtils.jsm");
this.EXPORTED_SYMBOLS = ["LoopCalls"]; this.EXPORTED_SYMBOLS = ["LoopCalls"];
const EMAIL_OR_PHONE_RE = /^(:?\S+@\S+|\+\d+)$/;
XPCOMUtils.defineLazyModuleGetter(this, "MozLoopService", XPCOMUtils.defineLazyModuleGetter(this, "MozLoopService",
"resource:///modules/loop/MozLoopService.jsm"); "resource:///modules/loop/MozLoopService.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "LOOP_SESSION_TYPE", XPCOMUtils.defineLazyModuleGetter(this, "LOOP_SESSION_TYPE",
"resource:///modules/loop/MozLoopService.jsm"); "resource:///modules/loop/MozLoopService.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "LoopContacts",
"resource:///modules/loop/LoopContacts.jsm");
/** /**
* Attempts to open a websocket. * Attempts to open a websocket.
* *
@@ -269,7 +274,35 @@ let LoopCallsInternal = {
* "outgoing". * "outgoing".
*/ */
_startCall: function(callData) { _startCall: function(callData) {
const openChat = () => {
this.conversationInProgress.id = MozLoopService.openChatWindow(callData); this.conversationInProgress.id = MozLoopService.openChatWindow(callData);
};
if (callData.type == "incoming" && ("callerId" in callData) &&
EMAIL_OR_PHONE_RE.test(callData.callerId)) {
LoopContacts.search({
q: callData.callerId,
field: callData.callerId.contains("@") ? "email" : "tel"
}, (err, contacts) => {
if (err) {
// Database error, helas!
openChat();
return;
}
for (let contact of contacts) {
if (contact.blocked) {
// Blocked! Send a busy signal back to the caller.
this._returnBusy(callData);
return;
}
}
openChat();
})
} else {
openChat();
}
}, },
/** /**

View File

@@ -18,8 +18,6 @@ const LOOP_SESSION_TYPE = {
// See LOG_LEVELS in Console.jsm. Common examples: "All", "Info", "Warn", & "Error". // See LOG_LEVELS in Console.jsm. Common examples: "All", "Info", "Warn", & "Error".
const PREF_LOG_LEVEL = "loop.debug.loglevel"; const PREF_LOG_LEVEL = "loop.debug.loglevel";
const EMAIL_OR_PHONE_RE = /^(:?\S+@\S+|\+\d+)$/;
Cu.import("resource://gre/modules/Services.jsm"); Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Promise.jsm"); Cu.import("resource://gre/modules/Promise.jsm");