Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

refactor(app): unexport gateway values and inline read ack logic

Hampus48e02720bdb7
diff --git a/fluxer_app/src/features/gateway/events/GatewayReady.ts b/fluxer_app/src/features/gateway/events/GatewayReady.ts
index 31bac0496..696011775 100644
--- a/fluxer_app/src/features/gateway/events/GatewayReady.ts
+++ b/fluxer_app/src/features/gateway/events/GatewayReady.ts
@@ -82,14 +82,14 @@ export interface ReadyPayload {
webauthn_credentials?: Array<WebAuthnCredential>;
}
-export class GatewayReadyIdentityMismatchError extends Error {
+class GatewayReadyIdentityMismatchError extends Error {
constructor(expectedUserId: string, receivedUserId: string) {
super(`READY user mismatch: expected ${expectedUserId}, received ${receivedUserId}`);
this.name = 'GatewayReadyIdentityMismatchError';
}
}
-export class GatewayReadyAccountContextMissingError extends Error {
+class GatewayReadyAccountContextMissingError extends Error {
constructor() {
super('Gateway READY has no account context');
this.name = 'GatewayReadyAccountContextMissingError';
diff --git a/fluxer_app/src/features/gateway/snapshot/SnapshotChannelReducer.ts b/fluxer_app/src/features/gateway/snapshot/SnapshotChannelReducer.ts
index 166eb9152..92844ef37 100644
--- a/fluxer_app/src/features/gateway/snapshot/SnapshotChannelReducer.ts
+++ b/fluxer_app/src/features/gateway/snapshot/SnapshotChannelReducer.ts
@@ -33,12 +33,12 @@ import {THREAD_CHANNEL_TYPES, THREAD_ONLY_CHANNEL_TYPES} from '@fluxer/constants
import type {Channel as WireChannel} from '@fluxer/schema/src/domains/channel/ChannelSchemas';
import type {ThreadMemberResponse} from '@fluxer/schema/src/domains/channel/ThreadSchemas';
-export interface SnapshotChannelUserAuthority {
+interface SnapshotChannelUserAuthority {
readonly getSelfUserId: () => string | null;
readonly retainUser: (emit: SnapshotEmit, user: SnapshotUserRow) => void;
}
-export interface SnapshotChannelReadyEntries {
+interface SnapshotChannelReadyEntries {
readonly channels: Array<SnapshotRowReplaceEntityEntry<'channel'>>;
readonly readStates: Array<SnapshotRowReplaceEntityEntry<'read_state'>>;
}
@@ -463,7 +463,11 @@ export class SnapshotChannelReducer {
return;
}
const current = this.readState(channel.id);
- const privateAck = this.isPrivateAckOnCreateChannel(channel);
+ const privateAck =
+ channel.last_message_id != null &&
+ (channel.type === ChannelTypes.DM ||
+ channel.type === ChannelTypes.GROUP_DM ||
+ channel.type === ChannelTypes.DM_PERSONAL_NOTES);
this.writeReadState(emit, channel.id, {
...current,
lastMessageId: channel.last_message_id ?? null,
@@ -481,24 +485,27 @@ export class SnapshotChannelReducer {
): void {
const current = this.readState(message.channel_id);
const authoredBySelf = message.author?.id === this.users.getSelfUserId();
- this.writeReadState(emit, message.channel_id, {
+ const channelId = message.channel_id;
+ const next = {
...current,
lastMessageId: message.id,
guildId: channel.guild_id ?? message.guild_id ?? current.guildId,
readStateKnown: authoredBySelf || !current.readStateKnown ? true : current.readStateKnown,
- ackMessageId: authoredBySelf ? message.id : current.readStateKnown ? current.ackMessageId : previousLastMessageId,
+ };
+ let ackMessageId: string | null;
+ if (authoredBySelf) {
+ ackMessageId = message.id;
+ } else if (current.readStateKnown) {
+ ackMessageId = current.ackMessageId;
+ } else {
+ ackMessageId = previousLastMessageId;
+ }
+ this.writeReadState(emit, channelId, {
+ ...next,
+ ackMessageId,
mentionCount: authoredBySelf ? 0 : current.mentionCount,
});
}
-
- private isPrivateAckOnCreateChannel(channel: WireChannel): boolean {
- return (
- channel.last_message_id != null &&
- (channel.type === ChannelTypes.DM ||
- channel.type === ChannelTypes.GROUP_DM ||
- channel.type === ChannelTypes.DM_PERSONAL_NOTES)
- );
- }
}
function threadRow(wire: SnapshotThreadWire, guildId: string, existing: WireChannel | undefined): SnapshotThreadWire {
diff --git a/fluxer_app/src/features/gateway/snapshot/SnapshotDispatchEvent.ts b/fluxer_app/src/features/gateway/snapshot/SnapshotDispatchEvent.ts
index ff411f16b..3bf83d4c1 100644
--- a/fluxer_app/src/features/gateway/snapshot/SnapshotDispatchEvent.ts
+++ b/fluxer_app/src/features/gateway/snapshot/SnapshotDispatchEvent.ts
@@ -78,11 +78,11 @@ export interface SnapshotVoiceStateUpdatePayload extends Omit<VoiceState, 'guild
readonly connection_id?: string;
}
-export interface SnapshotRelationshipRemovePayload {
+interface SnapshotRelationshipRemovePayload {
readonly id: string;
}
-export interface SnapshotDispatchDataMap {
+interface SnapshotDispatchDataMap {
readonly GUILD_CREATE: GuildReadyData;
readonly GUILD_SYNC: GuildReadyData;
readonly GUILD_UPDATE: WireGuild;
@@ -134,7 +134,7 @@ export interface SnapshotDispatchDataMap {
readonly THREAD_MEMBERS_UPDATE: SnapshotThreadMembersUpdatePayload;
}
-export const SnapshotDispatchEvent = Object.freeze({
+const SnapshotDispatchEvent = Object.freeze({
GUILD_CREATE: 'GUILD_CREATE',
GUILD_SYNC: 'GUILD_SYNC',
GUILD_UPDATE: 'GUILD_UPDATE',
@@ -186,7 +186,7 @@ export const SnapshotDispatchEvent = Object.freeze({
THREAD_MEMBERS_UPDATE: 'THREAD_MEMBERS_UPDATE',
} as const);
-export type SnapshotDispatchType = (typeof SnapshotDispatchEvent)[keyof typeof SnapshotDispatchEvent];
+type SnapshotDispatchType = (typeof SnapshotDispatchEvent)[keyof typeof SnapshotDispatchEvent];
export type SnapshotDispatch = {
readonly [Type in SnapshotDispatchType]: {
@@ -204,7 +204,7 @@ const SNAPSHOT_ARRAY_DISPATCH_TYPES: ReadonlySet<SnapshotDispatchType> = new Set
'WEBAUTHN_CREDENTIALS_UPDATE',
]);
-export function isSnapshotDispatchType(type: string): type is SnapshotDispatchType {
+function isSnapshotDispatchType(type: string): type is SnapshotDispatchType {
return SNAPSHOT_DISPATCH_TYPES.has(type);
}
diff --git a/fluxer_app/src/features/gateway/snapshot/SnapshotEntities.ts b/fluxer_app/src/features/gateway/snapshot/SnapshotEntities.ts
index 76fc33214..97276a21c 100644
--- a/fluxer_app/src/features/gateway/snapshot/SnapshotEntities.ts
+++ b/fluxer_app/src/features/gateway/snapshot/SnapshotEntities.ts
@@ -35,7 +35,7 @@ declare const SNAPSHOT_RELATIONSHIP_KEY_BRAND: unique symbol;
declare const SNAPSHOT_USER_KEY_BRAND: unique symbol;
declare const SNAPSHOT_PRESENCE_KEY_BRAND: unique symbol;
-export type SnapshotRowKey = string & {readonly [SNAPSHOT_ROW_KEY_BRAND]: true};
+type SnapshotRowKey = string & {readonly [SNAPSHOT_ROW_KEY_BRAND]: true};
export type SnapshotRowKeyPrefix = string & {readonly [SNAPSHOT_ROW_KEY_PREFIX_BRAND]: true};
export type SnapshotSingletonKey = SnapshotRowKey & {readonly [SNAPSHOT_SINGLETON_KEY_BRAND]: true};
export type SnapshotGuildKey = SnapshotRowKey & {readonly [SNAPSHOT_GUILD_KEY_BRAND]: true};
@@ -54,17 +54,17 @@ export type SnapshotPresenceKey = SnapshotRowKey & {readonly [SNAPSHOT_PRESENCE_
export const SNAPSHOT_SINGLETON_KEY = snapshotSingletonKey('@me');
-export function snapshotRowKey(value: string): SnapshotRowKey {
+function snapshotRowKey(value: string): SnapshotRowKey {
requireNonEmpty(value, 'snapshot row key');
return value as SnapshotRowKey;
}
-export function snapshotRowKeyPrefix(value: string): SnapshotRowKeyPrefix {
+function snapshotRowKeyPrefix(value: string): SnapshotRowKeyPrefix {
requireNonEmpty(value, 'snapshot row key prefix');
return value as SnapshotRowKeyPrefix;
}
-export function snapshotSingletonKey(value: '@me'): SnapshotSingletonKey {
+function snapshotSingletonKey(value: '@me'): SnapshotSingletonKey {
return snapshotRowKey(value) as SnapshotSingletonKey;
}
@@ -253,34 +253,34 @@ export interface SnapshotEntityKeyMap {
export type SnapshotSingletonEntity = 'user_settings' | 'account_metadata' | 'user_connections';
-export interface SnapshotRowUpsertOpFor<E extends SnapshotEntity> {
+interface SnapshotRowUpsertOpFor<E extends SnapshotEntity> {
readonly kind: 'upsert';
readonly entity: E;
readonly key: SnapshotEntityKeyMap[E];
readonly value: SnapshotEntityRowMap[E];
}
-export type SnapshotRowUpsertOp<E extends SnapshotEntity = SnapshotEntity> = E extends SnapshotEntity
+type SnapshotRowUpsertOp<E extends SnapshotEntity = SnapshotEntity> = E extends SnapshotEntity
? SnapshotRowUpsertOpFor<E>
: never;
-export interface SnapshotRowDeleteOpFor<E extends SnapshotEntity> {
+interface SnapshotRowDeleteOpFor<E extends SnapshotEntity> {
readonly kind: 'delete';
readonly entity: E;
readonly key: SnapshotEntityKeyMap[E];
}
-export type SnapshotRowDeleteOp<E extends SnapshotEntity = SnapshotEntity> = E extends SnapshotEntity
+type SnapshotRowDeleteOp<E extends SnapshotEntity = SnapshotEntity> = E extends SnapshotEntity
? SnapshotRowDeleteOpFor<E>
: never;
-export interface SnapshotRowDeleteByPrefixOpFor<E extends SnapshotEntity> {
+interface SnapshotRowDeleteByPrefixOpFor<E extends SnapshotEntity> {
readonly kind: 'deleteByPrefix';
readonly entity: E;
readonly keyPrefix: SnapshotRowKeyPrefix;
}
-export type SnapshotRowDeleteByPrefixOp<E extends SnapshotEntity = SnapshotEntity> = E extends SnapshotEntity
+type SnapshotRowDeleteByPrefixOp<E extends SnapshotEntity = SnapshotEntity> = E extends SnapshotEntity
? SnapshotRowDeleteByPrefixOpFor<E>
: never;
@@ -289,13 +289,13 @@ export interface SnapshotRowReplaceEntityEntry<E extends SnapshotEntity = Snapsh
readonly value: SnapshotEntityRowMap[E];
}
-export interface SnapshotRowReplaceEntityOpFor<E extends SnapshotEntity> {
+interface SnapshotRowReplaceEntityOpFor<E extends SnapshotEntity> {
readonly kind: 'replaceEntity';
readonly entity: E;
readonly entries: ReadonlyArray<SnapshotRowReplaceEntityEntry<E>>;
}
-export type SnapshotRowReplaceEntityOp<E extends SnapshotEntity = SnapshotEntity> = E extends SnapshotEntity
+type SnapshotRowReplaceEntityOp<E extends SnapshotEntity = SnapshotEntity> = E extends SnapshotEntity
? SnapshotRowReplaceEntityOpFor<E>
: never;
@@ -329,7 +329,7 @@ export function parseSnapshotSingleton<E extends SnapshotSingletonEntity>(
return parseSnapshotRow(entries, entity, SNAPSHOT_SINGLETON_KEY);
}
-export function parseSnapshotRow<E extends SnapshotEntity>(
+function parseSnapshotRow<E extends SnapshotEntity>(
entries: StateSnapshotEntries,
entity: E,
key: SnapshotEntityKeyMap[E],
diff --git a/fluxer_app/src/features/gateway/transport/GatewayCompression.ts b/fluxer_app/src/features/gateway/transport/GatewayCompression.ts
index 6cec00659..21a637ca4 100644
--- a/fluxer_app/src/features/gateway/transport/GatewayCompression.ts
+++ b/fluxer_app/src/features/gateway/transport/GatewayCompression.ts
@@ -15,7 +15,7 @@ export type CompressionType = 'none' | 'zstd-stream';
const ZSTD_STREAM_LEVEL = 3;
-export class GatewayCompressionError extends Error {
+class GatewayCompressionError extends Error {
readonly compression: CompressionType;
readonly originalError: unknown;
diff --git a/fluxer_app/src/features/gateway/transport/GatewayDispatchBufferBounds.ts b/fluxer_app/src/features/gateway/transport/GatewayDispatchBufferBounds.ts
index cbf5b6b43..6b72c3d85 100644
--- a/fluxer_app/src/features/gateway/transport/GatewayDispatchBufferBounds.ts
+++ b/fluxer_app/src/features/gateway/transport/GatewayDispatchBufferBounds.ts
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
-export const GATEWAY_DISPATCH_BUFFER_MAX_ENTRIES = 1024;
-export const GATEWAY_DISPATCH_BUFFER_MAX_BYTES = 16 * 1024 * 1024;
+const GATEWAY_DISPATCH_BUFFER_MAX_ENTRIES = 1024;
+const GATEWAY_DISPATCH_BUFFER_MAX_BYTES = 16 * 1024 * 1024;
export function exceedsDispatchBufferCapacity(
entryCount: number,
diff --git a/fluxer_app/src/features/gateway/transport/GatewayReadinessWaiters.ts b/fluxer_app/src/features/gateway/transport/GatewayReadinessWaiters.ts
index ace1f7710..a24296634 100644
--- a/fluxer_app/src/features/gateway/transport/GatewayReadinessWaiters.ts
+++ b/fluxer_app/src/features/gateway/transport/GatewayReadinessWaiters.ts
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
-export const GATEWAY_FOREGROUND_READY_TIMEOUT_MS = 60_000;
+const GATEWAY_FOREGROUND_READY_TIMEOUT_MS = 60_000;
export class GatewayReadyTimeoutError extends Error {
constructor() {