|
|
@@ -1,17 +1,23 @@
|
|
|
-function SlackTeam(a){this.id=a.id;this.name=a.name;this.domain=a.domain;this.callApp=a.prefs.calling_app_id;this.callAppName=a.prefs.calling_app_name;this.fileUploadPermission=a.prefs.disable_file_uploads;this.fileEditPermission=a.prefs.disable_file_editing;this.fileDeletePermission=a.prefs.disable_file_deleting;this.icons={image_34:a.icon.image_34,image_44:a.icon.image_44,image_68:a.icon.image_68,image_88:a.icon.image_88,image_102:a.icon.image_102,image_132:a.icon.image_132,image_230:a.icon.image_230,
|
|
|
-image_default:a.icon.image_default}}
|
|
|
-function SlackChan(a,c){this.id=a.id;this.name=a.name;this.created=a.created;this.creator=c.getMember(a.creator);this.archived=a.is_archived;this.isMember=a.is_member;this.lastRead=a.last_read;this.members={};if(a.members)for(var b=0,d=a.members.length;b<d;b++){var e=c.getMember(a.members[b]);this.members[e.id]=e;e.channels[this.id]=this}a.topic&&(this.topic=a.topic.value,this.topicCreator=c.getMember(a.topic.creator),this.topicTs=a.topic.last_set);a.purpose&&(this.purpose=a.purpose.value,this.purposeCreator=
|
|
|
-c.getMember(a.purpose.creator),this.purposeTs=a.purpose.last_set)}function SlackGroup(a){}function SlackIms(a){}
|
|
|
-function SlackUser(a){this.id=a.id;this.name=a.name;this.deleted=a.deleted;this.status=a.status;this.realName=a.real_name||a.profile.real_name;this.presence="away"!==a.presence;this.icons={image_24:a.profile.image_24,image_32:a.profile.image_32,image_48:a.profile.image_48,image_72:a.profile.image_72,image_192:a.profile.image_192,image_512:a.profile.image_512};this.email=a.profile.email;this.firstName=a.profile.first_name;this.lastName=a.profile.last_name;this.channels={}}
|
|
|
-function SlackBot(a){this.id=a.id;this.deleted=a.deleted;this.name=a.name;this.appId=a.app_id;this.icons={image_36:a.icons.image_36,image_48:a.icons.image_48,image_72:a.icons.image_72};this.channels={}}function SlackHistory(a){this.id=a.id;this.target=a;this.v=0;this.messages=[]}function SlackData(a){this.team=null;this.channels={};this.groups=[];this.ims=[];this.users={};this.self=null;this.bots={};this.history={};this.slack=a;this.liveV=this.staticV=0}
|
|
|
-SlackTeam.prototype.toStatic=function(){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(a){};SlackHistory.prototype.getUpdates=function(a){};
|
|
|
-SlackChan.prototype.toStatic=function(){var a={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};this.isMember&&(a.members=Object.keys(this.members),a.topic={value:this.topic,creator:this.topicCreator?this.topicCreator.id:null,last_set:this.topicTs},a.purpose={value:this.purpose,creator:this.purposeCreator?this.purposeCreator.id:null,last_set:this.purposeTs});return a};
|
|
|
-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}}};
|
|
|
-SlackData.prototype.updateStatic=function(a,c){for(var b=0,d=a.bots.length;b<d;b++)this.bots[a.bots[b].id]=new SlackBot(a.bots[b]);this.team=new SlackTeam(a.team);b=0;for(d=a.users.length;b<d;b++)this.users[a.users[b].id]=new SlackUser(a.users[b]);b=0;for(d=a.channels.length;b<d;b++)this.channels[a.channels[b].id]=new SlackChan(a.channels[b],this);this.staticV=parseFloat(a.latest_event_ts);this.self=this.getMember(a.self.id);if(this.slack){var e={},d=!1;for(b in this.channels)this.history[b]||(d=
|
|
|
-!0,e[b]=this.channels[b]);if(d)for(b in e){var f=this;this.slack.fetchHistory(b,function(a,b){if(null!=b){f.setHistory(e[a],b);e[a]=null;for(var d in e)if(e[d])return}c()})}else c()}};SlackData.prototype.setHistory=function(a,c){this.history[a.id]||(this.history[a.id]=new SlackHistory(a));this.history[a.id].update(c)};SlackData.prototype.getBotsByAppId=function(a){var c=[],b;for(b in this.bots)this.bots[b].appId===a&&c.push(this.bots[b]);return c};
|
|
|
-SlackData.prototype.getMember=function(a){return this.users[a]||this.bots[a]||null};SlackData.prototype.buildLive=function(a){var c={},b;for(b in this.history)this.history[b].v>a&&(c[b]=this.history[b].getUpdates(a));return c};
|
|
|
-SlackData.prototype.buildStatic=function(){var a={team:this.team.toStatic(),channels:[],groups:[],ims:[],users:[],bots:[],self:{id:this.self.id}},c;for(c in this.channels)a.channels.push(this.channels[c].toStatic());for(var b in this.users)a.users.push(this.users[b].toStatic());return a};SlackData.prototype.getUpdates=function(a){var c={};this.liveV>a&&(c.live=this.buildLive(a));this.staticV>a&&(c["static"]=this.buildStatic());return c};
|
|
|
-(function(){"undefined"!==typeof module&&(module.exports.SlackData=SlackData)})();var R={id:{chanList:"chanList",chatList:"chatList",currentRoom:{title:"currentRoomTitle"}},klass:{selected:"selected",noRoomSelected:"no-room-selected",chatList:{entry:"slack-context-room"}}};function createChanListItem(a){var c=document.createElement("li");c.id=a.id;c.className=R.klass.chatList.entry;c.textContent=a.name;return c}function onContextUpdated(){var a=document.createDocumentFragment(),c;for(c in SLACK.context.self.channels){var b=createChanListItem(SLACK.context.channels[c]);b&&a.appendChild(b)}document.getElementById(R.id.chanList).textContent="";document.getElementById(R.id.chanList).appendChild(a)}
|
|
|
-function onRoomSelected(){var a=SELECTED_ROOM.name;if(!a){var a=[],c;for(c in SELECTED_ROOM.members)a.push(SELECTED_ROOM.members[c].name);a=a.join(", ")}document.getElementById(R.id.currentRoom.title).textContent=a}
|
|
|
-function onChanClick(a){for(;a.target!==a.currentTarget&&a.target;){if(a.target.classList.contains(R.klass.chatList.entry)){(a=SLACK.context.channels[a.target.id]||SLACK.context.ims[a.target.id]||SLACK.context.groups[a.target.id])&&a!==SELECTED_ROOM&&selectRoom(a);break}a.target=a.target.parentElement}}document.addEventListener("DOMContentLoaded",function(){document.getElementById(R.id.chatList).addEventListener("click",onChanClick);startPolling()});var SLACK;function SlackWrapper(){this.lastServerVersion=0;this.context=new SlackData(null)}SlackWrapper.prototype.update=function(a){a.v&&(this.lastServerVersion=a.v);a["static"]&&(this.context.updateStatic(a["static"]),onContextUpdated());a.live&&console.log("updated LIVE");console.log(this)};SLACK=new SlackWrapper;var NEXT_RETRY=5,SELECTED_ROOM=null;function poll(a){var c=new XMLHttpRequest;c.timeout=6E4;c.onreadystatechange=function(b){if(4===c.readyState)if(0===c.status)poll(a),NEXT_RETRY=5;else{b=null;var d=2===Math.floor(c.status/100);if(d){NEXT_RETRY=5;b=c.response;try{b=JSON.parse(b)}catch(e){b=null}}else NEXT_RETRY+=Math.floor(NEXT_RETRY/2),NEXT_RETRY=Math.min(60,NEXT_RETRY);a(d,b)}};c.open("GET","api?v="+SLACK.lastServerVersion,!0);c.send(null)}
|
|
|
-function onPollResponse(a,c){a?(c&&SLACK.update(c),startPolling()):setTimeout(startPolling,1E3*NEXT_RETRY)}function startPolling(){poll(onPollResponse)}function selectRoom(a){SELECTED_ROOM&&unselectRoom();document.getElementById(a.id).classList.add(R.klass.selected);document.body.classList.remove(R.klass.noRoomSelected);SELECTED_ROOM=a;onRoomSelected()}function unselectRoom(){document.getElementById(SELECTED_ROOM.id).classList.remove(R.klass.selected)};
|
|
|
+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={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"]}}
|
|
|
+function SlackChan(chanData,slackData){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={};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"]}}function SlackGroup(groupData){}
|
|
|
+function SlackIms(user,imsData){this.id=imsData["id"];this.created=imsData["created"];this.user=user;this.lastRead=imsData["last_read"]}
|
|
|
+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.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"]};
|
|
|
+this.email=userData["profile"]["email"];this.firstName=userData["profile"]["first_name"];this.lastName=userData["profile"]["last_name"];this.channels={};this.ims=null}function SlackBot(botData){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={}}
|
|
|
+function SlackHistory(target){this.id=target.id;this.target=target;this.v=0;this.messages=[]}function SlackData(slack){this.team=null;this.channels={};this.groups=[];this.ims={};this.users={};this.self=null;this.bots={};this.history={};this.slack=slack;this.staticV=0;this.liveV=0}
|
|
|
+SlackTeam.prototype.toStatic=function(){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){};SlackHistory.prototype.getUpdates=function(knownVersion){};
|
|
|
+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};
|
|
|
+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}}};
|
|
|
+SlackIms.prototype.toStatic=function(){return{"id":this.id,"created":this.created,"user":this.user.id,"last_read":this.lastRead}};SlackBot.prototype.toStatic=function(){return{"id":this.id,"deleted":this.deleted,"name":this.name,"app_id":this.appId,"icons":{"image_36":this.icons.image_36,"image_48":this.icons.image_48,"image_72":this.icons.image_72}}};
|
|
|
+SlackData.prototype.updateStatic=function(data){for(var i=0,nbBots=data["bots"].length;i<nbBots;i++)this.bots[data.bots[i].id]=new SlackBot(data["bots"][i]);for(var i=0,nbUsers=data["users"].length;i<nbUsers;i++)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}for(var i=0,nbChan=data["channels"].length;i<nbChan;i++)this.channels[data["channels"][i].id]=
|
|
|
+new SlackChan(data["channels"][i],this);this.team=new SlackTeam(data["team"]);this.staticV=parseFloat(data["latest_event_ts"]);this.self=this.getMember(data["self"]["id"]);if(!this.slack)return};SlackData.prototype.setHistory=function(target,data){if(!this.history[target.id])this.history[target.id]=new SlackHistory(target);this.history[target.id].update(data)};
|
|
|
+SlackData.prototype.getBotsByAppId=function(appId){var bots=[];for(var botId in this.bots)if(this.bots[botId].appId===appId)bots.push(this.bots[botId]);return bots};SlackData.prototype.getMember=function(mId){return this.users[mId]||this.bots[mId]||null};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};
|
|
|
+SlackData.prototype.buildStatic=function(){var res={"team":this.team.toStatic(),"channels":[],"groups":[],"ims":[],"users":[],"bots":[],"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());res["ims"].push(this.users[userId].ims.toStatic())}for(var botId in this.bots)res["bots"].push(this.bots[botId].toStatic());return res};
|
|
|
+SlackData.prototype.getUpdates=function(knownVersion){var res={};if(this.liveV>knownVersion)res["live"]=this.buildLive(knownVersion);if(this.staticV>knownVersion)res["static"]=this.buildStatic();return res};(function(){if(typeof module!=="undefined")module.exports.SlackData=SlackData})();var R={id:{chanList:"chanList",chatList:"chatList",currentRoom:{title:"currentRoomTitle"}},klass:{selected:"selected",noRoomSelected:"no-room-selected",chatList:{entry:"slack-context-room"}}};function createChanListItem(chan){var dom=document.createElement("li");dom.id=chan.id;dom.className=R.klass.chatList.entry;dom.textContent=chan.name;return dom}function createImsListItem(ims){var dom=document.createElement("li");dom.id=ims.id;dom.className=R.klass.chatList.entry;dom.textContent=ims.user.name;return dom}
|
|
|
+function onContextUpdated(){var chanListFram=document.createDocumentFragment();for(var chanId in SLACK.context.self.channels){var chan=SLACK.context.channels[chanId],chanListItem=createChanListItem(chan);if(chanListItem)chanListFram.appendChild(chanListItem)}for(var userId in SLACK.context.users){var ims=SLACK.context.users[userId].ims,imsListItem=createImsListItem(ims);if(imsListItem)chanListFram.appendChild(imsListItem)}document.getElementById(R.id.chanList).textContent="";document.getElementById(R.id.chanList).appendChild(chanListFram)}
|
|
|
+function onRoomSelected(){var name=SELECTED_ROOM.name||(SELECTED_ROOM.user?SELECTED_ROOM.user.name:undefined);if(!name){var members=[];for(var i in SELECTED_ROOM.members)members.push(SELECTED_ROOM.members[i].name);name=members.join(", ")}document.getElementById(R.id.currentRoom.title).textContent=name}
|
|
|
+function onChanClick(e){while(e.target!==e.currentTarget&&e.target){if(e.target.classList.contains(R.klass.chatList.entry)){var room=SLACK.context.channels[e.target.id]||SLACK.context.ims[e.target.id]||SLACK.context.groups[e.target.id];if(room&&room!==SELECTED_ROOM)selectRoom(room);return}e.target=e.target.parentElement}}document.addEventListener("DOMContentLoaded",function(){document.getElementById(R.id.chatList).addEventListener("click",onChanClick);startPolling()});var SLACK;function SlackWrapper(){this.lastServerVersion=0;this.context=new SlackData(null)}SlackWrapper.prototype.update=function(data){if(data.v)this.lastServerVersion=data.v;if(data["static"]){this.context.updateStatic(data["static"]);onContextUpdated()}if(data.live)console.log("updated LIVE");console.log(this)};SLACK=new SlackWrapper;var NEXT_RETRY=5,SELECTED_ROOM=null;
|
|
|
+function poll(callback){var xhr=new XMLHttpRequest;xhr.timeout=1E3*60*1;xhr.onreadystatechange=function(e){if(xhr.readyState===4){if(xhr.status===0){poll(callback);NEXT_RETRY=5;return}var resp=null,success=Math.floor(xhr.status/100)===2;if(success){NEXT_RETRY=5;resp=xhr.response;try{resp=JSON.parse((resp))}catch(e){resp=null}}else{NEXT_RETRY+=Math.floor(NEXT_RETRY/2);NEXT_RETRY=Math.min(60,NEXT_RETRY)}callback(success,resp)}};xhr.open("GET","api?v="+SLACK.lastServerVersion,true);xhr.send(null)}
|
|
|
+function onPollResponse(success,response){if(success){if(response)SLACK.update(response);startPolling()}else setTimeout(startPolling,NEXT_RETRY*1E3)}function startPolling(){poll(onPollResponse)}function selectRoom(room){if(SELECTED_ROOM)unselectRoom();document.getElementById(room.id).classList.add(R.klass.selected);document.body.classList.remove(R.klass.noRoomSelected);SELECTED_ROOM=room;onRoomSelected()}
|
|
|
+function unselectRoom(){document.getElementById(SELECTED_ROOM.id).classList.remove(R.klass.selected)};
|