wip: clean up & refactor
This commit is contained in:
@@ -1,92 +0,0 @@
|
||||
import { create } from 'zustand';
|
||||
import { immer } from 'zustand/middleware/immer';
|
||||
|
||||
import { createChannelMessage, getChannelMessages, getChannels } from '@libs/storage';
|
||||
|
||||
import { LumeEvent } from '@utils/types';
|
||||
|
||||
export const useChannels = create(
|
||||
immer((set) => ({
|
||||
channels: [],
|
||||
fetch: async () => {
|
||||
const response = await getChannels();
|
||||
set({ channels: response });
|
||||
},
|
||||
add: (event) => {
|
||||
set((state) => {
|
||||
const target = state.channels.findIndex(
|
||||
(m: { event_id: string }) => m.event_id === event.id
|
||||
);
|
||||
if (target !== -1) {
|
||||
state.channels[target]['new_messages'] =
|
||||
state.channels[target]['new_messages'] + 1 || 1;
|
||||
} else {
|
||||
state.channels.push({ event_id: event.id, ...event });
|
||||
}
|
||||
});
|
||||
},
|
||||
clearBubble: (id: string) => {
|
||||
set((state) => {
|
||||
const target = state.channels.findIndex(
|
||||
(m: { event_id: string }) => m.event_id === id
|
||||
);
|
||||
state.channels[target]['new_messages'] = 0;
|
||||
});
|
||||
},
|
||||
}))
|
||||
);
|
||||
|
||||
export const useChannelMessages = create(
|
||||
immer((set) => ({
|
||||
messages: [],
|
||||
replyTo: { id: null, pubkey: null, content: null },
|
||||
fetch: async (id: string) => {
|
||||
const events = await getChannelMessages(id);
|
||||
set({ messages: events });
|
||||
},
|
||||
add: (id, event: LumeEvent) => {
|
||||
set((state: any) => {
|
||||
createChannelMessage(
|
||||
id,
|
||||
event.id,
|
||||
event.pubkey,
|
||||
event.kind,
|
||||
event.content,
|
||||
event.tags,
|
||||
event.created_at
|
||||
);
|
||||
state.messages.push({
|
||||
event_id: event.id,
|
||||
channel_id: id,
|
||||
hide: 0,
|
||||
mute: 0,
|
||||
...event,
|
||||
});
|
||||
});
|
||||
},
|
||||
openReply: (id: string, pubkey: string, content: string) => {
|
||||
set(() => ({ replyTo: { id, pubkey, content } }));
|
||||
},
|
||||
closeReply: () => {
|
||||
set(() => ({ replyTo: { id: null, pubkey: null, content: null } }));
|
||||
},
|
||||
hideMessage: (id: string) => {
|
||||
set((state) => {
|
||||
const target = state.messages.findIndex((m) => m.id === id);
|
||||
state.messages[target]['hide'] = true;
|
||||
});
|
||||
},
|
||||
muteUser: (pubkey: string) => {
|
||||
set((state) => {
|
||||
const target = state.messages.findIndex((m) => m.pubkey === pubkey);
|
||||
state.messages[target]['mute'] = true;
|
||||
});
|
||||
},
|
||||
clear: () => {
|
||||
set(() => ({
|
||||
messages: [],
|
||||
replyTo: { id: null, pubkey: null, content: null },
|
||||
}));
|
||||
},
|
||||
}))
|
||||
);
|
||||
@@ -1,76 +1,12 @@
|
||||
export const APP_VERSION = '1.2.0';
|
||||
|
||||
export const DEFAULT_AVATAR = 'https://void.cat/d/5VKmKyuHyxrNMf9bWSVPih';
|
||||
|
||||
export const OPENGRAPH = {
|
||||
REGEX_VALID_URL: new RegExp(
|
||||
'^' +
|
||||
// protocol identifier
|
||||
'(?:(?:https?|ftp)://)' +
|
||||
// user:pass authentication
|
||||
'(?:\\S+(?::\\S*)?@)?' +
|
||||
'(?:' +
|
||||
// IP address exclusion
|
||||
// private & local networks
|
||||
'(?!(?:10|127)(?:\\.\\d{1,3}){3})' +
|
||||
'(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})' +
|
||||
'(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})' +
|
||||
// IP address dotted notation octets
|
||||
// excludes loopback network 0.0.0.0
|
||||
// excludes reserved space >= 224.0.0.0
|
||||
// excludes network & broacast addresses
|
||||
// (first & last IP address of each class)
|
||||
'(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])' +
|
||||
'(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}' +
|
||||
'(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))' +
|
||||
'|' +
|
||||
// host name
|
||||
'(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)' +
|
||||
// domain name
|
||||
'(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*' +
|
||||
// TLD identifier
|
||||
'(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))' +
|
||||
// TLD may end with dot
|
||||
'\\.?' +
|
||||
')' +
|
||||
// port number
|
||||
'(?::\\d{2,5})?' +
|
||||
// resource path
|
||||
'(?:[/?#]\\S*)?' +
|
||||
'$',
|
||||
'i'
|
||||
),
|
||||
|
||||
REGEX_LOOPBACK: new RegExp(
|
||||
'^' +
|
||||
'(?:(?:10|127)(?:\\.\\d{1,3}){3})' +
|
||||
'|' +
|
||||
'(?:(?:169\\.254|192\\.168|192\\.0)(?:\\.\\d{1,3}){2})' +
|
||||
'|' +
|
||||
'(?:172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})' +
|
||||
'$',
|
||||
'i'
|
||||
),
|
||||
|
||||
REGEX_CONTENT_TYPE_IMAGE: new RegExp('image/.*', 'i'),
|
||||
|
||||
REGEX_CONTENT_TYPE_AUDIO: new RegExp('audio/.*', 'i'),
|
||||
|
||||
REGEX_CONTENT_TYPE_VIDEO: new RegExp('video/.*', 'i'),
|
||||
|
||||
REGEX_CONTENT_TYPE_TEXT: new RegExp('text/.*', 'i'),
|
||||
|
||||
REGEX_CONTENT_TYPE_APPLICATION: new RegExp('application/.*', 'i'),
|
||||
};
|
||||
|
||||
export const FULL_RELAYS = [
|
||||
'wss://relayable.org',
|
||||
'wss://relay.damus.io',
|
||||
'wss://relay.nostr.band/all',
|
||||
'wss://nostr.mutinywallet.com',
|
||||
];
|
||||
|
||||
export const BLOCK_KINDS = {
|
||||
export const widgetKinds = {
|
||||
image: 0,
|
||||
feed: 1,
|
||||
thread: 2,
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
export const COMPOSE_SHORTCUT = 'meta+n';
|
||||
export const ADD_IMAGEBLOCK_SHORTCUT = 'meta+i';
|
||||
export const ADD_FEEDBLOCK_SHORTCUT = 'meta+f';
|
||||
export const ADD_HASHTAGBLOCK_SHORTCUT = 'meta+t';
|
||||
@@ -18,6 +18,15 @@ export const useWidgets = create<WidgetState>()(
|
||||
widgets: null,
|
||||
fetchWidgets: async (db: LumeStorage) => {
|
||||
const widgets = await db.getWidgets();
|
||||
|
||||
// default: add network widget
|
||||
widgets.unshift({
|
||||
id: String(widgets.length + 1),
|
||||
title: 'Network',
|
||||
content: '',
|
||||
kind: 9999,
|
||||
});
|
||||
|
||||
set({ widgets: widgets });
|
||||
},
|
||||
setWidget: async (db: LumeStorage, { kind, title, content }: Widget) => {
|
||||
|
||||
Reference in New Issue
Block a user