typing indicators: Use user ids internally.

We now ask compose_pm_pill to give us a list of user
ids that we are PM'ing to, and we only convert user
ids to emails right before we put requests on the wire.

We also let the "pill system" tell us whether we
have unconverted data.

It also sets up for an upcoming server change where we
can just send user ids to the server.

This change should be transparent to the majority of users.
For Zephyr users we are slightly less aggressive about
sending typing indicators, since we now require valid
user ids.
This commit is contained in:
Steve Howell 2018-08-25 15:22:48 +00:00 committed by Tim Abbott
parent c0edcf6fe4
commit 72295e94b4
1 changed files with 19 additions and 21 deletions

View File

@ -7,11 +7,12 @@ var exports = {};
//
// See docs/subsystems/typing-indicators.md for details on typing indicators.
function send_typing_notification_ajax(recipients, operation) {
function send_typing_notification_ajax(user_ids_string, operation) {
var typing_to = people.user_ids_string_to_emails_string(user_ids_string);
channel.post({
url: '/json/typing',
data: {
to: recipients,
to: typing_to,
op: operation,
},
success: function () {},
@ -21,21 +22,26 @@ function send_typing_notification_ajax(recipients, operation) {
});
}
function get_recipient() {
var compose_recipient = compose_state.recipient();
if (compose_recipient === "") {
function get_user_ids_string() {
var user_ids_string = compose_pm_pill.get_user_ids_string();
if (user_ids_string === "") {
return;
}
return compose_recipient;
return user_ids_string;
}
function is_valid_conversation(recipient) {
function is_valid_conversation(user_ids_string) {
// TODO: Check to make sure we're in a PM conversation
// with valid emails.
if (!recipient) {
if (!user_ids_string) {
return false;
}
if (compose_pm_pill.has_unconverted_data()) {
return true;
}
var compose_empty = !compose_state.has_message_content();
if (compose_empty) {
return false;
@ -50,14 +56,6 @@ function is_valid_conversation(recipient) {
return false;
}
if (compose.get_invalid_recipient_emails().length > 0) {
// If we have invalid recipient emails, it's highly
// likely the user is either still deciding who to
// compose to, or is confused. Also, the server
// will just reject our requests.
return false;
}
return true;
}
@ -65,17 +63,17 @@ function get_current_time() {
return new Date();
}
function notify_server_start(recipients) {
send_typing_notification_ajax(recipients, "start");
function notify_server_start(user_ids_string) {
send_typing_notification_ajax(user_ids_string, "start");
}
function notify_server_stop(recipients) {
send_typing_notification_ajax(recipients, "stop");
function notify_server_stop(user_ids_string) {
send_typing_notification_ajax(user_ids_string, "stop");
}
exports.initialize = function () {
var worker = {
get_recipient: get_recipient,
get_recipient: get_user_ids_string,
is_valid_conversation: is_valid_conversation,
get_current_time: get_current_time,
notify_server_start: notify_server_start,