bug: filter dms
This commit is contained in:
@ -27,11 +27,16 @@ export default function useLoginFeed() {
|
|||||||
sub.Kinds = new Set([EventKind.ContactList, EventKind.SetMetadata, EventKind.DirectMessage]);
|
sub.Kinds = new Set([EventKind.ContactList, EventKind.SetMetadata, EventKind.DirectMessage]);
|
||||||
|
|
||||||
let notifications = new Subscriptions();
|
let notifications = new Subscriptions();
|
||||||
notifications.Kinds = new Set([EventKind.TextNote, EventKind.DirectMessage]);
|
notifications.Kinds = new Set([EventKind.TextNote]);
|
||||||
notifications.PTags = new Set([pubKey]);
|
notifications.PTags = new Set([pubKey]);
|
||||||
notifications.Limit = 100;
|
notifications.Limit = 100;
|
||||||
sub.AddSubscription(notifications);
|
sub.AddSubscription(notifications);
|
||||||
|
|
||||||
|
let dms = new Subscriptions();
|
||||||
|
dms.Kinds = new Set([EventKind.DirectMessage]);
|
||||||
|
dms.PTags = new Set([pubKey]);
|
||||||
|
sub.AddSubscription(dms);
|
||||||
|
|
||||||
return sub;
|
return sub;
|
||||||
}, [pubKey]);
|
}, [pubKey]);
|
||||||
|
|
||||||
|
@ -54,12 +54,17 @@ export function setLastReadDm(pk: HexKey) {
|
|||||||
window.localStorage.setItem(k, now.toString());
|
window.localStorage.setItem(k, now.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function dmTo(e: RawEvent) {
|
||||||
|
let firstP = e.tags.find(b => b[0] === "p");
|
||||||
|
return firstP ? firstP[1] : "";
|
||||||
|
}
|
||||||
|
|
||||||
export function isToSelf(e: RawEvent, pk: HexKey) {
|
export function isToSelf(e: RawEvent, pk: HexKey) {
|
||||||
return e.pubkey === pk && e.tags.some(a => a[0] === "p" && a[1] === pk);
|
return e.pubkey === pk && dmTo(e) === pk;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function dmsInChat(dms: RawEvent[], pk: HexKey) {
|
export function dmsInChat(dms: RawEvent[], pk: HexKey) {
|
||||||
return dms.filter(a => a.pubkey === pk || a.tags.some(b => b[0] === "p" && b[1] === pk));
|
return dms.filter(a => a.pubkey === pk || dmTo(a) == pk);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function totalUnread(dms: RawEvent[], myPubKey: HexKey) {
|
export function totalUnread(dms: RawEvent[], myPubKey: HexKey) {
|
||||||
@ -78,7 +83,7 @@ function newestMessage(dms: RawEvent[], myPubKey: HexKey, pk: HexKey) {
|
|||||||
|
|
||||||
|
|
||||||
export function extractChats(dms: RawEvent[], myPubKey: HexKey) {
|
export function extractChats(dms: RawEvent[], myPubKey: HexKey) {
|
||||||
const keys = dms.map(a => [a.pubkey, ...a.tags.filter(b => b[0] === "p").map(b => b[1])]).flat();
|
const keys = dms.map(a => [a.pubkey, dmTo(a)]).flat();
|
||||||
const filteredKeys = Array.from(new Set<string>(keys));
|
const filteredKeys = Array.from(new Set<string>(keys));
|
||||||
return filteredKeys.map(a => {
|
return filteredKeys.map(a => {
|
||||||
return {
|
return {
|
||||||
|
Reference in New Issue
Block a user