mirror of
https://github.com/stoatchat/for-legacy-web.git
synced 2026-03-09 02:05:28 +00:00
Import assets and add PWA.
This commit is contained in:
@@ -30,18 +30,19 @@ export function auth(
|
||||
accounts: {
|
||||
...state.accounts,
|
||||
[action.session.user_id]: {
|
||||
session: action.session
|
||||
}
|
||||
session: action.session,
|
||||
},
|
||||
},
|
||||
active: action.session.user_id
|
||||
active: action.session.user_id,
|
||||
};
|
||||
case "LOGOUT":
|
||||
case "LOGOUT": {
|
||||
const accounts = Object.assign({}, state.accounts);
|
||||
action.user_id && delete accounts[action.user_id];
|
||||
|
||||
return {
|
||||
accounts
|
||||
accounts,
|
||||
};
|
||||
}
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
||||
@@ -20,11 +20,13 @@ export function drafts(state: Drafts = {}, action: DraftAction): Drafts {
|
||||
case "SET_DRAFT":
|
||||
return {
|
||||
...state,
|
||||
[action.channel]: action.content
|
||||
[action.channel]: action.content,
|
||||
};
|
||||
case "CLEAR_DRAFT":
|
||||
case "CLEAR_DRAFT": {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const { [action.channel]: _, ...newState } = state;
|
||||
return newState;
|
||||
}
|
||||
case "RESET":
|
||||
return {};
|
||||
default:
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
export type Experiments = never;
|
||||
export const AVAILABLE_EXPERIMENTS: Experiments[] = [ ];
|
||||
export const AVAILABLE_EXPERIMENTS: Experiments[] = [];
|
||||
|
||||
export interface ExperimentOptions {
|
||||
enabled?: Experiments[]
|
||||
enabled?: Experiments[];
|
||||
}
|
||||
|
||||
export type ExperimentsAction =
|
||||
@@ -26,16 +26,17 @@ export function experiments(
|
||||
...state,
|
||||
enabled: [
|
||||
...(state.enabled ?? [])
|
||||
.filter(x => AVAILABLE_EXPERIMENTS.includes(x))
|
||||
.filter(v => v !== action.key),
|
||||
action.key
|
||||
]
|
||||
.filter((x) => AVAILABLE_EXPERIMENTS.includes(x))
|
||||
.filter((v) => v !== action.key),
|
||||
action.key,
|
||||
],
|
||||
};
|
||||
case "EXPERIMENTS_DISABLE":
|
||||
return {
|
||||
...state,
|
||||
enabled: state.enabled?.filter(v => v !== action.key)
|
||||
.filter(x => AVAILABLE_EXPERIMENTS.includes(x))
|
||||
enabled: state.enabled
|
||||
?.filter((v) => v !== action.key)
|
||||
.filter((x) => AVAILABLE_EXPERIMENTS.includes(x)),
|
||||
};
|
||||
default:
|
||||
return state;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { State } from "..";
|
||||
import { combineReducers } from "redux";
|
||||
|
||||
import { settings, SettingsAction } from "./settings";
|
||||
@@ -19,7 +20,7 @@ export default combineReducers({
|
||||
typing,
|
||||
drafts,
|
||||
sync,
|
||||
experiments
|
||||
experiments,
|
||||
});
|
||||
|
||||
export type Action =
|
||||
@@ -32,11 +33,13 @@ export type Action =
|
||||
| DraftAction
|
||||
| SyncAction
|
||||
| ExperimentsAction
|
||||
| { type: "__INIT"; state: any };
|
||||
| { type: "__INIT"; state: State };
|
||||
|
||||
export type WithDispatcher = { dispatcher: (action: Action) => void };
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
export function filter(obj: any, keys: string[]) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const newObj: any = {};
|
||||
for (const key of keys) {
|
||||
const v = obj[key];
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Language } from "../../context/Locale";
|
||||
import { SyncData, SyncKeys, SyncUpdateAction } from "./sync";
|
||||
import { SyncUpdateAction } from "./sync";
|
||||
|
||||
export type LocaleAction =
|
||||
| { type: undefined }
|
||||
@@ -19,19 +19,20 @@ export function findLanguage(lang?: string): Language {
|
||||
}
|
||||
|
||||
const code = lang.replace("-", "_");
|
||||
|
||||
const short = code.split("_")[0];
|
||||
for (const key of Object.keys(Language)) {
|
||||
const value = (Language as any)[key];
|
||||
|
||||
const values = [];
|
||||
for (const key in Language) {
|
||||
const value = Language[key as keyof typeof Language];
|
||||
values.push(value);
|
||||
if (value.startsWith(code)) {
|
||||
return value;
|
||||
return value as Language;
|
||||
}
|
||||
}
|
||||
|
||||
for (const key of Object.keys(Language).reverse()) {
|
||||
const value = (Language as any)[key];
|
||||
for (const value of values.reverse()) {
|
||||
if (value.startsWith(short)) {
|
||||
return value;
|
||||
return value as Language;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import { MessageObject } from "../../context/revoltjs/messages";
|
||||
|
||||
export enum QueueStatus {
|
||||
SENDING = "sending",
|
||||
ERRORED = "errored"
|
||||
ERRORED = "errored",
|
||||
}
|
||||
|
||||
export interface QueuedMessage {
|
||||
@@ -51,47 +51,47 @@ export function queue(
|
||||
switch (action.type) {
|
||||
case "QUEUE_ADD": {
|
||||
return [
|
||||
...state.filter(x => x.id !== action.nonce),
|
||||
...state.filter((x) => x.id !== action.nonce),
|
||||
{
|
||||
id: action.nonce,
|
||||
data: action.message,
|
||||
channel: action.channel,
|
||||
status: QueueStatus.SENDING
|
||||
}
|
||||
status: QueueStatus.SENDING,
|
||||
},
|
||||
];
|
||||
}
|
||||
case "QUEUE_FAIL": {
|
||||
const entry = state.find(
|
||||
x => x.id === action.nonce
|
||||
(x) => x.id === action.nonce
|
||||
) as QueuedMessage;
|
||||
return [
|
||||
...state.filter(x => x.id !== action.nonce),
|
||||
...state.filter((x) => x.id !== action.nonce),
|
||||
{
|
||||
...entry,
|
||||
status: QueueStatus.ERRORED,
|
||||
error: action.error
|
||||
}
|
||||
error: action.error,
|
||||
},
|
||||
];
|
||||
}
|
||||
case "QUEUE_START": {
|
||||
const entry = state.find(
|
||||
x => x.id === action.nonce
|
||||
(x) => x.id === action.nonce
|
||||
) as QueuedMessage;
|
||||
return [
|
||||
...state.filter(x => x.id !== action.nonce),
|
||||
...state.filter((x) => x.id !== action.nonce),
|
||||
{
|
||||
...entry,
|
||||
status: QueueStatus.SENDING
|
||||
}
|
||||
status: QueueStatus.SENDING,
|
||||
},
|
||||
];
|
||||
}
|
||||
case "QUEUE_REMOVE":
|
||||
return state.filter(x => x.id !== action.nonce);
|
||||
return state.filter((x) => x.id !== action.nonce);
|
||||
case "QUEUE_FAIL_ALL":
|
||||
return state.map(x => {
|
||||
return state.map((x) => {
|
||||
return {
|
||||
...x,
|
||||
status: QueueStatus.ERRORED
|
||||
status: QueueStatus.ERRORED,
|
||||
};
|
||||
});
|
||||
case "QUEUE_DROP_ALL":
|
||||
|
||||
@@ -8,9 +8,9 @@ export interface NotificationOptions {
|
||||
outgoingSoundEnabled?: boolean;
|
||||
}
|
||||
|
||||
export type EmojiPacks = 'mutant' | 'twemoji' | 'noto' | 'openmoji';
|
||||
export type EmojiPacks = "mutant" | "twemoji" | "noto" | "openmoji";
|
||||
export interface AppearanceOptions {
|
||||
emojiPack?: EmojiPacks
|
||||
emojiPack?: EmojiPacks;
|
||||
}
|
||||
|
||||
export interface Settings {
|
||||
@@ -53,9 +53,9 @@ export function settings(
|
||||
return {
|
||||
...state,
|
||||
theme: {
|
||||
...filter(state.theme, [ 'custom', 'preset' ]),
|
||||
...filter(state.theme, ["custom", "preset"]),
|
||||
...action.theme,
|
||||
}
|
||||
},
|
||||
};
|
||||
case "SETTINGS_SET_THEME_OVERRIDE":
|
||||
return {
|
||||
@@ -64,32 +64,32 @@ export function settings(
|
||||
...state.theme,
|
||||
custom: {
|
||||
...state.theme?.custom,
|
||||
...action.custom
|
||||
}
|
||||
}
|
||||
...action.custom,
|
||||
},
|
||||
},
|
||||
};
|
||||
case "SETTINGS_SET_NOTIFICATION_OPTIONS":
|
||||
return {
|
||||
...state,
|
||||
notification: {
|
||||
...state.notification,
|
||||
...action.options
|
||||
}
|
||||
...action.options,
|
||||
},
|
||||
};
|
||||
case "SETTINGS_SET_APPEARANCE":
|
||||
return {
|
||||
...state,
|
||||
appearance: {
|
||||
...filter(state.appearance, [ 'emojiPack' ]),
|
||||
...action.options
|
||||
}
|
||||
}
|
||||
...filter(state.appearance, ["emojiPack"]),
|
||||
...action.options,
|
||||
},
|
||||
};
|
||||
case "SYNC_UPDATE":
|
||||
return {
|
||||
...state,
|
||||
appearance: action.update.appearance?.[1] ?? state.appearance,
|
||||
theme: action.update.theme?.[1] ?? state.theme
|
||||
}
|
||||
theme: action.update.theme?.[1] ?? state.theme,
|
||||
};
|
||||
case "RESET":
|
||||
return {};
|
||||
default:
|
||||
|
||||
@@ -2,7 +2,7 @@ import { AppearanceOptions } from "./settings";
|
||||
import { Language } from "../../context/Locale";
|
||||
import { ThemeOptions } from "../../context/Theme";
|
||||
|
||||
export type SyncKeys = 'theme' | 'appearance' | 'locale';
|
||||
export type SyncKeys = "theme" | "appearance" | "locale";
|
||||
|
||||
export interface SyncData {
|
||||
locale?: Language;
|
||||
@@ -10,17 +10,21 @@ export interface SyncData {
|
||||
appearance?: AppearanceOptions;
|
||||
}
|
||||
|
||||
export const DEFAULT_ENABLED_SYNC: SyncKeys[] = [ 'theme', 'appearance', 'locale' ];
|
||||
export const DEFAULT_ENABLED_SYNC: SyncKeys[] = [
|
||||
"theme",
|
||||
"appearance",
|
||||
"locale",
|
||||
];
|
||||
export interface SyncOptions {
|
||||
disabled?: SyncKeys[]
|
||||
disabled?: SyncKeys[];
|
||||
revision?: {
|
||||
[key: string]: number
|
||||
}
|
||||
[key: string]: number;
|
||||
};
|
||||
}
|
||||
|
||||
export type SyncUpdateAction = {
|
||||
type: "SYNC_UPDATE";
|
||||
update: { [key in SyncKeys]?: [ number, SyncData[key] ] }
|
||||
update: { [key in SyncKeys]?: [number, SyncData[key]] };
|
||||
};
|
||||
|
||||
export type SyncAction =
|
||||
@@ -49,24 +53,24 @@ export function sync(
|
||||
return {
|
||||
...state,
|
||||
disabled: [
|
||||
...(state.disabled ?? []).filter(v => v !== action.key),
|
||||
action.key
|
||||
]
|
||||
...(state.disabled ?? []).filter((v) => v !== action.key),
|
||||
action.key,
|
||||
],
|
||||
};
|
||||
case "SYNC_ENABLE_KEY":
|
||||
return {
|
||||
...state,
|
||||
disabled: state.disabled?.filter(v => v !== action.key)
|
||||
disabled: state.disabled?.filter((v) => v !== action.key),
|
||||
};
|
||||
case "SYNC_SET_REVISION":
|
||||
return {
|
||||
...state,
|
||||
revision: {
|
||||
...state.revision,
|
||||
[action.key]: action.timestamp
|
||||
}
|
||||
[action.key]: action.timestamp,
|
||||
},
|
||||
};
|
||||
case "SYNC_UPDATE":
|
||||
case "SYNC_UPDATE": {
|
||||
const revision = { ...state.revision };
|
||||
for (const key of Object.keys(action.update)) {
|
||||
const value = action.update[key as SyncKeys];
|
||||
@@ -77,8 +81,9 @@ export function sync(
|
||||
|
||||
return {
|
||||
...state,
|
||||
revision
|
||||
}
|
||||
revision,
|
||||
};
|
||||
}
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export type TypingUser = { id: string, started: number };
|
||||
export type TypingUser = { id: string; started: number };
|
||||
export type Typing = { [key: string]: TypingUser[] };
|
||||
|
||||
export type TypingAction =
|
||||
@@ -24,19 +24,21 @@ export function typing(state: Typing = {}, action: TypingAction): Typing {
|
||||
...state,
|
||||
[action.channel]: [
|
||||
...(state[action.channel] ?? []).filter(
|
||||
x => x.id !== action.user
|
||||
(x) => x.id !== action.user
|
||||
),
|
||||
{
|
||||
id: action.user,
|
||||
started: + new Date()
|
||||
}
|
||||
]
|
||||
started: +new Date(),
|
||||
},
|
||||
],
|
||||
};
|
||||
case "TYPING_STOP":
|
||||
return {
|
||||
...state,
|
||||
[action.channel]:
|
||||
state[action.channel]?.filter(x => x.id !== action.user) ?? []
|
||||
state[action.channel]?.filter(
|
||||
(x) => x.id !== action.user
|
||||
) ?? [],
|
||||
};
|
||||
case "RESET":
|
||||
return {};
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
import { Sync } from "revolt.js/dist/api/objects";
|
||||
|
||||
export interface Unreads {
|
||||
[key: string]: Partial<Omit<Sync.ChannelUnread, '_id'>>;
|
||||
[key: string]: Partial<Omit<Sync.ChannelUnread, "_id">>;
|
||||
}
|
||||
|
||||
export type UnreadsAction =
|
||||
| { type: undefined }
|
||||
| {
|
||||
type: "UNREADS_MARK_READ";
|
||||
channel: string;
|
||||
message: string;
|
||||
request: boolean;
|
||||
type: "UNREADS_MARK_READ";
|
||||
channel: string;
|
||||
message: string;
|
||||
request: boolean;
|
||||
}
|
||||
| {
|
||||
type: "UNREADS_SET";
|
||||
unreads: Sync.ChannelUnread[];
|
||||
}
|
||||
type: "UNREADS_SET";
|
||||
unreads: Sync.ChannelUnread[];
|
||||
}
|
||||
| {
|
||||
type: "UNREADS_MENTION";
|
||||
channel: string;
|
||||
message: string;
|
||||
}
|
||||
type: "UNREADS_MENTION";
|
||||
channel: string;
|
||||
message: string;
|
||||
}
|
||||
| {
|
||||
type: "RESET";
|
||||
type: "RESET";
|
||||
};
|
||||
|
||||
export function unreads(state = {}, action: UnreadsAction): Unreads {
|
||||
export function unreads(state = {} as Unreads, action: UnreadsAction): Unreads {
|
||||
switch (action.type) {
|
||||
case "UNREADS_MARK_READ":
|
||||
if (action.request) {
|
||||
@@ -35,31 +35,29 @@ export function unreads(state = {}, action: UnreadsAction): Unreads {
|
||||
return {
|
||||
...state,
|
||||
[action.channel]: {
|
||||
last_id: action.message
|
||||
}
|
||||
last_id: action.message,
|
||||
},
|
||||
};
|
||||
case "UNREADS_SET":
|
||||
{
|
||||
const obj: Unreads = {};
|
||||
for (const entry of action.unreads) {
|
||||
const { _id, ...v } = entry;
|
||||
obj[_id.channel] = v;
|
||||
}
|
||||
|
||||
return obj;
|
||||
case "UNREADS_SET": {
|
||||
const obj: Unreads = {};
|
||||
for (const entry of action.unreads) {
|
||||
const { _id, ...v } = entry;
|
||||
obj[_id.channel] = v;
|
||||
}
|
||||
case "UNREADS_MENTION":
|
||||
{
|
||||
const obj = (state as any)[action.channel];
|
||||
|
||||
return {
|
||||
...state,
|
||||
[action.channel]: {
|
||||
...obj,
|
||||
mentions: [ ...(obj?.mentions ?? []), action.message ]
|
||||
}
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
case "UNREADS_MENTION": {
|
||||
const obj = state[action.channel];
|
||||
|
||||
return {
|
||||
...state,
|
||||
[action.channel]: {
|
||||
...obj,
|
||||
mentions: [...(obj?.mentions ?? []), action.message],
|
||||
},
|
||||
};
|
||||
}
|
||||
case "RESET":
|
||||
return {};
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user