mirror of
https://github.com/urbit/shrub.git
synced 2024-12-19 08:32:39 +03:00
interface: make pending messages work for flat graphs
This commit is contained in:
parent
ae1edbbe2c
commit
8201a3c68b
@ -230,7 +230,7 @@ const addNodes = (json, state) => {
|
|||||||
return graph;
|
return graph;
|
||||||
};
|
};
|
||||||
|
|
||||||
const _killByFuzzyTimestamp = (graph, resource, timestamp) => {
|
const _killByFuzzyTimestamp = (graph, resource, timestamp, isFlat = false) => {
|
||||||
if (state.graphTimesentMap[resource][timestamp]) {
|
if (state.graphTimesentMap[resource][timestamp]) {
|
||||||
const index = state.graphTimesentMap[resource][timestamp];
|
const index = state.graphTimesentMap[resource][timestamp];
|
||||||
|
|
||||||
@ -238,17 +238,23 @@ const addNodes = (json, state) => {
|
|||||||
const indexArr = index.split('/').slice(1).map((ind) => bigInt(ind));
|
const indexArr = index.split('/').slice(1).map((ind) => bigInt(ind));
|
||||||
|
|
||||||
delete state.graphTimesentMap[resource][timestamp];
|
delete state.graphTimesentMap[resource][timestamp];
|
||||||
return _remove(graph, indexArr);
|
|
||||||
|
if (isFlat) {
|
||||||
|
return graph.delete(indexArr);
|
||||||
|
} else {
|
||||||
|
return _remove(graph, indexArr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return graph;
|
return graph;
|
||||||
};
|
};
|
||||||
|
|
||||||
const _removePending = (graph, post, resource) => {
|
const _removePending = (graph, post, resource, isFlat = false) => {
|
||||||
if (!post.hash) { return graph; }
|
if (!post.hash) { return graph; }
|
||||||
|
|
||||||
graph = _killByFuzzyTimestamp(graph, resource, post['time-sent']);
|
graph = _killByFuzzyTimestamp(graph, resource, post['time-sent'], isFlat);
|
||||||
graph = _killByFuzzyTimestamp(graph, resource, post['time-sent'] - 1);
|
graph = _killByFuzzyTimestamp(graph, resource, post['time-sent'] - 1, isFlat);
|
||||||
graph = _killByFuzzyTimestamp(graph, resource, post['time-sent'] + 1);
|
graph = _killByFuzzyTimestamp(graph, resource, post['time-sent'] + 1, isFlat);
|
||||||
|
|
||||||
return graph;
|
return graph;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -280,11 +286,24 @@ const addNodes = (json, state) => {
|
|||||||
indices.forEach((index) => {
|
indices.forEach((index) => {
|
||||||
let node = data.nodes[index];
|
let node = data.nodes[index];
|
||||||
const old = state.graphs[resource].size;
|
const old = state.graphs[resource].size;
|
||||||
state.graphs[resource] = _removePending(
|
|
||||||
state.graphs[resource],
|
if (resource in state.flatGraphs) {
|
||||||
node.post,
|
// TODO: will this cause multiple pending replies to render
|
||||||
resource
|
// in the reply view and thread view? probably
|
||||||
);
|
|
||||||
|
state.flatGraphs[resource] = _removePending(
|
||||||
|
state.flatGraphs[resource],
|
||||||
|
node.post,
|
||||||
|
resource,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
state.graphs[resource] = _removePending(
|
||||||
|
state.graphs[resource],
|
||||||
|
node.post,
|
||||||
|
resource
|
||||||
|
);
|
||||||
|
}
|
||||||
const newSize = state.graphs[resource].size;
|
const newSize = state.graphs[resource].size;
|
||||||
|
|
||||||
if (index.split('/').length === 0) { return; }
|
if (index.split('/').length === 0) { return; }
|
||||||
@ -305,46 +324,13 @@ const addNodes = (json, state) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (resource in state.flatGraphs) {
|
if (resource in state.flatGraphs) {
|
||||||
console.log('flat update', node.post);
|
|
||||||
const _flatKill = (graph, resource, timestamp) => {
|
|
||||||
console.log('flat kill', resource in state.graphTimesentMap);
|
|
||||||
console.log(timestamp, state.graphTimesentMap[resource]);
|
|
||||||
console.log(state.graphTimesentMap[resource][timestamp.toString()]);
|
|
||||||
debugger;
|
|
||||||
if (state.graphTimesentMap[resource][timestamp.toString()]) {
|
|
||||||
console.log('never reach this console log because 312 is undefined');
|
|
||||||
const index = state.graphTimesentMap[resource][timestamp.toString()];
|
|
||||||
|
|
||||||
if (index.split('/').length === 0) { return graph; }
|
|
||||||
const indexArr = index.split('/').slice(1).map((ind) => bigInt(ind));
|
|
||||||
|
|
||||||
delete state.graphTimesentMap[resource][timestamp];
|
|
||||||
return graph.delete(indexArr);
|
|
||||||
}
|
|
||||||
return graph;
|
|
||||||
};
|
|
||||||
|
|
||||||
const _removeFlatPending = (graph, post, resource) => {
|
|
||||||
if (!post.hash) { return graph; }
|
|
||||||
|
|
||||||
graph = _flatKill(graph, resource, post['time-sent']);
|
|
||||||
graph = _flatKill(graph, resource, post['time-sent'] - 1);
|
|
||||||
graph = _flatKill(graph, resource, post['time-sent'] + 1);
|
|
||||||
return graph;
|
|
||||||
};
|
|
||||||
|
|
||||||
state.flatGraphs[resource] = _removeFlatPending(
|
|
||||||
state.flatGraphs[resource],
|
|
||||||
node.post,
|
|
||||||
resource
|
|
||||||
);
|
|
||||||
|
|
||||||
state.flatGraphs[resource] =
|
state.flatGraphs[resource] =
|
||||||
state.flatGraphs[resource].set(indexArr, produce(node, draft => {
|
state.flatGraphs[resource].set(indexArr, produce(node, draft => {
|
||||||
draft.children = mapifyChildren({});
|
draft.children = mapifyChildren({});
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: make pending work here too
|
||||||
let threadKey = indexArr[0].toString();
|
let threadKey = indexArr[0].toString();
|
||||||
if (resource in state.threadGraphs &&
|
if (resource in state.threadGraphs &&
|
||||||
threadKey in state.threadGraphs[resource]) {
|
threadKey in state.threadGraphs[resource]) {
|
||||||
|
Loading…
Reference in New Issue
Block a user