|
|
@@ -33,6 +33,8 @@ const SLACK_ENDPOINT = "https://slack.com/api/"
|
|
|
,setPresence: "users.setPresence"
|
|
|
,emojiList: "emoji.list"
|
|
|
,slashList: "commands.list"
|
|
|
+ ,pinMsg: "pins.add"
|
|
|
+ ,unpinMsg: "pins.remove"
|
|
|
,listPinned: "pins.list"
|
|
|
,listMpims: "mpim.list"
|
|
|
,slashExec: "chat.command"
|
|
|
@@ -237,12 +239,8 @@ Slack.prototype.onMessage = function(msg, t) {
|
|
|
if ((msg["channel"] || msg["channel_id"] || (msg["item"] && msg["item"]["channel"])) && msg["type"] && UPDATE_LIVE.indexOf(msg["type"]) !== -1) {
|
|
|
var channelId = this.data.team.id +'|' +(msg["channel"] || msg["channel_id"] || msg["item"]["channel"])
|
|
|
,channel = this.data.channels[channelId]
|
|
|
- ,histo = this.history[channelId];
|
|
|
+ ,histo = this.lazyHistory(channel);
|
|
|
// FIXME remove typing for user
|
|
|
- if (!histo) {
|
|
|
- histo = this.history[channelId] = new SlackHistory(this, channel.remoteId, channelId, this.data.team.id +'|', HISTORY_LENGTH);
|
|
|
- histo.isNew = true;
|
|
|
- }
|
|
|
var lastMsg = histo.push(msg, t);
|
|
|
if (lastMsg)
|
|
|
this.data.liveV = t;
|
|
|
@@ -604,6 +602,28 @@ Slack.prototype.unstarMsg = function(channel, msgId) {
|
|
|
+"×tamp=" +msgId);
|
|
|
};
|
|
|
|
|
|
+/**
|
|
|
+ * @param {SlackChan|SlackGroup|SlackIms} channel
|
|
|
+ * @param {string} msgId
|
|
|
+**/
|
|
|
+Slack.prototype.pinMsg = function(channel, msgId) {
|
|
|
+ httpsRequest(SLACK_ENDPOINT +GETAPI.pinMsg
|
|
|
+ +"?token=" +this.token
|
|
|
+ +"&channel=" +channel.remoteId
|
|
|
+ +"×tamp=" +msgId);
|
|
|
+};
|
|
|
+
|
|
|
+/**
|
|
|
+ * @param {SlackChan|SlackGroup|SlackIms} channel
|
|
|
+ * @param {string} msgId
|
|
|
+**/
|
|
|
+Slack.prototype.unpinMsg = function(channel, msgId) {
|
|
|
+ httpsRequest(SLACK_ENDPOINT +GETAPI.unpinMsg
|
|
|
+ +"?token=" +this.token
|
|
|
+ +"&channel=" +channel.remoteId
|
|
|
+ +"×tamp=" +msgId);
|
|
|
+};
|
|
|
+
|
|
|
/**
|
|
|
* @param {SlackChan|SlackGroup|SlackIms} channel
|
|
|
* @param {Array.<string>} text
|
|
|
@@ -663,6 +683,18 @@ Slack.prototype.editMsg = function(channel, msgId, text) {
|
|
|
+"&as_user=true");
|
|
|
};
|
|
|
|
|
|
+/**
|
|
|
+ * @param {SlackChan|SlackGroup|SlackIms} target
|
|
|
+**/
|
|
|
+Slack.prototype.lazyHistory = function(target) {
|
|
|
+ var histo = this.history[target.id];
|
|
|
+ if (!histo) {
|
|
|
+ histo = this.history[target.id] = new SlackHistory(this, target.remoteId, target.id, this.data.team.id +'|', HISTORY_LENGTH, HISTORY_MAX_AGE);
|
|
|
+ histo.isNew = true;
|
|
|
+ }
|
|
|
+ return histo;
|
|
|
+};
|
|
|
+
|
|
|
/**
|
|
|
* @param {SlackChan|SlackGroup|SlackIms} target
|
|
|
**/
|
|
|
@@ -675,11 +707,9 @@ Slack.prototype.fetchPinned = function(target) {
|
|
|
(status, resp) => {
|
|
|
if (status === 200 && resp && resp.ok) {
|
|
|
var msgs = [],
|
|
|
- histo = _this.history[target.id],
|
|
|
+ histo = _this.lazyHistory(target);
|
|
|
now = Date.now();
|
|
|
|
|
|
- if (!histo)
|
|
|
- histo = _this.history[target.id] = new SlackHistory(_this, target.remoteId, target.id, this.data.team.id +'|', HISTORY_LENGTH, HISTORY_MAX_AGE);
|
|
|
resp.items.forEach(function(msg) {
|
|
|
msgs.push(histo.messageFactory(msg.message, now));
|
|
|
});
|
|
|
@@ -714,9 +744,8 @@ Slack.prototype.fetchHistory = function(target, cb, count, firstMsgId) {
|
|
|
(status, resp) => {
|
|
|
var history = [];
|
|
|
if (status === 200 && resp && resp.ok) {
|
|
|
- var histo = this.history[target.id];
|
|
|
- if (!histo)
|
|
|
- histo = this.history[target.id] = new SlackHistory(_this, target.remoteId, target.id, this.data.team.id +'|', HISTORY_LENGTH, HISTORY_MAX_AGE);
|
|
|
+ var histo = this.lazyHistory(target);
|
|
|
+
|
|
|
resp.messages.forEach((respMsg) => {
|
|
|
respMsg["id"] = respMsg["ts"];
|
|
|
history.push(histo.messageFactory(histo.prepareMessage(respMsg)));
|