Limited post send size and post syncing is working for small posts 😮

This commit is contained in:
2025-05-19 02:09:50 -07:00
parent d86519cf6b
commit 9df18d7f35
4 changed files with 40 additions and 4 deletions

View File

@@ -707,6 +707,11 @@ class PeerConnection {
this.messageSuperlog && console.log.apply(null, log(`[${logID(this.remotePeerID)}]<-datachannel[${logID(this.peerManager.peerID)}]:`, message.type, message, `message size:${messageJSON.length}`));
if (messageJSON.length > (32 * 1024)) {
this.messageSuperlog && console.log.apply(null, log(`[datachannel] Not sending long message: `, messageJSON.length));
return;
}
this.dataChannel?.send(messageJSON);
// this.onMessage(messageJSON);

View File

@@ -215,6 +215,29 @@ export class Sync {
// console.log.apply(null, log(`getPostsForUser`,output));
}
async writePostForUser(userID:string, post:any) {
// HACK: Some posts have insanely large images, so I'm gonna skip them.
// Once we support delete then we we could delete these posts in a sensible way.
if (this.postBlockList.has(post.post_id)) {
console.log.apply(null, log(`Skipping blocked post: ${post.post_id}`));;
return;
}
// HACK - some posts had the wrong author ID
if (userID === this.userID) {
post.author_id = this.userID;
}
post.post_timestamp = new Date(post.post_timestamp);
if (post.image_data) {
post.image_data = await base64ToArrayBuffer(post.image_data);
}
console.log.apply(null, log(`Merging same user peer posts...`));
await mergeDataArray(userID, [post]);
}
// async getPostIdsForUserHandler(data: any) {
// let message = data.message;
// let postIds = await getAllIds(message.user_id) ?? [];

View File

@@ -834,8 +834,12 @@ class App {
// return postIDs;
});
this.peerManager.registerRPC('sendPostForUser', async (requestingPeerID:string, userID:string, post:string) => {
console.log.apply(null, log(`[app] sendPostForUser to [${logID(requestingPeerID)}] `, userID, post));
this.peerManager.registerRPC('sendPostForUser', async (userID:string, post:string) => {
console.log.apply(null, log(`[app] sendPostForUser`, userID, post));
await this.sync.writePostForUser(userID, post);
if (userID === this.userID) {
await this.render();
}
});