interface: fix deleting DM messages

Fixes urbit/landscape#1050
This commit is contained in:
Liam Fitzgerald 2021-07-12 13:13:16 +10:00
parent 5602a19cbd
commit 1704fe5039
No known key found for this signature in database
GPG Key ID: D390E12C61D1CFFB
3 changed files with 35 additions and 19 deletions

View File

@ -405,26 +405,17 @@ export const addNodes = (json, state) => {
const removePosts = (json, state: GraphState): GraphState => {
const _remove = (graph, index) => {
const child = graph.get(index[0]);
if(!child) {
return graph;
}
if (index.length === 1) {
if (child) {
return graph.set(index[0], {
post: child.post.hash || '',
children: child.children
});
}
return graph.set(index[0], {
post: child.post.hash || '',
children: child.children
});
} else {
if (child) {
_remove(child.children, index.slice(1));
return graph.set(index[0], child);
} else {
const child = graph.get(index[0]);
if (child) {
return graph.set(index[0], produce((draft: any) => {
draft.children = _remove(draft.children, index.slice(1));
}));
}
return graph;
}
const node = { ...child, children: _remove(child.children, index.slice(1)) };
return graph.set(index[0], node);
}
};

View File

@ -1,4 +1,4 @@
import { cite, Content, Post } from '@urbit/api';
import { cite, Content, Post, removeDmMessage } from '@urbit/api';
import React, { useCallback, useEffect } from 'react';
import _ from 'lodash';
import bigInt from 'big-integer';
@ -11,6 +11,7 @@ import useHarkState, { useHarkDm } from '~/logic/state/hark';
import useSettingsState, { selectCalmState } from '~/logic/state/settings';
import { ChatPane } from './components/ChatPane';
import shallow from 'zustand/shallow';
import airlock from '~/logic/api';
interface DmResourceProps {
ship: string;
@ -121,6 +122,9 @@ export function DmResource(props: DmResourceProps) {
[ship, addDmMessage]
);
const onDelete = useCallback((msg: Post) => {
airlock.poke(removeDmMessage(`~${window.ship}`, msg.index));
}, []);
return (
<Col width="100%" height="100%" overflow="hidden">
<Row
@ -169,6 +173,7 @@ export function DmResource(props: DmResourceProps) {
onReply={quoteReply}
fetchMessages={fetchMessages}
dismissUnread={dismissUnread}
onDelete={onDelete}
getPermalink={() => undefined}
isAdmin={false}
onSubmit={onSubmit}

View File

@ -336,6 +336,26 @@ export const removePosts = (
}
});
/**
* Remove a DM message from our inbox
*
* @remarks
* This does not remove the message from the recipients inbox
*/
export const removeDmMessage = (
our: Patp,
index: string
): Poke<any> => ({
app: 'graph-store',
mark: `graph-update-${GRAPH_UPDATE_VERSION}`,
json: {
'remove-posts': {
resource: { ship: our, name: 'dm-inbox' },
indices: [index]
}
}
});
/**
* Send a DM to a ship
*