mirror of
https://github.com/spacebarchat/client.git
synced 2024-11-22 02:12:38 +01:00
expire typing events
This commit is contained in:
parent
cfb4567db4
commit
fec514c8e7
@ -31,6 +31,7 @@ import {
|
||||
} from "@spacebarchat/spacebar-api-types/v9";
|
||||
import { action, makeObservable, observable, runInAction } from "mobx";
|
||||
import Logger from "../utils/Logger";
|
||||
import { debounce } from "../utils/debounce";
|
||||
import AppStore from "./AppStore";
|
||||
|
||||
const GATEWAY_VERSION = "9";
|
||||
@ -635,12 +636,17 @@ export default class GatewayConnectionStore {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!channel.typingIds.has(data.user_id)) {
|
||||
this.logger.debug(`[TypingStart] ${data.user_id} has started typing in ${channel.id}`);
|
||||
channel.typingIds.add(data.user_id);
|
||||
const stop = debounce(() => {
|
||||
this.logger.debug(`[TypingStart] ${data.user_id} has stopped typing in ${channel.id}`);
|
||||
channel.typingIds.delete(data.user_id);
|
||||
}, 12_000); // little bit of extra delay to allow clients to send continuation typing events
|
||||
|
||||
// TODO: expire typing after 10 seconds
|
||||
if (!channel.typingIds.has(data.user_id)) {
|
||||
channel.typingIds.set(data.user_id, stop);
|
||||
stop();
|
||||
} else {
|
||||
this.logger.debug(`[TypingStart] ${data.user_id} is still typing in ${channel.id}`);
|
||||
channel.typingIds.get(data.user_id)?.();
|
||||
}
|
||||
// TODO: reset expiration timer
|
||||
};
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ import type {
|
||||
Snowflake as SnowflakeType,
|
||||
} from "@spacebarchat/spacebar-api-types/v9";
|
||||
import { ChannelType, Routes } from "@spacebarchat/spacebar-api-types/v9";
|
||||
import { ObservableSet, action, computed, makeObservable, observable } from "mobx";
|
||||
import { ObservableMap, action, computed, makeObservable, observable } from "mobx";
|
||||
import Logger from "../../utils/Logger";
|
||||
import type { PermissionResolvable } from "../../utils/Permissions";
|
||||
import { Permissions } from "../../utils/Permissions";
|
||||
@ -57,13 +57,13 @@ export default class Channel {
|
||||
@observable flags: number;
|
||||
@observable defaultThreadRateLimitPerUser: number;
|
||||
@observable channelIcon?: keyof typeof Icons;
|
||||
@observable typingIds: ObservableSet<SnowflakeType>;
|
||||
@observable typingIds: ObservableMap<SnowflakeType, (...args: unknown[]) => void>;
|
||||
@observable typing: number | null = null;
|
||||
private hasFetchedInitialMessages = false;
|
||||
|
||||
constructor(app: AppStore, channel: APIChannel) {
|
||||
this.app = app;
|
||||
this.typingIds = new ObservableSet();
|
||||
this.typingIds = new ObservableMap();
|
||||
|
||||
this.id = channel.id;
|
||||
this.createdAt = new Date(channel.created_at);
|
||||
@ -237,7 +237,7 @@ export default class Channel {
|
||||
|
||||
@computed
|
||||
get typingUsers(): User[] {
|
||||
return Array.from(this.typingIds.values())
|
||||
return Array.from(this.typingIds.keys())
|
||||
.map((x) => this.app.users.get(x) as User)
|
||||
.filter((x) => x && x.id !== this.app.account!.id);
|
||||
}
|
||||
@ -261,8 +261,10 @@ export default class Channel {
|
||||
}
|
||||
|
||||
@action
|
||||
stopTyping() {
|
||||
this.logger.debug("Client user has stopped typing");
|
||||
this.typing = null;
|
||||
stopTyping(force?: boolean) {
|
||||
if (force || this.typing) {
|
||||
this.logger.debug("Client user has stopped typing");
|
||||
this.typing = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user