chore: bug fix cleanup (#4)

This commit is contained in:
hampus-fluxer
2026-01-03 06:44:40 +01:00
committed by GitHub
parent 275126d61b
commit c9c5dceb47
80 changed files with 4639 additions and 3709 deletions

View File

@@ -53,6 +53,10 @@ type GuildEmojiContext = Readonly<{
usableEmojis: ReadonlyArray<GuildEmojiRecord>;
}>;
export function normalizeEmojiSearchQuery(query: string): string {
return query.trim().replace(/^:+/, '').replace(/:+$/, '');
}
class EmojiDisambiguations {
private static _lastInstance: EmojiDisambiguations | null = null;
private readonly guildId: string | null;
@@ -299,7 +303,8 @@ class EmojiStore {
}
search(channel: ChannelRecord | null, query: string, count = 0): ReadonlyArray<Emoji> {
const lowerCasedQuery = query.toLowerCase();
const normalizedQuery = normalizeEmojiSearchQuery(query);
const lowerCasedQuery = normalizedQuery.toLowerCase();
if (!lowerCasedQuery) {
const allEmojis = this.getAllEmojis(channel);
const sorted = [...allEmojis].sort(

View File

@@ -17,7 +17,7 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import {makeAutoObservable} from 'mobx';
import {makeAutoObservable, reaction} from 'mobx';
import type {StatusType} from '~/Constants';
import {StatusTypes} from '~/Constants';
import {
@@ -44,15 +44,26 @@ class LocalPresenceStore {
since: number = 0;
afk: boolean = false;
mobile: boolean = false;
customStatus: CustomStatus | null = null;
constructor() {
makeAutoObservable(this, {}, {autoBind: true});
reaction(
() => MobileLayoutStore.isMobileLayout(),
() => this.updatePresence(),
);
}
updatePresence(): void {
const userStatus = UserSettingsStore.status;
const idleSince = IdleStore.getIdleSince();
const isMobile = MobileLayoutStore.isMobileLayout();
const afk = this.computeAfk(idleSince, isMobile);
const effectiveStatus = userStatus === StatusTypes.ONLINE && idleSince > 0 ? StatusTypes.IDLE : userStatus;
@@ -60,6 +71,8 @@ class LocalPresenceStore {
this.customStatus = normalizedCustomStatus ? {...normalizedCustomStatus} : null;
this.status = effectiveStatus;
this.since = idleSince;
this.afk = afk;
this.mobile = isMobile;
}
getStatus(): StatusType {
@@ -67,24 +80,23 @@ class LocalPresenceStore {
}
getPresence(): Presence {
const isMobile = MobileLayoutStore.isMobileLayout();
const idleSince = IdleStore.getIdleSince();
const afkTimeout = UserSettingsStore.getAfkTimeout();
const timeSinceLastActivity = idleSince > 0 ? Date.now() - idleSince : 0;
const afk = !isMobile && timeSinceLastActivity > afkTimeout * 1000;
return {
status: this.status,
since: this.since,
afk,
mobile: isMobile,
afk: this.afk,
mobile: this.mobile,
custom_status: toGatewayCustomStatus(this.customStatus),
};
}
get presenceFingerprint(): string {
return `${this.status}|${customStatusToKey(this.customStatus)}`;
return `${this.status}|${customStatusToKey(this.customStatus)}|afk:${this.afk ? '1' : '0'}`;
}
private computeAfk(idleSince: number, isMobile: boolean): boolean {
if (isMobile || idleSince <= 0) return false;
const afkTimeout = UserSettingsStore.getAfkTimeout();
return Date.now() - idleSince > afkTimeout * 1000;
}
}

View File

@@ -305,7 +305,11 @@ class MediaEngineFacade {
VoiceStateManager.handleGatewayVoiceStateDelete(guildId, userId);
}
getCurrentUserVoiceState(guildId?: string | null): VoiceState | null {
return VoiceStateManager.getCurrentUserVoiceState(guildId, UserStore.getCurrentUser()?.id);
return VoiceStateManager.getCurrentUserVoiceState(
guildId,
UserStore.getCurrentUser()?.id,
VoiceConnectionManager.connectionId,
);
}
getVoiceState(guildId: string | null, userId?: string): VoiceState | null {
return VoiceStateManager.getVoiceState(guildId, userId, UserStore.getCurrentUser()?.id);

View File

@@ -95,7 +95,22 @@ class VoiceStateManager {
this.gatewayHandler.handleGuildDelete(deletedGuildId);
}
getCurrentUserVoiceState(guildId?: string | null, currentUserId?: string): VoiceState | null {
getCurrentUserVoiceState(
guildId?: string | null,
currentUserId?: string,
connectionId?: string | null,
): VoiceState | null {
const requestedGuildKey = guildId ?? ME;
if (connectionId) {
const byConnection = this.connectionVoiceStates[connectionId];
if (byConnection) {
if (!guildId || byConnection.guild_id === requestedGuildKey) {
return byConnection;
}
}
}
if (!currentUserId) {
logger.debug('[VoiceStateManager] Cannot get current user voice state: no user ID provided');
return null;