EXPORTED_SYMBOLS = ["module"];
var module = function (application) {
var log = function (message) {
application.logger.debug("[VK pages] " + message);
}
;
var Pages = function () {
this.userId = 0;
var pages = this;
var mailman = application.mailman;
mailman.addSubscriber({
subject: "please-open-page",
subscriber: {
receive: function ({body: page}) {
var url = pages.getURL(page) || null;
pages.open(url);
}
}});
mailman.addSubscriber({
subject: "please-open-url",
subscriber: {
receive: function ({body: url}) {
pages.open(url);
}
}});
mailman.addSubscriber({
subject: "user-id",
subscriber: {
receive: function ({body: id}) {
pages.userId = id;
}
}});
}
;
Pages.prototype = {
constructor: Pages,
getURL: function (id) {
var self = this;
var url = this._url[id];
var data = {
id: self.userId};
for(let i in data) {
url = url.replace("{{" + i + "}}",data[i],"g");
}

return url;
}
,
_url: {
profile: "http://vk.com/id{{id}}",
messages: "http://vk.com/im",
friends: "http://vk.com/friends",
friends_all: "http://vk.com/friends?section=all",
events: "http://vk.com/events",
groups: "http://vk.com/groups",
photos: "http://vk.com/photos.php",
video: "http://vk.com/video",
notes: "http://vk.com/notes",
audio: "http://vk.com/audio",
news: "http://vk.com/feed",
bookmarks: "http://vk.com/fave",
ads: "http://vk.com/matches.php",
opinions: "http://vk.com/opinions.php",
applications: "http://vk.com/apps",
questions: "http://vk.com/questions.php"},
open: function (url) {
if (null !== url)
{
log("open " + url);
application.api.Controls.navigateBrowser({
url: url,
target: "new tab"});
}

}
};
return Pages;
}
;
