chatter.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /**
  2. * @constructor
  3. **/
  4. function Chatter(id) {
  5. /** @const @type {string} */
  6. this.id = id;
  7. /** @type {string} */
  8. this.name;
  9. /** @type {boolean} */
  10. this.deleted;
  11. /** @type {string} */
  12. this.status;
  13. /** @type {string} */
  14. this.realName;
  15. /** @type {string} */
  16. this.goal;
  17. /** @type {string} */
  18. this.phone;
  19. /** @type {boolean} */
  20. this.presence;
  21. /** @type {string} */
  22. this.email;
  23. /** @type {string} */
  24. this.firstName;
  25. /** @type {string} */
  26. this.lastName;
  27. /** @type {!Object.<string, Room>} */
  28. this.channels = {};
  29. /** @type {SelfPreferences|null} */
  30. this.prefs = null;
  31. /** @type {boolean} */
  32. this.isBot;
  33. /** @type {PrivateMessageRoom|null} */
  34. this.privateRoom = null;
  35. /** @type {number} */
  36. this.version = 0;
  37. };
  38. Chatter.prototype.toStatic = function(t) {
  39. return t >= this.version ? null : {
  40. "id": this.id
  41. ,"name": this.name
  42. ,"deleted": this.deleted
  43. ,"status": this.status
  44. ,"real_name": this.realName
  45. ,"isPresent": this.presence
  46. ,"isBot": this.isBot
  47. ,"email": this.email
  48. ,"phone": this.phone
  49. ,"goal": this.goal
  50. ,"first_name": this.firstName
  51. ,"last_name": this.lastName
  52. };
  53. };
  54. /**
  55. * @param {*} userData
  56. * @param {number} t
  57. **/
  58. Chatter.prototype.update = function(userData, t) {
  59. if (userData["name"] !== undefined) this.name = userData["name"];
  60. if (userData["deleted"] !== undefined) this.deleted = userData["deleted"];
  61. if (userData["status"] !== undefined) this.status = userData["status"];
  62. if (userData["goal"] !== undefined) this.goal = userData["goal"];
  63. if (userData["phone"] !== undefined) this.phone = userData["phone"];
  64. if (userData["email"] !== undefined) this.email = userData["email"];
  65. if (userData["first_name"] !== undefined) this.firstName = userData["first_name"];
  66. if (userData["last_name"] !== undefined) this.lastName = userData["last_name"];
  67. if (userData["real_name"] !== undefined) this.realName = userData["real_name"];
  68. if (userData["isPresent"] !== undefined) this.presence = userData["isPresent"];
  69. if (userData["isBot"]) this.isBot = userData["isBot"];
  70. this.version = Math.max(this.version, t);
  71. };
  72. Chatter.prototype.getSmallIcon = function() {
  73. return "api/avatar?user=" +this.id;
  74. };
  75. Chatter.prototype.getLargeIcon = function() {
  76. return "api/avatar?size=l&user=" +this.id;
  77. };
  78. Chatter.prototype.getName = function() {
  79. return this.name || this.realName || this.firstName || this.lastName;
  80. };
  81. /** @suppress {undefinedVars,checkTypes} */
  82. (function() {
  83. if (typeof module !== "undefined") {
  84. module.exports.Chatter = Chatter;
  85. }
  86. })();