data.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. var
  2. /**
  3. * @type SlackWrapper
  4. **/
  5. SLACK
  6. ;
  7. /**
  8. * @constructor
  9. **/
  10. function SlackWrapper() {
  11. /** @type {number} */
  12. this.lastServerVersion = 0;
  13. /** @type {SlackData} */
  14. this.context = new SlackData(null);
  15. /** @type {!Object.<string, SlackHistory>} **/
  16. this.history = {};
  17. }
  18. SlackWrapper.prototype.update = function(data) {
  19. if (data["v"])
  20. this.lastServerVersion = data["v"];
  21. if (data["static"]) {
  22. this.context.updateStatic(data["static"]);
  23. onContextUpdated();
  24. }
  25. if (data["live"]) {
  26. for (var i in data["live"]) {
  27. var history = this.history[i];
  28. if (!history)
  29. this.history[i] = new SlackHistory(i, 500, data["live"][i]);
  30. else
  31. history.pushAll(data["live"][i]);
  32. }
  33. for (var roomId in data["live"]) {
  34. if (SELECTED_ROOM && data["live"][SELECTED_ROOM.id])
  35. onRoomUpdated();
  36. else
  37. onMsgReceived(this.context.getChannel(roomId), data["live"][roomId]);
  38. }
  39. }
  40. };
  41. SLACK = new SlackWrapper();