diff --git a/apps/ssb/tf-message.js b/apps/ssb/tf-message.js index 135e5875..d829fec7 100644 --- a/apps/ssb/tf-message.js +++ b/apps/ssb/tf-message.js @@ -11,7 +11,7 @@ class TfMessageElement extends LitElement { message: {type: Object}, users: {type: Object}, drafts: {type: Object}, - raw: {type: Boolean}, + format: {type: String}, blog_data: {type: String}, expanded: {type: Object}, decrypted: {type: Object}, @@ -27,7 +27,7 @@ class TfMessageElement extends LitElement { this.message = {}; this.users = {}; this.drafts = {}; - this.raw = false; + this.format = 'message'; this.expanded = {}; this.decrypted = undefined; } @@ -255,16 +255,30 @@ class TfMessageElement extends LitElement { content = this.decrypted; } let self = this; - let raw_button = this.raw ? - html` self.raw = false}>` : - html` self.raw = true}>`; + let raw_button; + switch (this.format) { + case 'raw': + if (content?.type == 'post' || content?.type == 'blog') { + raw_button = html` self.format = 'md'}>`; + } else { + raw_button = html` self.format = 'message'}>`; + } + break; + case 'md': + raw_button = html` self.format = 'message'}>`; + break; + default: + raw_button = html` self.format = 'raw'}>`; + break; + } function small_frame(inner) { + let body; return html`
% ${new Date(self.message.timestamp).toLocaleString()} ${raw_button} - ${self.raw ? self.render_raw() : inner} + ${self.format == 'raw' ? self.render_raw() : inner} ${self.render_votes()}
`; @@ -342,9 +356,18 @@ class TfMessageElement extends LitElement { `; let self = this; - let body = this.raw ? - this.render_raw() : - unsafeHTML(tfutils.markdown(content.text)); + let body; + switch (this.format) { + case 'raw': + body = this.render_raw(); + break; + case 'md': + body = html`${content.text}`; + break; + case 'message': + body = unsafeHTML(tfutils.markdown(content.text)); + break; + } let content_warning = html`
this.toggle_expanded(':cw')}>${content.contentWarning}
`; @@ -406,9 +429,16 @@ class TfMessageElement extends LitElement { this.expanded[(this.message.id || '') + ':blog'] ? html`
${this.blog_data ? unsafeHTML(tfutils.markdown(this.blog_data)) : 'Loading...'}
` : undefined; - let body = this.raw ? - this.render_raw() : - html` + let body; + switch (this.format) { + case 'raw': + body = this.render_raw(); + break; + case 'md': + body = content.summary; + break; + case 'message': + body = html`
self.toggle_expanded(':blog')}> @@ -420,6 +450,8 @@ class TfMessageElement extends LitElement {
${payload} `; + break; + } return html`