|
|
@@ -3,14 +3,23 @@
|
|
|
* @constructor
|
|
|
**/
|
|
|
function SlackTeam(teamData) {
|
|
|
+ /** @type {string} */
|
|
|
this.id = teamData["id"];
|
|
|
+ /** @type {string} */
|
|
|
this.name = teamData["name"];
|
|
|
+ /** @type {string} */
|
|
|
this.domain = teamData["domain"];
|
|
|
+ /** @type {string} */
|
|
|
this.callApp = teamData["prefs"]["calling_app_id"];
|
|
|
+ /** @type {string} */
|
|
|
this.callAppName = teamData["prefs"]["calling_app_name"];
|
|
|
+ /** @type {boolean} */
|
|
|
this.fileUploadPermission = teamData["prefs"]["disable_file_uploads"];
|
|
|
+ /** @type {boolean} */
|
|
|
this.fileEditPermission = teamData["prefs"]["disable_file_editing"];
|
|
|
+ /** @type {boolean} */
|
|
|
this.fileDeletePermission = teamData["prefs"]["disable_file_deleting"];
|
|
|
+ /** @type {Object.<string, string>} */
|
|
|
this.icons = {
|
|
|
image_34: teamData["icon"]["image_34"]
|
|
|
,image_44: teamData["icon"]["image_44"]
|
|
|
@@ -27,19 +36,39 @@ function SlackTeam(teamData) {
|
|
|
* @constructor
|
|
|
**/
|
|
|
function SlackChan(chanData, slackData) {
|
|
|
+ /** @type {string} */
|
|
|
this.id = chanData["id"];
|
|
|
+ /** @type {string} */
|
|
|
this.name = chanData["name"];
|
|
|
+ /** @type {string} */
|
|
|
this.created = chanData["created"];
|
|
|
+ /** @type {SlackUser|SlackBot} */
|
|
|
this.creator = slackData.getMember(chanData["creator"]);
|
|
|
+ /** @type {boolean} */
|
|
|
this.archived = chanData["is_archived"];
|
|
|
+ /** @type {boolean} */
|
|
|
this.isMember = chanData["is_member"];
|
|
|
+ /** @type {number} */
|
|
|
this.lastRead = chanData["last_read"];
|
|
|
+ /** @type {Object.<string, SlackBot|SlackUser>} */
|
|
|
this.members = {};
|
|
|
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;
|
|
|
}
|
|
|
+ /** @type {string|undefined} */
|
|
|
+ this.topic;
|
|
|
+ /** @type {number|undefined} */
|
|
|
+ this.topicTs;
|
|
|
+ /** @type {SlackUser|SlackBot|undefined} */
|
|
|
+ this.topicCreator;
|
|
|
+ /** @type {string|undefined} */
|
|
|
+ this.purpose;
|
|
|
+ /** @type {number|undefined} */
|
|
|
+ this.purposeTs;
|
|
|
+ /** @type {SlackUser|SlackBot|undefined} */
|
|
|
+ this.purposeCreator;
|
|
|
if (chanData["topic"]) {
|
|
|
this.topic = chanData["topic"]["value"];
|
|
|
this.topicCreator = slackData.getMember(chanData["topic"]["creator"]);
|
|
|
@@ -54,20 +83,69 @@ function SlackChan(chanData, slackData) {
|
|
|
|
|
|
/**
|
|
|
* @constructor
|
|
|
+ * @param {SlackData} slack
|
|
|
+ * @param {*} groupData
|
|
|
**/
|
|
|
-function SlackGroup(groupData) {
|
|
|
- // TODO
|
|
|
+function SlackGroup(slack, groupData) {
|
|
|
+ var memberNames = [];
|
|
|
+
|
|
|
+ /** @type {string} */
|
|
|
+ this.id = groupData["id"];
|
|
|
+ /** @type {Object.<string, SlackUser|SlackBot>} */
|
|
|
+ this.members = {};
|
|
|
+ for (var i =0, nbMembers = groupData["members"].length; i < nbMembers; i++) {
|
|
|
+ var member = slack.getMember(groupData["members"][i]);
|
|
|
+ this.members[groupData["members"][i]] = member;
|
|
|
+ member.channels[this.id] = this;
|
|
|
+ memberNames.push(member.name);
|
|
|
+ }
|
|
|
+ /** @type {string} */
|
|
|
+ this.name = memberNames.join(", ");
|
|
|
+ /** @type {number} */
|
|
|
+ this.created = groupData["created"];
|
|
|
+ /** @type {SlackUser|SlackBot} */
|
|
|
+ this.creator = slack.getMember(groupData["creator"]);
|
|
|
+ /** @type {boolean} */
|
|
|
+ this.archived = groupData["is_archived"];
|
|
|
+ /** @type {number} */
|
|
|
+ this.lastRead = groupData["last_read"];
|
|
|
+ /** @type {string|undefined} */
|
|
|
+ this.topic;
|
|
|
+ /** @type {number|undefined} */
|
|
|
+ this.topicTs;
|
|
|
+ /** @type {SlackUser|SlackBot|undefined} */
|
|
|
+ this.topicCreator;
|
|
|
+ /** @type {string|undefined} */
|
|
|
+ this.purpose;
|
|
|
+ /** @type {number|undefined} */
|
|
|
+ this.purposeTs;
|
|
|
+ /** @type {SlackUser|SlackBot|undefined} */
|
|
|
+ this.purposeCreator;
|
|
|
+ if (groupData["topic"]) {
|
|
|
+ this.topic = groupData["topic"]["value"];
|
|
|
+ this.topicCreator = slack.getMember(groupData["topic"]["creator"]);
|
|
|
+ this.topicTs = groupData["topic"]["last_set"];
|
|
|
+ }
|
|
|
+ if (groupData["purpose"]) {
|
|
|
+ this.purpose = groupData["purpose"]["value"];
|
|
|
+ this.purposeCreator = slack.getMember(groupData["purpose"]["creator"]);
|
|
|
+ this.purposeTs = groupData["purpose"]["last_set"];
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @constructor
|
|
|
- * @param {SlackUser} user
|
|
|
+ * @param {SlackUser|SlackBot} user
|
|
|
* @param {*} imsData
|
|
|
**/
|
|
|
function SlackIms(user, imsData) {
|
|
|
+ /** @type {string} */
|
|
|
this.id = imsData["id"];
|
|
|
+ /** @type {number} */
|
|
|
this.created = imsData["created"];
|
|
|
+ /** @type {SlackUser|SlackBot} */
|
|
|
this.user = user;
|
|
|
+ /** @type {number} */
|
|
|
this.lastRead = imsData["last_read"];
|
|
|
}
|
|
|
|
|
|
@@ -75,12 +153,19 @@ function SlackIms(user, imsData) {
|
|
|
* @constructor
|
|
|
**/
|
|
|
function SlackUser(userData) {
|
|
|
+ /** @type {string} */
|
|
|
this.id = userData["id"];
|
|
|
+ /** @type {string} */
|
|
|
this.name = userData["name"];
|
|
|
+ /** @type {boolean} */
|
|
|
this.deleted = userData["deleted"];
|
|
|
+ /** @type {string} */
|
|
|
this.status = userData["status"];
|
|
|
+ /** @type {string} */
|
|
|
this.realName = userData["real_name"] || userData["profile"]["real_name"];
|
|
|
+ /** @type {boolean} */
|
|
|
this.presence = userData["presence"] !== 'away';
|
|
|
+ /** @type {Object.<string, string>} */
|
|
|
this.icons = {
|
|
|
image_24: userData["profile"]["image_24"]
|
|
|
,image_32: userData["profile"]["image_32"]
|
|
|
@@ -89,10 +174,15 @@ function SlackUser(userData) {
|
|
|
,image_192: userData["profile"]["image_192"]
|
|
|
,image_512: userData["profile"]["image_512"]
|
|
|
};
|
|
|
+ /** @type {string} */
|
|
|
this.email = userData["profile"]["email"];
|
|
|
+ /** @type {string} */
|
|
|
this.firstName = userData["profile"]["first_name"];
|
|
|
+ /** @type {string} */
|
|
|
this.lastName = userData["profile"]["last_name"];
|
|
|
+ /** @type {!Object.<string, SlackChan|SlackGroup>} */
|
|
|
this.channels = {};
|
|
|
+ /** @type {SlackIms} */
|
|
|
this.ims = null;
|
|
|
}
|
|
|
|
|
|
@@ -100,16 +190,24 @@ function SlackUser(userData) {
|
|
|
* @constructor
|
|
|
**/
|
|
|
function SlackBot(botData) {
|
|
|
+ /** @type {string} */
|
|
|
this.id = botData["id"];
|
|
|
+ /** @type {boolean} */
|
|
|
this.deleted = botData["deleted"];
|
|
|
+ /** @type {string} */
|
|
|
this.name = botData["name"];
|
|
|
+ /** @type {string} */
|
|
|
this.appId = botData["app_id"];
|
|
|
+ /** @type {Object.<string, string>} */
|
|
|
this.icons = {
|
|
|
image_36: botData["icons"]["image_36"]
|
|
|
,image_48: botData["icons"]["image_48"]
|
|
|
,image_72: botData["icons"]["image_72"]
|
|
|
};
|
|
|
+ /** @type {!Object.<string, SlackGroup|SlackChan>} */
|
|
|
this.channels = {};
|
|
|
+ /** @type {SlackIms|null} */
|
|
|
+ this.ims = null;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -126,15 +224,27 @@ function SlackHistory(target) {
|
|
|
* @constructor
|
|
|
**/
|
|
|
function SlackData(slack) {
|
|
|
+ /** @type {SlackTeam|null} */
|
|
|
this.team = null;
|
|
|
+ /** @type {Object.<string, SlackChan>} */
|
|
|
this.channels = {};
|
|
|
- this.groups = [];
|
|
|
+ /** @type {Object.<string, SlackGroup>} */
|
|
|
+ this.groups = {};
|
|
|
+ /** @type {Object.<string, SlackIms>} */
|
|
|
this.ims = {};
|
|
|
+ /** @type {Object.<string, SlackUser>} */
|
|
|
this.users = {};
|
|
|
+ /** @type {SlackUser|SlackBot} */
|
|
|
this.self = null;
|
|
|
+ /** @type {Object.<string, SlackBot>} */
|
|
|
this.bots = {};
|
|
|
// channel/ims id -> array of events
|
|
|
this.history = {};
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Node serv handler
|
|
|
+ * @type {*}
|
|
|
+ **/
|
|
|
this.slack = slack;
|
|
|
|
|
|
/** @type {number} */
|
|
|
@@ -184,7 +294,7 @@ SlackChan.prototype.toStatic = function() {
|
|
|
,"last_read": this.lastRead
|
|
|
};
|
|
|
if (this.isMember) {
|
|
|
- res["members"] = Object.keys(this.members);
|
|
|
+ res["members"] = this.members ? Object.keys(this.members) : [];
|
|
|
res["topic"] = {
|
|
|
"value": this.topic
|
|
|
,"creator": this.topicCreator ? this.topicCreator.id : null
|
|
|
@@ -209,7 +319,6 @@ SlackUser.prototype.toStatic = function() {
|
|
|
,"deleted": this.deleted
|
|
|
,"status": this.status
|
|
|
,"real_name": this.realName
|
|
|
- ,"presence": this.presence ? "present" : "away"
|
|
|
,"profile": {
|
|
|
"email": this.email
|
|
|
,"first_name": this.firstName
|
|
|
@@ -225,6 +334,35 @@ SlackUser.prototype.toStatic = function() {
|
|
|
};
|
|
|
};
|
|
|
|
|
|
+SlackGroup.prototype.toStatic = function() {
|
|
|
+ var res = {
|
|
|
+ "id": this.id
|
|
|
+ ,"members": []
|
|
|
+ ,"created": this.created
|
|
|
+ ,"creator": this.creator.id
|
|
|
+ ,"is_archived": this.archived
|
|
|
+ ,"last_read": this.lastRead
|
|
|
+ };
|
|
|
+ for (var mId in this.members) {
|
|
|
+ res["members"].push(mId);
|
|
|
+ }
|
|
|
+ if (this.topic) {
|
|
|
+ res["topic"] = {
|
|
|
+ "value": this.topic
|
|
|
+ ,"creator": this.topicCreator.id
|
|
|
+ ,"last_set": this.topicTs
|
|
|
+ };
|
|
|
+ }
|
|
|
+ if (this.purpose) {
|
|
|
+ res["purpose"] = {
|
|
|
+ "value": this.purpose
|
|
|
+ ,"creator": this.purposeCreator.id
|
|
|
+ ,"last_set": this.purposeTs
|
|
|
+ };
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+};
|
|
|
+
|
|
|
SlackIms.prototype.toStatic = function() {
|
|
|
return {
|
|
|
"id": this.id
|
|
|
@@ -258,12 +396,15 @@ SlackData.prototype.updateStatic = function(data) {
|
|
|
this.users[data["users"][i].id] = new SlackUser(data["users"][i]);
|
|
|
for (var i =0, nbIms = data["ims"].length; i < nbIms; i++) {
|
|
|
var user = this.getMember(data["ims"][i]["user"]);
|
|
|
- user.ims = new SlackIms(user, data["ims"][i]);
|
|
|
- this.ims[user.ims.id] = user.ims;
|
|
|
+ if (user) {
|
|
|
+ user.ims = new SlackIms(user, data["ims"][i]);
|
|
|
+ this.ims[user.ims.id] = user.ims;
|
|
|
+ }
|
|
|
}
|
|
|
for (var i =0, nbChan = data["channels"].length; i < nbChan; i++)
|
|
|
this.channels[data["channels"][i].id] = new SlackChan(data["channels"][i], this);
|
|
|
- //this.groups.push(new SlackGroup(data.groups)); TODO
|
|
|
+ for (var i =0, nbGroups = data["groups"].length; i < nbGroups; i++)
|
|
|
+ this.groups[data["groups"][i]["id"]] = new SlackGroup(this, data["groups"][i]);
|
|
|
this.team = new SlackTeam(data["team"]);
|
|
|
this.staticV = parseFloat(data["latest_event_ts"]);
|
|
|
this.self = this.getMember(data["self"]["id"]);
|
|
|
@@ -326,7 +467,7 @@ SlackData.prototype.getBotsByAppId = function(appId) {
|
|
|
|
|
|
/**
|
|
|
* @param {string} mId
|
|
|
- * @return {SlackUser|null}
|
|
|
+ * @return {SlackUser|SlackBot|null}
|
|
|
**/
|
|
|
SlackData.prototype.getMember = function(mId) {
|
|
|
return this.users[mId] || this.bots[mId] || null;
|
|
|
@@ -338,6 +479,7 @@ SlackData.prototype.getMember = function(mId) {
|
|
|
**/
|
|
|
SlackData.prototype.buildLive = function(knownVersion) {
|
|
|
var res = {};
|
|
|
+ //TODO include presence/typing stream
|
|
|
for (var i in this.history)
|
|
|
if (this.history[i].v > knownVersion)
|
|
|
res[i] = this.history[i].getUpdates(knownVersion);
|
|
|
@@ -349,7 +491,7 @@ SlackData.prototype.buildStatic = function() {
|
|
|
var res = {
|
|
|
"team": this.team.toStatic()
|
|
|
,"channels": []
|
|
|
- ,"groups": [] //TODO
|
|
|
+ ,"groups": []
|
|
|
,"ims": []
|
|
|
,"users": []
|
|
|
,"bots": []
|
|
|
@@ -367,6 +509,9 @@ SlackData.prototype.buildStatic = function() {
|
|
|
for (var botId in this.bots) {
|
|
|
res["bots"].push(this.bots[botId].toStatic());
|
|
|
}
|
|
|
+ for (var groupId in this.groups) {
|
|
|
+ res["groups"].push(this.groups[groupId].toStatic());
|
|
|
+ }
|
|
|
return res;
|
|
|
};
|
|
|
|