new notifications design

This commit is contained in:
2023-08-02 18:27:29 +01:00
parent 2adce0ead1
commit f968299f4d
17 changed files with 327 additions and 44 deletions

View File

@ -1,6 +1,14 @@
import { useSyncExternalStore } from "react";
import { Nip4ChatSystem } from "./nip4";
import { EventKind, EventPublisher, NostrEvent, RequestBuilder, SystemInterface, UserMetadata } from "@snort/system";
import {
EventKind,
EventPublisher,
NostrEvent,
RequestBuilder,
SystemInterface,
TaggedRawEvent,
UserMetadata,
} from "@snort/system";
import { unwrap } from "@snort/shared";
import { Chats, GiftsCache } from "Cache";
import { findTag, unixNow } from "SnortUtils";
@ -49,7 +57,7 @@ export interface ChatSystem {
* Create a request for this system to get updates
*/
subscription(id: string): RequestBuilder | undefined;
onEvent(evs: Array<NostrEvent>): Promise<void> | void;
onEvent(evs: readonly TaggedRawEvent[]): Promise<void> | void;
listChats(pk: string): Array<Chat>;
}

View File

@ -1,5 +1,5 @@
import { ExternalStore, FeedCache, dedupe } from "@snort/shared";
import { RequestBuilder, NostrEvent, EventKind, SystemInterface } from "@snort/system";
import { RequestBuilder, NostrEvent, EventKind, SystemInterface, TaggedRawEvent } from "@snort/system";
import { unwrap } from "SnortUtils";
import { Chat, ChatSystem, ChatType, lastReadInChat } from "chat";
@ -31,8 +31,8 @@ export class Nip29ChatSystem extends ExternalStore<Array<Chat>> implements ChatS
return rb;
}
async onEvent(evs: NostrEvent[]) {
const msg = evs.filter(a => a.kind === EventKind.SimpleChatMessage);
async onEvent(evs: readonly TaggedRawEvent[]) {
const msg = evs.filter(a => a.kind === EventKind.SimpleChatMessage && a.tags.some(b => b[0] === "g"));
if (msg.length > 0) {
await this.#cache.bulkSet(msg);
this.notifyChange();

View File

@ -8,8 +8,9 @@ import {
TLVEntryType,
decodeTLV,
encodeTLVEntries,
TaggedNostrEvent,
} from "@snort/system";
import { Chat, ChatSystem, ChatType, inChatWith, lastReadInChat, selfChat } from "chat";
import { Chat, ChatSystem, ChatType, inChatWith, lastReadInChat } from "chat";
import { debug } from "debug";
export class Nip4ChatSystem extends ExternalStore<Array<Chat>> implements ChatSystem {
@ -21,8 +22,8 @@ export class Nip4ChatSystem extends ExternalStore<Array<Chat>> implements ChatSy
this.#cache = cache;
}
async onEvent(evs: Array<NostrEvent>) {
const dms = evs.filter(a => a.kind === EventKind.DirectMessage);
async onEvent(evs: readonly TaggedNostrEvent[]) {
const dms = evs.filter(a => a.kind === EventKind.DirectMessage && a.tags.some(b => b[0] === "p"));
if (dms.length > 0) {
await this.#cache.bulkSet(dms);
this.notifyChange();