forked from Kieran/snort
Merge pull request #86 from 13x-tech/fix/allow-self-dms
filter for self dms
This commit is contained in:
commit
3fb1350e39
@ -10,7 +10,7 @@ import useEventPublisher from "../feed/EventPublisher";
|
|||||||
|
|
||||||
import DM from "../element/DM";
|
import DM from "../element/DM";
|
||||||
import { RawEvent } from "../nostr";
|
import { RawEvent } from "../nostr";
|
||||||
import { dmsInChat } from "./MessagesPage";
|
import { dmsInChat, isToSelf } from "./MessagesPage";
|
||||||
|
|
||||||
type RouterParams = {
|
type RouterParams = {
|
||||||
id: string
|
id: string
|
||||||
@ -20,13 +20,14 @@ export default function ChatPage() {
|
|||||||
const params = useParams<RouterParams>();
|
const params = useParams<RouterParams>();
|
||||||
const publisher = useEventPublisher();
|
const publisher = useEventPublisher();
|
||||||
const id = bech32ToHex(params.id ?? "");
|
const id = bech32ToHex(params.id ?? "");
|
||||||
|
const pubKey = useSelector<any>(s => s.login.publicKey);
|
||||||
const dms = useSelector<any, RawEvent[]>(s => filterDms(s.login.dms));
|
const dms = useSelector<any, RawEvent[]>(s => filterDms(s.login.dms));
|
||||||
const [content, setContent] = useState<string>();
|
const [content, setContent] = useState<string>();
|
||||||
const { ref, inView, entry } = useInView();
|
const { ref, inView, entry } = useInView();
|
||||||
const dmListRef = useRef<HTMLDivElement>(null);
|
const dmListRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
function filterDms(dms: RawEvent[]) {
|
function filterDms(dms: RawEvent[]) {
|
||||||
return dmsInChat(dms, id);
|
return dmsInChat(id === pubKey ? dms.filter(d => isToSelf(d, pubKey)) : dms, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
const sortedDms = useMemo<any[]>(() => {
|
const sortedDms = useMemo<any[]>(() => {
|
||||||
|
@ -92,6 +92,10 @@ function unreadDms(dms: RawEvent[], myPubKey: HexKey, pk: HexKey) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function newestMessage(dms: RawEvent[], myPubKey: HexKey, pk: HexKey) {
|
function newestMessage(dms: RawEvent[], myPubKey: HexKey, pk: HexKey) {
|
||||||
|
if(pk === myPubKey) {
|
||||||
|
return dmsInChat(dms.filter(d => isToSelf(d, myPubKey)), pk).reduce((acc, v) => acc = v.created_at > acc ? v.created_at : acc, 0);
|
||||||
|
}
|
||||||
|
|
||||||
return dmsInChat(dms, pk).reduce((acc, v) => acc = v.created_at > acc ? v.created_at : acc, 0);
|
return dmsInChat(dms, pk).reduce((acc, v) => acc = v.created_at > acc ? v.created_at : acc, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user