Skip to content

Commit

Permalink
Remove the anti bridge stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
mybearworld committed Jun 25, 2024
1 parent 668e855 commit fba9345
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 45 deletions.
7 changes: 1 addition & 6 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@
<title>Roarer</title>
</head>
<body class="text-gray-900 dark:text-gray-200 dark:[color-scheme:dark]">
<div id="root" class="px-2 py-1">
MikeDEV has made clients on mybearworld.github.io unable to connect.<br />
Use
<a href="https://eris.pages.dev/meo" class="font-bold text-lime-600">
meo
</a>
<div id="root">
</div>
<script type="module" src="/src/main.tsx"></script>
</body>
Expand Down
39 changes: 8 additions & 31 deletions src/lib/api/posts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export type PostsSlice = {
Errorable<{
posts: string[];
stopLoadingMore: boolean;
currentOptimistics: Record<string, { mock: string; real: string }>;
currentOptimistics: Record<string, string>;
}>
>;
posts: Record<string, Errorable<Post | { isDeleted: true }>>;
Expand Down Expand Up @@ -115,33 +115,24 @@ export const createPostsSlice: Slice<PostsSlice> = (set, get) => {
if (!state.chatPosts[post.post_origin]) {
return;
}
state.addPost(post);
set((draft) => {
const chatPosts = draft.chatPosts[post.post_origin];
if (!chatPosts || chatPosts.error) {
return;
}
chatPosts.posts.unshift(post.post_id);
if (post.u === draft.credentials?.username) {
const optimisticPost = Object.entries(
chatPosts.currentOptimistics,
).find(
([_id, optimisticPostContent]) =>
optimisticPostContent.mock === post.p,
);
if (!optimisticPost) {
const id = Object.entries(chatPosts.currentOptimistics).find(
([_id, optimisticPostContent]) => optimisticPostContent === post.p,
)?.[0];
if (!id) {
return;
}
const [id, content] = optimisticPost;
post.p = content.real;
const state = get();
if (content.mock !== content.real) {
state.editPost(post.post_id, content.real);
}
delete chatPosts.currentOptimistics[id];
draft.posts[id] = { error: false, isDeleted: true };
}
});
state.addPost(post);
});
cloudlink.on("direct", (packet: unknown) => {
const parsed = POST_UPDATE_PACKET_SCHEMA.safeParse(packet);
Expand Down Expand Up @@ -288,8 +279,6 @@ export const createPostsSlice: Slice<PostsSlice> = (set, get) => {
if (!credentials) {
return;
}
const mock = chat !== "livechat";
const mockPostContent = mock ? createMockPostContent() : content;
set((draft) => {
const trimmedContent = content.trim();
draft.posts[optimisticId] = {
Expand All @@ -307,10 +296,7 @@ export const createPostsSlice: Slice<PostsSlice> = (set, get) => {
const chatPosts = draft.chatPosts[chat];
if (chatPosts && !chatPosts.error) {
chatPosts.posts.unshift(optimisticId);
chatPosts.currentOptimistics[optimisticId] = {
mock: mockPostContent,
real: content,
};
chatPosts.currentOptimistics[optimisticId] = trimmedContent;
}
});
const response = await request(
Expand All @@ -321,7 +307,7 @@ export const createPostsSlice: Slice<PostsSlice> = (set, get) => {
...(state.credentials ? { Token: state.credentials.token } : {}),
"Content-Type": "application/json",
},
body: JSON.stringify({ content: mockPostContent, attachments }),
body: JSON.stringify({ content, attachments }),
method: "POST",
},
),
Expand Down Expand Up @@ -366,12 +352,3 @@ export const createPostsSlice: Slice<PostsSlice> = (set, get) => {
},
};
};

const MOCK_CHARACTERS =
"!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
const createMockPostContent = () =>
Array.from({ length: 20 })
.map(
() => MOCK_CHARACTERS[Math.floor(Math.random() * MOCK_CHARACTERS.length)],
)
.join("");
16 changes: 8 additions & 8 deletions src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// import React from "react";
// import ReactDOM from "react-dom/client";
// import { App } from "./App.tsx";
import React from "react";
import ReactDOM from "react-dom/client";
import { App } from "./App.tsx";
import "./style.css";

// ReactDOM.createRoot(document.getElementById("root")!).render(
// <React.StrictMode>
// <App />
// </React.StrictMode>,
// );
ReactDOM.createRoot(document.getElementById("root")!).render(
<React.StrictMode>
<App />
</React.StrictMode>,
);

console.log("%cWarning!", "font-size: 22px; font-weight: bold; color: red;");
console.log(
Expand Down

0 comments on commit fba9345

Please sign in to comment.