Source: models/rooms/matrix.js

  1. "use strict";
  2. /**
  3. * Create a matrix room.
  4. * @constructor
  5. * @param {string} roomId The room ID
  6. */
  7. function MatrixRoom(roomId, data) {
  8. this.roomId = roomId;
  9. this._extras = {};
  10. if (data) {
  11. this.deserialize(data);
  12. }
  13. }
  14. /**
  15. * Get the room ID.
  16. * @return {string} The room ID
  17. */
  18. MatrixRoom.prototype.getId = function() {
  19. return this.roomId;
  20. };
  21. /**
  22. * Get the data value for the given key.
  23. * @param {string} key An arbitrary bridge-specific key.
  24. * @return {*} Stored data for this key. May be undefined.
  25. */
  26. MatrixRoom.prototype.get = function(key) {
  27. return this._extras[key];
  28. };
  29. /**
  30. * Set an arbitrary bridge-specific data value for this room. This will be serailized
  31. * under an 'extras' key.
  32. * @param {string} key The key to store the data value under.
  33. * @param {*} val The data value. This value should be serializable via
  34. * <code>JSON.stringify(data)</code>.
  35. */
  36. MatrixRoom.prototype.set = function(key, val) {
  37. this._extras[key] = val;
  38. };
  39. /**
  40. * Serialize data about this room into a JSON object.
  41. * @return {Object} The serialised data
  42. */
  43. MatrixRoom.prototype.serialize = function() {
  44. return {
  45. name: this.name,
  46. topic: this.topic,
  47. extras: this._extras
  48. };
  49. };
  50. /**
  51. * Set data about this room from a serialized data object.
  52. * @param {Object} data The serialized data
  53. */
  54. MatrixRoom.prototype.deserialize = function(data) {
  55. this.name = data.name;
  56. this.topic = data.topic;
  57. this._extras = data.extras;
  58. };
  59. /** The MatrixRoom class. */
  60. module.exports = MatrixRoom;