mirror of
https://github.com/stoatchat/for-legacy-web.git
synced 2026-04-28 16:20:36 +00:00
Format and automatically fix linted code.
This commit is contained in:
@@ -74,10 +74,15 @@ export class SingletonRenderer extends EventEmitter3 {
|
||||
|
||||
async init(id: string, message_id?: string) {
|
||||
if (message_id) {
|
||||
if (this.state.type === 'RENDER') {
|
||||
let message = this.state.messages.find(x => x._id === message_id);
|
||||
if (this.state.type === "RENDER") {
|
||||
const message = this.state.messages.find(
|
||||
(x) => x._id === message_id,
|
||||
);
|
||||
if (message) {
|
||||
this.emit("scroll", { type: "ScrollToView", id: message_id });
|
||||
this.emit("scroll", {
|
||||
type: "ScrollToView",
|
||||
id: message_id,
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -103,9 +108,9 @@ export class SingletonRenderer extends EventEmitter3 {
|
||||
function generateScroll(end: string): ScrollState {
|
||||
if (ref) {
|
||||
let heightRemoved = 0;
|
||||
let messageContainer = ref.children[0];
|
||||
const messageContainer = ref.children[0];
|
||||
if (messageContainer) {
|
||||
for (let child of Array.from(messageContainer.children)) {
|
||||
for (const child of Array.from(messageContainer.children)) {
|
||||
// If this child has a ulid.
|
||||
if (child.id?.length === 26) {
|
||||
// Check whether it was removed.
|
||||
@@ -127,12 +132,11 @@ export class SingletonRenderer extends EventEmitter3 {
|
||||
type: "OffsetTop",
|
||||
previousHeight: ref.scrollHeight - heightRemoved,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
type: "OffsetTop",
|
||||
previousHeight: 0,
|
||||
};
|
||||
}
|
||||
return {
|
||||
type: "OffsetTop",
|
||||
previousHeight: 0,
|
||||
};
|
||||
}
|
||||
|
||||
await this.currentRenderer.loadTop(this, generateScroll);
|
||||
@@ -148,9 +152,9 @@ export class SingletonRenderer extends EventEmitter3 {
|
||||
function generateScroll(start: string): ScrollState {
|
||||
if (ref) {
|
||||
let heightRemoved = 0;
|
||||
let messageContainer = ref.children[0];
|
||||
const messageContainer = ref.children[0];
|
||||
if (messageContainer) {
|
||||
for (let child of Array.from(messageContainer.children)) {
|
||||
for (const child of Array.from(messageContainer.children)) {
|
||||
// If this child has a ulid.
|
||||
if (child.id?.length === 26) {
|
||||
// Check whether it was removed.
|
||||
@@ -172,11 +176,10 @@ export class SingletonRenderer extends EventEmitter3 {
|
||||
type: "ScrollTop",
|
||||
y: ref.scrollTop - heightRemoved,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
type: "ScrollToBottom",
|
||||
};
|
||||
}
|
||||
return {
|
||||
type: "ScrollToBottom",
|
||||
};
|
||||
}
|
||||
|
||||
await this.currentRenderer.loadBottom(this, generateScroll);
|
||||
|
||||
@@ -8,10 +8,14 @@ export const SimpleRenderer: RendererRoutines = {
|
||||
if (renderer.client!.websocket.connected) {
|
||||
if (nearby)
|
||||
renderer
|
||||
.client!.channels.fetchMessagesWithUsers(id, { nearby, limit: 100 }, true)
|
||||
.client!.channels.fetchMessagesWithUsers(
|
||||
id,
|
||||
{ nearby, limit: 100 },
|
||||
true,
|
||||
)
|
||||
.then(({ messages: data }) => {
|
||||
data.sort((a, b) => a._id.localeCompare(b._id));
|
||||
let messages = data.map((x) => mapMessage(x));
|
||||
const messages = data.map((x) => mapMessage(x));
|
||||
renderer.setState(
|
||||
id,
|
||||
{
|
||||
@@ -28,7 +32,7 @@ export const SimpleRenderer: RendererRoutines = {
|
||||
.client!.channels.fetchMessagesWithUsers(id, {}, true)
|
||||
.then(({ messages: data }) => {
|
||||
data.reverse();
|
||||
let messages = data.map((x) => mapMessage(x));
|
||||
const messages = data.map((x) => mapMessage(x));
|
||||
renderer.setState(
|
||||
id,
|
||||
{
|
||||
@@ -72,11 +76,11 @@ export const SimpleRenderer: RendererRoutines = {
|
||||
if (!channel) return;
|
||||
if (renderer.state.type !== "RENDER") return;
|
||||
|
||||
let messages = [...renderer.state.messages];
|
||||
let index = messages.findIndex((x) => x._id === id);
|
||||
const messages = [...renderer.state.messages];
|
||||
const index = messages.findIndex((x) => x._id === id);
|
||||
|
||||
if (index > -1) {
|
||||
let message = { ...messages[index], ...mapMessage(patch) };
|
||||
const message = { ...messages[index], ...mapMessage(patch) };
|
||||
messages.splice(index, 1, message);
|
||||
|
||||
renderer.setState(
|
||||
@@ -94,8 +98,8 @@ export const SimpleRenderer: RendererRoutines = {
|
||||
if (!channel) return;
|
||||
if (renderer.state.type !== "RENDER") return;
|
||||
|
||||
let messages = [...renderer.state.messages];
|
||||
let index = messages.findIndex((x) => x._id === id);
|
||||
const messages = [...renderer.state.messages];
|
||||
const index = messages.findIndex((x) => x._id === id);
|
||||
|
||||
if (index > -1) {
|
||||
messages.splice(index, 1);
|
||||
|
||||
@@ -8,7 +8,7 @@ export type ScrollState =
|
||||
| { type: "Free" }
|
||||
| { type: "Bottom"; scrollingUntil?: number }
|
||||
| { type: "ScrollToBottom" | "StayAtBottom"; smooth?: boolean }
|
||||
| { type: "ScrollToView", id: string }
|
||||
| { type: "ScrollToView"; id: string }
|
||||
| { type: "OffsetTop"; previousHeight: number }
|
||||
| { type: "ScrollTop"; y: number };
|
||||
|
||||
|
||||
Reference in New Issue
Block a user