2024-04-21 14:18:06 -04:00
|
|
|
import {LitElement, html, render, unsafeHTML} from './lit-all.min.js';
|
2022-09-06 19:26:43 -04:00
|
|
|
import * as tfrpc from '/static/tfrpc.js';
|
|
|
|
import * as tfutils from './tf-utils.js';
|
|
|
|
import * as emojis from './emojis.js';
|
|
|
|
import {styles} from './tf-styles.js';
|
|
|
|
|
|
|
|
class TfMessageElement extends LitElement {
|
|
|
|
static get properties() {
|
|
|
|
return {
|
|
|
|
whoami: {type: String},
|
|
|
|
message: {type: Object},
|
|
|
|
users: {type: Object},
|
2023-01-20 19:16:18 -05:00
|
|
|
drafts: {type: Object},
|
2023-08-09 19:39:17 -04:00
|
|
|
format: {type: String},
|
2022-12-02 21:18:48 -05:00
|
|
|
blog_data: {type: String},
|
2023-01-24 19:56:10 -05:00
|
|
|
expanded: {type: Object},
|
2023-03-29 18:02:12 -04:00
|
|
|
};
|
2022-09-06 19:26:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static styles = styles;
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
let self = this;
|
|
|
|
this.whoami = null;
|
|
|
|
this.message = {};
|
|
|
|
this.users = {};
|
2023-01-20 19:16:18 -05:00
|
|
|
this.drafts = {};
|
2023-08-09 19:39:17 -04:00
|
|
|
this.format = 'message';
|
2023-01-24 19:56:10 -05:00
|
|
|
this.expanded = {};
|
2022-09-06 19:26:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
show_reply() {
|
2024-02-24 11:09:34 -05:00
|
|
|
let event = new CustomEvent('tf-draft', {
|
|
|
|
bubbles: true,
|
|
|
|
composed: true,
|
|
|
|
detail: {
|
|
|
|
id: this.message?.id,
|
|
|
|
draft: {
|
|
|
|
encrypt_to: this.message?.decrypted?.recps,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
2023-01-20 19:16:18 -05:00
|
|
|
this.dispatchEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
discard_reply() {
|
2024-02-24 11:09:34 -05:00
|
|
|
this.dispatchEvent(
|
|
|
|
new CustomEvent('tf-draft', {
|
|
|
|
bubbles: true,
|
|
|
|
composed: true,
|
|
|
|
detail: {id: this.id, draft: undefined},
|
|
|
|
})
|
|
|
|
);
|
2022-09-06 19:26:43 -04:00
|
|
|
}
|
|
|
|
|
2024-04-21 14:18:06 -04:00
|
|
|
show_reactions() {
|
|
|
|
let modal = document.getElementById('reactions_modal');
|
|
|
|
modal.users = this.users;
|
|
|
|
modal.votes = this.message?.votes || [];
|
|
|
|
}
|
|
|
|
|
2022-09-06 19:26:43 -04:00
|
|
|
render_votes() {
|
|
|
|
function normalize_expression(expression) {
|
|
|
|
if (expression === 'Like' || !expression) {
|
|
|
|
return '👍';
|
2022-09-09 22:56:15 -04:00
|
|
|
} else if (expression === 'Unlike') {
|
|
|
|
return '👎';
|
|
|
|
} else if (expression === 'heart') {
|
|
|
|
return '❤️';
|
2022-09-06 19:26:43 -04:00
|
|
|
} else {
|
|
|
|
return expression;
|
|
|
|
}
|
|
|
|
}
|
2024-04-26 18:19:13 -04:00
|
|
|
if (this.message?.votes?.length) {
|
|
|
|
return html`<div class="w3-button" @click=${this.show_reactions}>
|
|
|
|
${(this.message.votes || []).map(
|
|
|
|
(vote) => html`
|
|
|
|
<span
|
|
|
|
title="${this.users[vote.author]?.name ?? vote.author} ${new Date(
|
|
|
|
vote.timestamp
|
|
|
|
)}"
|
|
|
|
>
|
|
|
|
${normalize_expression(vote.content.vote.expression)}
|
|
|
|
</span>
|
|
|
|
`
|
|
|
|
)}
|
|
|
|
</div>`;
|
|
|
|
}
|
2022-09-06 19:26:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
render_raw() {
|
2022-09-25 08:33:54 -04:00
|
|
|
let raw = {
|
|
|
|
id: this.message?.id,
|
|
|
|
previous: this.message?.previous,
|
|
|
|
author: this.message?.author,
|
|
|
|
sequence: this.message?.sequence,
|
|
|
|
timestamp: this.message?.timestamp,
|
|
|
|
hash: this.message?.hash,
|
|
|
|
content: this.message?.content,
|
|
|
|
signature: this.message?.signature,
|
2023-03-29 18:02:12 -04:00
|
|
|
};
|
2024-02-24 11:09:34 -05:00
|
|
|
return html`<div style="white-space: pre-wrap">
|
|
|
|
${JSON.stringify(raw, null, 2)}
|
|
|
|
</div>`;
|
2022-09-06 19:26:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
vote(emoji) {
|
2023-05-03 20:32:50 -04:00
|
|
|
let reaction = emoji;
|
2022-09-06 19:26:43 -04:00
|
|
|
let message = this.message.id;
|
2024-02-24 11:09:34 -05:00
|
|
|
if (
|
|
|
|
confirm(
|
|
|
|
'Are you sure you want to react with ' +
|
|
|
|
reaction +
|
|
|
|
' to ' +
|
|
|
|
message +
|
|
|
|
'?'
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
tfrpc.rpc
|
|
|
|
.appendMessage(this.whoami, {
|
2022-09-06 19:26:43 -04:00
|
|
|
type: 'vote',
|
|
|
|
vote: {
|
|
|
|
link: message,
|
|
|
|
value: 1,
|
|
|
|
expression: reaction,
|
|
|
|
},
|
2024-02-24 11:09:34 -05:00
|
|
|
})
|
|
|
|
.catch(function (error) {
|
2022-09-06 19:26:43 -04:00
|
|
|
alert(error?.message);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
react(event) {
|
2024-04-03 21:12:43 -04:00
|
|
|
emojis.picker((x) => this.vote(x), null, this.whoami);
|
2022-09-06 19:26:43 -04:00
|
|
|
}
|
|
|
|
|
2022-09-14 19:49:25 -04:00
|
|
|
show_image(link) {
|
|
|
|
let div = document.createElement('div');
|
|
|
|
div.style.left = 0;
|
|
|
|
div.style.top = 0;
|
|
|
|
div.style.width = '100%';
|
|
|
|
div.style.height = '100%';
|
|
|
|
div.style.position = 'fixed';
|
|
|
|
div.style.background = '#000';
|
|
|
|
div.style.zIndex = 100;
|
|
|
|
div.style.display = 'grid';
|
|
|
|
let img = document.createElement('img');
|
|
|
|
img.src = link;
|
|
|
|
img.style.maxWidth = '100%';
|
|
|
|
img.style.maxHeight = '100%';
|
|
|
|
img.style.display = 'block';
|
|
|
|
img.style.margin = 'auto';
|
|
|
|
img.style.objectFit = 'contain';
|
|
|
|
img.style.width = '100%';
|
|
|
|
div.appendChild(img);
|
|
|
|
function image_close(event) {
|
|
|
|
document.body.removeChild(div);
|
|
|
|
window.removeEventListener('keydown', image_close);
|
|
|
|
}
|
|
|
|
div.onclick = image_close;
|
|
|
|
window.addEventListener('keydown', image_close);
|
|
|
|
document.body.appendChild(div);
|
|
|
|
}
|
|
|
|
|
2022-09-25 08:33:54 -04:00
|
|
|
body_click(event) {
|
|
|
|
if (event.srcElement.tagName == 'IMG') {
|
|
|
|
this.show_image(event.srcElement.src);
|
2024-02-24 11:09:34 -05:00
|
|
|
} else if (
|
|
|
|
event.srcElement.tagName == 'DIV' &&
|
|
|
|
event.srcElement.classList.contains('img_caption')
|
|
|
|
) {
|
2023-04-12 20:03:22 -04:00
|
|
|
let next = event.srcElement.nextSibling;
|
|
|
|
if (next.style.display == 'block') {
|
|
|
|
next.style.display = 'none';
|
|
|
|
} else {
|
|
|
|
next.style.display = 'block';
|
|
|
|
}
|
2022-09-25 08:33:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-14 19:33:57 -04:00
|
|
|
render_mention(mention) {
|
2024-02-24 11:09:34 -05:00
|
|
|
if (!mention?.link || typeof mention.link != 'string') {
|
2022-10-21 19:31:32 -04:00
|
|
|
return html` <pre>${JSON.stringify(mention)}</pre>`;
|
2024-02-24 11:09:34 -05:00
|
|
|
} else if (
|
|
|
|
mention?.link?.startsWith('&') &&
|
|
|
|
mention?.type?.startsWith('image/')
|
|
|
|
) {
|
2022-09-14 19:33:57 -04:00
|
|
|
return html`
|
2024-02-24 11:09:34 -05:00
|
|
|
<img
|
|
|
|
src=${'/' + mention.link + '/view'}
|
|
|
|
style="max-width: 128px; max-height: 128px"
|
|
|
|
title=${mention.name}
|
|
|
|
@click=${() => this.show_image('/' + mention.link + '/view')}
|
|
|
|
/>
|
2022-09-14 19:33:57 -04:00
|
|
|
`;
|
2024-02-24 11:09:34 -05:00
|
|
|
} else if (
|
|
|
|
mention.link?.startsWith('&') &&
|
|
|
|
mention.name?.startsWith('audio:')
|
|
|
|
) {
|
2022-09-14 19:33:57 -04:00
|
|
|
return html`
|
|
|
|
<audio controls style="height: 32px">
|
|
|
|
<source src=${'/' + mention.link + '/view'}></source>
|
|
|
|
</audio>
|
|
|
|
`;
|
2024-02-24 11:09:34 -05:00
|
|
|
} else if (
|
|
|
|
mention.link?.startsWith('&') &&
|
|
|
|
mention.name?.startsWith('video:')
|
|
|
|
) {
|
2022-11-29 21:37:27 -05:00
|
|
|
return html`
|
2023-03-19 19:31:08 -04:00
|
|
|
<video controls style="max-height: 240px; max-width: 128px">
|
2022-11-29 21:37:27 -05:00
|
|
|
<source src=${'/' + mention.link + '/view'}></source>
|
|
|
|
</video>
|
|
|
|
`;
|
2024-02-24 11:09:34 -05:00
|
|
|
} else if (
|
|
|
|
mention.link?.startsWith('&') &&
|
|
|
|
mention?.type === 'application/tildefriends'
|
|
|
|
) {
|
2022-10-21 19:31:32 -04:00
|
|
|
return html` <a href=${`/${mention.link}/`}>😎 ${mention.name}</a>`;
|
2022-09-14 19:33:57 -04:00
|
|
|
} else if (mention.link?.startsWith('%') || mention.link?.startsWith('@')) {
|
2024-02-24 11:09:34 -05:00
|
|
|
return html` <a href=${'#' + encodeURIComponent(mention.link)}
|
|
|
|
>${mention.name}</a
|
|
|
|
>`;
|
2022-09-14 19:33:57 -04:00
|
|
|
} else if (mention.link?.startsWith('#')) {
|
2024-02-24 11:09:34 -05:00
|
|
|
return html` <a href=${'#q=' + encodeURIComponent(mention.link)}
|
|
|
|
>${mention.link}</a
|
|
|
|
>`;
|
|
|
|
} else if (
|
|
|
|
Object.keys(mention).length == 2 &&
|
|
|
|
mention.link &&
|
|
|
|
mention.name
|
|
|
|
) {
|
2022-10-21 19:31:32 -04:00
|
|
|
return html` <a href=${`/${mention.link}/view`}>${mention.name}</a>`;
|
2022-09-14 19:33:57 -04:00
|
|
|
} else {
|
2024-02-24 11:09:34 -05:00
|
|
|
return html` <pre style="white-space: pre-wrap">
|
|
|
|
${JSON.stringify(mention, null, 2)}</pre
|
|
|
|
>`;
|
2022-09-14 19:33:57 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render_mentions() {
|
2022-09-25 08:33:54 -04:00
|
|
|
let mentions = this.message?.content?.mentions || [];
|
2024-02-24 11:09:34 -05:00
|
|
|
mentions = mentions.filter(
|
|
|
|
(x) => this.message?.content?.text?.indexOf(x.link) === -1
|
|
|
|
);
|
2022-09-25 08:33:54 -04:00
|
|
|
if (mentions.length) {
|
2022-09-14 19:33:57 -04:00
|
|
|
let self = this;
|
|
|
|
return html`
|
2024-05-11 17:44:09 -04:00
|
|
|
<fieldset style="padding: 0.5em; border: 1px solid black">
|
2022-09-14 19:33:57 -04:00
|
|
|
<legend>Mentions</legend>
|
2024-02-24 11:09:34 -05:00
|
|
|
${mentions.map((x) => self.render_mention(x))}
|
2022-09-14 19:33:57 -04:00
|
|
|
</fieldset>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-21 13:58:49 -05:00
|
|
|
total_child_messages(message) {
|
|
|
|
if (!message.child_messages) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
let total = message.child_messages.length;
|
2024-02-24 11:09:34 -05:00
|
|
|
for (let m of message.child_messages) {
|
2023-01-21 13:58:49 -05:00
|
|
|
total += this.total_child_messages(m);
|
|
|
|
}
|
|
|
|
return total;
|
|
|
|
}
|
|
|
|
|
2023-01-25 21:08:14 -05:00
|
|
|
set_expanded(expanded, tag) {
|
2024-02-24 11:09:34 -05:00
|
|
|
this.dispatchEvent(
|
|
|
|
new CustomEvent('tf-expand', {
|
|
|
|
bubbles: true,
|
|
|
|
composed: true,
|
|
|
|
detail: {id: (this.message.id || '') + (tag || ''), expanded: expanded},
|
|
|
|
})
|
|
|
|
);
|
2023-01-25 21:08:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
toggle_expanded(tag) {
|
2024-02-24 11:09:34 -05:00
|
|
|
this.set_expanded(
|
|
|
|
!this.expanded[(this.message.id || '') + (tag || '')],
|
|
|
|
tag
|
|
|
|
);
|
2023-01-24 19:56:10 -05:00
|
|
|
}
|
|
|
|
|
2022-10-18 18:31:54 -04:00
|
|
|
render_children() {
|
|
|
|
let self = this;
|
2022-12-28 12:17:44 -05:00
|
|
|
if (this.message.child_messages?.length) {
|
2023-01-24 19:56:10 -05:00
|
|
|
if (!this.expanded[this.message.id]) {
|
2024-02-24 11:09:34 -05:00
|
|
|
return html`<button
|
2024-04-04 20:35:09 -04:00
|
|
|
class="w3-button w3-theme-d1"
|
2024-02-24 11:09:34 -05:00
|
|
|
@click=${() => self.set_expanded(true)}
|
|
|
|
>
|
|
|
|
+ ${this.total_child_messages(this.message) + ' More'}
|
|
|
|
</button>`;
|
2022-12-28 12:17:44 -05:00
|
|
|
} else {
|
2024-02-24 11:09:34 -05:00
|
|
|
return html`<button
|
2024-04-04 20:35:09 -04:00
|
|
|
class="w3-button w3-theme-d1"
|
2024-02-24 11:09:34 -05:00
|
|
|
@click=${() => self.set_expanded(false)}
|
|
|
|
>
|
|
|
|
Collapse</button
|
|
|
|
>${(this.message.child_messages || []).map(
|
|
|
|
(x) =>
|
|
|
|
html`<tf-message
|
|
|
|
.message=${x}
|
|
|
|
whoami=${this.whoami}
|
|
|
|
.users=${this.users}
|
|
|
|
.drafts=${this.drafts}
|
|
|
|
.expanded=${this.expanded}
|
|
|
|
></tf-message>`
|
|
|
|
)}`;
|
2022-12-28 12:17:44 -05:00
|
|
|
}
|
2022-10-18 18:31:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-21 20:27:27 -04:00
|
|
|
render_channels() {
|
|
|
|
let content = this.message?.content;
|
2023-09-01 22:06:29 -04:00
|
|
|
if (this?.messsage?.decrypted?.type == 'post') {
|
|
|
|
content = this.message.decrypted;
|
2023-06-21 20:27:27 -04:00
|
|
|
}
|
|
|
|
let channels = [];
|
|
|
|
if (typeof content.channel === 'string') {
|
|
|
|
channels.push(`#${content.channel}`);
|
|
|
|
}
|
|
|
|
if (Array.isArray(content.mentions)) {
|
|
|
|
for (let mention of content.mentions) {
|
2024-02-24 11:09:34 -05:00
|
|
|
if (typeof mention?.link === 'string' && mention.link.startsWith('#')) {
|
2023-06-21 20:27:27 -04:00
|
|
|
channels.push(mention.link);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-02-24 11:09:34 -05:00
|
|
|
return channels.map((x) => html`<tf-tag tag=${x}></tf-tag>`);
|
2023-06-21 20:27:27 -04:00
|
|
|
}
|
|
|
|
|
2022-09-06 19:26:43 -04:00
|
|
|
render() {
|
|
|
|
let content = this.message?.content;
|
2023-09-01 22:06:29 -04:00
|
|
|
if (this.message?.decrypted?.type == 'post') {
|
|
|
|
content = this.message.decrypted;
|
2023-05-17 10:10:49 -04:00
|
|
|
}
|
2024-05-01 12:34:36 -04:00
|
|
|
let class_background = this.message?.decrypted
|
|
|
|
? 'w3-pale-red'
|
|
|
|
: 'w3-theme-d4';
|
2022-09-06 19:26:43 -04:00
|
|
|
let self = this;
|
2023-08-09 19:39:17 -04:00
|
|
|
let raw_button;
|
|
|
|
switch (this.format) {
|
|
|
|
case 'raw':
|
|
|
|
if (content?.type == 'post' || content?.type == 'blog') {
|
2024-02-24 11:09:34 -05:00
|
|
|
raw_button = html`<button
|
2024-04-04 20:35:09 -04:00
|
|
|
class="w3-button w3-theme-d1"
|
2024-02-24 11:09:34 -05:00
|
|
|
@click=${() => (self.format = 'md')}
|
|
|
|
>
|
|
|
|
Markdown
|
|
|
|
</button>`;
|
2023-08-09 19:39:17 -04:00
|
|
|
} else {
|
2024-02-24 11:09:34 -05:00
|
|
|
raw_button = html`<button
|
2024-04-04 20:35:09 -04:00
|
|
|
class="w3-button w3-theme-d1"
|
2024-02-24 11:09:34 -05:00
|
|
|
@click=${() => (self.format = 'message')}
|
|
|
|
>
|
|
|
|
Message
|
|
|
|
</button>`;
|
2023-08-09 19:39:17 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'md':
|
2024-02-24 11:09:34 -05:00
|
|
|
raw_button = html`<button
|
2024-04-04 20:35:09 -04:00
|
|
|
class="w3-button w3-theme-d1"
|
2024-02-24 11:09:34 -05:00
|
|
|
@click=${() => (self.format = 'message')}
|
|
|
|
>
|
|
|
|
Message
|
|
|
|
</button>`;
|
2023-08-09 19:39:17 -04:00
|
|
|
break;
|
2023-11-07 20:43:58 -05:00
|
|
|
case 'decrypted':
|
2024-02-24 11:09:34 -05:00
|
|
|
raw_button = html`<button
|
2024-04-04 20:35:09 -04:00
|
|
|
class="w3-button w3-theme-d1"
|
2024-02-24 11:09:34 -05:00
|
|
|
@click=${() => (self.format = 'raw')}
|
|
|
|
>
|
|
|
|
Raw
|
|
|
|
</button>`;
|
2023-08-09 19:39:17 -04:00
|
|
|
break;
|
2023-11-07 20:43:58 -05:00
|
|
|
default:
|
|
|
|
if (this.message.decrypted) {
|
2024-02-24 11:09:34 -05:00
|
|
|
raw_button = html`<button
|
2024-04-04 20:35:09 -04:00
|
|
|
class="w3-button w3-theme-d1"
|
2024-02-24 11:09:34 -05:00
|
|
|
@click=${() => (self.format = 'decrypted')}
|
|
|
|
>
|
|
|
|
Decrypted
|
|
|
|
</button>`;
|
2023-11-07 20:43:58 -05:00
|
|
|
} else {
|
2024-02-24 11:09:34 -05:00
|
|
|
raw_button = html`<button
|
2024-04-04 20:35:09 -04:00
|
|
|
class="w3-button w3-theme-d1"
|
2024-02-24 11:09:34 -05:00
|
|
|
@click=${() => (self.format = 'raw')}
|
|
|
|
>
|
|
|
|
Raw
|
|
|
|
</button>`;
|
2023-11-07 20:43:58 -05:00
|
|
|
}
|
|
|
|
break;
|
2023-08-09 19:39:17 -04:00
|
|
|
}
|
2022-09-06 19:26:43 -04:00
|
|
|
function small_frame(inner) {
|
2023-08-09 19:39:17 -04:00
|
|
|
let body;
|
2022-09-06 19:26:43 -04:00
|
|
|
return html`
|
2024-02-24 11:09:34 -05:00
|
|
|
<div
|
2024-05-01 12:34:36 -04:00
|
|
|
class="w3-card-4 w3-theme-d4 w3-border-theme"
|
|
|
|
style="margin-top: 8px; padding: 16px; display: inline-block; overflow-wrap: anywhere"
|
2024-02-24 11:09:34 -05:00
|
|
|
>
|
2022-09-06 19:26:43 -04:00
|
|
|
<tf-user id=${self.message.author} .users=${self.users}></tf-user>
|
2024-02-24 11:09:34 -05:00
|
|
|
<span style="padding-right: 8px"
|
|
|
|
><a tfarget="_top" href=${'#' + self.message.id}>%</a> ${new Date(
|
|
|
|
self.message.timestamp
|
|
|
|
).toLocaleString()}</span
|
|
|
|
>
|
|
|
|
${raw_button} ${self.format == 'raw' ? self.render_raw() : inner}
|
2022-09-06 19:26:43 -04:00
|
|
|
${self.render_votes()}
|
2024-04-28 12:55:17 -04:00
|
|
|
${(self.message.child_messages || []).map(
|
|
|
|
(x) => html`
|
|
|
|
<tf-message
|
|
|
|
.message=${x}
|
|
|
|
whoami=${self.whoami}
|
|
|
|
.users=${self.users}
|
|
|
|
.drafts=${self.drafts}
|
|
|
|
.expanded=${self.expanded}
|
|
|
|
></tf-message>
|
|
|
|
`
|
|
|
|
)}
|
2022-09-06 19:26:43 -04:00
|
|
|
</div>
|
2023-03-29 18:02:12 -04:00
|
|
|
`;
|
2022-09-06 19:26:43 -04:00
|
|
|
}
|
2023-03-19 19:31:08 -04:00
|
|
|
if (this.message?.type === 'contact_group') {
|
2024-02-24 11:09:34 -05:00
|
|
|
return html` <div
|
2024-05-01 12:34:36 -04:00
|
|
|
class="w3-card-4 w3-theme-d4 w3-border-theme"
|
|
|
|
style="margin-top: 8px; padding: 16px; overflow-wrap: anywhere"
|
2024-02-24 11:09:34 -05:00
|
|
|
>
|
|
|
|
${this.message.messages.map(
|
|
|
|
(x) =>
|
|
|
|
html`<tf-message
|
|
|
|
.message=${x}
|
|
|
|
whoami=${this.whoami}
|
|
|
|
.users=${this.users}
|
|
|
|
.drafts=${this.drafts}
|
|
|
|
.expanded=${this.expanded}
|
|
|
|
></tf-message>`
|
|
|
|
)}
|
|
|
|
</div>`;
|
2023-03-19 19:31:08 -04:00
|
|
|
} else if (this.message.placeholder) {
|
2024-02-24 11:09:34 -05:00
|
|
|
return html` <div
|
2024-05-01 12:34:36 -04:00
|
|
|
class="w3-card-4 w3-theme-d4 w3-border-theme"
|
|
|
|
style="margin-top: 8px; padding: 16px; overflow-wrap: anywhere"
|
2024-02-24 11:09:34 -05:00
|
|
|
>
|
|
|
|
<a target="_top" href=${'#' + this.message.id}>${this.message.id}</a>
|
|
|
|
(placeholder)
|
|
|
|
<div>${this.render_votes()}</div>
|
|
|
|
${(this.message.child_messages || []).map(
|
|
|
|
(x) => html`
|
|
|
|
<tf-message
|
|
|
|
.message=${x}
|
|
|
|
whoami=${this.whoami}
|
|
|
|
.users=${this.users}
|
|
|
|
.drafts=${this.drafts}
|
|
|
|
.expanded=${this.expanded}
|
|
|
|
></tf-message>
|
|
|
|
`
|
|
|
|
)}
|
|
|
|
</div>`;
|
|
|
|
} else if (typeof (content?.type === 'string')) {
|
2022-09-25 08:33:54 -04:00
|
|
|
if (content.type == 'about') {
|
2022-12-24 13:50:01 -05:00
|
|
|
let name;
|
|
|
|
let image;
|
|
|
|
let description;
|
|
|
|
if (content.name !== undefined) {
|
|
|
|
name = html`<div><b>Name:</b> ${content.name}</div>`;
|
|
|
|
}
|
|
|
|
if (content.image !== undefined) {
|
|
|
|
image = html`
|
2024-02-24 11:09:34 -05:00
|
|
|
<div><img src=${'/' + (typeof content.image?.link == 'string' ? content.image.link : content.image) + '/view'} style="width: 256px; height: auto"></img></div>
|
2022-12-24 13:50:01 -05:00
|
|
|
`;
|
|
|
|
}
|
|
|
|
if (content.description !== undefined) {
|
|
|
|
description = html`
|
2023-01-22 12:25:37 -05:00
|
|
|
<div style="flex: 1 0 50%; overflow-wrap: anywhere">
|
2022-12-24 13:50:01 -05:00
|
|
|
<div>${unsafeHTML(tfutils.markdown(content.description))}</div>
|
|
|
|
</div>
|
2023-03-29 18:02:12 -04:00
|
|
|
`;
|
2022-12-24 13:50:01 -05:00
|
|
|
}
|
2024-02-24 11:09:34 -05:00
|
|
|
let update =
|
|
|
|
content.about == this.message.author
|
|
|
|
? html`<div style="font-weight: bold">Updated profile.</div>`
|
|
|
|
: html`<div style="font-weight: bold">
|
|
|
|
Updated profile for
|
|
|
|
<tf-user id=${content.about} .users=${this.users}></tf-user>.
|
|
|
|
</div>`;
|
|
|
|
return small_frame(html` ${update} ${name} ${image} ${description} `);
|
2022-09-25 08:33:54 -04:00
|
|
|
} else if (content.type == 'contact') {
|
2023-03-19 19:31:08 -04:00
|
|
|
return html`
|
2022-09-25 08:33:54 -04:00
|
|
|
<div>
|
2023-03-19 19:31:08 -04:00
|
|
|
<tf-user id=${this.message.author} .users=${this.users}></tf-user>
|
2022-09-25 08:33:54 -04:00
|
|
|
is
|
2024-02-24 11:09:34 -05:00
|
|
|
${content.blocking === true
|
|
|
|
? 'blocking'
|
|
|
|
: content.blocking === false
|
|
|
|
? 'no longer blocking'
|
|
|
|
: content.following === true
|
|
|
|
? 'following'
|
|
|
|
: content.following === false
|
|
|
|
? 'no longer following'
|
|
|
|
: '?'}
|
|
|
|
<tf-user
|
|
|
|
id=${this.message.content.contact}
|
|
|
|
.users=${this.users}
|
|
|
|
></tf-user>
|
2022-09-25 08:33:54 -04:00
|
|
|
</div>
|
2023-03-19 19:31:08 -04:00
|
|
|
`;
|
2022-09-25 08:33:54 -04:00
|
|
|
} else if (content.type == 'post') {
|
2024-02-24 11:09:34 -05:00
|
|
|
let reply =
|
|
|
|
this.drafts[this.message?.id] !== undefined
|
|
|
|
? html`
|
|
|
|
<tf-compose
|
|
|
|
whoami=${this.whoami}
|
|
|
|
.users=${this.users}
|
2024-03-03 12:09:03 -05:00
|
|
|
root=${content.root || this.message.id}
|
2024-02-24 11:09:34 -05:00
|
|
|
branch=${this.message.id}
|
|
|
|
.drafts=${this.drafts}
|
|
|
|
@tf-discard=${this.discard_reply}
|
2024-04-03 19:50:59 -04:00
|
|
|
author=${this.message.author}
|
2024-02-24 11:09:34 -05:00
|
|
|
></tf-compose>
|
|
|
|
`
|
|
|
|
: html`
|
2024-04-11 18:36:31 -04:00
|
|
|
<button class="w3-button w3-theme-d1" @click=${this.show_reply}>
|
2024-02-24 11:09:34 -05:00
|
|
|
Reply
|
|
|
|
</button>
|
|
|
|
`;
|
2022-09-25 08:33:54 -04:00
|
|
|
let self = this;
|
2023-08-09 19:39:17 -04:00
|
|
|
let body;
|
|
|
|
switch (this.format) {
|
|
|
|
case 'raw':
|
|
|
|
body = this.render_raw();
|
|
|
|
break;
|
|
|
|
case 'md':
|
2024-02-24 11:09:34 -05:00
|
|
|
body = html`<code
|
|
|
|
style="white-space: pre-wrap; overflow-wrap: anywhere"
|
|
|
|
>${content.text}</code
|
|
|
|
>`;
|
2023-08-09 19:39:17 -04:00
|
|
|
break;
|
|
|
|
case 'message':
|
|
|
|
body = unsafeHTML(tfutils.markdown(content.text));
|
|
|
|
break;
|
2024-02-15 20:09:08 -05:00
|
|
|
case 'decrypted':
|
2024-02-24 11:09:34 -05:00
|
|
|
body = html`<pre
|
|
|
|
style="white-space: pre-wrap; overflow-wrap: anywhere"
|
|
|
|
>
|
|
|
|
${JSON.stringify(content, null, 2)}</pre
|
|
|
|
>`;
|
2024-02-15 20:09:08 -05:00
|
|
|
break;
|
2023-08-09 19:39:17 -04:00
|
|
|
}
|
2022-11-18 21:06:23 -05:00
|
|
|
let content_warning = html`
|
2024-02-24 11:09:34 -05:00
|
|
|
<div
|
2024-04-04 20:35:09 -04:00
|
|
|
class="w3-panel w3-round-xlarge w3-theme-l4"
|
2024-02-24 11:09:34 -05:00
|
|
|
style="cursor: pointer"
|
|
|
|
@click=${(x) => this.toggle_expanded(':cw')}
|
|
|
|
>
|
|
|
|
<p>${content.contentWarning}</p>
|
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
let content_html = html`
|
|
|
|
${this.render_channels()}
|
|
|
|
<div @click=${this.body_click}>${body}</div>
|
|
|
|
${this.render_mentions()}
|
|
|
|
`;
|
|
|
|
let payload = content.contentWarning
|
|
|
|
? self.expanded[(this.message.id || '') + ':cw']
|
|
|
|
? html` ${content_warning} ${content_html} `
|
|
|
|
: content_warning
|
|
|
|
: content_html;
|
|
|
|
let is_encrypted = this.message?.decrypted
|
|
|
|
? html`<span style="align-self: center">🔓</span>`
|
|
|
|
: undefined;
|
2022-09-25 08:33:54 -04:00
|
|
|
return html`
|
|
|
|
<style>
|
|
|
|
code {
|
|
|
|
white-space: pre-wrap;
|
|
|
|
overflow-wrap: break-word;
|
|
|
|
}
|
2022-10-04 22:11:46 -04:00
|
|
|
div {
|
|
|
|
overflow-wrap: anywhere;
|
|
|
|
}
|
2022-09-25 08:33:54 -04:00
|
|
|
img {
|
|
|
|
max-width: 100%;
|
|
|
|
height: auto;
|
2022-11-16 19:30:58 -05:00
|
|
|
display: block;
|
2022-09-25 08:33:54 -04:00
|
|
|
}
|
|
|
|
</style>
|
2024-02-24 11:09:34 -05:00
|
|
|
<div
|
2024-05-01 12:34:36 -04:00
|
|
|
class="w3-card-4 ${class_background} w3-border-theme"
|
|
|
|
style="margin-top: 8px; padding: 16px"
|
2024-02-24 11:09:34 -05:00
|
|
|
>
|
2022-09-25 08:33:54 -04:00
|
|
|
<div style="display: flex; flex-direction: row">
|
|
|
|
<tf-user id=${this.message.author} .users=${this.users}></tf-user>
|
2023-05-17 10:10:49 -04:00
|
|
|
${is_encrypted}
|
2022-09-25 08:33:54 -04:00
|
|
|
<span style="flex: 1"></span>
|
2024-02-24 11:09:34 -05:00
|
|
|
<span style="padding-right: 8px"
|
|
|
|
><a target="_top" href=${'#' + self.message.id}>%</a>
|
|
|
|
${new Date(this.message.timestamp).toLocaleString()}</span
|
|
|
|
>
|
2022-09-25 08:33:54 -04:00
|
|
|
<span>${raw_button}</span>
|
|
|
|
</div>
|
2024-02-24 11:09:34 -05:00
|
|
|
${payload} ${this.render_votes()}
|
2024-01-18 21:12:17 -05:00
|
|
|
<p>
|
2022-09-25 08:33:54 -04:00
|
|
|
${reply}
|
2024-04-04 20:35:09 -04:00
|
|
|
<button class="w3-button w3-theme-d1" @click=${this.react}>
|
2024-02-24 11:09:34 -05:00
|
|
|
React
|
|
|
|
</button>
|
2024-01-18 21:12:17 -05:00
|
|
|
</p>
|
2022-10-18 18:31:54 -04:00
|
|
|
${this.render_children()}
|
2022-09-06 19:26:43 -04:00
|
|
|
</div>
|
2022-09-25 08:33:54 -04:00
|
|
|
`;
|
2023-09-06 18:35:20 -04:00
|
|
|
} else if (content.type === 'issue') {
|
2024-02-24 11:09:34 -05:00
|
|
|
let is_encrypted = this.message?.decrypted
|
|
|
|
? html`<span style="align-self: center">🔓</span>`
|
|
|
|
: undefined;
|
2023-09-06 18:35:20 -04:00
|
|
|
return html`
|
|
|
|
<style>
|
|
|
|
code {
|
|
|
|
white-space: pre-wrap;
|
|
|
|
overflow-wrap: break-word;
|
|
|
|
}
|
|
|
|
div {
|
|
|
|
overflow-wrap: anywhere;
|
|
|
|
}
|
|
|
|
img {
|
|
|
|
max-width: 100%;
|
|
|
|
height: auto;
|
|
|
|
display: block;
|
|
|
|
}
|
|
|
|
</style>
|
2024-02-24 11:09:34 -05:00
|
|
|
<div
|
2024-05-01 12:34:36 -04:00
|
|
|
class="w3-card-4 ${class_background} w3-border-theme"
|
|
|
|
style="margin-top: 8px; padding: 16px"
|
2024-02-24 11:09:34 -05:00
|
|
|
>
|
2023-09-06 18:35:20 -04:00
|
|
|
<div style="display: flex; flex-direction: row">
|
|
|
|
<tf-user id=${this.message.author} .users=${this.users}></tf-user>
|
|
|
|
${is_encrypted}
|
|
|
|
<span style="flex: 1"></span>
|
2024-02-24 11:09:34 -05:00
|
|
|
<span style="padding-right: 8px"
|
|
|
|
><a target="_top" href=${'#' + self.message.id}>%</a>
|
|
|
|
${new Date(this.message.timestamp).toLocaleString()}</span
|
|
|
|
>
|
2023-09-06 18:35:20 -04:00
|
|
|
<span>${raw_button}</span>
|
|
|
|
</div>
|
2024-02-24 11:09:34 -05:00
|
|
|
${content.text} ${this.render_votes()}
|
2024-01-18 21:12:17 -05:00
|
|
|
<p>
|
2024-04-04 20:35:09 -04:00
|
|
|
<button class="w3-button w3-theme-d1" @click=${this.react}>
|
2024-02-24 11:09:34 -05:00
|
|
|
React
|
|
|
|
</button>
|
2024-01-18 21:12:17 -05:00
|
|
|
</p>
|
2023-09-06 18:35:20 -04:00
|
|
|
${this.render_children()}
|
|
|
|
</div>
|
|
|
|
`;
|
2022-12-02 21:18:48 -05:00
|
|
|
} else if (content.type === 'blog') {
|
|
|
|
let self = this;
|
2024-02-24 11:09:34 -05:00
|
|
|
tfrpc.rpc.get_blob(content.blog).then(function (data) {
|
2022-12-02 21:18:48 -05:00
|
|
|
self.blog_data = data;
|
|
|
|
});
|
2024-02-24 11:09:34 -05:00
|
|
|
let payload = this.expanded[(this.message.id || '') + ':blog']
|
|
|
|
? html`<div>
|
|
|
|
${this.blog_data
|
|
|
|
? unsafeHTML(tfutils.markdown(this.blog_data))
|
|
|
|
: 'Loading...'}
|
|
|
|
</div>`
|
|
|
|
: undefined;
|
2023-08-09 19:39:17 -04:00
|
|
|
let body;
|
|
|
|
switch (this.format) {
|
|
|
|
case 'raw':
|
|
|
|
body = this.render_raw();
|
|
|
|
break;
|
|
|
|
case 'md':
|
|
|
|
body = content.summary;
|
|
|
|
break;
|
|
|
|
case 'message':
|
|
|
|
body = html`
|
2022-12-03 09:58:44 -05:00
|
|
|
<div
|
|
|
|
style="border: 1px solid #fff; border-radius: 1em; padding: 8px; margin: 4px; cursor: pointer"
|
2024-02-24 11:09:34 -05:00
|
|
|
@click=${(x) => self.toggle_expanded(':blog')}>
|
2022-12-03 09:58:44 -05:00
|
|
|
<h2>${content.title}</h2>
|
|
|
|
<div style="display: flex; flex-direction: row">
|
|
|
|
<img src=/${content.thumbnail}/view></img>
|
|
|
|
<span>${content.summary}</span>
|
|
|
|
</div>
|
2022-12-02 21:18:48 -05:00
|
|
|
</div>
|
2022-12-03 09:58:44 -05:00
|
|
|
${payload}
|
2022-12-02 21:18:48 -05:00
|
|
|
`;
|
2023-08-09 19:39:17 -04:00
|
|
|
break;
|
|
|
|
}
|
2024-02-24 11:09:34 -05:00
|
|
|
let reply =
|
|
|
|
this.drafts[this.message?.id] !== undefined
|
|
|
|
? html`
|
|
|
|
<tf-compose
|
|
|
|
whoami=${this.whoami}
|
|
|
|
.users=${this.users}
|
2024-03-03 12:09:03 -05:00
|
|
|
root=${content.root || this.message.id}
|
2024-02-24 11:09:34 -05:00
|
|
|
branch=${this.message.id}
|
|
|
|
.drafts=${this.drafts}
|
|
|
|
@tf-discard=${this.discard_reply}
|
2024-04-03 19:50:59 -04:00
|
|
|
author=${this.message.author}
|
2024-02-24 11:09:34 -05:00
|
|
|
></tf-compose>
|
|
|
|
`
|
|
|
|
: html`
|
2024-04-11 18:36:31 -04:00
|
|
|
<button class="w3-button w3-theme-d1" @click=${this.show_reply}>
|
2024-02-24 11:09:34 -05:00
|
|
|
Reply
|
|
|
|
</button>
|
|
|
|
`;
|
2022-12-02 21:18:48 -05:00
|
|
|
return html`
|
|
|
|
<style>
|
|
|
|
code {
|
|
|
|
white-space: pre-wrap;
|
|
|
|
overflow-wrap: break-word;
|
|
|
|
}
|
|
|
|
div {
|
|
|
|
overflow-wrap: anywhere;
|
|
|
|
}
|
|
|
|
img {
|
|
|
|
max-width: 100%;
|
|
|
|
height: auto;
|
|
|
|
display: block;
|
|
|
|
}
|
|
|
|
</style>
|
2024-02-24 11:09:34 -05:00
|
|
|
<div
|
2024-05-01 12:34:36 -04:00
|
|
|
class="w3-card-4 w3-theme-d4 w3-border-theme"
|
|
|
|
style="margin-top: 8px; padding: 16px"
|
2024-02-24 11:09:34 -05:00
|
|
|
>
|
2022-12-02 21:18:48 -05:00
|
|
|
<div style="display: flex; flex-direction: row">
|
|
|
|
<tf-user id=${this.message.author} .users=${this.users}></tf-user>
|
|
|
|
<span style="flex: 1"></span>
|
2024-02-24 11:09:34 -05:00
|
|
|
<span style="padding-right: 8px"
|
|
|
|
><a target="_top" href=${'#' + self.message.id}>%</a>
|
|
|
|
${new Date(this.message.timestamp).toLocaleString()}</span
|
|
|
|
>
|
2022-12-02 21:18:48 -05:00
|
|
|
<span>${raw_button}</span>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div>${body}</div>
|
|
|
|
${this.render_mentions()}
|
2023-12-29 15:13:35 -05:00
|
|
|
<div>
|
|
|
|
${reply}
|
2024-04-04 20:35:09 -04:00
|
|
|
<button class="w3-button w3-theme-d1" @click=${this.react}>
|
2024-02-24 11:09:34 -05:00
|
|
|
React
|
|
|
|
</button>
|
2023-12-29 15:13:35 -05:00
|
|
|
</div>
|
2024-02-24 11:09:34 -05:00
|
|
|
${this.render_votes()} ${this.render_children()}
|
2022-12-02 21:18:48 -05:00
|
|
|
</div>
|
|
|
|
`;
|
2022-09-25 08:33:54 -04:00
|
|
|
} else if (content.type === 'pub') {
|
2024-02-24 11:09:34 -05:00
|
|
|
return small_frame(
|
|
|
|
html` <style>
|
|
|
|
span {
|
|
|
|
overflow-wrap: anywhere;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
<span>
|
|
|
|
<div>
|
|
|
|
🍻
|
|
|
|
<tf-user
|
|
|
|
.users=${this.users}
|
|
|
|
id=${content.address.key}
|
|
|
|
></tf-user>
|
|
|
|
</div>
|
|
|
|
<pre>${content.address.host}:${content.address.port}</pre>
|
|
|
|
</span>`
|
|
|
|
);
|
2022-12-07 18:37:06 -05:00
|
|
|
} else if (content.type === 'channel') {
|
|
|
|
return small_frame(html`
|
|
|
|
<div>
|
2024-02-24 11:09:34 -05:00
|
|
|
${content.subscribed ? 'subscribed to' : 'unsubscribed from'}
|
|
|
|
<a href=${'#q=' + encodeURIComponent('#' + content.channel)}
|
|
|
|
>#${content.channel}</a
|
|
|
|
>
|
2022-12-07 18:37:06 -05:00
|
|
|
</div>
|
|
|
|
`);
|
2024-02-24 11:09:34 -05:00
|
|
|
} else if (typeof this.message.content == 'string') {
|
2023-09-01 22:06:29 -04:00
|
|
|
if (this.message?.decrypted) {
|
2023-11-07 20:43:58 -05:00
|
|
|
if (this.format == 'decrypted') {
|
2024-02-24 11:09:34 -05:00
|
|
|
return small_frame(
|
|
|
|
html`<span>🔓</span>
|
|
|
|
<pre>${JSON.stringify(this.message.decrypted, null, 2)}</pre>`
|
|
|
|
);
|
2023-11-07 20:43:58 -05:00
|
|
|
} else {
|
2024-02-24 11:09:34 -05:00
|
|
|
return small_frame(
|
|
|
|
html`<span>🔓</span>
|
|
|
|
<div>${this.message.decrypted.type}</div>`
|
|
|
|
);
|
2023-11-07 20:43:58 -05:00
|
|
|
}
|
2023-05-17 10:10:49 -04:00
|
|
|
} else {
|
2023-09-01 22:06:29 -04:00
|
|
|
return small_frame(html`<span>🔒</span>`);
|
2023-05-17 10:10:49 -04:00
|
|
|
}
|
2022-09-25 08:33:54 -04:00
|
|
|
} else {
|
|
|
|
return small_frame(html`<div><b>type</b>: ${content.type}</div>`);
|
|
|
|
}
|
2022-09-06 19:26:43 -04:00
|
|
|
} else {
|
|
|
|
return small_frame(this.render_raw());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-24 11:09:34 -05:00
|
|
|
customElements.define('tf-message', TfMessageElement);
|