mirror of https://github.com/zulip/zulip.git
shared: Describe interface of typing_status in Flow.
This allows the mobile app to stay well-typed while using this code.
This commit is contained in:
parent
a63786ac0d
commit
b70b7df22c
|
@ -30,8 +30,10 @@ var TYPING_STOPPED_WAIT_PERIOD = 5000; // 5s
|
||||||
appropriately.)
|
appropriately.)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/** Exported only for tests. */
|
||||||
export const state = {};
|
export const state = {};
|
||||||
|
|
||||||
|
/** Exported only for tests. */
|
||||||
export function initialize_state() {
|
export function initialize_state() {
|
||||||
state.current_recipient = undefined;
|
state.current_recipient = undefined;
|
||||||
state.next_send_start_time = undefined;
|
state.next_send_start_time = undefined;
|
||||||
|
@ -40,6 +42,7 @@ export function initialize_state() {
|
||||||
|
|
||||||
initialize_state();
|
initialize_state();
|
||||||
|
|
||||||
|
/** Exported only for tests. */
|
||||||
export function stop_last_notification(worker) {
|
export function stop_last_notification(worker) {
|
||||||
if (state.idle_timer) {
|
if (state.idle_timer) {
|
||||||
clearTimeout(state.idle_timer);
|
clearTimeout(state.idle_timer);
|
||||||
|
@ -48,6 +51,7 @@ export function stop_last_notification(worker) {
|
||||||
initialize_state();
|
initialize_state();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Exported only for tests. */
|
||||||
export function start_or_extend_idle_timer(worker) {
|
export function start_or_extend_idle_timer(worker) {
|
||||||
function on_idle_timeout() {
|
function on_idle_timeout() {
|
||||||
// We don't do any real error checking here, because
|
// We don't do any real error checking here, because
|
||||||
|
@ -75,6 +79,7 @@ function actually_ping_server(worker, recipient, current_time) {
|
||||||
set_next_start_time(current_time);
|
set_next_start_time(current_time);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Exported only for tests. */
|
||||||
export function maybe_ping_server(worker, recipient) {
|
export function maybe_ping_server(worker, recipient) {
|
||||||
var current_time = worker.get_current_time();
|
var current_time = worker.get_current_time();
|
||||||
if (current_time > state.next_send_start_time) {
|
if (current_time > state.next_send_start_time) {
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
/**
|
||||||
|
* @flow strict
|
||||||
|
*/
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
type RecipientUserIds = number[];
|
||||||
|
|
||||||
|
type Worker = {|
|
||||||
|
get_recipient: () => RecipientUserIds | void,
|
||||||
|
is_valid_conversation: (RecipientUserIds | void) => boolean,
|
||||||
|
get_current_time: () => number, // as ms since epoch
|
||||||
|
notify_server_start: RecipientUserIds => void,
|
||||||
|
notify_server_stop: RecipientUserIds => void
|
||||||
|
|};
|
||||||
|
|
||||||
|
declare export function handle_text_input(Worker): void;
|
||||||
|
|
||||||
|
declare export function stop(Worker): void;
|
Loading…
Reference in New Issue