eslint: Fix unicorn/no-lonely-if.

https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v24.0.0/docs/rules/no-lonely-if.md

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2020-12-22 02:26:39 -08:00
committed by Tim Abbott
parent 6acbcec39d
commit 2f80415756
23 changed files with 223 additions and 247 deletions

View File

@@ -46,10 +46,8 @@ exports.initialize = function () {
// Later we check whether after MS_DELAY the user is still // Later we check whether after MS_DELAY the user is still
// long touching the same message as it can be possible that // long touching the same message as it can be possible that
// user touched another message within MS_DELAY period. // user touched another message within MS_DELAY period.
if (meta.touchdown === true && !meta.invalid) { if (meta.touchdown === true && !meta.invalid && id === meta.current_target) {
if (id === meta.current_target) { $(this).trigger("longtap");
$(this).trigger("longtap");
}
} }
}, MS_DELAY); }, MS_DELAY);
}); });

View File

@@ -19,13 +19,15 @@ exports.smart_insert = function (textarea, syntax) {
const before_str = textarea.val().slice(0, pos); const before_str = textarea.val().slice(0, pos);
const after_str = textarea.val().slice(pos); const after_str = textarea.val().slice(pos);
if (pos > 0) { if (
pos > 0 &&
// If there isn't space either at the end of the content // If there isn't space either at the end of the content
// before the insert or (unlikely) at the start of the syntax, // before the insert or (unlikely) at the start of the syntax,
// add one. // add one.
if (!is_space(before_str.slice(-1)) && !is_space(syntax[0])) { !is_space(before_str.slice(-1)) &&
syntax = " " + syntax; !is_space(syntax[0])
} ) {
syntax = " " + syntax;
} }
// If there isn't whitespace either at the end of the syntax or the // If there isn't whitespace either at the end of the syntax or the

View File

@@ -227,12 +227,13 @@ function handle_keydown(e) {
function handle_keyup(e) { function handle_keyup(e) {
const code = e.keyCode || e.which; const code = e.keyCode || e.which;
if (code === 13 || (code === 9 && !e.shiftKey)) { if (
// Enter key or Tab key // Enter key or Tab key
if (nextFocus) { (code === 13 || (code === 9 && !e.shiftKey)) &&
nextFocus.trigger("focus"); nextFocus
nextFocus = false; ) {
} nextFocus.trigger("focus");
nextFocus = false;
} }
} }

View File

@@ -473,30 +473,28 @@ exports.drafts_handle_events = function (e, event_key) {
const focused_draft_id = row_with_focus().data("draft-id"); const focused_draft_id = row_with_focus().data("draft-id");
// Allows user to delete drafts with Backspace // Allows user to delete drafts with Backspace
if (event_key === "backspace" || event_key === "delete") { if ((event_key === "backspace" || event_key === "delete") && focused_draft_id !== undefined) {
if (focused_draft_id !== undefined) { const draft_row = row_with_focus();
const draft_row = row_with_focus(); const next_draft_row = row_after_focus();
const next_draft_row = row_after_focus(); const prev_draft_row = row_before_focus();
const prev_draft_row = row_before_focus(); let draft_to_be_focused_id;
let draft_to_be_focused_id;
// Try to get the next draft in the list and 'focus' it // Try to get the next draft in the list and 'focus' it
// Use previous draft as a fallback // Use previous draft as a fallback
if (next_draft_row[0] !== undefined) { if (next_draft_row[0] !== undefined) {
draft_to_be_focused_id = next_draft_row.data("draft-id"); draft_to_be_focused_id = next_draft_row.data("draft-id");
} else if (prev_draft_row[0] !== undefined) { } else if (prev_draft_row[0] !== undefined) {
draft_to_be_focused_id = prev_draft_row.data("draft-id"); draft_to_be_focused_id = prev_draft_row.data("draft-id");
}
const new_focus_element = document.querySelectorAll(
'[data-draft-id="' + draft_to_be_focused_id + '"]',
);
if (new_focus_element[0] !== undefined) {
activate_element(new_focus_element[0].children[0]);
}
remove_draft(draft_row);
} }
const new_focus_element = document.querySelectorAll(
'[data-draft-id="' + draft_to_be_focused_id + '"]',
);
if (new_focus_element[0] !== undefined) {
activate_element(new_focus_element[0].children[0]);
}
remove_draft(draft_row);
} }
// This handles when pressing Enter while looking at drafts. // This handles when pressing Enter while looking at drafts.

View File

@@ -512,30 +512,32 @@ exports.navigate = function (event_name, e) {
function process_keypress(e) { function process_keypress(e) {
const is_filter_focused = $(".emoji-popover-filter").is(":focus"); const is_filter_focused = $(".emoji-popover-filter").is(":focus");
const pressed_key = e.which; const pressed_key = e.which;
if (!is_filter_focused && pressed_key !== 58) { if (
!is_filter_focused &&
// ':' => 58, is a hotkey for toggling reactions popover. // ':' => 58, is a hotkey for toggling reactions popover.
if ((pressed_key >= 32 && pressed_key <= 126) || pressed_key === 8) { pressed_key !== 58 &&
// Handle only printable characters or Backspace. ((pressed_key >= 32 && pressed_key <= 126) || pressed_key === 8)
e.preventDefault(); ) {
e.stopPropagation(); // Handle only printable characters or Backspace.
e.preventDefault();
e.stopPropagation();
const emoji_filter = $(".emoji-popover-filter"); const emoji_filter = $(".emoji-popover-filter");
const old_query = emoji_filter.val(); const old_query = emoji_filter.val();
let new_query = ""; let new_query = "";
if (pressed_key === 8) { if (pressed_key === 8) {
// Handles Backspace. // Handles Backspace.
new_query = old_query.slice(0, -1); new_query = old_query.slice(0, -1);
} else { } else {
// Handles any printable character. // Handles any printable character.
const key_str = String.fromCharCode(e.which); const key_str = String.fromCharCode(e.which);
new_query = old_query + key_str; new_query = old_query + key_str;
}
emoji_filter.val(new_query);
change_focus_to_filter();
filter_emojis();
} }
emoji_filter.val(new_query);
change_focus_to_filter();
filter_emojis();
} }
} }

View File

@@ -58,15 +58,17 @@ exports.first_visible_message = function (bar) {
// Important: This will break if we ever have things that are // Important: This will break if we ever have things that are
// not message rows inside a recipient_row block. // not message rows inside a recipient_row block.
message = message.next(".message_row"); message = message.next(".message_row");
if (message.length > 0 && result) { if (
message.length > 0 &&
result &&
// Before returning a result, we check whether the next // Before returning a result, we check whether the next
// message's top is actually below the bottom of the // message's top is actually below the bottom of the
// floating recipient bar; this is different from the // floating recipient bar; this is different from the
// bottom of our current message because there may be a // bottom of our current message because there may be a
// between-messages date separator row in between. // between-messages date separator row in between.
if (top_offset(message) < frb_bottom - date_bar_height_offset) { top_offset(message) < frb_bottom - date_bar_height_offset
result = message; ) {
} result = message;
} }
if (result) { if (result) {
return result; return result;

View File

@@ -150,37 +150,35 @@ function do_hashchange_overlay(old_hash) {
// //
// In most situations we skip by this logic and load // In most situations we skip by this logic and load
// the new overlay. // the new overlay.
if (coming_from_overlay) { if (coming_from_overlay && base === old_base) {
if (base === old_base) { if (base === "streams") {
if (base === "streams") { subs.change_state(section);
subs.change_state(section);
return;
}
if (base === "settings") {
if (!section) {
// We may be on a really old browser or somebody
// hand-typed a hash.
blueslip.warn("missing section for settings");
}
settings_panel_menu.normal_settings.activate_section_or_default(section);
return;
}
if (base === "organization") {
if (!section) {
// We may be on a really old browser or somebody
// hand-typed a hash.
blueslip.warn("missing section for organization");
}
settings_panel_menu.org_settings.activate_section_or_default(section);
return;
}
// TODO: handle other cases like internal settings
// changes.
return; return;
} }
if (base === "settings") {
if (!section) {
// We may be on a really old browser or somebody
// hand-typed a hash.
blueslip.warn("missing section for settings");
}
settings_panel_menu.normal_settings.activate_section_or_default(section);
return;
}
if (base === "organization") {
if (!section) {
// We may be on a really old browser or somebody
// hand-typed a hash.
blueslip.warn("missing section for organization");
}
settings_panel_menu.org_settings.activate_section_or_default(section);
return;
}
// TODO: handle other cases like internal settings
// changes.
return;
} }
// It's not super likely that an overlay is already open, // It's not super likely that an overlay is already open,

View File

@@ -559,18 +559,14 @@ exports.process_hotkey = function (e, hotkey) {
return false; return false;
} }
if (event_name === "up_arrow") { if (event_name === "up_arrow" && list_util.inside_list(e)) {
if (list_util.inside_list(e)) { list_util.go_up(e);
list_util.go_up(e); return true;
return true;
}
} }
if (event_name === "down_arrow") { if (event_name === "down_arrow" && list_util.inside_list(e)) {
if (list_util.inside_list(e)) { list_util.go_down(e);
list_util.go_down(e); return true;
return true;
}
} }
if (menu_dropdown_hotkeys.has(event_name)) { if (menu_dropdown_hotkeys.has(event_name)) {
@@ -618,11 +614,9 @@ exports.process_hotkey = function (e, hotkey) {
// The next two sections date back to 00445c84 and are Mac/Chrome-specific, // The next two sections date back to 00445c84 and are Mac/Chrome-specific,
// and they should possibly be eliminated in favor of keeping standard // and they should possibly be eliminated in favor of keeping standard
// browser behavior. // browser behavior.
if (event_name === "backspace") { if (event_name === "backspace" && $("#compose-send-button").is(":focus")) {
if ($("#compose-send-button").is(":focus")) { // Ignore Backspace; don't navigate back a page.
// Ignore Backspace; don't navigate back a page. return true;
return true;
}
} }
if (event_name === "narrow_to_compose_target") { if (event_name === "narrow_to_compose_target") {

View File

@@ -282,10 +282,8 @@ exports.create = function (opts) {
// should switch to focus the last pill in the list. // should switch to focus the last pill in the list.
// the rest of the events then will be taken care of in the function // the rest of the events then will be taken care of in the function
// below that handles events on the ".pill" class. // below that handles events on the ".pill" class.
if (char === KEY.LEFT_ARROW) { if (char === KEY.LEFT_ARROW && window.getSelection().anchorOffset === 0) {
if (window.getSelection().anchorOffset === 0) { store.$parent.find(".pill").last().trigger("focus");
store.$parent.find(".pill").last().trigger("focus");
}
} }
// Typing of the comma is prevented if the last field doesn't validate, // Typing of the comma is prevented if the last field doesn't validate,

View File

@@ -35,14 +35,14 @@ const ls = {
let data = localStorage.getItem(key); let data = localStorage.getItem(key);
data = ls.parseJSON(data); data = ls.parseJSON(data);
if (data) { if (
if (data.__valid) { data &&
// JSON forms of data with `Infinity` turns into `null`, data.__valid &&
// so if null then it hasn't expired since nothing was specified. // JSON forms of data with `Infinity` turns into `null`,
if (!ls.isExpired(data.expires) || data.expires === null) { // so if null then it hasn't expired since nothing was specified.
return data; (!ls.isExpired(data.expires) || data.expires === null)
} ) {
} return data;
} }
return undefined; return undefined;

View File

@@ -168,14 +168,16 @@ exports.update_messages = function update_messages(events) {
// The event.message_ids received from the server are not in sorted order. // The event.message_ids received from the server are not in sorted order.
event_messages.sort((a, b) => a.id - b.id); event_messages.sort((a, b) => a.id - b.id);
if (going_forward_change && stream_name && compose_stream_name) { if (
if (stream_name.toLowerCase() === compose_stream_name.toLowerCase()) { going_forward_change &&
if (orig_topic === compose_state.topic()) { stream_name &&
changed_compose = true; compose_stream_name &&
compose_state.topic(new_topic); stream_name.toLowerCase() === compose_stream_name.toLowerCase() &&
compose_fade.set_focused_recipient("stream"); orig_topic === compose_state.topic()
} ) {
} changed_compose = true;
compose_state.topic(new_topic);
compose_fade.set_focused_recipient("stream");
} }
for (const msg of event_messages) { for (const msg of event_messages) {
@@ -224,7 +226,8 @@ exports.update_messages = function update_messages(events) {
}); });
} }
if (going_forward_change) { if (
going_forward_change &&
// This logic is a bit awkward. What we're trying to // This logic is a bit awkward. What we're trying to
// accomplish is two things: // accomplish is two things:
// //
@@ -238,45 +241,45 @@ exports.update_messages = function update_messages(events) {
// //
// Code further down takes care of the actual rerendering of // Code further down takes care of the actual rerendering of
// messages within a narrow. // messages within a narrow.
if (selection_changed_topic) { selection_changed_topic &&
if (current_filter && current_filter.has_topic(stream_name, orig_topic)) { current_filter &&
let new_filter = current_filter; current_filter.has_topic(stream_name, orig_topic)
if (new_filter && stream_changed) { ) {
// TODO: This logic doesn't handle the let new_filter = current_filter;
// case where we're a guest user and the if (new_filter && stream_changed) {
// message moves to a stream we cannot // TODO: This logic doesn't handle the
// access, which would cause the // case where we're a guest user and the
// stream_data lookup here to fail. // message moves to a stream we cannot
// // access, which would cause the
// The fix is likely somewhat involved, so punting for now. // stream_data lookup here to fail.
const new_stream_name = stream_data.get_sub_by_id(new_stream_id).name; //
new_filter = new_filter.filter_with_new_params({ // The fix is likely somewhat involved, so punting for now.
operator: "stream", const new_stream_name = stream_data.get_sub_by_id(new_stream_id).name;
operand: new_stream_name, new_filter = new_filter.filter_with_new_params({
}); operator: "stream",
changed_narrow = true; operand: new_stream_name,
} });
changed_narrow = true;
}
if (new_filter && topic_edited) { if (new_filter && topic_edited) {
new_filter = new_filter.filter_with_new_params({ new_filter = new_filter.filter_with_new_params({
operator: "topic", operator: "topic",
operand: new_topic, operand: new_topic,
}); });
changed_narrow = true; changed_narrow = true;
} }
// NOTE: We should always be changing narrows after we finish // NOTE: We should always be changing narrows after we finish
// updating the local data and UI. This avoids conflict // updating the local data and UI. This avoids conflict
// with data fetched from the server (which is already updated) // with data fetched from the server (which is already updated)
// when we move to new narrow and what data is locally available. // when we move to new narrow and what data is locally available.
if (changed_narrow) { if (changed_narrow) {
const operators = new_filter.operators(); const operators = new_filter.operators();
const opts = { const opts = {
trigger: "stream/topic change", trigger: "stream/topic change",
then_select_id: current_selected_id, then_select_id: current_selected_id,
}; };
narrow.activate(operators, opts); narrow.activate(operators, opts);
}
}
} }
} }

View File

@@ -69,10 +69,8 @@ exports.get_messages_in_topic = function (stream_id, topic) {
exports.get_max_message_id_in_stream = function (stream_id) { exports.get_max_message_id_in_stream = function (stream_id) {
let max_message_id = 0; let max_message_id = 0;
for (const msg of message_list.all.all_messages()) { for (const msg of message_list.all.all_messages()) {
if (msg.type === "stream" && msg.stream_id === stream_id) { if (msg.type === "stream" && msg.stream_id === stream_id && msg.id > max_message_id) {
if (msg.id > max_message_id) { max_message_id = msg.id;
max_message_id = msg.id;
}
} }
} }
return max_message_id; return max_message_id;

View File

@@ -32,10 +32,8 @@ const get_step = function ($process) {
function should_show_notifications(ls) { function should_show_notifications(ls) {
// if the user said to never show banner on this computer again, it will // if the user said to never show banner on this computer again, it will
// be stored as `true` so we want to negate that. // be stored as `true` so we want to negate that.
if (localstorage.supported()) { if (localstorage.supported() && ls.get("dontAskForNotifications") === true) {
if (ls.get("dontAskForNotifications") === true) { return false;
return false;
}
} }
return ( return (

View File

@@ -3,15 +3,13 @@
$(() => { $(() => {
// This code will be executed when the user visits /login and // This code will be executed when the user visits /login and
// dev_login.html is rendered. // dev_login.html is rendered.
if ($("[data-page-id='dev-login']").length > 0) { if ($("[data-page-id='dev-login']").length > 0 && window.location.hash.slice(0, 1) === "#") {
if (window.location.hash.slice(0, 1) === "#") { /* We append the location.hash to the input field with name next so that URL can be
/* We append the location.hash to the input field with name next so that URL can be
preserved after user is logged in. See this: preserved after user is logged in. See this:
https://stackoverflow.com/questions/5283395/url-hash-is-persisting-between-redirects */ https://stackoverflow.com/questions/5283395/url-hash-is-persisting-between-redirects */
$("input[name='next']").each(function () { $("input[name='next']").each(function () {
const new_value = $(this).attr("value") + window.location.hash; const new_value = $(this).attr("value") + window.location.hash;
$(this).attr("value", new_value); $(this).attr("value", new_value);
}); });
}
} }
}); });

View File

@@ -95,23 +95,22 @@ $(() => {
// Code in this block will be executed when the user visits /register // Code in this block will be executed when the user visits /register
// i.e. accounts_home.html is rendered. // i.e. accounts_home.html is rendered.
if ($("[data-page-id='accounts-home']").length > 0) { if (
if (window.location.hash.slice(0, 1) === "#") { $("[data-page-id='accounts-home']").length > 0 &&
document.email_form.action += window.location.hash; window.location.hash.slice(0, 1) === "#"
} ) {
document.email_form.action += window.location.hash;
} }
// Code in this block will be executed when the user is at login page // Code in this block will be executed when the user is at login page
// i.e. login.html is rendered. // i.e. login.html is rendered.
if ($("[data-page-id='login-page']").length > 0) { if ($("[data-page-id='login-page']").length > 0 && window.location.hash.slice(0, 1) === "#") {
if (window.location.hash.slice(0, 1) === "#") { /* We append the location.hash to the formaction so that URL can be
/* We append the location.hash to the formaction so that URL can be preserved after user is logged in. See this:
preserved after user is logged in. See this: https://stackoverflow.com/questions/5283395/url-hash-is-persisting-between-redirects */
https://stackoverflow.com/questions/5283395/url-hash-is-persisting-between-redirects */ const email_formaction = $("#login_form").attr("action");
const email_formaction = $("#login_form").attr("action"); $("#login_form").attr("action", email_formaction + "/" + window.location.hash);
$("#login_form").attr("action", email_formaction + "/" + window.location.hash); $(".social_login_form input[name='next']").attr("value", "/" + window.location.hash);
$(".social_login_form input[name='next']").attr("value", "/" + window.location.hash);
}
} }
$("#send_confirm").validate({ $("#send_confirm").validate({

View File

@@ -124,16 +124,12 @@ exports.update_info_from_event = function (user_id, info, server_timestamp) {
raw.server_timestamp = server_timestamp; raw.server_timestamp = server_timestamp;
for (const rec of Object.values(info)) { for (const rec of Object.values(info)) {
if (rec.status === "active") { if (rec.status === "active" && rec.timestamp > (raw.active_timestamp || 0)) {
if (rec.timestamp > (raw.active_timestamp || 0)) { raw.active_timestamp = rec.timestamp;
raw.active_timestamp = rec.timestamp;
}
} }
if (rec.status === "idle") { if (rec.status === "idle" && rec.timestamp > (raw.idle_timestamp || 0)) {
if (rec.timestamp > (raw.idle_timestamp || 0)) { raw.idle_timestamp = rec.timestamp;
raw.idle_timestamp = rec.timestamp;
}
} }
} }

View File

@@ -114,21 +114,19 @@ exports.get_direction = function (str) {
// Extracting high and low surrogates and putting them together. // Extracting high and low surrogates and putting them together.
// See https://en.wikipedia.org/wiki/UTF-16#Description or section 3 of https://tools.ietf.org/html/rfc2781. // See https://en.wikipedia.org/wiki/UTF-16#Description or section 3 of https://tools.ietf.org/html/rfc2781.
let ch = str.charCodeAt(i); let ch = str.charCodeAt(i);
if (ch >= 0xd800 && ch < 0xe000) { if (ch >= 0xd800 && ch < 0xdc00) {
// 0xd800 <= ch < 0xe000 // 0xd800 <= ch < 0xdc00
// ch is inside surrogate range. // ch is inside high surrogate range.
// If it made a surrogate pair with the next character, put them together. // If it made a surrogate pair with the next character, put them together.
// Otherwise, ignore the encoding error and leave it as it is. // Otherwise, ignore the encoding error and leave it as it is.
if (ch < 0xdc00) { const ch2 = i + 1 < str.length ? str.charCodeAt(i + 1) : 0;
const ch2 = i + 1 < str.length ? str.charCodeAt(i + 1) : 0; if (ch2 >= 0xdc00 && ch2 < 0xe000) {
if (ch2 >= 0xdc00 && ch2 < 0xe000) { // 0xdc00 <= ch2 < 0xe000
// 0xdc00 <= ch2 < 0xe000 // ch = ch & 0x3ff;
// ch = ch & 0x3ff; ch -= 0xd800;
ch -= 0xd800; // ch = 0x10000 | (ch << 10) | (ch2 & 0x3ff);
// ch = 0x10000 | (ch << 10) | (ch2 & 0x3ff); ch = 0x10000 + ch * 0x400 + (ch2 - 0xdc00);
ch = 0x10000 + ch * 0x400 + (ch2 - 0xdc00); i += 1;
i += 1;
}
} }
} }
@@ -145,10 +143,8 @@ exports.get_direction = function (str) {
if (isolations === 0) { if (isolations === 0) {
return "rtl"; return "rtl";
} }
} else if (bidi_class === "L") { } else if (bidi_class === "L" && isolations === 0) {
if (isolations === 0) { return "ltr";
return "ltr";
}
} }
} }
return "ltr"; return "ltr";

View File

@@ -702,16 +702,17 @@ exports.get_search_result = function (base_query, query) {
} }
} }
if (!page_params.search_pills_enabled) { if (
!page_params.search_pills_enabled &&
// This is unique to the legacy search system. With pills // This is unique to the legacy search system. With pills
// it is difficult to "suggest" a subset of operators, // it is difficult to "suggest" a subset of operators,
// and there's a more natural mechanism under that paradigm, // and there's a more natural mechanism under that paradigm,
// where the user just deletes one or more pills. So you // where the user just deletes one or more pills. So you
// won't see this is in the new code. // won't see this is in the new code.
if (attacher.result.length < max_items) { attacher.result.length < max_items
const subset_suggestions = get_operator_subset_suggestions(search_operators); ) {
attacher.concat(subset_suggestions); const subset_suggestions = get_operator_subset_suggestions(search_operators);
} attacher.concat(subset_suggestions);
} }
return attacher.result.slice(0, max_items); return attacher.result.slice(0, max_items);

View File

@@ -97,11 +97,9 @@ exports.render_bots = function () {
user_owns_an_active_bot = user_owns_an_active_bot || elem.is_active; user_owns_an_active_bot = user_owns_an_active_bot || elem.is_active;
} }
if (exports.can_create_new_bots()) { if (exports.can_create_new_bots() && !user_owns_an_active_bot) {
if (!user_owns_an_active_bot) { focus_tab.add_a_new_bot_tab();
focus_tab.add_a_new_bot_tab(); return;
return;
}
} }
if ($("#bots_lists_navbar .add-a-new-bot-tab").hasClass("active")) { if ($("#bots_lists_navbar .add-a-new-bot-tab").hasClass("active")) {

View File

@@ -154,12 +154,10 @@ class PerStreamHistory {
const existing = this.topics.get(topic_name); const existing = this.topics.get(topic_name);
if (existing) { if (existing && !existing.historical) {
if (!existing.historical) { // Trust out local data more, since it
// Trust out local data more, since it // maintains counts.
// maintains counts. continue;
continue;
}
} }
// If we get here, we are either finding out about // If we get here, we are either finding out about

View File

@@ -343,11 +343,9 @@ exports.update_settings_for_unsubscribed = function (sub) {
}; };
function triage_stream(query, sub) { function triage_stream(query, sub) {
if (query.subscribed_only) { if (query.subscribed_only && !sub.subscribed) {
// reject non-subscribed streams // reject non-subscribed streams
if (!sub.subscribed) { return "rejected";
return "rejected";
}
} }
const search_terms = search_util.get_search_terms(query.input); const search_terms = search_util.get_search_terms(query.input);

View File

@@ -95,13 +95,15 @@ exports.last_seen_status_from_date = function (last_active_date, current_date) {
if (days < 90) { if (days < 90) {
return i18n.t("__days__ days ago", {days}); return i18n.t("__days__ days ago", {days});
} else if (days > 90 && days < 365) { } else if (
if (current_date.getFullYear() === last_active_date.getFullYear()) { days > 90 &&
// Online more than 90 days ago, in the same year days < 365 &&
return i18n.t("__last_active_date__", { current_date.getFullYear() === last_active_date.getFullYear()
last_active_date: last_active_date.toString("MMM\u00A0dd"), ) {
}); // Online more than 90 days ago, in the same year
} return i18n.t("__last_active_date__", {
last_active_date: last_active_date.toString("MMM\u00A0dd"),
});
} }
return i18n.t("__last_active_date__", { return i18n.t("__last_active_date__", {
last_active_date: last_active_date.toString("MMM\u00A0dd,\u00A0yyyy"), last_active_date: last_active_date.toString("MMM\u00A0dd,\u00A0yyyy"),

View File

@@ -74,10 +74,8 @@ exports.initialize_kitchen_sink_stuff = function () {
if (message_viewport.at_top()) { if (message_viewport.at_top()) {
navigate.up(); navigate.up();
} }
} else if (delta > 0) { } else if (delta > 0 && message_viewport.at_bottom()) {
if (message_viewport.at_bottom()) { navigate.down();
navigate.down();
}
} }
message_viewport.set_last_movement_direction(delta); message_viewport.set_last_movement_direction(delta);