working on showing single posts for users we dont know about

This commit is contained in:
2025-12-31 07:11:35 +00:00
parent 0b82283622
commit bac14446bb
17 changed files with 127 additions and 74 deletions

View File

@@ -1,7 +1,7 @@
import { generateID } from "IDUtils";
import { PeerManager, PeerEventTypes } from "PeerManager";
import { Sync } from "Sync";
import { openDatabase, getData, addData, addDataArray, clearData, deleteData, mergeDataArray, getAllData, checkPostIds, getAllIds, getPostsByIds } from "db";
import { openDatabase, getData, addData, addDataArray, clearData, deleteData, mergeDataArray, getAllData, checkPostIds, getAllIds, getPostsByIds, getPostForUser } from "db";
import { arrayBufferToBase64, compressString } from "dataUtils";
import { log, logID, renderLog, setLogVisibility } from "log"
@@ -189,7 +189,7 @@ export class App {
let neededPostCount = neededPostIDs.length;
this.statusBar.updatePeerStatus(peerID, `need(${logID(userID)} | ${neededPostCount})`, { havePostCount: 0, neededPostCount: neededPostCount });
let neededPosts = await this.peerManager?.rpc.getPostsForUser(peerID, this.peerID, userID, neededPostIDs);
await this.peerManager?.rpc.getPostsForUser(peerID, this.peerID, userID, neededPostIDs);
}
else {
console.log.apply(null, log(`[app] Don't need any posts for user ${logID(userID)} from peer ${logID(peerID)}`));
@@ -236,7 +236,7 @@ export class App {
for (let userID of userIDs) {
// console.log.apply(null, log(`[app] announceUsers, got user:${userID} from peer ${sendingPeerID}`));
this.sync.addUserPeer(userID, sendingPeerID);
if (!(this.sync.shouldSyncUserID(userID) || (this.router.route === App.Route.USER && userID === this.router.userID))) {
if (!(this.sync.shouldSyncUserID(userID) || (this.router.route & (App.Route.USER | App.Route.POST) && userID === this.router.userID))) {
console.log.apply(null, log(`[app] announceUser_rpc_response skipping user[${logID(userID)}] from[${logID(sendingPeerID)}]`));
continue;
}
@@ -244,7 +244,17 @@ export class App {
console.log.apply(null, log(`[app] calling getPostIDsForUser for user [${logID(userID)}] on peer [${logID(sendingPeerID)}]`));
this.statusBar.updatePeerStatus(sendingPeerID, `getPostIDs(${logID(userID)})⬆️`);
let postIDs = await this.peerManager?.rpc.getPostIDsForUser(sendingPeerID, userID);
let postIDs = null;
if (this.router.route === App.Route.POST && this.router.userID == userID) {
postIDs = [this.router.postID];
} else {
postIDs = await this.peerManager?.rpc.getPostIDsForUser(sendingPeerID, userID);
}
if (!postIDs) {
continue;
}
this.statusBar.updatePeerStatus(sendingPeerID, `syncing(${logID(userID)} ${postIDs.length})`);
@@ -306,6 +316,8 @@ export class App {
if (postIDs) {
return postIDs;
}
return [];
});
this.peerManager.registerRPC('getPostsForUser', async (requestingPeerID: string, userID: string, postIDs: string[]) => {
@@ -1078,17 +1090,20 @@ export class App {
this.timerStart();
let posts: StoragePost[] = [];
// if (postID) {
// posts = await gePostForUser(userID, postID);
// }
if (postID) {
posts = await getPostForUser(userID, postID);
} else {
posts = await getData(userID, new Date(2022, 8), new Date());
}
posts = await getData(userID, new Date(2022, 8), new Date());
if (posts.length > 0) {
if (posts?.length) {
console.log.apply(null, log(`Loaded ${posts.length} posts in ${this.timerDelta().toFixed(2)}ms`));;
return posts;
}
console.log.apply(null, log(`No posts found for userID:${userID}, postID:${postID}`));;
// posts = await createTestData2(userID);
// log("Adding test data...");
@@ -1602,11 +1617,11 @@ export class App {
export namespace App {
export enum Route {
USER,
POST,
MEDIA,
GROUP,
HOME,
CONNECT,
USER = 1,
POST = 2,
MEDIA = 4,
GROUP = 8,
HOME = 16,
CONNECT = 32,
}
};