Move MessageComposer typing timeout to TypingStore

This commit is contained in:
Travis Ralston 2019-06-27 10:35:44 -06:00
parent eb1f911d15
commit 17ed62de7d
2 changed files with 18 additions and 53 deletions

View file

@ -18,7 +18,8 @@ import MatrixClientPeg from "../MatrixClientPeg";
import SettingsStore from "../settings/SettingsStore";
import Timer from "../utils/Timer";
export const TYPING_SERVER_TIMEOUT = 30000;
const TYPING_USER_TIMEOUT = 10000;
const TYPING_SERVER_TIMEOUT = 30000;
/**
* Tracks typing state for users.
@ -40,7 +41,13 @@ export default class TypingStore {
* MatrixClientPeg client changes.
*/
reset() {
this._typingStates = {}; // roomId => { isTyping, Timer }
this._typingStates = {
// "roomId": {
// isTyping: bool, // Whether the user is typing or not
// userTimer: Timer, // Local timeout for "user has stopped typing"
// serverTimer: Timer, // Maximum timeout for the typing state
// },
};
}
/**
@ -61,21 +68,25 @@ export default class TypingStore {
if (!currentTyping) {
currentTyping = this._typingStates[roomId] = {
isTyping: isTyping,
timer: new Timer(TYPING_SERVER_TIMEOUT),
serverTimer: new Timer(TYPING_SERVER_TIMEOUT),
userTimer: new Timer(TYPING_USER_TIMEOUT),
};
}
currentTyping.isTyping = isTyping;
if (isTyping) {
currentTyping.timer.restart();
currentTyping.timer.finished().then(() => {
currentTyping.serverTimer.restart().finished().then(() => {
const currentTyping = this._typingStates[roomId];
if (currentTyping) currentTyping.isTyping = false;
// The server will (should) time us out on typing, so we don't
// need to advertise a stop of typing.
});
currentTyping.userTimer.restart().finished().then(() => {
this.setSelfTyping(roomId, false);
});
}
MatrixClientPeg.get().sendTyping(roomId, isTyping, TYPING_SERVER_TIMEOUT);