mirror of
https://github.com/BlowaterNostr/blowater.git
synced 2024-10-18 15:43:20 +00:00
remove kind-1 related code (#203)
This commit is contained in:
parent
7d251ed93c
commit
de889d8317
@ -12,9 +12,8 @@ import { ConversationLists, ConversationSummary } from "./conversation-list.ts";
|
||||
import { new_DM_EditorModel } from "./editor.tsx";
|
||||
import { initialModel, Model } from "./app_model.ts";
|
||||
import { AppEventBus, Database_Update, UI_Interaction_Event, UI_Interaction_Update } from "./app_update.tsx";
|
||||
import { getSocialPosts } from "../features/social.ts";
|
||||
import * as time from "../time.ts";
|
||||
import { PrivateKey, PublicKey } from "../lib/nostr-ts/key.ts";
|
||||
import { PublicKey } from "../lib/nostr-ts/key.ts";
|
||||
import { NostrAccountContext, NostrEvent, NostrKind } from "../lib/nostr-ts/nostr.ts";
|
||||
import { ConnectionPool } from "../lib/nostr-ts/relay.ts";
|
||||
import { getCurrentSignInCtx, setSignInState, SignIn } from "./signIn.tsx";
|
||||
@ -24,8 +23,7 @@ import { EventSyncer } from "./event_syncer.ts";
|
||||
import { defaultRelays, RelayConfig } from "./relay-config.ts";
|
||||
import { DexieDatabase } from "./dexie-db.ts";
|
||||
import { About } from "./about.tsx";
|
||||
import { SocialPanel } from "./social.tsx";
|
||||
import { getProfileEvent, ProfilesSyncer } from "../features/profile.ts";
|
||||
import { ProfilesSyncer } from "../features/profile.ts";
|
||||
import { Popover, PopOverInputChannel } from "./components/popover.tsx";
|
||||
import { Channel } from "https://raw.githubusercontent.com/BlowaterNostr/csp/master/csp.ts";
|
||||
import { GroupChatController } from "../group-chat.ts";
|
||||
@ -194,9 +192,6 @@ export class App {
|
||||
}
|
||||
})(this.database, this.ctx, this.pool);
|
||||
|
||||
console.log("App allUsersInfo");
|
||||
this.model.social.threads = getSocialPosts(this.database, this.conversationLists.convoSummaries);
|
||||
|
||||
/* my profile */
|
||||
this.model.myProfile = this.conversationLists.convoSummaries.get(this.ctx.publicKey.hex)?.profile
|
||||
?.profile;
|
||||
|
@ -1,14 +1,10 @@
|
||||
import { PublicKey } from "../lib/nostr-ts/key.ts";
|
||||
import { NostrEvent, NostrFilters } from "../lib/nostr-ts/nostr.ts";
|
||||
|
||||
import { DM_EditorModel, new_Social_EditorModel, Social_EditorModel } from "./editor.tsx";
|
||||
import { DM_EditorModel } from "./editor.tsx";
|
||||
import { NavigationModel } from "./nav.tsx";
|
||||
import { SearchInitModel, SearchModel } from "./search_model.ts";
|
||||
import { ProfileData } from "../features/profile.ts";
|
||||
import { RightPanelModel } from "./message-panel.tsx";
|
||||
import { DM_Model } from "./dm.ts";
|
||||
import { App } from "./app.tsx";
|
||||
import { MessageThread } from "./dm.tsx";
|
||||
import { SignInModel } from "./signIn.tsx";
|
||||
|
||||
export type Model = {
|
||||
@ -24,21 +20,6 @@ export type Model = {
|
||||
value: string;
|
||||
};
|
||||
|
||||
// social
|
||||
social: {
|
||||
threads: MessageThread[];
|
||||
editor: Social_EditorModel;
|
||||
replyEditors: Map<string, Social_EditorModel>;
|
||||
focusedContent: NostrEvent /* thread root event */ | PublicKey /* focused user profile */ | undefined;
|
||||
filter: {
|
||||
content: string;
|
||||
pubkeys: string[];
|
||||
author: Set<string>;
|
||||
adding_author: string;
|
||||
};
|
||||
activeSyncingFilter: NostrFilters | undefined;
|
||||
};
|
||||
|
||||
// UI
|
||||
navigationModel: NavigationModel;
|
||||
rightPanelModel: RightPanelModel;
|
||||
@ -64,19 +45,6 @@ export function initialModel(): Model {
|
||||
key: "",
|
||||
value: "",
|
||||
},
|
||||
social: {
|
||||
threads: [],
|
||||
editor: new_Social_EditorModel(),
|
||||
replyEditors: new Map<string, Social_EditorModel>(),
|
||||
focusedContent: undefined,
|
||||
filter: {
|
||||
content: "",
|
||||
pubkeys: [],
|
||||
author: new Set(),
|
||||
adding_author: "",
|
||||
},
|
||||
activeSyncingFilter: undefined,
|
||||
},
|
||||
navigationModel: {
|
||||
activeNav: "DM",
|
||||
},
|
||||
|
@ -19,13 +19,7 @@ import { notify } from "./notification.ts";
|
||||
import { emitFunc, EventBus } from "../event-bus.ts";
|
||||
import { ContactUpdate } from "./conversation-list.tsx";
|
||||
import { MyProfileUpdate } from "./edit-profile.tsx";
|
||||
import {
|
||||
DM_EditorModel,
|
||||
EditorEvent,
|
||||
new_DM_EditorModel,
|
||||
SendMessage,
|
||||
Social_EditorModel,
|
||||
} from "./editor.tsx";
|
||||
import { DM_EditorModel, EditorEvent, new_DM_EditorModel, SendMessage } from "./editor.tsx";
|
||||
import { DirectMessagePanelUpdate } from "./message-panel.tsx";
|
||||
import { NavigationUpdate } from "./nav.tsx";
|
||||
import { Model } from "./app_model.ts";
|
||||
@ -44,8 +38,6 @@ import {
|
||||
} from "../nostr.ts";
|
||||
import { MessageThread } from "./dm.tsx";
|
||||
import { DexieDatabase } from "./dexie-db.ts";
|
||||
import { getSocialPosts } from "../features/social.ts";
|
||||
import { SocialUpdates } from "./social.tsx";
|
||||
import { RelayConfigChange } from "./setting.tsx";
|
||||
import { PopOverInputChannel } from "./components/popover.tsx";
|
||||
import { Search } from "./search.tsx";
|
||||
@ -69,7 +61,6 @@ export type UI_Interaction_Event =
|
||||
| PinContact
|
||||
| UnpinContact
|
||||
| SignInEvent
|
||||
| SocialUpdates
|
||||
| RelayConfigChange
|
||||
| CreateGroupChat
|
||||
| StartCreateGroupChat;
|
||||
@ -216,8 +207,6 @@ export async function* UI_Interaction_Update(args: {
|
||||
app.lamport,
|
||||
pool,
|
||||
app.model.editors,
|
||||
app.model.social.editor,
|
||||
app.model.social.replyEditors,
|
||||
app.database,
|
||||
);
|
||||
if (err instanceof Error) {
|
||||
@ -233,17 +222,6 @@ export async function* UI_Interaction_Update(args: {
|
||||
console.log(event.target.receiver, event.id);
|
||||
throw new Error("impossible state");
|
||||
}
|
||||
} else {
|
||||
if (event.id == "social") {
|
||||
model.social.editor.files = event.files;
|
||||
} else {
|
||||
const editor = model.social.replyEditors.get(event.id);
|
||||
if (editor) {
|
||||
editor.files = event.files;
|
||||
} else {
|
||||
throw new Error("impossible state");
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (event.type == "UpdateMessageText") {
|
||||
if (event.target.kind == NostrKind.DIRECT_MESSAGE) {
|
||||
@ -254,17 +232,6 @@ export async function* UI_Interaction_Update(args: {
|
||||
console.log(event.target.receiver, event.id);
|
||||
throw new Error("impossible state");
|
||||
}
|
||||
} else {
|
||||
if (event.id == "social") {
|
||||
model.social.editor.text = event.text;
|
||||
} else {
|
||||
const editor = model.social.replyEditors.get(event.id);
|
||||
if (editor) {
|
||||
editor.text = event.text;
|
||||
} else {
|
||||
throw new Error("impossible state");
|
||||
}
|
||||
}
|
||||
}
|
||||
} //
|
||||
//
|
||||
@ -344,10 +311,7 @@ export async function* UI_Interaction_Update(args: {
|
||||
root = res;
|
||||
}
|
||||
|
||||
if (root.kind == NostrKind.TEXT_NOTE) {
|
||||
// model.navigationModel.activeNav = "Social";
|
||||
model.social.focusedContent = root;
|
||||
} else if (root.kind == NostrKind.DIRECT_MESSAGE) {
|
||||
if (root.kind == NostrKind.DIRECT_MESSAGE) {
|
||||
const myPubkey = app.ctx.publicKey.hex;
|
||||
if (root.pubkey != myPubkey && !getTags(root).p.includes(myPubkey)) {
|
||||
continue; // if no conversation
|
||||
@ -401,37 +365,6 @@ export async function* UI_Interaction_Update(args: {
|
||||
app.popOverInputChan.put({ children: undefined });
|
||||
console.log(profileEvent, groupAdminCtx.publicKey.hex);
|
||||
app.profileSyncer.add(groupAdminCtx.publicKey.hex);
|
||||
} //
|
||||
//
|
||||
// Social
|
||||
//
|
||||
else if (event.type == "SocialFilterChanged_content") {
|
||||
model.social.filter.content = event.content;
|
||||
} else if (event.type == "SocialFilterChanged_authors") {
|
||||
if (model.social.filter.adding_author) {
|
||||
model.social.filter.author.add(model.social.filter.adding_author);
|
||||
model.social.filter.adding_author = "";
|
||||
|
||||
const pubkeys: string[] = [];
|
||||
for (const userInfo of app.conversationLists.convoSummaries.values()) {
|
||||
for (const name of model.social.filter.author) {
|
||||
if (userInfo.profile?.profile.name?.toLowerCase().includes(name.toLowerCase())) {
|
||||
pubkeys.push(userInfo.pubkey.hex);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* do not await */ app.eventSyncer.syncEvents({
|
||||
kinds: [NostrKind.TEXT_NOTE],
|
||||
authors: pubkeys,
|
||||
});
|
||||
// model.social.activeSyncingFilter =
|
||||
}
|
||||
} else if (event.type == "SocialFilterChanged_adding_author") {
|
||||
model.social.filter.adding_author = event.value;
|
||||
} else if (event.type == "SocialFilterChanged_remove_author") {
|
||||
model.social.filter.author.delete(event.value);
|
||||
} else if (event.type == "RelayConfigChange") {
|
||||
const e = await app.relayConfig.toNostrEvent(app.ctx);
|
||||
if (e instanceof Error) {
|
||||
@ -708,8 +641,6 @@ export async function handle_SendMessage(
|
||||
lamport: LamportTime,
|
||||
pool: ConnectionPool,
|
||||
dmEditors: Map<string, DM_EditorModel>,
|
||||
socialEditor: Social_EditorModel,
|
||||
replyEditors: Map<string, Social_EditorModel>,
|
||||
db: Database_Contextual_View,
|
||||
) {
|
||||
if (event.target.kind == NostrKind.DIRECT_MESSAGE) {
|
||||
@ -737,26 +668,5 @@ export async function handle_SendMessage(
|
||||
editor.files = [];
|
||||
editor.text = "";
|
||||
}
|
||||
} else {
|
||||
const eventSent = await sendSocialPost({
|
||||
sender: ctx,
|
||||
message: event.text,
|
||||
lamport_timestamp: lamport.now(),
|
||||
pool,
|
||||
tags: event.tags,
|
||||
});
|
||||
if (eventSent instanceof Error) {
|
||||
return eventSent;
|
||||
}
|
||||
await db.addEvent(eventSent);
|
||||
if (event.id == "social") {
|
||||
socialEditor.files = [];
|
||||
socialEditor.text = "";
|
||||
}
|
||||
const editor = replyEditors.get(event.id);
|
||||
if (editor) {
|
||||
editor.files = [];
|
||||
editor.text = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ import { DividerBackgroundColor, PrimaryBackgroundColor, PrimaryTextColor } from
|
||||
import { SendIcon } from "./icons2/send-icon.tsx";
|
||||
import { RemoveIcon } from "./icons2/remove-icon.tsx";
|
||||
|
||||
export type EditorModel = DM_EditorModel | Social_EditorModel;
|
||||
export type EditorModel = DM_EditorModel;
|
||||
|
||||
export type DM_EditorModel = {
|
||||
id: string;
|
||||
@ -22,15 +22,7 @@ export type DM_EditorModel = {
|
||||
readonly target: DM_Target;
|
||||
};
|
||||
|
||||
export type Social_EditorModel = {
|
||||
id: string;
|
||||
text: string;
|
||||
files: Blob[];
|
||||
tags: Tag[];
|
||||
readonly target: Social_Target;
|
||||
};
|
||||
|
||||
export type EditorSubmissionTarget = DM_Target | Social_Target;
|
||||
export type EditorSubmissionTarget = DM_Target;
|
||||
|
||||
export type DM_Target = {
|
||||
kind: NostrKind.DIRECT_MESSAGE;
|
||||
@ -40,9 +32,6 @@ export type DM_Target = {
|
||||
picture?: string;
|
||||
};
|
||||
};
|
||||
export type Social_Target = {
|
||||
kind: NostrKind.TEXT_NOTE;
|
||||
};
|
||||
|
||||
export function new_DM_EditorModel(receiver: {
|
||||
pubkey: PublicKey;
|
||||
@ -61,18 +50,6 @@ export function new_DM_EditorModel(receiver: {
|
||||
};
|
||||
}
|
||||
|
||||
export function new_Social_EditorModel(): Social_EditorModel {
|
||||
return {
|
||||
id: "social",
|
||||
text: "",
|
||||
files: [],
|
||||
tags: [],
|
||||
target: {
|
||||
kind: NostrKind.TEXT_NOTE,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export type EditorEvent = SendMessage | UpdateMessageText | UpdateMessageFiles;
|
||||
|
||||
export type SendMessage = {
|
||||
|
191
UI/social.tsx
191
UI/social.tsx
@ -1,191 +0,0 @@
|
||||
/** @jsx h */
|
||||
import { h } from "https://esm.sh/preact@10.17.1";
|
||||
import { tw } from "https://esm.sh/twind@0.16.16";
|
||||
import { DirectMessagePanelUpdate, MessagePanel } from "./message-panel.tsx";
|
||||
import { Model } from "./app_model.ts";
|
||||
import { NostrAccountContext } from "../lib/nostr-ts/nostr.ts";
|
||||
import { Database_Contextual_View } from "../database.ts";
|
||||
import { emitFunc, EventEmitter } from "../event-bus.ts";
|
||||
import { ConversationLists, getConversationSummaryFromPublicKey } from "./conversation-list.ts";
|
||||
import { EventSyncer } from "./event_syncer.ts";
|
||||
import { PrimaryTextColor } from "./style/colors.ts";
|
||||
import { EditorEvent } from "./editor.tsx";
|
||||
import { PinContact, UnpinContact } from "../nostr.ts";
|
||||
import { CenterClass, LinearGradientsClass } from "./components/tw.ts";
|
||||
import { ProfilesSyncer } from "../features/profile.ts";
|
||||
|
||||
export type SocialUpdates =
|
||||
| SocialFilterChanged_content
|
||||
| SocialFilterChanged_authors
|
||||
| SocialFilterChanged_adding_author
|
||||
| SocialFilterChanged_remove_author;
|
||||
|
||||
type SocialFilterChanged_content = {
|
||||
type: "SocialFilterChanged_content";
|
||||
content: string;
|
||||
};
|
||||
|
||||
type SocialFilterChanged_authors = {
|
||||
type: "SocialFilterChanged_authors";
|
||||
};
|
||||
|
||||
type SocialFilterChanged_adding_author = {
|
||||
type: "SocialFilterChanged_adding_author";
|
||||
value: string;
|
||||
};
|
||||
|
||||
type SocialFilterChanged_remove_author = {
|
||||
type: "SocialFilterChanged_remove_author";
|
||||
value: string;
|
||||
};
|
||||
|
||||
export function SocialPanel(props: {
|
||||
focusedContent: any;
|
||||
model: Model;
|
||||
ctx: NostrAccountContext;
|
||||
db: Database_Contextual_View;
|
||||
emit: emitFunc<
|
||||
SocialUpdates | EditorEvent | DirectMessagePanelUpdate | PinContact | UnpinContact
|
||||
>;
|
||||
profileSyncer: ProfilesSyncer;
|
||||
eventSyncer: EventSyncer;
|
||||
allUsersInfo: ConversationLists;
|
||||
}) {
|
||||
const t = Date.now();
|
||||
const model = props.model;
|
||||
|
||||
const messages = [];
|
||||
// todo: can move this logic to update to speed up
|
||||
for (const thread of model.social.threads) {
|
||||
// content
|
||||
if (!thread.root.content.toLowerCase().includes(model.social.filter.content.toLowerCase())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// authors
|
||||
let matched_at_least_one_author = false;
|
||||
for (const author of model.social.filter.author) {
|
||||
const userInfo = getConversationSummaryFromPublicKey(
|
||||
thread.root.event.publicKey,
|
||||
props.allUsersInfo.convoSummaries,
|
||||
);
|
||||
if (userInfo && userInfo.profile?.profile.name?.toLowerCase().includes(author.toLowerCase())) {
|
||||
matched_at_least_one_author = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (model.social.filter.author.size > 0 && !matched_at_least_one_author) {
|
||||
continue;
|
||||
}
|
||||
|
||||
messages.push(thread);
|
||||
}
|
||||
console.log("SocialPanel:filter threads", Date.now() - t, model.social.threads.length);
|
||||
|
||||
const messagePanel = (
|
||||
<MessagePanel
|
||||
focusedContent={props.focusedContent}
|
||||
editorModel={model.social.editor}
|
||||
myPublicKey={props.ctx.publicKey}
|
||||
messages={messages}
|
||||
rightPanelModel={model.rightPanelModel}
|
||||
db={props.db}
|
||||
emit={props.emit}
|
||||
profilesSyncer={props.profileSyncer}
|
||||
eventSyncer={props.eventSyncer}
|
||||
allUserInfo={props.allUsersInfo.convoSummaries}
|
||||
/>
|
||||
);
|
||||
console.log("SocialPanel:MessagePanel", Date.now() - t);
|
||||
|
||||
return (
|
||||
<div
|
||||
class={tw`flex-1 overflow-hidden flex-col flex bg-[#313338]`}
|
||||
>
|
||||
{Filter(props)}
|
||||
<div class={tw`flex-1 overflow-x-auto`}>
|
||||
{messagePanel}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Filter(
|
||||
props: {
|
||||
emit: emitFunc<SocialUpdates>;
|
||||
model: Model;
|
||||
},
|
||||
) {
|
||||
const authors = [];
|
||||
for (const author of props.model.social.filter.author) {
|
||||
authors.push(
|
||||
<div class={tw`flex mx-1 border border-indigo-600`}>
|
||||
<p class={tw`mx-1`}>
|
||||
{author}
|
||||
</p>
|
||||
<button
|
||||
class={tw`text-[${PrimaryTextColor}] rounded-lg ${CenterClass} bg-[#36393F] hover:bg-transparent font-bold`}
|
||||
onClick={(e) => {
|
||||
props.emit({
|
||||
type: "SocialFilterChanged_remove_author",
|
||||
value: author,
|
||||
});
|
||||
}}
|
||||
>
|
||||
X
|
||||
</button>
|
||||
</div>,
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div class={tw`flex-col text-[${PrimaryTextColor}] ml-5 my-3`}>
|
||||
<p>Filter</p>
|
||||
<div class={tw`flex-col`}>
|
||||
<div class={tw`flex flex-wrap`}>
|
||||
<p class={tw`mr-3`}>Content</p>
|
||||
<input
|
||||
class={tw`text-black`}
|
||||
onInput={(e) => {
|
||||
props.emit({
|
||||
type: "SocialFilterChanged_content",
|
||||
content: e.currentTarget.value,
|
||||
});
|
||||
}}
|
||||
value={props.model.social.filter.content}
|
||||
>
|
||||
</input>
|
||||
</div>
|
||||
<div class={tw`flex flex-wrap mt-3`}>
|
||||
<p class={tw`mr-3`}>Authors</p>
|
||||
{authors}
|
||||
<input
|
||||
class={tw`text-black`}
|
||||
onInput={(e) => {
|
||||
props.emit({
|
||||
type: "SocialFilterChanged_adding_author",
|
||||
value: e.currentTarget.value,
|
||||
});
|
||||
}}
|
||||
value={props.model.social.filter.adding_author}
|
||||
>
|
||||
</input>
|
||||
<div
|
||||
class={tw`ml-3 rounded-lg ${LinearGradientsClass}`}
|
||||
>
|
||||
<button
|
||||
class={tw`w-[4.8rem] text-[${PrimaryTextColor}] rounded-lg ${CenterClass} bg-[#36393F] hover:bg-transparent font-bold`}
|
||||
onClick={(e) => {
|
||||
props.emit({
|
||||
type: "SocialFilterChanged_authors",
|
||||
});
|
||||
}}
|
||||
>
|
||||
Add
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
import { ChatMessage } from "../UI/message.ts";
|
||||
import { Database_Contextual_View } from "../database.ts";
|
||||
import { NostrKind } from "../lib/nostr-ts/nostr.ts";
|
||||
|
||||
import { computeThreads } from "../nostr.ts";
|
||||
|
||||
import { MessageThread } from "../UI/dm.tsx";
|
||||
import { ConversationSummary } from "../UI/conversation-list.ts";
|
||||
|
||||
export function getSocialPosts(
|
||||
db: Database_Contextual_View,
|
||||
allUsersInfo: Map<string, ConversationSummary>,
|
||||
) {
|
||||
const t = Date.now();
|
||||
const events = [];
|
||||
for (const e of db.events) {
|
||||
if (e.kind == NostrKind.TEXT_NOTE) {
|
||||
events.push(e);
|
||||
}
|
||||
}
|
||||
console.log("getSocialPosts:filterEvents", Date.now() - t);
|
||||
const threads = computeThreads(events);
|
||||
console.log("getSocialPosts:computeThreads", Date.now() - t);
|
||||
const msgs: MessageThread[] = new Array(threads.length);
|
||||
for (let i = 0; i < threads.length; i++) {
|
||||
const thread = threads[i];
|
||||
const messages: ChatMessage[] = [];
|
||||
for (let j = 0; j < thread.length; j++) {
|
||||
const event = thread[j];
|
||||
messages[j] = {
|
||||
event: event,
|
||||
content: event.content,
|
||||
created_at: new Date(event.created_at * 1000),
|
||||
type: "text",
|
||||
lamport: event.parsedTags.lamport_timestamp,
|
||||
};
|
||||
}
|
||||
msgs[i] = {
|
||||
root: messages[0],
|
||||
replies: messages.slice(1),
|
||||
};
|
||||
}
|
||||
console.log("getSocialPosts:end", Date.now() - t);
|
||||
return msgs;
|
||||
}
|
Loading…
Reference in New Issue
Block a user