class Role { constructor(json) { this.json = json; if (json.tag == 'payload-reference') { this.name = json['payload-label']; } else if (json.authorized) { this.name = json.authorized['dnf-terms'][0][0].var + ' (auth)'; } else if (json.user) { this.name = json.user; } else if (json.tag) { this.name = json.tag + ' (tag)'; } else { this.name = JSON.stringify(json); } } format() { return [document.createTextNode(this.name)]; } } class Message { constructor(json) { var content = json.content; this.fallback = content.fallback; this.fallbackLang = content['fallback-lang']; this.translations = content.translations; this.status = json.status; this.viewers = []; json.viewers.viewers.forEach(v => this.viewers.push(new Role(v))); } format() { var v = document.createElement('h3'); var viewers = document.createTextNode('Viewers'); v.appendChild(viewers); var viewerList = document.createElement('ul'); this.viewers.forEach(v => { var viewer = document.createElement('li'); viewer.appendChild(document.createTextNode(v.name)); viewerList.appendChild(viewer); }); var h = document.createElement('h3'); var heading = document.createTextNode('Status'); h.appendChild(heading); var p = document.createElement('p'); var text = document.createTextNode(this.status); p.appendChild(text); var result = [v, viewerList, h, p]; h = document.createElement('h3'); heading = document.createTextNode(this.fallbackLang); h.appendChild(heading); p = document.createElement('html'); p.setAttribute('lang', this.fallbackLang); p.innerHTML = this.fallback; result.push(h, p); for (var t in this.translations) { h = document.createElement('h3'); heading = document.createTextNode(t); h.appendChild(heading); p = document.createElement('html'); p.setAttribute('lang', this.translations[t]); p.innerHTML = this.translations[t]; result.push(h, p); } return result; } } class Payload { constructor(json) { this.fields = []; if (json === null) return; for (var f in json) { this.fields.push(f); } } format() { var fieldList = document.createElement('ul'); this.fields.forEach(f => { var field = document.createElement('li'); field.appendChild(document.createTextNode(f)); fieldList.appendChild(field); }); return [fieldList]; } }