Merge branch 'master' into 'cleanup'

# Conflicts:
#   src/components/common/LocaleSelector.tsx
This commit is contained in:
insert
2021-07-05 10:17:57 +00:00
28 changed files with 322 additions and 208 deletions

View File

@@ -2,12 +2,12 @@ import { openDB } from 'idb';
import { Client } from "revolt.js";
import { takeError } from "./util";
import { createContext } from "preact";
import { dispatch } from '../../redux';
import { Children } from "../../types/Preact";
import { useHistory } from 'react-router-dom';
import { Route } from "revolt.js/dist/api/routes";
import { connectState } from "../../redux/connector";
import Preloader from "../../components/ui/Preloader";
import { WithDispatcher } from "../../redux/reducers";
import { AuthState } from "../../redux/reducers/auth";
import { useEffect, useMemo, useState } from "preact/hooks";
import { useIntermediate } from '../intermediate/Intermediate';
@@ -41,12 +41,12 @@ export const AppContext = createContext<Client>(null!);
export const StatusContext = createContext<ClientStatus>(null!);
export const OperationsContext = createContext<ClientOperations>(null!);
type Props = WithDispatcher & {
type Props = {
auth: AuthState;
children: Children;
};
function Context({ auth, children, dispatcher }: Props) {
function Context({ auth, children }: Props) {
const history = useHistory();
const { openScreen } = useIntermediate();
const [status, setStatus] = useState(ClientStatus.INIT);
@@ -94,7 +94,7 @@ function Context({ auth, children, dispatcher }: Props) {
const onboarding = await client.login(data);
setReconnectDisallowed(false);
const login = () =>
dispatcher({
dispatch({
type: "LOGIN",
session: client.session! // This [null assertion] is ok, we should have a session by now. - insert's words
});
@@ -114,10 +114,10 @@ function Context({ auth, children, dispatcher }: Props) {
}
},
logout: async shouldRequest => {
dispatcher({ type: "LOGOUT" });
dispatch({ type: "LOGOUT" });
client.reset();
dispatcher({ type: "RESET" });
dispatch({ type: "RESET" });
openScreen({ id: "none" });
setStatus(ClientStatus.READY);
@@ -145,7 +145,7 @@ function Context({ auth, children, dispatcher }: Props) {
}
}, [ client, auth.active ]);
useEffect(() => registerEvents({ operations, dispatcher }, setStatus, client), [ client ]);
useEffect(() => registerEvents({ operations }, setStatus, client), [ client ]);
useEffect(() => {
(async () => {
@@ -154,7 +154,7 @@ function Context({ auth, children, dispatcher }: Props) {
}
if (auth.active) {
dispatcher({ type: "QUEUE_FAIL_ALL" });
dispatch({ type: "QUEUE_FAIL_ALL" });
const active = auth.accounts[auth.active];
client.user = client.users.get(active.session.user_id);
@@ -226,6 +226,5 @@ export default connectState<{ children: Children }>(
auth: state.auth,
sync: state.sync
};
},
true
}
);

View File

@@ -7,10 +7,10 @@ import { AppContext } from "./RevoltClient";
import { Typing } from "../../redux/reducers/typing";
import { useContext, useEffect } from "preact/hooks";
import { connectState } from "../../redux/connector";
import { WithDispatcher } from "../../redux/reducers";
import { QueuedMessage } from "../../redux/reducers/queue";
import { dispatch } from "../../redux";
type Props = WithDispatcher & {
type Props = {
messages: QueuedMessage[];
typing: Typing
};
@@ -19,7 +19,7 @@ function StateMonitor(props: Props) {
const client = useContext(AppContext);
useEffect(() => {
props.dispatcher({
dispatch({
type: 'QUEUE_DROP_ALL'
});
}, [ ]);
@@ -29,7 +29,7 @@ function StateMonitor(props: Props) {
if (!msg.nonce) return;
if (!props.messages.find(x => x.id === msg.nonce)) return;
props.dispatcher({
dispatch({
type: 'QUEUE_REMOVE',
nonce: msg.nonce
});
@@ -47,7 +47,7 @@ function StateMonitor(props: Props) {
for (let user of users) {
if (+ new Date() > user.started + 5000) {
props.dispatcher({
dispatch({
type: 'TYPING_STOP',
channel,
user: user.id
@@ -73,6 +73,5 @@ export default connectState(
messages: [...state.queue],
typing: state.typing
};
},
true
}
);

View File

@@ -7,14 +7,14 @@ import { Language } from "../Locale";
import { Sync } from "revolt.js/dist/api/objects";
import { useContext, useEffect } from "preact/hooks";
import { connectState } from "../../redux/connector";
import { WithDispatcher } from "../../redux/reducers";
import { Settings } from "../../redux/reducers/settings";
import { Notifications } from "../../redux/reducers/notifications";
import { AppContext, ClientStatus, StatusContext } from "./RevoltClient";
import { ClientboundNotification } from "revolt.js/dist/websocket/notifications";
import { DEFAULT_ENABLED_SYNC, SyncData, SyncKeys, SyncOptions } from "../../redux/reducers/sync";
import { dispatch } from "../../redux";
type Props = WithDispatcher & {
type Props = {
settings: Settings,
locale: Language,
sync: SyncOptions,
@@ -54,7 +54,7 @@ function SyncManager(props: Props) {
client
.syncFetchSettings(DEFAULT_ENABLED_SYNC.filter(x => !props.sync?.disabled?.includes(x)))
.then(data => {
props.dispatcher({
dispatch({
type: 'SYNC_UPDATE',
update: mapSync(data)
});
@@ -62,13 +62,13 @@ function SyncManager(props: Props) {
client
.syncFetchUnreads()
.then(unreads => props.dispatcher({ type: 'UNREADS_SET', unreads }));
.then(unreads => dispatch({ type: 'UNREADS_SET', unreads }));
}
}, [ status ]);
function syncChange(key: SyncKeys, data: any) {
let timestamp = + new Date();
props.dispatcher({
dispatch({
type: 'SYNC_SET_REVISION',
key,
timestamp
@@ -99,7 +99,7 @@ function SyncManager(props: Props) {
if (packet.type === 'UserSettingsUpdate') {
let update: { [key in SyncKeys]?: [ number, SyncData[key] ] } = mapSync(packet.update, props.sync.revision);
props.dispatcher({
dispatch({
type: 'SYNC_UPDATE',
update
});
@@ -122,6 +122,5 @@ export default connectState(
sync: state.sync,
notifications: state.notifications
};
},
true
}
);

View File

@@ -1,11 +1,11 @@
import { ClientboundNotification } from "revolt.js/dist/websocket/notifications";
import { WithDispatcher } from "../../redux/reducers";
import { Client, Message } from "revolt.js/dist";
import {
ClientOperations,
ClientStatus
} from "./RevoltClient";
import { StateUpdater } from "preact/hooks";
import { dispatch } from "../../redux";
export var preventReconnect = false;
let preventUntil = 0;
@@ -15,9 +15,8 @@ export function setReconnectDisallowed(allowed: boolean) {
}
export function registerEvents({
operations,
dispatcher
}: { operations: ClientOperations } & WithDispatcher, setStatus: StateUpdater<ClientStatus>, client: Client) {
operations
}: { operations: ClientOperations }, setStatus: StateUpdater<ClientStatus>, client: Client) {
function attemptReconnect() {
if (preventReconnect) return;
function reconnect() {
@@ -47,7 +46,7 @@ export function registerEvents({
switch (packet.type) {
case "ChannelStartTyping": {
if (packet.user === client.user?._id) return;
dispatcher({
dispatch({
type: "TYPING_START",
channel: packet.id,
user: packet.user
@@ -56,7 +55,7 @@ export function registerEvents({
}
case "ChannelStopTyping": {
if (packet.user === client.user?._id) return;
dispatcher({
dispatch({
type: "TYPING_STOP",
channel: packet.id,
user: packet.user
@@ -64,7 +63,7 @@ export function registerEvents({
break;
}
case "ChannelAck": {
dispatcher({
dispatch({
type: "UNREADS_MARK_READ",
channel: packet.id,
message: packet.message_id
@@ -76,7 +75,7 @@ export function registerEvents({
message: (message: Message) => {
if (message.mentions?.includes(client.user!._id)) {
dispatcher({
dispatch({
type: "UNREADS_MENTION",
channel: message.channel,
message: message._id