From 9df18d7f35ca919d773ad00726feee36fd94367d Mon Sep 17 00:00:00 2001 From: bobbydigitales Date: Mon, 19 May 2025 02:09:50 -0700 Subject: [PATCH] =?UTF-8?q?Limited=20post=20send=20size=20and=20post=20syn?= =?UTF-8?q?cing=20is=20working=20for=20small=20posts=20=F0=9F=98=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/PeerManager.ts | 5 +++++ src/Sync.ts | 23 +++++++++++++++++++++++ src/main2.ts | 8 ++++++-- static/main2.js | 8 ++++++-- 4 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/PeerManager.ts b/src/PeerManager.ts index b4fab62..c086765 100644 --- a/src/PeerManager.ts +++ b/src/PeerManager.ts @@ -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); diff --git a/src/Sync.ts b/src/Sync.ts index 27d7aa0..07e4bbc 100644 --- a/src/Sync.ts +++ b/src/Sync.ts @@ -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) ?? []; diff --git a/src/main2.ts b/src/main2.ts index d2c76b5..93592bd 100644 --- a/src/main2.ts +++ b/src/main2.ts @@ -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(); + } }); diff --git a/static/main2.js b/static/main2.js index e4afbd0..4c22da3 100644 --- a/static/main2.js +++ b/static/main2.js @@ -642,8 +642,12 @@ class App { // return posts; // return postIDs; }); - this.peerManager.registerRPC('sendPostForUser', async (requestingPeerID, userID, post) => { - console.log.apply(null, log(`[app] sendPostForUser to [${logID(requestingPeerID)}] `, userID, post)); + this.peerManager.registerRPC('sendPostForUser', async (userID, post) => { + console.log.apply(null, log(`[app] sendPostForUser`, userID, post)); + await this.sync.writePostForUser(userID, post); + if (userID === this.userID) { + await this.render(); + } }); await this.peerManager.connect(); console.log.apply(null, log("*************** after peerManager.connect"));