This commit is contained in:
parent
2328f3afb5
commit
763f7d45d8
@ -272,7 +272,9 @@ class TfElement extends LitElement {
|
|||||||
async get_latest_private(following) {
|
async get_latest_private(following) {
|
||||||
const k_version = 1;
|
const k_version = 1;
|
||||||
// { "version": 1, "range": [1234, 5678], messages: [ "%1.sha256", "%2.sha256", ... ], latest: rowid }
|
// { "version": 1, "range": [1234, 5678], messages: [ "%1.sha256", "%2.sha256", ... ], latest: rowid }
|
||||||
let cache = JSON.parse(await tfrpc.rpc.databaseGet(`private:${this.whoami}`) ?? '{}');
|
let cache = JSON.parse(
|
||||||
|
(await tfrpc.rpc.databaseGet(`private:${this.whoami}`)) ?? '{}'
|
||||||
|
);
|
||||||
if (cache.version !== k_version) {
|
if (cache.version !== k_version) {
|
||||||
cache = {
|
cache = {
|
||||||
version: k_version,
|
version: k_version,
|
||||||
@ -290,7 +292,11 @@ class TfElement extends LitElement {
|
|||||||
ranges.push([i, Math.min(i + k_chunk_size, latest), true]);
|
ranges.push([i, Math.min(i + k_chunk_size, latest), true]);
|
||||||
}
|
}
|
||||||
for (let i = cache.range[0]; i >= 0; i -= k_chunk_size) {
|
for (let i = cache.range[0]; i >= 0; i -= k_chunk_size) {
|
||||||
ranges.push([Math.max(i - k_chunk_size, 0), Math.min(cache.range[0], i + k_chunk_size), false]);
|
ranges.push([
|
||||||
|
Math.max(i - k_chunk_size, 0),
|
||||||
|
Math.min(cache.range[0], i + k_chunk_size),
|
||||||
|
false,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (let i = 0; i < latest; i += k_chunk_size) {
|
for (let i = 0; i < latest; i += k_chunk_size) {
|
||||||
@ -309,23 +315,26 @@ class TfElement extends LitElement {
|
|||||||
json(messages.content) LIKE '"%'
|
json(messages.content) LIKE '"%'
|
||||||
ORDER BY sequence DESC
|
ORDER BY sequence DESC
|
||||||
`,
|
`,
|
||||||
[
|
[range[0], range[1]]
|
||||||
range[0],
|
|
||||||
range[1],
|
|
||||||
]
|
|
||||||
);
|
);
|
||||||
messages = (await this.decrypt(messages)).filter((x) => x.decrypted);
|
messages = (await this.decrypt(messages)).filter((x) => x.decrypted);
|
||||||
if (messages.length) {
|
if (messages.length) {
|
||||||
cache.latest = Math.max(cache.latest ?? 0, ...messages.map((x) => x.rowid));
|
cache.latest = Math.max(
|
||||||
|
cache.latest ?? 0,
|
||||||
|
...messages.map((x) => x.rowid)
|
||||||
|
);
|
||||||
if (range[2]) {
|
if (range[2]) {
|
||||||
cache.messages = [...cache.messages, ...messages.map(x => x.id)];
|
cache.messages = [...cache.messages, ...messages.map((x) => x.id)];
|
||||||
} else {
|
} else {
|
||||||
cache.messages = [...messages.map(x => x.id), ...cache.messages];
|
cache.messages = [...messages.map((x) => x.id), ...cache.messages];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cache.range[0] = Math.min(cache.range[0] ?? range[0], range[0]);
|
cache.range[0] = Math.min(cache.range[0] ?? range[0], range[0]);
|
||||||
cache.range[1] = Math.max(cache.range[1] ?? range[1], range[1]);
|
cache.range[1] = Math.max(cache.range[1] ?? range[1], range[1]);
|
||||||
await tfrpc.rpc.databaseSet(`private:${this.whoami}`, JSON.stringify(cache));
|
await tfrpc.rpc.databaseSet(
|
||||||
|
`private:${this.whoami}`,
|
||||||
|
JSON.stringify(cache)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
console.log(cache);
|
console.log(cache);
|
||||||
return cache.latest;
|
return cache.latest;
|
||||||
@ -428,7 +437,9 @@ class TfElement extends LitElement {
|
|||||||
);
|
);
|
||||||
this.following = Object.keys(following);
|
this.following = Object.keys(following);
|
||||||
this.users = users;
|
this.users = users;
|
||||||
console.log(`load finished ${whoami} => ${this.whoami} in ${(new Date() - start_time) / 1000}`);
|
console.log(
|
||||||
|
`load finished ${whoami} => ${this.whoami} in ${(new Date() - start_time) / 1000}`
|
||||||
|
);
|
||||||
this.whoami = whoami;
|
this.whoami = whoami;
|
||||||
this.loaded = whoami;
|
this.loaded = whoami;
|
||||||
}
|
}
|
||||||
|
@ -605,7 +605,11 @@ class TfComposeElement extends LitElement {
|
|||||||
<footer class="w3-container">
|
<footer class="w3-container">
|
||||||
${this.render_attach_app()} ${this.render_content_warning()}
|
${this.render_attach_app()} ${this.render_content_warning()}
|
||||||
${this.render_new_thread()}
|
${this.render_new_thread()}
|
||||||
<button class="w3-button w3-theme-d1" id="submit" @click=${this.submit}>
|
<button
|
||||||
|
class="w3-button w3-theme-d1"
|
||||||
|
id="submit"
|
||||||
|
@click=${this.submit}
|
||||||
|
>
|
||||||
Submit
|
Submit
|
||||||
</button>
|
</button>
|
||||||
<button class="w3-button w3-theme-d1" @click=${this.attach}>
|
<button class="w3-button w3-theme-d1" @click=${this.attach}>
|
||||||
|
@ -437,9 +437,9 @@ class TfMessageElement extends LitElement {
|
|||||||
render_header() {
|
render_header() {
|
||||||
let is_encrypted = this.message?.decrypted
|
let is_encrypted = this.message?.decrypted
|
||||||
? html`<span class="w3-bar-item">🔓</span>`
|
? html`<span class="w3-bar-item">🔓</span>`
|
||||||
: typeof(this.message?.content) == 'string'
|
: typeof this.message?.content == 'string'
|
||||||
? html`<span class="w3-bar-item">🔒</span>`
|
? html`<span class="w3-bar-item">🔒</span>`
|
||||||
: undefined;
|
: undefined;
|
||||||
return html`
|
return html`
|
||||||
<header class="w3-bar">
|
<header class="w3-bar">
|
||||||
<span class="w3-bar-item">
|
<span class="w3-bar-item">
|
||||||
@ -448,9 +448,7 @@ class TfMessageElement extends LitElement {
|
|||||||
${is_encrypted}
|
${is_encrypted}
|
||||||
<span class="w3-bar-item w3-right">${this.render_raw_button()}</span>
|
<span class="w3-bar-item w3-right">${this.render_raw_button()}</span>
|
||||||
<span class="w3-bar-item w3-right" style="text-wrap: nowrap"
|
<span class="w3-bar-item w3-right" style="text-wrap: nowrap"
|
||||||
><a
|
><a target="_top" href=${'#' + encodeURIComponent(this.message.id)}
|
||||||
target="_top"
|
|
||||||
href=${'#' + encodeURIComponent(this.message.id)}
|
|
||||||
>%</a
|
>%</a
|
||||||
>
|
>
|
||||||
${new Date(this.message.timestamp).toLocaleString()}</span
|
${new Date(this.message.timestamp).toLocaleString()}</span
|
||||||
@ -481,28 +479,30 @@ class TfMessageElement extends LitElement {
|
|||||||
>
|
>
|
||||||
${inner}
|
${inner}
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
render_small_frame(inner) {
|
render_small_frame(inner) {
|
||||||
let self = this;
|
let self = this;
|
||||||
return this.render_frame(html`
|
return this.render_frame(html`
|
||||||
${self.render_header()}
|
${self.render_header()}
|
||||||
${self.format == 'raw' ? html`<div class="w3-container">${self.render_raw()}</div>` : inner}
|
${self.format == 'raw'
|
||||||
${self.render_votes()}
|
? html`<div class="w3-container">${self.render_raw()}</div>`
|
||||||
${(self.message.child_messages || []).map(
|
: inner}
|
||||||
(x) => html`
|
${self.render_votes()}
|
||||||
<tf-message
|
${(self.message.child_messages || []).map(
|
||||||
.message=${x}
|
(x) => html`
|
||||||
whoami=${self.whoami}
|
<tf-message
|
||||||
.users=${self.users}
|
.message=${x}
|
||||||
.drafts=${self.drafts}
|
whoami=${self.whoami}
|
||||||
.expanded=${self.expanded}
|
.users=${self.users}
|
||||||
channel=${self.channel}
|
.drafts=${self.drafts}
|
||||||
channel_unread=${self.channel_unread}
|
.expanded=${self.expanded}
|
||||||
></tf-message>
|
channel=${self.channel}
|
||||||
`
|
channel_unread=${self.channel_unread}
|
||||||
)}
|
></tf-message>
|
||||||
|
`
|
||||||
|
)}
|
||||||
`);
|
`);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -545,8 +545,8 @@ class TfMessageElement extends LitElement {
|
|||||||
let class_background = this.class_background();
|
let class_background = this.class_background();
|
||||||
let self = this;
|
let self = this;
|
||||||
if (this.message?.type === 'contact_group') {
|
if (this.message?.type === 'contact_group') {
|
||||||
return this.render_frame(html`
|
return this.render_frame(
|
||||||
${this.message.messages.map(
|
html` ${this.message.messages.map(
|
||||||
(x) =>
|
(x) =>
|
||||||
html`<tf-message
|
html`<tf-message
|
||||||
.message=${x}
|
.message=${x}
|
||||||
@ -557,34 +557,38 @@ class TfMessageElement extends LitElement {
|
|||||||
channel=${this.channel}
|
channel=${this.channel}
|
||||||
channel_unread=${this.channel_unread}
|
channel_unread=${this.channel_unread}
|
||||||
></tf-message>`
|
></tf-message>`
|
||||||
)}`);
|
)}`
|
||||||
|
);
|
||||||
} else if (this.message.placeholder) {
|
} else if (this.message.placeholder) {
|
||||||
return this.render_frame(html`
|
return this.render_frame(
|
||||||
<a target="_top" href=${'#' + encodeURIComponent(this.message.id)}
|
html` <a target="_top" href=${'#' + encodeURIComponent(this.message.id)}
|
||||||
>${this.message.id}</a
|
>${this.message.id}</a
|
||||||
>
|
>
|
||||||
(placeholder)
|
(placeholder)
|
||||||
<div>${this.render_votes()}</div>
|
<div>${this.render_votes()}</div>
|
||||||
${(this.message.child_messages || []).map(
|
${(this.message.child_messages || []).map(
|
||||||
(x) => html`
|
(x) => html`
|
||||||
<tf-message
|
<tf-message
|
||||||
.message=${x}
|
.message=${x}
|
||||||
whoami=${this.whoami}
|
whoami=${this.whoami}
|
||||||
.users=${this.users}
|
.users=${this.users}
|
||||||
.drafts=${this.drafts}
|
.drafts=${this.drafts}
|
||||||
.expanded=${this.expanded}
|
.expanded=${this.expanded}
|
||||||
channel=${this.channel}
|
channel=${this.channel}
|
||||||
channel_unread=${this.channel_unread}
|
channel_unread=${this.channel_unread}
|
||||||
></tf-message>
|
></tf-message>
|
||||||
`
|
`
|
||||||
)}`);
|
)}`
|
||||||
} else if (typeof(content?.type) === 'string') {
|
);
|
||||||
|
} else if (typeof content?.type === 'string') {
|
||||||
if (content.type == 'about') {
|
if (content.type == 'about') {
|
||||||
let name;
|
let name;
|
||||||
let image;
|
let image;
|
||||||
let description;
|
let description;
|
||||||
if (content.name !== undefined) {
|
if (content.name !== undefined) {
|
||||||
name = html`<div class="w3-container"><b>Name:</b> ${content.name}</div>`;
|
name = html`<div class="w3-container">
|
||||||
|
<b>Name:</b> ${content.name}
|
||||||
|
</div>`;
|
||||||
}
|
}
|
||||||
if (content.image !== undefined) {
|
if (content.image !== undefined) {
|
||||||
image = html`
|
image = html`
|
||||||
@ -593,14 +597,19 @@ class TfMessageElement extends LitElement {
|
|||||||
}
|
}
|
||||||
if (content.description !== undefined) {
|
if (content.description !== undefined) {
|
||||||
description = html`
|
description = html`
|
||||||
<div class="w3-container" style="flex: 1 0 50%; overflow-wrap: anywhere">
|
<div
|
||||||
|
class="w3-container"
|
||||||
|
style="flex: 1 0 50%; overflow-wrap: anywhere"
|
||||||
|
>
|
||||||
<div>${unsafeHTML(tfutils.markdown(content.description))}</div>
|
<div>${unsafeHTML(tfutils.markdown(content.description))}</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
let update =
|
let update =
|
||||||
content.about == this.message.author
|
content.about == this.message.author
|
||||||
? html`<div class="w3-container" style="font-weight: bold">Updated profile.</div>`
|
? html`<div class="w3-container" style="font-weight: bold">
|
||||||
|
Updated profile.
|
||||||
|
</div>`
|
||||||
: html`<div class="w3-container" style="font-weight: bold">
|
: html`<div class="w3-container" style="font-weight: bold">
|
||||||
Updated profile for
|
Updated profile for
|
||||||
<tf-user id=${content.about} .users=${this.users}></tf-user>.
|
<tf-user id=${content.about} .users=${this.users}></tf-user>.
|
||||||
@ -675,8 +684,7 @@ class TfMessageElement extends LitElement {
|
|||||||
`);
|
`);
|
||||||
} else if (content.type === 'issue') {
|
} else if (content.type === 'issue') {
|
||||||
return this.render_frame(html`
|
return this.render_frame(html`
|
||||||
${this.render_header()}
|
${this.render_header()} ${content.text} ${this.render_votes()}
|
||||||
${content.text} ${this.render_votes()}
|
|
||||||
<footer class="w3-container">
|
<footer class="w3-container">
|
||||||
<button class="w3-button w3-theme-d1" @click=${this.react}>
|
<button class="w3-button w3-theme-d1" @click=${this.react}>
|
||||||
React
|
React
|
||||||
@ -752,11 +760,13 @@ class TfMessageElement extends LitElement {
|
|||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
`);
|
`);
|
||||||
} else if (typeof(this.message.content) == 'string') {
|
} else if (typeof this.message.content == 'string') {
|
||||||
if (this.message?.decrypted) {
|
if (this.message?.decrypted) {
|
||||||
if (this.format == 'decrypted') {
|
if (this.format == 'decrypted') {
|
||||||
return this.render_small_frame(
|
return this.render_small_frame(
|
||||||
html`<span class="w3-container">🔓</span> ${this.render_json(this.message.decrypted)}`
|
html`<span class="w3-container">🔓</span> ${this.render_json(
|
||||||
|
this.message.decrypted
|
||||||
|
)}`
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return this.render_small_frame(
|
return this.render_small_frame(
|
||||||
@ -772,7 +782,7 @@ class TfMessageElement extends LitElement {
|
|||||||
html`<div class="w3-container"><b>type</b>: ${content.type}</div>`
|
html`<div class="w3-container"><b>type</b>: ${content.type}</div>`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else if (typeof(this.message.content) == 'string') {
|
} else if (typeof this.message.content == 'string') {
|
||||||
return this.render_small_frame();
|
return this.render_small_frame();
|
||||||
} else {
|
} else {
|
||||||
return this.render_small_frame(this.render_raw());
|
return this.render_small_frame(this.render_raw());
|
||||||
|
@ -396,9 +396,9 @@ function is_dark(hex, value) {
|
|||||||
function generated() {
|
function generated() {
|
||||||
let now = new Date();
|
let now = new Date();
|
||||||
let k_color = rgb_to_hex([
|
let k_color = rgb_to_hex([
|
||||||
now.getDay() * 255 / 6,
|
(now.getDay() * 255) / 6,
|
||||||
now.getHours() * 255 / 23,
|
(now.getHours() * 255) / 23,
|
||||||
now.getSeconds() * 255 / 59,
|
(now.getSeconds() * 255) / 59,
|
||||||
]);
|
]);
|
||||||
//let k_color = '#034f84';
|
//let k_color = '#034f84';
|
||||||
//let k_color = rgb_to_hex([Math.random() * 256, Math.random() * 256, Math.random() * 256]);
|
//let k_color = rgb_to_hex([Math.random() * 256, Math.random() * 256, Math.random() * 256]);
|
||||||
|
@ -194,11 +194,18 @@ class TfTabNewsElement extends LitElement {
|
|||||||
>
|
>
|
||||||
`
|
`
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<div class="w3-bar-item w3-theme-d2">Connections</div>
|
<div class="w3-bar-item w3-theme-d2">Connections</div>
|
||||||
${this.connections.map((x) => (html`
|
${this.connections.map(
|
||||||
<tf-user class="w3-bar-item" style="max-width: 100%" id=${x.id} .users=${this.users}></tf-user>
|
(x) => html`
|
||||||
`))}
|
<tf-user
|
||||||
|
class="w3-bar-item"
|
||||||
|
style="max-width: 100%"
|
||||||
|
id=${x.id}
|
||||||
|
.users=${this.users}
|
||||||
|
></tf-user>
|
||||||
|
`
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="w3-overlay"
|
class="w3-overlay"
|
||||||
|
@ -25,7 +25,9 @@ class TfUserElement extends LitElement {
|
|||||||
>?</span
|
>?</span
|
||||||
>`;
|
>`;
|
||||||
let name = this.users?.[this.id]?.name;
|
let name = this.users?.[this.id]?.name;
|
||||||
name = html`<a target="_top" href=${'#' + this.id}>${name !== undefined ? name : this.id}</a>`
|
name = html`<a target="_top" href=${'#' + this.id}
|
||||||
|
>${name !== undefined ? name : this.id}</a
|
||||||
|
>`;
|
||||||
|
|
||||||
if (this.users[this.id]) {
|
if (this.users[this.id]) {
|
||||||
let image_link = this.users[this.id].image;
|
let image_link = this.users[this.id].image;
|
||||||
@ -39,7 +41,9 @@ class TfUserElement extends LitElement {
|
|||||||
/>`;
|
/>`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return html` <div style="display: inline-block; vertical-align: middle; font-weight: bold; text-wrap: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis">
|
return html` <div
|
||||||
|
style="display: inline-block; vertical-align: middle; font-weight: bold; text-wrap: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis"
|
||||||
|
>
|
||||||
${image} ${name}
|
${image} ${name}
|
||||||
</div>`;
|
</div>`;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user