Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added BBM presence for other users #152

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions ext/bbm.platform/BBMEvents.js
Expand Up @@ -20,16 +20,18 @@ module.exports = {
addEventListener: function (event, trigger) {
if (event === "onaccesschanged") {
bbm.startEvents(trigger);
}
else {
} else if (event === "onupdate") {
bbm.startContactEvents(trigger);
} else {
console.log("Ignore registration for unknown event: " + event);
}
},
removeEventListener: function (event) {
if (event === "onaccesschanged") {
bbm.stopEvents();
}
else {
} else if (event === "onupdate") {
bbm.stopContactEvents();
} else {
console.log("Ignore un-registration for unknown event: " + event);
}
}
Expand Down
124 changes: 71 additions & 53 deletions ext/bbm.platform/BBMJNEXT.js
@@ -1,25 +1,26 @@
/*
* Copyright 2012 Research In Motion Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright 2012 Research In Motion Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

function requireLocal(id) {
return !!require.resolve ? require("../../" + id) : window.require(id);
}

var bbm,
accesschangedCallback = null,
updateCallback = null,
_event = require("../../lib/event");

///////////////////////////////////////////////////////////////////
Expand All @@ -28,89 +29,106 @@ var bbm,

JNEXT.BBM = function ()
{
var self = this;
var _self = this;
_self.self = {};
_self.users = {};

self.startEvents = function (trigger) {
_self.startEvents = function (trigger) {
if (accesschangedCallback === null) {
accesschangedCallback = trigger;
JNEXT.invoke(self.m_id, "startEvents");
JNEXT.invoke(_self.m_id, "startEvents");
}
};

self.stopEvents = function () {
_self.stopEvents = function () {
accesschangedCallback = null;
JNEXT.invoke(self.m_id, "stopEvents");
JNEXT.invoke(_self.m_id, "stopEvents");
};

self.register = function (options) {
JNEXT.invoke(self.m_id, "register " + JSON.stringify(options));
_self.startContactEvents = function (trigger) {
if (updateCallback === null) {
updateCallback = trigger;
JNEXT.invoke(_self.m_id, "startContactEvents");
}
};

_self.stopContactEvents = function () {
updateCallback = null;
JNEXT.invoke(_self.m_id, "stopContactEvents");
};

_self.register = function (options) {
JNEXT.invoke(_self.m_id, "register " + JSON.stringify(options));
};

_self.getgid = function () {
return JNEXT.invoke(_self.m_id, "getgid");
};

self.getProfile = function (field) {
return JNEXT.invoke(self.m_id, "getProfile " + field);
_self.self.getProfile = function (field) {
return JNEXT.invoke(_self.m_id, "self.getProfile " + field);
};

self.getDisplayPicture = function (eventId) {
self.displayPictureEventId = eventId;
return JNEXT.invoke(self.m_id, "getDisplayPicture");
_self.self.getDisplayPicture = function (eventId) {
_self.displayPictureEventId = eventId;
return JNEXT.invoke(_self.m_id, "self.getDisplayPicture");
};

self.setStatus = function (statusArgs) {
JNEXT.invoke(self.m_id, "setStatus " + JSON.stringify(statusArgs));
_self.self.setStatus = function (statusArgs) {
JNEXT.invoke(_self.m_id, "self.setStatus " + JSON.stringify(statusArgs));
};

self.setPersonalMessage = function (personalMessage) {
JNEXT.invoke(self.m_id, "setPersonalMessage " + personalMessage);
_self.self.setPersonalMessage = function (personalMessage) {
JNEXT.invoke(_self.m_id, "self.setPersonalMessage " + personalMessage);
};

self.setDisplayPicture = function (displayPicture) {
JNEXT.invoke(self.m_id, "setDisplayPicture " + displayPicture);
_self.self.setDisplayPicture = function (displayPicture) {
JNEXT.invoke(_self.m_id, "self.setDisplayPicture " + displayPicture);
};

self.getId = function () {
return self.m_id;
_self.getId = function () {
return _self.m_id;
};

self.init = function () {
_self.init = function () {
if (!JNEXT.require("bbm")) {
return false;
}

self.m_id = JNEXT.createObject("bbm.BBM");
if (self.m_id === "") {
_self.m_id = JNEXT.createObject("bbm.BBM");

if (_self.m_id === "") {
return false;
}

JNEXT.registerEvents(self);
JNEXT.registerEvents(_self);
};
self.onEvent = function (strData) {

_self.onEvent = function (strData) {
var arData = strData.split(" "),
strEventDesc = arData[0],
allowed;

allowed,
obj;

if (strEventDesc === "onaccesschanged") {
if (arData[1] === "allowed") {
allowed = true;
} else {
allowed = false;
}

accesschangedCallback(allowed, arData[1]);
} else if (strEventDesc === "onupdate") {
obj = arData.slice(2, arData.length).join(" ");
updateCallback(JSON.parse(obj), arData[1]);
} else if (strEventDesc === "self.getDisplayPicture") {
_event.trigger(self.displayPictureEventId, arData[1]);
_event.trigger(_self.displayPictureEventId, arData[1]);
}
};

_self.m_id = "";
_self.displayPictureEventId = "";

self.getgid = function () {
return JNEXT.invoke(self.m_id, "getgid");
};

self.m_id = "";
self.displayPictureEventId = "";

self.init();
_self.init();
};

bbm = new JNEXT.BBM();
Expand Down
31 changes: 19 additions & 12 deletions ext/bbm.platform/index.js
Expand Up @@ -24,6 +24,13 @@ var bbm = require("./BBMJNEXT").bbm,
trigger: function (allowed, reason) {
_event.trigger("onaccesschanged", allowed, reason);
}
},
onupdate: {
context: require("./BBMEvents"),
event: "onupdate",
trigger: function (user, event) {
_event.trigger("onupdate", user, event);
}
}
},
BBM_DISPLAY_NAME = 0,
Expand Down Expand Up @@ -62,42 +69,42 @@ module.exports = {

self : {
appVersion : function (success, fail, args, env) {
success(bbm.getProfile(BBM_APP_VERSION));
success(bbm.self.getProfile(BBM_APP_VERSION));
},

bbmsdkVersion : function (success, fail, args, env) {
success(parseInt(bbm.getProfile(BBM_SDK_VERSION), 10));
success(parseInt(bbm.self.getProfile(BBM_SDK_VERSION), 10));
},

displayName : function (success, fail, args, env) {
success(bbm.getProfile(BBM_DISPLAY_NAME));
success(bbm.self.getProfile(BBM_DISPLAY_NAME));
},

handle : function (success, fail, args, env) {
success(bbm.getProfile(BBM_HANDLE));
success(bbm.self.getProfile(BBM_HANDLE));
},

personalMessage : function (success, fail, args, env) {
success(bbm.getProfile(BBM_PERSONAL_MESSAGE));
success(bbm.self.getProfile(BBM_PERSONAL_MESSAGE));
},

ppid : function (success, fail, args, env) {
success(bbm.getProfile(BBM_PPID));
success(bbm.self.getProfile(BBM_PPID));
},

status : function (success, fail, args, env) {
success(bbm.getProfile(BBM_STATUS));
success(bbm.self.getProfile(BBM_STATUS));
},

statusMessage : function (success, fail, args, env) {
success(bbm.getProfile(BBM_STATUS_MESSAGE));
success(bbm.self.getProfile(BBM_STATUS_MESSAGE));
},

getDisplayPicture : function (success, fail, args, env) {
if (args) {
args.eventId = JSON.parse(decodeURIComponent(args.eventId));

bbm.getDisplayPicture(args.eventId);
bbm.self.getDisplayPicture(args.eventId);
success();
}
},
Expand All @@ -113,7 +120,7 @@ module.exports = {
}
}

bbm.setStatus(args);
bbm.self.setStatus(args);
success();
},

Expand All @@ -127,7 +134,7 @@ module.exports = {
}
}

bbm.setPersonalMessage(args.personalMessage);
bbm.self.setPersonalMessage(args.personalMessage);
success();
},

Expand All @@ -141,7 +148,7 @@ module.exports = {
}
}

bbm.setDisplayPicture(args.displayPicture);
bbm.self.setDisplayPicture(args.displayPicture);
success();
}
},
Expand Down