|
|
@@ -6,6 +6,7 @@ const Message = require('./message.js').Message
|
|
|
/**
|
|
|
* @constructor
|
|
|
* @extends {RoomHistory}
|
|
|
+ * @param {Slack} ctx
|
|
|
* @param {string} serviceId
|
|
|
* @param {Room|string} room or roomId
|
|
|
* @param {string} idPrefix
|
|
|
@@ -14,7 +15,7 @@ const Message = require('./message.js').Message
|
|
|
* @param {Array=} evts
|
|
|
* @param {number=} now
|
|
|
**/
|
|
|
-function SlackHistory(remoteId, room, idPrefix, keepMessages, maxAge, evts, now) {
|
|
|
+function SlackHistory(ctx, remoteId, room, idPrefix, keepMessages, maxAge, evts, now) {
|
|
|
RoomHistory.call(this, room, keepMessages, maxAge, evts, now);
|
|
|
|
|
|
/** @const @type {string} */
|
|
|
@@ -22,6 +23,9 @@ function SlackHistory(remoteId, room, idPrefix, keepMessages, maxAge, evts, now)
|
|
|
|
|
|
/** @const @type {string} */
|
|
|
this.idPrefix = idPrefix;
|
|
|
+
|
|
|
+ /** @const @type {Slack} */
|
|
|
+ this.ctx = ctx;
|
|
|
}
|
|
|
SlackHistory.prototype = Object.create(RoomHistory.prototype);
|
|
|
SlackHistory.prototype.constructor = SlackHistory;
|
|
|
@@ -103,12 +107,30 @@ SlackHistory.prototype.push = function(ev, t) {
|
|
|
} else if (ev["type"] === "reaction_added") {
|
|
|
msg = this.addReaction(ev["reaction"], this.idPrefix +ev["user"], ev["item"]["ts"], t);
|
|
|
if (!msg) {
|
|
|
- //FIXME fetch ev.item.channel / ev.item.ts
|
|
|
+ let self = this;
|
|
|
+ this.ctx.fetchHistory(this.ctx.getChatContext().channels[this.id], (msg) => {
|
|
|
+ if (msg && msg.length) {
|
|
|
+ msg[0].version = t;
|
|
|
+ self.messages.push(msg[0]);
|
|
|
+ self.resort();
|
|
|
+ self.v = Math.max(self.v, t);
|
|
|
+ self.ctx.getChatContext().liveV = Math.max(self.ctx.getChatContext().liveV, t);
|
|
|
+ }
|
|
|
+ }, 1, ev["item"]["ts"]);
|
|
|
}
|
|
|
} else if (ev["type"] === "reaction_removed") {
|
|
|
+ let self = this;
|
|
|
msg = this.removeReaction(ev["reaction"], this.idPrefix +ev["user"], ev["item"]["ts"], t);
|
|
|
if (!msg) {
|
|
|
- //FIXME fetch ev.item.channel / ev.item.ts
|
|
|
+ this.ctx.fetchHistory(this.ctx.getChatContext().channels[this.id], (msg) => {
|
|
|
+ if (msg && msg.length) {
|
|
|
+ msg[0].version = t;
|
|
|
+ self.messages.push(msg[0]);
|
|
|
+ self.resort();
|
|
|
+ self.v = Math.max(self.v, t);
|
|
|
+ self.ctx.getChatContext().liveV = Math.max(self.ctx.getChatContext().liveV, t);
|
|
|
+ }
|
|
|
+ }, 1, ev["item"]["ts"]);
|
|
|
}
|
|
|
} else {
|
|
|
return 0;
|