interface: screening DMs

This commit is contained in:
Liam Fitzgerald 2021-05-03 16:12:22 +10:00
parent 7a4546c4a1
commit bdf40b9deb
No known key found for this signature in database
GPG Key ID: D390E12C61D1CFFB
4 changed files with 44 additions and 0 deletions

View File

@ -218,6 +218,14 @@ export default class GraphApi extends BaseApi<StoreState> {
});
}
acceptDm(ship: Patp) {
return this.action('dm-hook', 'dm-hook-action', { "accept" : ship });
}
declineDm(ship: Patp) {
return this.action('dm-hook', 'dm-hook-action', { "decline" : ship });
}
addPost(ship: Patp, name: string, post: Post) {
const nodes = {};
nodes[post.index] = {

View File

@ -21,7 +21,38 @@ export const GraphReducer = (json) => {
if(loose) {
reduceState<GraphState, any>(useGraphState, loose, [addNodesLoose]);
}
const dm = _.get(json, 'dm-hook-action', false);
if(dm) {
console.log(dm);
reduceState<GraphState, any>(useGraphState, dm, [
acceptOrRejectDm,
pendings,
setScreen
])
}
};
const acceptOrRejectDm = (json: any, state: GraphState): GraphState => {
const data = _.get(json, 'accept', _.get(json, 'decline', false));
if(data) {
state.pendingDms.delete(data)
}
return state;
}
const pendings = (json: any, state: GraphState): GraphState => {
const data = _.get(json, 'pendings', false);
if(data) {
state.pendingDms = new Set(data);
}
return state;
}
const setScreen = (json: any, state: GraphState): GraphState => {
if('screen' in json) {
state.screening = json.screen;
}
return state;
}
const addNodesLoose = (json: any, state: GraphState): GraphState => {
const data = _.get(json, 'add-nodes', false);

View File

@ -14,6 +14,8 @@ export interface GraphState extends BaseState<GraphState> {
}
};
pendingIndices: Record<string, any>;
pendingDms: Set<string>;
screening: boolean;
graphTimesentMap: Record<string, any>;
// getKeys: () => Promise<void>;
// getTags: () => Promise<void>;
@ -32,6 +34,8 @@ const useGraphState = createState<GraphState>('Graph', {
looseNodes: {},
pendingIndices: {},
graphTimesentMap: {},
pendingDms: new Set(),
screening: false,
// getKeys: async () => {
// const api = useApi();
// const keys = await api.scry({

View File

@ -15,6 +15,7 @@ export default class GlobalSubscription extends BaseSubscription<StoreState> {
this.subscribe('/groups', 'group-store');
this.clearQueue();
this.subscribe('/updates', 'dm-hook');
this.subscribe('/all', 'contact-store');
this.subscribe('/all', 's3-store');
this.subscribe('/keys', 'graph-store');