working on showing single posts for users we dont know about
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { generateID } from "IDUtils";
|
||||
import { PeerManager, PeerEventTypes } from "PeerManager";
|
||||
import { Sync } from "Sync";
|
||||
import { openDatabase, getData, addData, deleteData, getAllData } from "db";
|
||||
import { openDatabase, getData, addData, deleteData, getAllData, getPostForUser } from "db";
|
||||
import { arrayBufferToBase64, compressString } from "dataUtils";
|
||||
import { log, logID, renderLog, setLogVisibility } from "log";
|
||||
class Post {
|
||||
@@ -139,7 +139,7 @@ export class App {
|
||||
console.log.apply(null, log(`[app] Need (${neededPostIDs.length}) posts for user ${logID(userID)} from peer ${logID(peerID)}`));
|
||||
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)}`));
|
||||
@@ -172,13 +172,22 @@ 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;
|
||||
}
|
||||
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})`);
|
||||
console.log.apply(null, log(`[app] Got (${postIDs.length}) post IDs for user [${logID(userID)}] from peer [${logID(sendingPeerID)}]`));
|
||||
this.addPostIDsToSyncQueue(userID, sendingPeerID, postIDs);
|
||||
@@ -223,6 +232,7 @@ export class App {
|
||||
if (postIDs) {
|
||||
return postIDs;
|
||||
}
|
||||
return [];
|
||||
});
|
||||
this.peerManager.registerRPC('getPostsForUser', async (requestingPeerID, userID, postIDs) => {
|
||||
let posts = await this.sync.getPostsForUser(userID, postIDs);
|
||||
@@ -798,15 +808,19 @@ export class App {
|
||||
async loadPostsFromStorage(userID, postID) {
|
||||
this.timerStart();
|
||||
let posts = [];
|
||||
// if (postID) {
|
||||
// posts = await gePostForUser(userID, postID);
|
||||
// }
|
||||
posts = await getData(userID, new Date(2022, 8), new Date());
|
||||
if (posts.length > 0) {
|
||||
if (postID) {
|
||||
posts = await getPostForUser(userID, postID);
|
||||
}
|
||||
else {
|
||||
posts = await getData(userID, new Date(2022, 8), new Date());
|
||||
}
|
||||
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...");
|
||||
// addDataArray(userID, posts);
|
||||
@@ -1174,12 +1188,12 @@ export class App {
|
||||
(function (App) {
|
||||
let Route;
|
||||
(function (Route) {
|
||||
Route[Route["USER"] = 0] = "USER";
|
||||
Route[Route["POST"] = 1] = "POST";
|
||||
Route[Route["MEDIA"] = 2] = "MEDIA";
|
||||
Route[Route["GROUP"] = 3] = "GROUP";
|
||||
Route[Route["HOME"] = 4] = "HOME";
|
||||
Route[Route["CONNECT"] = 5] = "CONNECT";
|
||||
Route[Route["USER"] = 1] = "USER";
|
||||
Route[Route["POST"] = 2] = "POST";
|
||||
Route[Route["MEDIA"] = 4] = "MEDIA";
|
||||
Route[Route["GROUP"] = 8] = "GROUP";
|
||||
Route[Route["HOME"] = 16] = "HOME";
|
||||
Route[Route["CONNECT"] = 32] = "CONNECT";
|
||||
})(Route = App.Route || (App.Route = {}));
|
||||
})(App || (App = {}));
|
||||
;
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -399,7 +399,7 @@ class PeerConnection {
|
||||
this.chunkSize = (16 * 1024) - 100;
|
||||
this.messageSuperlog = false;
|
||||
this.sendQueueSuperLog = false;
|
||||
this.rpcSuperlog = false;
|
||||
this.rpcSuperlog = true;
|
||||
this.pendingRPCs = new Map();
|
||||
this.connectionPromise = null;
|
||||
// private makingOffer:boolean = false;
|
||||
@@ -730,9 +730,9 @@ PeerConnection.config = {
|
||||
// { urls: "turn:ddln.app", username: "a", credential: "b" },
|
||||
{ urls: "stun:stun.l.google.com" }, // keeping this for now as my STUN server is not returning ipv6
|
||||
{ urls: "stun:stun1.l.google.com" },
|
||||
{ urls: "stun:stun2.l.google.com" },
|
||||
{ urls: "stun:stun3.l.google.com" },
|
||||
{ urls: "stun:stun4.l.google.com" },
|
||||
//{ urls: "stun:stun2.l.google.com" },
|
||||
//{ urls: "stun:stun3.l.google.com" },
|
||||
//{ urls: "stun:stun4.l.google.com" },
|
||||
],
|
||||
};
|
||||
//# sourceMappingURL=PeerManager.js.map
|
||||
File diff suppressed because one or more lines are too long
@@ -34,5 +34,28 @@
|
||||
"protocol": "web+ddln",
|
||||
"url": "/%s"
|
||||
}
|
||||
]
|
||||
],
|
||||
"share_target": {
|
||||
"action": "/share-target",
|
||||
"method": "POST",
|
||||
"enctype": "multipart/form-data",
|
||||
"params": {
|
||||
"title": "name",
|
||||
"text": "text",
|
||||
"url": "link",
|
||||
"files": [
|
||||
{
|
||||
"name": "photos",
|
||||
"accept": [
|
||||
"image/svg+xml",
|
||||
".svg",
|
||||
".jpg",
|
||||
".jpeg",
|
||||
".png",
|
||||
".gif"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,7 @@ export async function compressString(input) {
|
||||
// Read the compressed data from the stream
|
||||
const compressedArray = await new Response(compressionStream.readable).arrayBuffer();
|
||||
// Convert the compressed data to a Uint8Array
|
||||
return new Uint8Array(compressedArray);
|
||||
return compressedArray;
|
||||
}
|
||||
// Base58 character set
|
||||
// const BASE58_ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"version":3,"file":"dataUtils.js","sourceRoot":"","sources":["../src/dataUtils.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,KAAiB,EAAE,IAAI,GAAG,0BAA0B;IAC7F,OAAO,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC3C,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,UAAU,EAAE,EAAE;YAC7C,MAAM,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC;YACpC,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;SACpC,CAAC,CAAC;QACH,MAAM,CAAC,aAAa,CAAC,IAAI,IAAI,CAAC,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,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IAChD,qCAAqC;IACrC,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC;IACtC,MAAM,UAAU,GAAG,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAE7C,6BAA6B;IAC7B,MAAM,iBAAiB,GAAG,IAAI,iBAAiB,CAAC,MAAM,CAAC,CAAC;IACxD,MAAM,MAAM,GAAG,iBAAiB,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC;IAEtD,sCAAsC;IACtC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACzB,MAAM,CAAC,KAAK,EAAE,CAAC;IAEf,2CAA2C;IAC3C,MAAM,eAAe,GAAG,MAAM,IAAI,QAAQ,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE,CAAC;IAErF,8CAA8C;IAC9C,OAAO,eAAe,CAAC;AACzB,CAAC;AAED,uBAAuB;AACvB,wFAAwF;AACxF,kBAAkB;AAClB,kBAAkB;AAClB,sDAAsD;AACtD,eAAe;AACf,wBAAwB;AAExB,iCAAiC;AACjC,oBAAoB;AACpB,gDAAgD;AAChD,iCAAiC;AACjC,gCAAgC;AAChC,wCAAwC;AACxC,QAAQ;AACR,0BAA0B;AAC1B,iCAAiC;AACjC,wCAAwC;AACxC,QAAQ;AACR,MAAM;AAEN,qBAAqB;AACrB,4CAA4C;AAC5C,wCAAwC;AACxC,MAAM;AAEN,iCAAiC;AACjC,iCAAiC;AACjC,2BAA2B;AAC3B,8CAA8C;AAC9C,eAAe;AACf,eAAe;AACf,QAAQ;AACR,MAAM;AAEN,mBAAmB;AACnB,IAAI;AAEJ,4BAA4B;AAC5B,gDAAgD;AAChD,qCAAqC;AACrC,gCAAgC;AAChC,IAAI"}
|
||||
12
static/db.js
12
static/db.js
@@ -260,6 +260,18 @@ export async function mergeDataArray(userID, array) {
|
||||
}
|
||||
}
|
||||
export async function getPostForUser(userID, postID) {
|
||||
const { store } = await getDBTransactionStore(userID);
|
||||
const index = store.index("postIDIndex");
|
||||
return new Promise((resolve, reject) => {
|
||||
const getPostRequest = index.get(postID);
|
||||
getPostRequest.onsuccess = () => {
|
||||
resolve(getPostRequest.result);
|
||||
};
|
||||
getPostRequest.onerror = () => {
|
||||
console.error('Transaction failed:', getPostRequest.error?.message);
|
||||
reject(getPostRequest.error);
|
||||
};
|
||||
});
|
||||
}
|
||||
export async function getData(userID, lowerID, upperID) {
|
||||
const { store } = await getDBTransactionStore(userID);
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user