data.js 1.2 KB

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