diff --git a/frontend_tests/node_tests/alert_words.js b/frontend_tests/node_tests/alert_words.js index ea96597282..25e2a17fa6 100644 --- a/frontend_tests/node_tests/alert_words.js +++ b/frontend_tests/node_tests/alert_words.js @@ -1,3 +1,7 @@ +add_dependencies({ + util: 'js/util.js' +}); + set_global('page_params', { alert_words: ['alertone', 'alerttwo', 'alertthree', 'al*rt.*s', '.+'], email: 'tester@zulip.com' diff --git a/frontend_tests/node_tests/bot_data.js b/frontend_tests/node_tests/bot_data.js index 807f0f5728..78e3b13ae0 100644 --- a/frontend_tests/node_tests/bot_data.js +++ b/frontend_tests/node_tests/bot_data.js @@ -1,3 +1,7 @@ +add_dependencies({ + util: 'js/util.js' +}); + var _ = global._; set_global('$', function (f) { diff --git a/frontend_tests/node_tests/people.js b/frontend_tests/node_tests/people.js index c02f42314f..64a56fff86 100644 --- a/frontend_tests/node_tests/people.js +++ b/frontend_tests/node_tests/people.js @@ -5,7 +5,8 @@ add_dependencies({ var people = require("js/people.js"); set_global('page_params', { - people_list: [] + people_list: [], + email: 'hamlet@example.com' }); set_global('activity', { set_user_statuses: function () {} diff --git a/static/js/activity.js b/static/js/activity.js index 3c92fc4637..8a0e6a74f0 100644 --- a/static/js/activity.js +++ b/static/js/activity.js @@ -371,7 +371,7 @@ function focus_ping() { // Ping returns the active peer list _.each(data.presences, function (presence, this_email) { - if (page_params.email !== this_email) { + if (!util.is_current_user(this_email)) { exports.presence_info[this_email] = status_from_timestamp(data.server_timestamp, presence); } }); @@ -413,7 +413,7 @@ exports.set_user_statuses = function (users, server_time) { var updated_users = {}; var status; _.each(users, function (presence, email) { - if (email === page_params.email) { + if (util.is_current_user(email)) { return; } status = status_from_timestamp(server_time, presence); diff --git a/static/js/alert_words.js b/static/js/alert_words.js index a1ba0d8d21..5d9a7ec9ac 100644 --- a/static/js/alert_words.js +++ b/static/js/alert_words.js @@ -42,7 +42,7 @@ exports.process_message = function (message) { }; exports.notifies = function (message) { - return ((message.sender_email !== page_params.email) && message.alerted); + return !util.is_current_user(message.sender_email) && message.alerted; }; return exports; diff --git a/static/js/bot_data.js b/static/js/bot_data.js index a687d64e5b..a141afe312 100644 --- a/static/js/bot_data.js +++ b/static/js/bot_data.js @@ -13,7 +13,7 @@ var bot_data = (function () { var set_can_admin = function bot_data__set_can_admin(bot) { if (page_params.is_admin) { bot.can_admin = true; - } else if (page_params.email === bot.owner) { + } else if (bot.owner !== undefined && util.is_current_user(bot.owner)) { bot.can_admin = true; } else { bot.can_admin = false; diff --git a/static/js/compose_fade.js b/static/js/compose_fade.js index 446b691934..5f1377b883 100644 --- a/static/js/compose_fade.js +++ b/static/js/compose_fade.js @@ -103,7 +103,7 @@ exports.would_receive_message = function (email) { // helpful if we want to emphasize the '.unfaded' class later (applied // to users who will definitely receive the message). - if (email.toLowerCase() === page_params.email.toLowerCase()) { + if (util.is_current_user(email)) { // We never want to fade you yourself, so pretend it's true even if // it's not. return true; diff --git a/static/js/message_list_view.js b/static/js/message_list_view.js index 1a759656c8..3a9df1f7b6 100644 --- a/static/js/message_list_view.js +++ b/static/js/message_list_view.js @@ -332,7 +332,7 @@ MessageListView.prototype = { if (row.hasClass('mention')) { row.find('.user-mention').each(function () { var email = $(this).attr('data-user-email'); - if (email === '*' || email === page_params.email) { + if (email === '*' || util.is_current_user(email)) { $(this).addClass('user-mention-me'); } }); @@ -558,8 +558,7 @@ MessageListView.prototype = { var row_id = rows.id(elem); // check for `row_id` NaN in case we're looking at a date row or bookend row if (row_id > -1 && - this.get_message(row_id).sender_email === page_params.email) - { + util.is_current_user(this.get_message(row_id).sender_email)) { distance_to_last_message_sent_by_me += elem.height(); id_of_last_message_sent_by_us = rows.id(elem); } diff --git a/static/js/message_store.js b/static/js/message_store.js index 2397c2784d..a9de3a6b7e 100644 --- a/static/js/message_store.js +++ b/static/js/message_store.js @@ -20,7 +20,7 @@ exports.get_private_message_recipient = function (message, attr, fallback_attr) var recipient, i; var other_recipients = _.filter(message.display_recipient, function (element) { - return element.email !== page_params.email; + return !util.is_current_user(element.email); }); if (other_recipients.length === 0) { // private message with oneself @@ -131,7 +131,7 @@ function add_message_metadata(message) { var involved_people; - message.sent_by_me = (message.sender_email === page_params.email); + message.sent_by_me = util.is_current_user(message.sender_email); message.flags = message.flags || []; message.historical = (message.flags !== undefined && diff --git a/static/js/notifications.js b/static/js/notifications.js index 990e7fbd15..8dafa84dc9 100644 --- a/static/js/notifications.js +++ b/static/js/notifications.js @@ -488,7 +488,7 @@ function get_message_header(message) { if (message.display_recipient.length > 2) { return "group PM with " + message.display_reply_to; } - if (message.reply_to === page_params.email) { + if (util.is_current_user(message.reply_to)) { return "PM with yourself"; } return "PM with " + message.display_reply_to; @@ -496,7 +496,7 @@ function get_message_header(message) { exports.possibly_notify_new_messages_outside_viewport = function (messages) { _.each(messages, function (message) { - if (message.sender_email !== page_params.email) { + if (!util.is_current_user(message.sender_email)) { return; } // queue up offscreen because of narrowed, or (secondarily) offscreen @@ -533,7 +533,7 @@ exports.possibly_notify_new_messages_outside_viewport = function (messages) { // the current_msg_list (!can_apply_locally; a.k.a. "a search"). exports.notify_messages_outside_current_search = function (messages) { _.each(messages, function (message) { - if (message.sender_email !== page_params.email) { + if (!util.is_current_user(message.sender_email)) { return; } exports.notify_above_composebox("Sent! Your recent message is outside the current search.", diff --git a/static/js/people.js b/static/js/people.js index 2a8cc1ff95..6d7a7298c1 100644 --- a/static/js/people.js +++ b/static/js/people.js @@ -44,7 +44,7 @@ function people_cmp(person1, person2) { exports.get_rest_of_realm = function get_rest_of_realm() { var people_minus_you = []; realm_people_dict.each(function (person) { - if (person.email !== page_params.email) { + if (!util.is_current_user(person.email)) { people_minus_you.push({"email": person.email, "full_name": person.full_name}); } @@ -129,7 +129,7 @@ exports.update = function update(person) { person_obj.full_name = person.full_name; - if (person.email === page_params.email) { + if (util.is_current_user(person.email)) { page_params.fullname = person.full_name; } } @@ -137,7 +137,7 @@ exports.update = function update(person) { if (_.has(person, 'is_admin')) { person_obj.is_admin = person.is_admin; - if (person.email === page_params.email) { + if (util.is_current_user(person.email)) { page_params.is_admin = person.is_admin; admin.show_or_hide_menu_item(); } diff --git a/static/js/subs.js b/static/js/subs.js index a1fa4d5943..7672cf2d03 100644 --- a/static/js/subs.js +++ b/static/js/subs.js @@ -887,7 +887,7 @@ $(function () { if (data.subscribed.hasOwnProperty(principal)) { error_elem.addClass("hide"); warning_elem.addClass("hide"); - if (principal === page_params.email) { + if (util.is_current_user(principal)) { // mark_subscribed adds the user to the member list exports.mark_subscribed(stream); } else { @@ -925,7 +925,7 @@ $(function () { // Remove the user from the subscriber list. list_entry.remove(); - if (principal === page_params.email) { + if (util.is_current_user(principal)) { // If you're unsubscribing yourself, mark whole // stream entry as you being unsubscribed. exports.mark_unsubscribed(stream_name); diff --git a/static/js/util.js b/static/js/util.js index 215e2db94a..8b515dad1c 100644 --- a/static/js/util.js +++ b/static/js/util.js @@ -61,6 +61,10 @@ exports.same_stream_and_subject = function util_same_stream_and_subject(a, b) { (a.subject.toLowerCase() === b.subject.toLowerCase())); }; +exports.is_current_user = function (email) { + return email.toLowerCase() === page_params.email.toLowerCase(); +}; + exports.same_major_recipient = function (a, b) { // Same behavior as same_recipient, except that it returns true for messages // on different topics but the same stream.