Merge pull request #5089 from urbit/lf/remove-posts

interface: fix removing posts
This commit is contained in:
matildepark 2021-07-07 21:09:09 -04:00 committed by GitHub
commit fcf78f2d6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 25 deletions

View File

@ -1,17 +1,16 @@
import _ from 'lodash';
import { GroupPolicy, makeResource, Resource, resourceFromPath } from '../groups';
import { decToUd, deSig, unixToDa, Scry } from '../lib';
import { Enc, Path, Patp, PatpNoSig, Poke, Thread } from '../lib/types';
import { Content, Graph, GraphChildrenPoke, GraphNode, GraphNodePoke, Post } from './types';
import { Content, GraphChildrenPoke, GraphNode, GraphNodePoke, Post } from './types';
import { patp2dec } from 'urbit-ob';
export const GRAPH_UPDATE_VERSION: number = 2;
export const GRAPH_UPDATE_VERSION = 2;
export const createBlankNodeWithChildPost = (
ship: PatpNoSig,
parentIndex: string = '',
childIndex: string = '',
parentIndex = '',
childIndex = '',
contents: Content[]
): GraphNodePoke => {
const date = unixToDa(Date.now()).toString();
@ -57,8 +56,8 @@ export const markPending = (nodes: any): any => {
export const createPost = (
ship: PatpNoSig,
contents: Content[],
parentIndex: string = '',
childIndex:string = 'DATE_PLACEHOLDER'
parentIndex = '',
childIndex = 'DATE_PLACEHOLDER'
): Post => {
if (childIndex === 'DATE_PLACEHOLDER') {
childIndex = unixToDa(Date.now()).toString();
@ -117,7 +116,6 @@ const dmAction = <T>(data: T): Poke<T> => ({
export { hookAction as graphHookAction };
export const createManagedGraph = (
ship: PatpNoSig,
name: string,
@ -139,7 +137,7 @@ export const createManagedGraph = (
mark: moduleToMark(mod)
}
});
}
};
export const createUnmanagedGraph = (
ship: PatpNoSig,
@ -165,7 +163,7 @@ export const joinGraph = (
): Thread<any> => viewAction('graph-join', {
join: {
resource: makeResource(ship, name),
ship,
ship
}
});
@ -173,7 +171,7 @@ export const deleteGraph = (
ship: PatpNoSig,
name: string
): Thread<any> => viewAction('graph-delete', {
"delete": {
'delete': {
resource: makeResource(`~${ship}`, name)
}
});
@ -182,7 +180,7 @@ export const leaveGraph = (
ship: Patp,
name: string
): Thread<any> => viewAction('graph-leave', {
"leave": {
'leave': {
resource: makeResource(ship, name)
}
});
@ -201,7 +199,7 @@ export const groupifyGraph = (
to
}
});
}
};
export const evalCord = (
cord: string
@ -214,7 +212,7 @@ export const evalCord = (
eval: cord
}
});
}
};
export const addGraph = (
ship: Patp,
@ -229,7 +227,7 @@ export const addGraph = (
mark
}
});
}
};
export const addNodes = (
ship: Patp,
@ -252,24 +250,24 @@ export const addPost = (
name: string,
post: Post
): Thread<any> => {
let nodes: Record<string, GraphNode> = {};
const nodes: Record<string, GraphNode> = {};
nodes[post.index] = {
post,
children: null
};
return addNodes(ship, name, nodes);
}
};
export const addNode = (
ship: Patp,
name: string,
node: GraphNodePoke
): Thread<any> => {
let nodes: Record<string, GraphNodePoke> = {};
const nodes: Record<string, GraphNodePoke> = {};
nodes[node.post.index] = node;
return addNodes(ship, name, nodes);
}
};
export const createGroupFeed = (
group: Resource,
@ -332,7 +330,7 @@ export const removePosts = (
name: string,
indices: string[]
): Poke<any> => hookAction({
'remove-nodes': {
'remove-posts': {
resource: { ship, name },
indices
}
@ -363,8 +361,7 @@ export const addDmMessage = (our: PatpNoSig, ship: Patp, contents: Content[]): P
}
}
};
}
};
const encodeIndex = (idx: string) => idx.split('/').map(decToUd).join('/');
@ -436,7 +433,6 @@ export const getShallowChildren = (ship: string, name: string, index = '') => ({
path: `/shallow-children/${ship}/${name}${encodeIndex(index)}`
});
/**
* Fetch newest nodes in a graph as a flat map, including children,
* optionally starting at a specified key
@ -457,7 +453,6 @@ export const getDeepOlderThan = (
path: `/deep-nodes-older-than/${ship}/${name}/${count}/${start ? decToUd(start) : 'null'}`
});
/**
* Fetch a flat map of a nodes ancestors and firstborn children
*

View File

@ -195,7 +195,10 @@ module.exports = {
"sourceType": "module"
},
"plugins": ["@typescript-eslint"],
"rules": rules
"rules": {
...rules,
"valid-jsdoc": "off"
}
}
]
};

View File

@ -214,6 +214,7 @@ export class Urbit {
if (data.hasOwnProperty('ok')) {
funcs.onSuccess();
} else if (data.hasOwnProperty('err')) {
console.error(data.err);
funcs.onError(data.err);
} else {
console.error('Invalid poke response', data);
@ -223,6 +224,7 @@ export class Urbit {
(data.response === 'poke' && this.outstandingSubscriptions.has(data.id))) {
const funcs = this.outstandingSubscriptions.get(data.id);
if (data.hasOwnProperty('err')) {
console.error(data.err);
funcs.err(data.err, data.id);
this.outstandingSubscriptions.delete(data.id);
}