|
|
@@ -1,39 +1,67 @@
|
|
|
|
|
|
+/**
|
|
|
+ * @constructor
|
|
|
+**/
|
|
|
function SlackTeam(teamData) {
|
|
|
- this.id = teamData.id;
|
|
|
- this.name = teamData.name;
|
|
|
- this.domain = teamData.domain;
|
|
|
- this.callApp = teamData.prefs.calling_app_id;
|
|
|
- this.callAppName = teamData.prefs.calling_app_name;
|
|
|
- this.fileUploadPermission = teamData.prefs.disable_file_uploads;
|
|
|
- this.fileEditPermission = teamData.prefs.disable_file_editing;
|
|
|
- this.fileDeletePermission = teamData.prefs.disable_file_deleting;
|
|
|
- this.icons = teamData.icon; // image_34, image_44, image_68, image_88, image_102, image_132, image_230, image_default
|
|
|
+ this.id = teamData["id"];
|
|
|
+ this.name = teamData["name"];
|
|
|
+ this.domain = teamData["domain"];
|
|
|
+ this.callApp = teamData["prefs"]["calling_app_id"];
|
|
|
+ this.callAppName = teamData["prefs"]["calling_app_name"];
|
|
|
+ this.fileUploadPermission = teamData["prefs"]["disable_file_uploads"];
|
|
|
+ this.fileEditPermission = teamData["prefs"]["disable_file_editing"];
|
|
|
+ this.fileDeletePermission = teamData["prefs"]["disable_file_deleting"];
|
|
|
+ this.icons = {
|
|
|
+ image_34: teamData["icon"]["image_34"]
|
|
|
+ ,image_44: teamData["icon"]["image_44"]
|
|
|
+ ,image_68: teamData["icon"]["image_68"]
|
|
|
+ ,image_88: teamData["icon"]["image_88"]
|
|
|
+ ,image_102: teamData["icon"]["image_102"]
|
|
|
+ ,image_132: teamData["icon"]["image_132"]
|
|
|
+ ,image_230: teamData["icon"]["image_230"]
|
|
|
+ ,image_default: teamData["icon"]["image_default"]
|
|
|
+ };
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * @constructor
|
|
|
+**/
|
|
|
function SlackChan(chanData, slackData) {
|
|
|
- this.id = chanData.id;
|
|
|
- this.name = chanData.name;
|
|
|
- this.created = chanData.created;
|
|
|
- this.creator = chanData.creator;
|
|
|
- this.archived = chanData.is_archived;
|
|
|
- this.isMember = chanData.is_member;
|
|
|
- this.lastRead = chanData.last_read;
|
|
|
+ this.id = chanData["id"];
|
|
|
+ this.name = chanData["name"];
|
|
|
+ this.created = chanData["created"];
|
|
|
+ this.creator = slackData.getMember(chanData["creator"]);
|
|
|
+ this.archived = chanData["is_archived"];
|
|
|
+ this.isMember = chanData["is_member"];
|
|
|
+ this.lastRead = chanData["last_read"];
|
|
|
this.members = {};
|
|
|
- for (var i =0, nbMembers = chanData.members.length; i < nbMembers; i++)
|
|
|
- this.members[chanData.members[i]] = slackData.getMember(chanData.members[i]);
|
|
|
- this.topic = chanData.topic.value;
|
|
|
- this.topicCreator = slackData.getMember(chanData.topic.creator);
|
|
|
- this.topicTs = chanData.topic.last_set;
|
|
|
- this.purpose = chanData.purpose.value;
|
|
|
- this.purposeCreator = slackData.getMember(chanData.purpose.creator);
|
|
|
- this.purposeTs = chanData.purpose.last_set;
|
|
|
+ if (chanData["members"]) for (var i =0, nbMembers = chanData["members"].length; i < nbMembers; i++) {
|
|
|
+ var member = slackData.getMember(chanData["members"][i]);
|
|
|
+ this.members[member.id] = member;
|
|
|
+ member.channels[this.id] = this;
|
|
|
+ }
|
|
|
+ if (chanData["topic"]) {
|
|
|
+ this.topic = chanData["topic"]["value"];
|
|
|
+ this.topicCreator = slackData.getMember(chanData["topic"]["creator"]);
|
|
|
+ this.topicTs = chanData["topic"]["last_set"];
|
|
|
+ }
|
|
|
+ if (chanData["purpose"]) {
|
|
|
+ this.purpose = chanData["purpose"]["value"];
|
|
|
+ this.purposeCreator = slackData.getMember(chanData["purpose"]["creator"]);
|
|
|
+ this.purposeTs = chanData["purpose"]["last_set"];
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * @constructor
|
|
|
+**/
|
|
|
function SlackGroup(groupData) {
|
|
|
// TODO
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * @constructor
|
|
|
+**/
|
|
|
function SlackIms(imsData) {
|
|
|
/*
|
|
|
* TODO
|
|
|
@@ -55,35 +83,49 @@ function SlackIms(imsData) {
|
|
|
*/
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * @constructor
|
|
|
+**/
|
|
|
function SlackUser(userData) {
|
|
|
- this.id = userData.id;
|
|
|
- this.name = userData.name;
|
|
|
- this.deleted = userData.deleted;
|
|
|
- this.status = userData.status;
|
|
|
- this.realName = userData.real_name || userData.profile.real_name;
|
|
|
- this.presence = userData.presence !== 'away';
|
|
|
+ this.id = userData["id"];
|
|
|
+ this.name = userData["name"];
|
|
|
+ this.deleted = userData["deleted"];
|
|
|
+ this.status = userData["status"];
|
|
|
+ this.realName = userData["real_name"] || userData["profile"]["real_name"];
|
|
|
+ this.presence = userData["presence"] !== 'away';
|
|
|
this.icons = {
|
|
|
- image_24: userData.profile.image_24
|
|
|
- ,image_32: userData.profile.image_32
|
|
|
- ,image_48: userData.profile.image_48
|
|
|
- ,image_72: userData.profile.image_72
|
|
|
- ,image_192: userData.profile.image_192
|
|
|
- ,image_512: userData.profile.image_512
|
|
|
+ image_24: userData["profile"]["image_24"]
|
|
|
+ ,image_32: userData["profile"]["image_32"]
|
|
|
+ ,image_48: userData["profile"]["image_48"]
|
|
|
+ ,image_72: userData["profile"]["image_72"]
|
|
|
+ ,image_192: userData["profile"]["image_192"]
|
|
|
+ ,image_512: userData["profile"]["image_512"]
|
|
|
};
|
|
|
- this.email = userData.profile.email;
|
|
|
- this.firstName = userData.profile.first_name;
|
|
|
- this.lastName = userData.profile.last_name;
|
|
|
+ this.email = userData["profile"]["email"];
|
|
|
+ this.firstName = userData["profile"]["first_name"];
|
|
|
+ this.lastName = userData["profile"]["last_name"];
|
|
|
+ this.channels = {};
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * @constructor
|
|
|
+**/
|
|
|
function SlackBot(botData) {
|
|
|
- this.id = botData.id;
|
|
|
- this.deleted = botData.deleted;
|
|
|
- this.name = botData.name;
|
|
|
- this.appId = botData.app_id;
|
|
|
- // { image_36, image_48, image_72 }
|
|
|
- this.icons = botData.icons;
|
|
|
+ this.id = botData["id"];
|
|
|
+ this.deleted = botData["deleted"];
|
|
|
+ this.name = botData["name"];
|
|
|
+ this.appId = botData["app_id"];
|
|
|
+ this.icons = {
|
|
|
+ image_36: botData["icons"]["image_36"]
|
|
|
+ ,image_48: botData["icons"]["image_48"]
|
|
|
+ ,image_72: botData["icons"]["image_72"]
|
|
|
+ };
|
|
|
+ this.channels = {};
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * @constructor
|
|
|
+**/
|
|
|
function SlackHistory(target) {
|
|
|
this.id = target.id;
|
|
|
this.target = target;
|
|
|
@@ -91,6 +133,9 @@ function SlackHistory(target) {
|
|
|
this.messages = [];
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * @constructor
|
|
|
+**/
|
|
|
function SlackData(slack) {
|
|
|
this.team = null;
|
|
|
this.channels = {};
|
|
|
@@ -103,22 +148,98 @@ function SlackData(slack) {
|
|
|
this.history = {};
|
|
|
this.slack = slack;
|
|
|
|
|
|
+ /** @type {number} */
|
|
|
this.staticV = 0;
|
|
|
+ /** @type {number} */
|
|
|
this.liveV = 0;
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * @return {Object}
|
|
|
+**/
|
|
|
SlackTeam.prototype.toStatic = function() {
|
|
|
- return this;
|
|
|
-}
|
|
|
+ return {
|
|
|
+ "id": this.id
|
|
|
+ ,"name": this.name
|
|
|
+ ,"domain": this.domain
|
|
|
+ ,"prefs": {
|
|
|
+ "calling_app_id": this.callApp
|
|
|
+ ,"calling_app_name": this.callAppName
|
|
|
+ ,"disable_file_uploads": this.fileUploadPermission
|
|
|
+ ,"disable_file_editing": this.fileEditPermission
|
|
|
+ ,"disable_file_deleting": this.fileDeletePermission
|
|
|
+ }
|
|
|
+ ,"icon": this.icons
|
|
|
+ };
|
|
|
+};
|
|
|
|
|
|
SlackHistory.prototype.update = function(messages) {
|
|
|
// TODO
|
|
|
-}
|
|
|
+};
|
|
|
|
|
|
SlackHistory.prototype.getUpdates = function(knownVersion) {
|
|
|
// TODO
|
|
|
-}
|
|
|
+};
|
|
|
+
|
|
|
+/**
|
|
|
+ * @return {Object}
|
|
|
+**/
|
|
|
+SlackChan.prototype.toStatic = function() {
|
|
|
+ var res = {
|
|
|
+ "id": this.id
|
|
|
+ ,"name": this.name
|
|
|
+ ,"created": this.created
|
|
|
+ ,"creator": this.creator.id
|
|
|
+ ,"is_archived": this.archived
|
|
|
+ ,"is_member": this.isMember
|
|
|
+ ,"last_read": this.lastRead
|
|
|
+ };
|
|
|
+ if (this.isMember) {
|
|
|
+ res["members"] = Object.keys(this.members);
|
|
|
+ res["topic"] = {
|
|
|
+ "value": this.topic
|
|
|
+ ,"creator": this.topicCreator ? this.topicCreator.id : null
|
|
|
+ ,"last_set": this.topicTs
|
|
|
+ }
|
|
|
+ res["purpose"] = {
|
|
|
+ "value": this.purpose
|
|
|
+ ,"creator": this.purposeCreator ? this.purposeCreator.id : null
|
|
|
+ ,"last_set": this.purposeTs
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+};
|
|
|
+
|
|
|
+/**
|
|
|
+ * @return {Object}
|
|
|
+**/
|
|
|
+SlackUser.prototype.toStatic = function() {
|
|
|
+ return {
|
|
|
+ "id": this.id
|
|
|
+ ,"name": this.name
|
|
|
+ ,"deleted": this.deleted
|
|
|
+ ,"status": this.status
|
|
|
+ ,"real_name": this.realName
|
|
|
+ ,"presence": this.presence ? "present" : "away"
|
|
|
+ ,"profile": {
|
|
|
+ "email": this.email
|
|
|
+ ,"first_name": this.firstName
|
|
|
+ ,"last_name": this.lastName
|
|
|
+
|
|
|
+ ,"image_24": this.icons.image_24
|
|
|
+ ,"image_32": this.icons.image_32
|
|
|
+ ,"image_48": this.icons.image_48
|
|
|
+ ,"image_72": this.icons.image_72
|
|
|
+ ,"image_192": this.icons.image_192
|
|
|
+ ,"image_512": this.icons.image_512
|
|
|
+ }
|
|
|
+ };
|
|
|
+};
|
|
|
|
|
|
+/**
|
|
|
+ * @param {*} data
|
|
|
+ * @param {function()=} callback
|
|
|
+**/
|
|
|
SlackData.prototype.updateStatic = function(data, callback) {
|
|
|
for (var i =0, nbBots = data.bots.length; i < nbBots; i++)
|
|
|
this.bots[data.bots[i].id] = new SlackBot(data.bots[i]);
|
|
|
@@ -129,8 +250,12 @@ SlackData.prototype.updateStatic = function(data, callback) {
|
|
|
this.channels[data.channels[i].id] = new SlackChan(data.channels[i], this);
|
|
|
//this.groups.push(new SlackGroup(data.groups)); TODO
|
|
|
//this.ims.push(new SlackIms(data.ims[0])); TODO
|
|
|
- this.staticV = parseFloat(data.latest_event_ts);
|
|
|
+ this.staticV = parseFloat(data["latest_event_ts"]);
|
|
|
+ this.self = this.getMember(data["self"]["id"]);
|
|
|
|
|
|
+ if (!this.slack) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
var fetchHistory = {}
|
|
|
,doFetch = false;
|
|
|
for (var i in this.channels)
|
|
|
@@ -144,7 +269,7 @@ SlackData.prototype.updateStatic = function(data, callback) {
|
|
|
else for (var i in fetchHistory) {
|
|
|
var _this = this;
|
|
|
|
|
|
- this.slack.fetchHistory(i, (currentUpdated, data) => {
|
|
|
+ this.slack.fetchHistory(i, function(currentUpdated, data) {
|
|
|
if (data != null) {
|
|
|
_this.setHistory(fetchHistory[currentUpdated], data);
|
|
|
fetchHistory[currentUpdated] = null;
|
|
|
@@ -156,14 +281,18 @@ SlackData.prototype.updateStatic = function(data, callback) {
|
|
|
callback();
|
|
|
});
|
|
|
}
|
|
|
-}
|
|
|
+};
|
|
|
|
|
|
SlackData.prototype.setHistory = function(target, data) {
|
|
|
if (!this.history[target.id])
|
|
|
this.history[target.id] = new SlackHistory(target);
|
|
|
this.history[target.id].update(data);
|
|
|
-}
|
|
|
+};
|
|
|
|
|
|
+/**
|
|
|
+ * @param {string} appId
|
|
|
+ * @return {Array.<SlackBot>}
|
|
|
+**/
|
|
|
SlackData.prototype.getBotsByAppId = function(appId) {
|
|
|
var bots = [];
|
|
|
|
|
|
@@ -173,43 +302,70 @@ SlackData.prototype.getBotsByAppId = function(appId) {
|
|
|
}
|
|
|
}
|
|
|
return bots;
|
|
|
-}
|
|
|
+};
|
|
|
|
|
|
+/**
|
|
|
+ * @param {string} mId
|
|
|
+ * @return {SlackUser|null}
|
|
|
+**/
|
|
|
SlackData.prototype.getMember = function(mId) {
|
|
|
return this.users[mId] || this.bots[mId] || null;
|
|
|
-}
|
|
|
+};
|
|
|
|
|
|
+/**
|
|
|
+ * @param {number} knownVersion
|
|
|
+ * @return {Object}
|
|
|
+**/
|
|
|
SlackData.prototype.buildLive = function(knownVersion) {
|
|
|
var res = {};
|
|
|
for (var i in this.history)
|
|
|
if (this.history[i].v > knownVersion)
|
|
|
res[i] = this.history[i].getUpdates(knownVersion);
|
|
|
-}
|
|
|
+ return res;
|
|
|
+};
|
|
|
|
|
|
+/** @return {Object} */
|
|
|
SlackData.prototype.buildStatic = function() {
|
|
|
var res = {
|
|
|
- team: this.team.toStatic()
|
|
|
- ,channels: {}
|
|
|
- ,groups: {}
|
|
|
- ,ims: {}
|
|
|
- ,users: {}
|
|
|
- ,bots: {}
|
|
|
+ "team": this.team.toStatic()
|
|
|
+ ,"channels": []
|
|
|
+ ,"groups": [] // TODO
|
|
|
+ ,"ims": [] // TODO
|
|
|
+ ,"users": []
|
|
|
+ ,"bots": [] // TODO
|
|
|
+ ,"self": {
|
|
|
+ "id": this.self.id
|
|
|
+ }
|
|
|
};
|
|
|
+ for (var chanId in this.channels) {
|
|
|
+ res.channels.push(this.channels[chanId].toStatic());
|
|
|
+ }
|
|
|
+ for (var userId in this.users) {
|
|
|
+ res.users.push(this.users[userId].toStatic());
|
|
|
+ }
|
|
|
return res;
|
|
|
-}
|
|
|
+};
|
|
|
|
|
|
+/**
|
|
|
+ * @param {number} knownVersion
|
|
|
+ * @return {{live: (Object|undefined), static: (Object|undefined)}}
|
|
|
+**/
|
|
|
SlackData.prototype.getUpdates = function(knownVersion) {
|
|
|
var res = {};
|
|
|
+
|
|
|
if (this.liveV > knownVersion) {
|
|
|
- res.live = this.buildLive();
|
|
|
+ res["live"] = this.buildLive(knownVersion);
|
|
|
}
|
|
|
if (this.staticV > knownVersion) {
|
|
|
- res.static = this.buildStatic();
|
|
|
+ res["static"] = this.buildStatic();
|
|
|
}
|
|
|
return res;
|
|
|
-}
|
|
|
+};
|
|
|
|
|
|
-if (module.exports) {
|
|
|
- module.exports.SlackData = SlackData;
|
|
|
-}
|
|
|
+/** @suppress {undefinedVars,checkTypes} */
|
|
|
+(function() {
|
|
|
+ if (typeof module !== "undefined") {
|
|
|
+ module.exports.SlackData = SlackData;
|
|
|
+ }
|
|
|
+})();
|
|
|
|