Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
compose fade users: Remove fade logic in favor of buddy list split.
evykassirer231c0087a4b0
diff --git a/web/src/buddy_data.ts b/web/src/buddy_data.tsindex 717da6f253e..1e44a9bd015 100644--- a/web/src/buddy_data.ts+++ b/web/src/buddy_data.ts@@ -1,5 +1,4 @@import * as blueslip from "./blueslip";-import * as compose_fade_users from "./compose_fade_users";import * as hash_util from "./hash_util";import {$t} from "./i18n";import * as muted_users from "./muted_users";@@ -36,18 +35,6 @@ export function set_is_searching_users(val: boolean): void {is_searching_users = val;}-const fade_config: compose_fade_users.UserFadeConfig<BuddyUserInfo> = {- get_user_id(item) {- return item.user_id;- },- fade(item) {- item.faded = true;- },- unfade(item) {- item.faded = false;- },-};-export function get_user_circle_class(user_id: number): string {const status = presence.get_status(user_id);@@ -284,13 +271,11 @@ export function get_title_data(export function get_item(user_id: number): BuddyUserInfo {const info = info_for(user_id);- compose_fade_users.update_user_info([info], fade_config);return info;}export function get_items_for_users(user_ids: number[]): BuddyUserInfo[] {const user_info = user_ids.map((user_id) => info_for(user_id));- compose_fade_users.update_user_info(user_info, fade_config);return user_info;}diff --git a/web/src/buddy_list.js b/web/src/buddy_list.jsindex 99faa270537..af06b79cf20 100644--- a/web/src/buddy_list.js+++ b/web/src/buddy_list.js@@ -412,18 +412,6 @@ export class BuddyList extends BuddyListConf {this.update_padding();}- get_items() {- const $user_matching_view_obj = this.$users_matching_view_container.find(- `${this.item_selector}`,- );- const $users_matching_view_elems = $user_matching_view_obj.map((_i, elem) => $(elem));-- const $other_user_obj = this.$other_users_container.find(`${this.item_selector}`);- const $other_user_elems = $other_user_obj.map((_i, elem) => $(elem));-- return [...$users_matching_view_elems, ...$other_user_elems];- }-should_hide_headers(current_sub, pm_ids_set) {// If we have only "other users" and aren't in a stream/DM view// then we don't show section headers and only show one untitleddiff --git a/web/src/compose_fade.js b/web/src/compose_fade.jsindex ad25432e3d6..3994497c9d9 100644--- a/web/src/compose_fade.js+++ b/web/src/compose_fade.js@@ -1,9 +1,7 @@import $ from "jquery";import _ from "lodash";-import {buddy_list} from "./buddy_list";import * as compose_fade_helper from "./compose_fade_helper";-import * as compose_fade_users from "./compose_fade_users";import * as compose_state from "./compose_state";import * as message_lists from "./message_lists";import * as message_viewport from "./message_viewport";@@ -104,41 +102,16 @@ function fade_messages() {);}-const user_fade_config = {- get_user_id($li) {- return buddy_list.get_user_id_from_li({$li});- },- fade($li) {- return $li.addClass("user-fade");- },- unfade($li) {- return $li.removeClass("user-fade");- },-};-function do_update_all() {- const user_items = buddy_list.get_items();-if (compose_fade_helper.want_normal_display()) {if (!normal_display) {display_messages_normally();- compose_fade_users.display_users_normally(user_items, user_fade_config);}} else {fade_messages();- compose_fade_users.fade_users(user_items, user_fade_config);}}-// This one only updates the users, not both, like update_faded_messages.-// This is for when new presence information comes in, redrawing the presence-// list.-export function update_faded_users() {- const user_items = buddy_list.get_items();-- compose_fade_users.update_user_info(user_items, user_fade_config);-}-// This gets called on keyup events, hence the throttling.export const update_all = _.debounce(do_update_all, 50);@@ -150,7 +123,6 @@ export function start_compose(msg_type) {export function clear_compose() {compose_fade_helper.clear_focused_recipient();display_messages_normally();- update_faded_users();}export function update_message_list() {diff --git a/web/src/compose_fade_helper.ts b/web/src/compose_fade_helper.tsindex fed984e74f5..55e56f37d12 100644--- a/web/src/compose_fade_helper.ts+++ b/web/src/compose_fade_helper.ts@@ -1,7 +1,4 @@-import assert from "minimalistic-assert";-import type {Message} from "./message_store";-import * as stream_data from "./stream_data";import * as sub_store from "./sub_store";import type {Recipient} from "./util";import * as util from "./util";@@ -20,26 +17,6 @@ export function set_focused_recipient(recipient?: Recipient): void {focused_recipient = recipient;}-export function would_receive_message(user_id: number): boolean {- assert(focused_recipient !== undefined);- if (focused_recipient.type === "stream") {- const sub = sub_store.get(focused_recipient.stream_id);- if (!sub) {- // If the stream isn't valid, there is no risk of a mix- // yet, so we sort of "lie" and say they would receive a- // message.- return true;- }-- return stream_data.is_user_subscribed(focused_recipient.stream_id, user_id);- }-- // Direct message, so check if the given email is in the recipients list.- assert(focused_recipient.to_user_ids !== undefined);- const recipients = focused_recipient.to_user_ids.split(",");- return recipients.includes(user_id.toString());-}-export function want_normal_display(): boolean {// If we're not composing show a normal display.if (focused_recipient === undefined) {diff --git a/web/src/compose_fade_users.ts b/web/src/compose_fade_users.tsdeleted file mode 100644index a41a786a17f..00000000000--- a/web/src/compose_fade_users.ts+++ /dev/null@@ -1,39 +0,0 @@-import * as compose_fade_helper from "./compose_fade_helper";-import * as people from "./people";--export type UserFadeConfig<T> = {- get_user_id: (elem: T) => number;- fade: (elem: T) => void;- unfade: (elem: T) => void;-};--function update_user_row_when_fading<T>(item: T, conf: UserFadeConfig<T>): void {- const user_id = conf.get_user_id(item);- const would_receive = compose_fade_helper.would_receive_message(user_id);-- if (would_receive || people.is_my_user_id(user_id)) {- conf.unfade(item);- } else {- conf.fade(item);- }-}--export function fade_users<T>(items: T[], conf: UserFadeConfig<T>): void {- for (const item of items) {- update_user_row_when_fading(item, conf);- }-}--export function display_users_normally<T>(items: T[], conf: UserFadeConfig<T>): void {- for (const item of items) {- conf.unfade(item);- }-}--export function update_user_info<T>(items: T[], conf: UserFadeConfig<T>): void {- if (compose_fade_helper.want_normal_display()) {- display_users_normally(items, conf);- } else {- fade_users(items, conf);- }-}diff --git a/web/src/stream_events.js b/web/src/stream_events.jsindex 28ac9c5d590..d926263b246 100644--- a/web/src/stream_events.js+++ b/web/src/stream_events.js@@ -2,7 +2,6 @@ import $ from "jquery";import * as blueslip from "./blueslip";import * as color_data from "./color_data";-import * as compose_fade from "./compose_fade";import * as compose_recipient from "./compose_recipient";import * as message_lists from "./message_lists";import * as message_view_header from "./message_view_header";@@ -209,6 +208,5 @@ export function process_subscriber_update(user_ids, stream_ids) {const sub = sub_store.get(stream_id);stream_settings_ui.update_subscribers_ui(sub);}- compose_fade.update_faded_users();user_profile.update_user_profile_streams_list_for_users(user_ids);}diff --git a/web/tests/activity.test.js b/web/tests/activity.test.jsindex ad0954b0cb4..39de6e2ed65 100644--- a/web/tests/activity.test.js+++ b/web/tests/activity.test.js@@ -499,7 +499,6 @@ test("insert_one_user_into_empty_list", ({override, mock_template}) => {override(padded_widget, "update_padding", noop);mock_template("presence_row.hbs", true, (data, html) => {assert.deepEqual(data, {- faded: false,href: "#narrow/dm/1-Alice-Smith",name: "Alice Smith",user_id: 1,diff --git a/web/tests/buddy_data.test.js b/web/tests/buddy_data.test.jsindex e91e8a25dec..8e43bb6e46d 100644--- a/web/tests/buddy_data.test.js+++ b/web/tests/buddy_data.test.js@@ -18,7 +18,6 @@ const peer_data = zrequire("peer_data");const people = zrequire("people");const presence = zrequire("presence");const stream_data = zrequire("stream_data");-const sub_store = zrequire("sub_store");const user_status = zrequire("user_status");const buddy_data = zrequire("buddy_data");@@ -158,119 +157,6 @@ test("user_circle, level", () => {assert.equal(buddy_data.level(fred.user_id), 3);});-test("compose fade interactions (streams)", () => {- const sub = {- stream_id: 101,- name: "Devel",- subscribed: true,- };- stream_data.add_sub(sub);- stream_data.subscribe_myself(sub);-- people.add_active_user(fred);-- set_presence(fred.user_id, "active");-- function faded() {- return buddy_data.get_item(fred.user_id).faded;- }-- // If we are not narrowed, then we don't fade fred in the buddy list.- assert.equal(faded(), false);-- // If we narrow to a stream that fred has not subscribed- // to, we will fade him.- compose_fade_helper.set_focused_recipient({- type: "stream",- stream_id: sub.stream_id,- topic: "whatever",- });- assert.equal(faded(), true);-- // If we subscribe, we don't fade.- peer_data.add_subscriber(sub.stream_id, fred.user_id);- assert.equal(faded(), false);-- // Test our punting logic.- const bogus_stream_id = 99999;- assert.equal(sub_store.get(bogus_stream_id), undefined);-- compose_fade_helper.set_focused_recipient({- type: "stream",- stream_id: bogus_stream_id,- });-- assert.equal(faded(), false);-});--test("compose fade interactions (missing topic)", () => {- const sub = {- stream_id: 102,- name: "Social",- subscribed: true,- };- stream_data.add_sub(sub);- stream_data.subscribe_myself(sub);-- people.add_active_user(fred);-- set_presence(fred.user_id, "active");-- function faded() {- return buddy_data.get_item(fred.user_id).faded;- }-- // If we are not narrowed, then we don't fade fred in the buddy list.- assert.equal(faded(), false);-- // If we narrow to a stream that fred has not subscribed- // to, we will fade him.- compose_fade_helper.set_focused_recipient({- type: "stream",- stream_id: sub.stream_id,- topic: "whatever",- });- assert.equal(faded(), true);-- // If the user clears the topic, we won't fade fred.- compose_fade_helper.set_focused_recipient({- type: "stream",- stream_id: sub.stream_id,- topic: "",- });- assert.equal(faded(), false);-});--test("compose fade interactions (direct messages)", () => {- people.add_active_user(fred);-- set_presence(fred.user_id, "active");-- function faded() {- return buddy_data.get_item(fred.user_id).faded;- }-- // Don't fade if we're not in a narrow.- assert.equal(faded(), false);-- // Fade fred if we are narrowed to a direct message narrow- // that does not include him.- compose_fade_helper.set_focused_recipient({- type: "private",- to_user_ids: "9999999",- });- assert.equal(faded(), true);-- // Now include fred in a narrow with jill, and we will- // stop fading him.- compose_fade_helper.set_focused_recipient({- type: "private",- to_user_ids: [fred.user_id, jill.user_id].join(","),- });-- assert.equal(faded(), false);-});-test("title_data", () => {add_canned_users();@@ -576,7 +462,6 @@ test("get_items_for_users", () => {assert.deepEqual(buddy_data.get_items_for_users(user_ids), [{- faded: false,href: "#narrow/dm/1001-Human-Myself",is_current_user: true,name: "Human Myself",@@ -589,7 +474,6 @@ test("get_items_for_users", () => {should_add_guest_user_indicator: false,},{- faded: false,href: "#narrow/dm/1002-Alice-Smith",is_current_user: false,name: "Alice Smith",@@ -602,7 +486,6 @@ test("get_items_for_users", () => {should_add_guest_user_indicator: false,},{- faded: false,href: "#narrow/dm/1003-Fred-Flintstone",is_current_user: false,name: "Fred Flintstone",diff --git a/web/tests/compose_fade.test.js b/web/tests/compose_fade.test.jsindex 7cd28eae27c..0fae4c49e46 100644--- a/web/tests/compose_fade.test.js+++ b/web/tests/compose_fade.test.js@@ -61,23 +61,12 @@ run_test("set_focused_recipient", ({override_rewire}) => {subscribed: true,};- compose_fade.set_focused_recipient("stream");-- // If a stream is unknown, then we turn off the compose-fade- // feature, since a mix won't happen if the message can't be- // delivered.stream_data.clear_subscriptions();- assert.equal(compose_fade_helper.would_receive_message(bob.user_id), true);-stream_data.add_sub(sub);compose_state.set_stream_id(sub.stream_id);peer_data.set_subscribers(sub.stream_id, [me.user_id, alice.user_id]);compose_fade.set_focused_recipient("stream");- assert.equal(compose_fade_helper.would_receive_message(me.user_id), true);- assert.equal(compose_fade_helper.would_receive_message(alice.user_id), true);- assert.equal(compose_fade_helper.would_receive_message(bob.user_id), false);-const good_msg = {type: "stream",stream_id: 101,diff --git a/web/tests/stream_events.test.js b/web/tests/stream_events.test.jsindex 9cf75209cd3..f6bd013eeaa 100644--- a/web/tests/stream_events.test.js+++ b/web/tests/stream_events.test.js@@ -9,7 +9,6 @@ const blueslip = require("./lib/zblueslip");const $ = require("./lib/zjquery");const color_data = mock_esm("../src/color_data");-const compose_fade = mock_esm("../src/compose_fade");const stream_color_events = mock_esm("../src/stream_color_events");const stream_list = mock_esm("../src/stream_list");const stream_muting = mock_esm("../src/stream_muting");@@ -454,9 +453,6 @@ test("process_subscriber_update", ({override}) => {const subsStub = make_stub();stream_settings_ui.update_subscribers_ui = subsStub.f;- const fadedUsersStub = make_stub();- override(compose_fade, "update_faded_users", fadedUsersStub.f);-override(user_profile, "update_user_profile_streams_list_for_users", noop);// Sample user IDsconst userIds = [104, 2, 3];@@ -468,7 +464,4 @@ test("process_subscriber_update", ({override}) => {// Assert that update_subscribers_ui is called for each stream IDassert.equal(subsStub.num_calls, streamIds.length);-- // Assert that update_faded_users is called once- assert.equal(fadedUsersStub.num_calls, 1);});