1
0

config.js 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /** @type Config */
  2. var CONFIG;
  3. /** @constructor */
  4. function Config(configData) {
  5. this.deviceId = null;
  6. /** @type {Object.<string, Object<string, string>>} serviceType => { serviceId => serviceName } */
  7. this.services = {};
  8. /** @type {string|undefined} */
  9. this.emojiProvider;
  10. /** @type{boolean|undefined} */
  11. this.displayAvatar;
  12. /** @type{boolean|undefined} */
  13. this.colorfulNames;
  14. /** @type{boolean|undefined} */
  15. this.scrollAvatars;
  16. // Load global configurations
  17. for (var i =0, nbConfig = configData.length; i < nbConfig; i++)
  18. if (configData[i]["service"] === null && configData[i]["device"] === null)
  19. this.mergeConfig(JSON.parse(configData[i]["config"]));
  20. }
  21. Config.prototype.mergeConfig = function(configData) {
  22. if (configData["services"])
  23. for (var i in configData["services"]) {
  24. this.services[i] = configData["services"][i];
  25. }
  26. if (configData["emojiProvider"] !== undefined)
  27. this.emojiProvider = configData["emojiProvider"];
  28. if (configData["displayAvatar"] !== undefined)
  29. this.displayAvatar = configData["displayAvatar"];
  30. if (configData["colorfulNames"] !== undefined)
  31. this.colorfulNames = configData["colorfulNames"];
  32. if (configData["scrollAvatars"] !== undefined)
  33. this.scrollAvatars = configData["scrollAvatars"];
  34. };
  35. /** @return {string|undefined} */
  36. Config.prototype.getEmojiProvider = function() {
  37. return this.emojiProvider;
  38. };
  39. Config.prototype.isDisplayAvatars = function() {
  40. return this.displayAvatar !== false;
  41. };
  42. Config.prototype.isScrollAvatars = function() {
  43. return this.scrollAvatars !== false;
  44. };
  45. Config.prototype.isColorfulNames = function() {
  46. return this.colorfulNames === true;
  47. };
  48. Config.prototype.commitNewSettings = function(newSettings) {
  49. for (var i in newSettings) {
  50. // Just to check not empty object
  51. // TODO only global config atm
  52. this.mergeConfig(newSettings);
  53. onConfigUpdated();
  54. HttpRequestWrapper(HttpRequestMethod.POST, "api/settings?service=null&device=null").send(JSON.stringify(newSettings));
  55. return;
  56. }
  57. };
  58. Config.prototype.compileCSS = function() {
  59. var rules = {},
  60. css = '';
  61. if (!this.isDisplayAvatars()) {
  62. rules[".chatsystem-content .chatmsg-authorGroup .chatmsg-author-img-wrapper"] = ["display: none"];
  63. rules[".chatsystem-content .chatmsg-authorGroup"] = ["display: flex"];
  64. rules[".chatsystem-content .chatmsg-authorGroup .chatmsg-author"] = ["position:initial", "vertical-align:top", "min-width:75px"];
  65. rules[".chatsystem-content .chatmsg-authorGroup .chatmsg-author-messages"] = ["padding-top:0", "padding-left:0", "display:inline-block", "margin-top:-4px", "flex:1"];
  66. rules[".chatmsg-author-name::before"] = [ "content:'<'" ];
  67. rules[".chatmsg-author-name::after"] = [ "content:'>'" ];
  68. }
  69. if (!this.isColorfulNames()) {
  70. rules[".chatmsg-authorGroup .chatmsg-item .chatmsg-link-user, .chatsystem-content a.chatmsg-author-name, .chatmsg-author-name"] = ["background-color: transparent !important;"];
  71. }
  72. for (var i in rules) {
  73. css += i +'{';
  74. rules[i].forEach(function(rule) {
  75. css += rule +';';
  76. });
  77. css += '}';
  78. }
  79. return css;
  80. };
  81. CONFIG = new Config([]);