Working single post rendering
This commit is contained in:
20
src/App.ts
20
src/App.ts
@@ -236,9 +236,18 @@ export class App {
|
|||||||
for (let userID of userIDs) {
|
for (let userID of userIDs) {
|
||||||
// console.log.apply(null, log(`[app] announceUsers, got user:${userID} from peer ${sendingPeerID}`));
|
// console.log.apply(null, log(`[app] announceUsers, got user:${userID} from peer ${sendingPeerID}`));
|
||||||
this.sync.addUserPeer(userID, sendingPeerID);
|
this.sync.addUserPeer(userID, sendingPeerID);
|
||||||
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)}]`));
|
const isUserOrPostRoute = (this.router.route & (App.Route.USER | App.Route.POST)) !== 0;
|
||||||
continue;
|
|
||||||
|
if (isUserOrPostRoute) {
|
||||||
|
if (userID !== this.router.userID) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!this.sync.shouldSyncUserID(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)}]`));
|
console.log.apply(null, log(`[app] calling getPostIDsForUser for user [${logID(userID)}] on peer [${logID(sendingPeerID)}]`));
|
||||||
@@ -1091,7 +1100,10 @@ export class App {
|
|||||||
let posts: StoragePost[] = [];
|
let posts: StoragePost[] = [];
|
||||||
|
|
||||||
if (postID) {
|
if (postID) {
|
||||||
posts = await getPostForUser(userID, postID);
|
const post = await getPostForUser(userID, postID);
|
||||||
|
|
||||||
|
posts = post ? [post] : [];
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
posts = await getData(userID, new Date(2022, 8), new Date());
|
posts = await getData(userID, new Date(2022, 8), new Date());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -538,7 +538,7 @@ class PeerConnection {
|
|||||||
private chunkSize = (16 * 1024) - 100;
|
private chunkSize = (16 * 1024) - 100;
|
||||||
messageSuperlog: boolean = false;
|
messageSuperlog: boolean = false;
|
||||||
sendQueueSuperLog: boolean = false;
|
sendQueueSuperLog: boolean = false;
|
||||||
rpcSuperlog: boolean = true;
|
rpcSuperlog: boolean = false;
|
||||||
pendingRPCs: Map<
|
pendingRPCs: Map<
|
||||||
string,
|
string,
|
||||||
{ resolve: Function; reject: Function; functionName: string }
|
{ resolve: Function; reject: Function; functionName: string }
|
||||||
@@ -553,12 +553,7 @@ class PeerConnection {
|
|||||||
static config = {
|
static config = {
|
||||||
iceServers: [
|
iceServers: [
|
||||||
{ urls: "stun:ddln.app" },
|
{ urls: "stun:ddln.app" },
|
||||||
// { urls: "turn:ddln.app", username: "a", credential: "b" },
|
{ urls: "turn:ddln.app", username: "ddln1", credential: "ddln1" },
|
||||||
{ 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" },
|
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
// longMessageQueue: string[] = [];
|
// longMessageQueue: string[] = [];
|
||||||
|
|||||||
@@ -122,7 +122,8 @@ export class Sync {
|
|||||||
'e01eff89-5100-4b35-af4c-1c1bcb007dd0',
|
'e01eff89-5100-4b35-af4c-1c1bcb007dd0',
|
||||||
'194696a2-d850-4bb0-98f7-47416b3d1662',
|
'194696a2-d850-4bb0-98f7-47416b3d1662',
|
||||||
'f6b21eb1-a0ff-435b-8efc-6a3dd70c0dca',
|
'f6b21eb1-a0ff-435b-8efc-6a3dd70c0dca',
|
||||||
'dd1d92aa-aa24-4166-a925-94ba072a9048'
|
'dd1d92aa-aa24-4166-a925-94ba072a9048',
|
||||||
|
'290dbb4f-6ce1-491a-b90d-51d8efcd3d60'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
getFollowing(userID: string): string[] {
|
getFollowing(userID: string): string[] {
|
||||||
|
|||||||
21
src/db.ts
21
src/db.ts
@@ -198,15 +198,28 @@ export async function clearData(userID: string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// TODO - this function can return before the data is stored!
|
||||||
export async function addDataArray(userID: string, array: any[]): Promise<void> {
|
export async function addDataArray(userID: string, array: any[]): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const { db, transaction, store } = await getDBTransactionStore(userID, "readwrite");
|
const { db, transaction, store } = await getDBTransactionStore(userID, "readwrite");
|
||||||
|
|
||||||
|
|
||||||
transaction.onerror = (event: Event) => {
|
|
||||||
console.error('Error in adding data:', event);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
let completionPromise = new Promise<void>((resolve, reject) => {
|
||||||
|
transaction.oncomplete = (event: Event) => {
|
||||||
|
resolve();
|
||||||
|
};
|
||||||
|
|
||||||
|
transaction.onerror = (event: Event) => {
|
||||||
|
console.error('Error in adding data:', event);
|
||||||
|
reject();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// let count = 0;
|
// let count = 0;
|
||||||
|
|
||||||
array.reverse();
|
array.reverse();
|
||||||
@@ -230,6 +243,8 @@ export async function addDataArray(userID: string, array: any[]): Promise<void>
|
|||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return completionPromise;
|
||||||
|
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error in opening database:', error);
|
console.error('Error in opening database:', error);
|
||||||
|
|||||||
@@ -172,9 +172,17 @@ export class App {
|
|||||||
for (let userID of userIDs) {
|
for (let userID of userIDs) {
|
||||||
// console.log.apply(null, log(`[app] announceUsers, got user:${userID} from peer ${sendingPeerID}`));
|
// console.log.apply(null, log(`[app] announceUsers, got user:${userID} from peer ${sendingPeerID}`));
|
||||||
this.sync.addUserPeer(userID, sendingPeerID);
|
this.sync.addUserPeer(userID, sendingPeerID);
|
||||||
if (!(this.sync.shouldSyncUserID(userID) || (this.router.route & (App.Route.USER | App.Route.POST) && userID === this.router.userID))) {
|
const isUserOrPostRoute = (this.router.route & (App.Route.USER | App.Route.POST)) !== 0;
|
||||||
console.log.apply(null, log(`[app] announceUser_rpc_response skipping user[${logID(userID)}] from[${logID(sendingPeerID)}]`));
|
if (isUserOrPostRoute) {
|
||||||
continue;
|
if (userID !== this.router.userID) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (!this.sync.shouldSyncUserID(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)}]`));
|
console.log.apply(null, log(`[app] calling getPostIDsForUser for user [${logID(userID)}] on peer [${logID(sendingPeerID)}]`));
|
||||||
this.statusBar.updatePeerStatus(sendingPeerID, `getPostIDs(${logID(userID)})⬆️`);
|
this.statusBar.updatePeerStatus(sendingPeerID, `getPostIDs(${logID(userID)})⬆️`);
|
||||||
@@ -809,7 +817,8 @@ export class App {
|
|||||||
this.timerStart();
|
this.timerStart();
|
||||||
let posts = [];
|
let posts = [];
|
||||||
if (postID) {
|
if (postID) {
|
||||||
posts = await getPostForUser(userID, postID);
|
const post = await getPostForUser(userID, postID);
|
||||||
|
posts = post ? [post] : [];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
posts = await getData(userID, new Date(2022, 8), new Date());
|
posts = await getData(userID, new Date(2022, 8), new Date());
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -399,7 +399,7 @@ class PeerConnection {
|
|||||||
this.chunkSize = (16 * 1024) - 100;
|
this.chunkSize = (16 * 1024) - 100;
|
||||||
this.messageSuperlog = false;
|
this.messageSuperlog = false;
|
||||||
this.sendQueueSuperLog = false;
|
this.sendQueueSuperLog = false;
|
||||||
this.rpcSuperlog = true;
|
this.rpcSuperlog = false;
|
||||||
this.pendingRPCs = new Map();
|
this.pendingRPCs = new Map();
|
||||||
this.connectionPromise = null;
|
this.connectionPromise = null;
|
||||||
// private makingOffer:boolean = false;
|
// private makingOffer:boolean = false;
|
||||||
@@ -727,12 +727,7 @@ class PeerConnection {
|
|||||||
PeerConnection.config = {
|
PeerConnection.config = {
|
||||||
iceServers: [
|
iceServers: [
|
||||||
{ urls: "stun:ddln.app" },
|
{ urls: "stun:ddln.app" },
|
||||||
// { urls: "turn:ddln.app", username: "a", credential: "b" },
|
{ urls: "turn:ddln.app", username: "ddln1", credential: "ddln1" },
|
||||||
{ 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" },
|
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
//# sourceMappingURL=PeerManager.js.map
|
//# sourceMappingURL=PeerManager.js.map
|
||||||
File diff suppressed because one or more lines are too long
@@ -44,7 +44,8 @@ export class Sync {
|
|||||||
'e01eff89-5100-4b35-af4c-1c1bcb007dd0',
|
'e01eff89-5100-4b35-af4c-1c1bcb007dd0',
|
||||||
'194696a2-d850-4bb0-98f7-47416b3d1662',
|
'194696a2-d850-4bb0-98f7-47416b3d1662',
|
||||||
'f6b21eb1-a0ff-435b-8efc-6a3dd70c0dca',
|
'f6b21eb1-a0ff-435b-8efc-6a3dd70c0dca',
|
||||||
'dd1d92aa-aa24-4166-a925-94ba072a9048'
|
'dd1d92aa-aa24-4166-a925-94ba072a9048',
|
||||||
|
'290dbb4f-6ce1-491a-b90d-51d8efcd3d60'
|
||||||
]);
|
]);
|
||||||
// async getPostIdsForUserHandler(data: any) {
|
// async getPostIdsForUserHandler(data: any) {
|
||||||
// let message = data.message;
|
// let message = data.message;
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
14
static/db.js
14
static/db.js
@@ -147,12 +147,19 @@ export async function clearData(userID) {
|
|||||||
console.error('Error in opening database:', error);
|
console.error('Error in opening database:', error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// TODO - this function can return before the data is stored!
|
||||||
export async function addDataArray(userID, array) {
|
export async function addDataArray(userID, array) {
|
||||||
try {
|
try {
|
||||||
const { db, transaction, store } = await getDBTransactionStore(userID, "readwrite");
|
const { db, transaction, store } = await getDBTransactionStore(userID, "readwrite");
|
||||||
transaction.onerror = (event) => {
|
let completionPromise = new Promise((resolve, reject) => {
|
||||||
console.error('Error in adding data:', event);
|
transaction.oncomplete = (event) => {
|
||||||
};
|
resolve();
|
||||||
|
};
|
||||||
|
transaction.onerror = (event) => {
|
||||||
|
console.error('Error in adding data:', event);
|
||||||
|
reject();
|
||||||
|
};
|
||||||
|
});
|
||||||
// let count = 0;
|
// let count = 0;
|
||||||
array.reverse();
|
array.reverse();
|
||||||
for (let data of array) {
|
for (let data of array) {
|
||||||
@@ -170,6 +177,7 @@ export async function addDataArray(userID, array) {
|
|||||||
// console.log(`Added ${count} posts...`);
|
// console.log(`Added ${count} posts...`);
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
return completionPromise;
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
console.error('Error in opening database:', error);
|
console.error('Error in opening database:', error);
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user