graph-fe: clone requests, to ensure identical timestamps

This commit is contained in:
Liam Fitzgerald 2021-06-25 17:32:30 +10:00
parent 4ce46da9e3
commit 88265ea314
No known key found for this signature in database
GPG Key ID: D390E12C61D1CFFB
3 changed files with 17 additions and 12 deletions

View File

@ -539,3 +539,7 @@ export function binaryIndexOf(arr: BigInteger[], target: BigInteger): number | u
}
return undefined;
}
export function clone<T>(a: T) {
return JSON.parse(JSON.stringify(a)) as T;
}

View File

@ -250,9 +250,6 @@ export const addNodes = (json, state) => {
post,
resource
) => {
if (!post.hash) {
return [graph, flatGraph, threadGraphs];
}
const timestamp = post['time-sent'];
if (state.graphTimesentMap[resource][timestamp]) {

View File

@ -9,6 +9,7 @@ import airlock from '~/logic/api';
import { addDmMessage, addPost, Content, getDeepOlderThan, getFirstborn, getNewest, getNode, getOlderSiblings, getYoungerSiblings, markPending, Post, addNode, GraphNodePoke } from '@urbit/api/graph';
import { GraphReducer, reduceDm } from '../reducers/graph-update';
import _ from 'lodash';
import { clone } from '../lib/util';
export interface GraphState {
graphs: Graphs;
@ -48,18 +49,20 @@ const useGraphState = createState<GraphState>('Graph', (set, get) => ({
pendingDms: new Set(),
screening: false,
addDmMessage: async (ship: string, contents: Content[]) => {
const promise = airlock.poke(addDmMessage(window.ship, ship, contents));
const { json } = addDmMessage(window.ship, ship, contents);
markPending(json['add-nodes'].nodes);
json['add-nodes'].resource.ship = json['add-nodes'].resource.ship.slice(1);
const poke = addDmMessage(window.ship, ship, contents);
const promise = airlock.poke(poke);
const pending = clone(poke);
markPending(pending.json['add-nodes'].nodes);
pending.json['add-nodes'].resource.ship = pending.json['add-nodes'].resource.ship.slice(1);
GraphReducer({
'graph-update': json
'graph-update': pending.json
});
await promise;
},
addPost: async (ship, name, post) => {
const promise = airlock.thread(addPost(ship, name, post));
const { body } = addPost(ship, name, post);
const thread = addPost(ship, name, post);
const promise = airlock.thread(thread);
const { body } = clone(thread);
markPending(body['add-nodes'].nodes);
body['add-nodes'].resource.ship = body['add-nodes'].resource.ship.slice(1);
GraphReducer({
@ -70,8 +73,9 @@ const useGraphState = createState<GraphState>('Graph', (set, get) => ({
await promise;
},
addNode: async (ship, name, node) => {
const promise = airlock.thread(addNode(ship, name, node));
const { body } = addNode(ship, name, node);
const thread = addNode(ship, name, node);
const promise = airlock.thread(thread);
const { body } = clone(thread);
markPending(body['add-nodes'].nodes);
body['add-nodes'].resource.ship = body['add-nodes'].resource.ship.slice(1);
GraphReducer({