mirror of https://github.com/zulip/zulip.git
compose fade users: Remove fade logic in favor of buddy list split.
This also removes buddy_list.get_items which were only used for compose_fade logic.
This commit is contained in:
parent
231aa098cb
commit
231c0087a4
|
@ -1,5 +1,4 @@
|
||||||
import * as blueslip from "./blueslip";
|
import * as blueslip from "./blueslip";
|
||||||
import * as compose_fade_users from "./compose_fade_users";
|
|
||||||
import * as hash_util from "./hash_util";
|
import * as hash_util from "./hash_util";
|
||||||
import {$t} from "./i18n";
|
import {$t} from "./i18n";
|
||||||
import * as muted_users from "./muted_users";
|
import * as muted_users from "./muted_users";
|
||||||
|
@ -36,18 +35,6 @@ export function set_is_searching_users(val: boolean): void {
|
||||||
is_searching_users = val;
|
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 {
|
export function get_user_circle_class(user_id: number): string {
|
||||||
const status = presence.get_status(user_id);
|
const status = presence.get_status(user_id);
|
||||||
|
|
||||||
|
@ -284,13 +271,11 @@ export function get_title_data(
|
||||||
|
|
||||||
export function get_item(user_id: number): BuddyUserInfo {
|
export function get_item(user_id: number): BuddyUserInfo {
|
||||||
const info = info_for(user_id);
|
const info = info_for(user_id);
|
||||||
compose_fade_users.update_user_info([info], fade_config);
|
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function get_items_for_users(user_ids: number[]): BuddyUserInfo[] {
|
export function get_items_for_users(user_ids: number[]): BuddyUserInfo[] {
|
||||||
const user_info = user_ids.map((user_id) => info_for(user_id));
|
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;
|
return user_info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -412,18 +412,6 @@ export class BuddyList extends BuddyListConf {
|
||||||
this.update_padding();
|
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) {
|
should_hide_headers(current_sub, pm_ids_set) {
|
||||||
// If we have only "other users" and aren't in a stream/DM view
|
// 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 untitled
|
// then we don't show section headers and only show one untitled
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
import $ from "jquery";
|
import $ from "jquery";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
|
|
||||||
import {buddy_list} from "./buddy_list";
|
|
||||||
import * as compose_fade_helper from "./compose_fade_helper";
|
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 compose_state from "./compose_state";
|
||||||
import * as message_lists from "./message_lists";
|
import * as message_lists from "./message_lists";
|
||||||
import * as message_viewport from "./message_viewport";
|
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() {
|
function do_update_all() {
|
||||||
const user_items = buddy_list.get_items();
|
|
||||||
|
|
||||||
if (compose_fade_helper.want_normal_display()) {
|
if (compose_fade_helper.want_normal_display()) {
|
||||||
if (!normal_display) {
|
if (!normal_display) {
|
||||||
display_messages_normally();
|
display_messages_normally();
|
||||||
compose_fade_users.display_users_normally(user_items, user_fade_config);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fade_messages();
|
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.
|
// This gets called on keyup events, hence the throttling.
|
||||||
export const update_all = _.debounce(do_update_all, 50);
|
export const update_all = _.debounce(do_update_all, 50);
|
||||||
|
|
||||||
|
@ -150,7 +123,6 @@ export function start_compose(msg_type) {
|
||||||
export function clear_compose() {
|
export function clear_compose() {
|
||||||
compose_fade_helper.clear_focused_recipient();
|
compose_fade_helper.clear_focused_recipient();
|
||||||
display_messages_normally();
|
display_messages_normally();
|
||||||
update_faded_users();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function update_message_list() {
|
export function update_message_list() {
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
import assert from "minimalistic-assert";
|
|
||||||
|
|
||||||
import type {Message} from "./message_store";
|
import type {Message} from "./message_store";
|
||||||
import * as stream_data from "./stream_data";
|
|
||||||
import * as sub_store from "./sub_store";
|
import * as sub_store from "./sub_store";
|
||||||
import type {Recipient} from "./util";
|
import type {Recipient} from "./util";
|
||||||
import * as util from "./util";
|
import * as util from "./util";
|
||||||
|
@ -20,26 +17,6 @@ export function set_focused_recipient(recipient?: Recipient): void {
|
||||||
focused_recipient = recipient;
|
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 {
|
export function want_normal_display(): boolean {
|
||||||
// If we're not composing show a normal display.
|
// If we're not composing show a normal display.
|
||||||
if (focused_recipient === undefined) {
|
if (focused_recipient === undefined) {
|
||||||
|
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -2,7 +2,6 @@ import $ from "jquery";
|
||||||
|
|
||||||
import * as blueslip from "./blueslip";
|
import * as blueslip from "./blueslip";
|
||||||
import * as color_data from "./color_data";
|
import * as color_data from "./color_data";
|
||||||
import * as compose_fade from "./compose_fade";
|
|
||||||
import * as compose_recipient from "./compose_recipient";
|
import * as compose_recipient from "./compose_recipient";
|
||||||
import * as message_lists from "./message_lists";
|
import * as message_lists from "./message_lists";
|
||||||
import * as message_view_header from "./message_view_header";
|
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);
|
const sub = sub_store.get(stream_id);
|
||||||
stream_settings_ui.update_subscribers_ui(sub);
|
stream_settings_ui.update_subscribers_ui(sub);
|
||||||
}
|
}
|
||||||
compose_fade.update_faded_users();
|
|
||||||
user_profile.update_user_profile_streams_list_for_users(user_ids);
|
user_profile.update_user_profile_streams_list_for_users(user_ids);
|
||||||
}
|
}
|
||||||
|
|
|
@ -499,7 +499,6 @@ test("insert_one_user_into_empty_list", ({override, mock_template}) => {
|
||||||
override(padded_widget, "update_padding", noop);
|
override(padded_widget, "update_padding", noop);
|
||||||
mock_template("presence_row.hbs", true, (data, html) => {
|
mock_template("presence_row.hbs", true, (data, html) => {
|
||||||
assert.deepEqual(data, {
|
assert.deepEqual(data, {
|
||||||
faded: false,
|
|
||||||
href: "#narrow/dm/1-Alice-Smith",
|
href: "#narrow/dm/1-Alice-Smith",
|
||||||
name: "Alice Smith",
|
name: "Alice Smith",
|
||||||
user_id: 1,
|
user_id: 1,
|
||||||
|
|
|
@ -18,7 +18,6 @@ const peer_data = zrequire("peer_data");
|
||||||
const people = zrequire("people");
|
const people = zrequire("people");
|
||||||
const presence = zrequire("presence");
|
const presence = zrequire("presence");
|
||||||
const stream_data = zrequire("stream_data");
|
const stream_data = zrequire("stream_data");
|
||||||
const sub_store = zrequire("sub_store");
|
|
||||||
const user_status = zrequire("user_status");
|
const user_status = zrequire("user_status");
|
||||||
const buddy_data = zrequire("buddy_data");
|
const buddy_data = zrequire("buddy_data");
|
||||||
|
|
||||||
|
@ -158,119 +157,6 @@ test("user_circle, level", () => {
|
||||||
assert.equal(buddy_data.level(fred.user_id), 3);
|
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", () => {
|
test("title_data", () => {
|
||||||
add_canned_users();
|
add_canned_users();
|
||||||
|
|
||||||
|
@ -576,7 +462,6 @@ test("get_items_for_users", () => {
|
||||||
|
|
||||||
assert.deepEqual(buddy_data.get_items_for_users(user_ids), [
|
assert.deepEqual(buddy_data.get_items_for_users(user_ids), [
|
||||||
{
|
{
|
||||||
faded: false,
|
|
||||||
href: "#narrow/dm/1001-Human-Myself",
|
href: "#narrow/dm/1001-Human-Myself",
|
||||||
is_current_user: true,
|
is_current_user: true,
|
||||||
name: "Human Myself",
|
name: "Human Myself",
|
||||||
|
@ -589,7 +474,6 @@ test("get_items_for_users", () => {
|
||||||
should_add_guest_user_indicator: false,
|
should_add_guest_user_indicator: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
faded: false,
|
|
||||||
href: "#narrow/dm/1002-Alice-Smith",
|
href: "#narrow/dm/1002-Alice-Smith",
|
||||||
is_current_user: false,
|
is_current_user: false,
|
||||||
name: "Alice Smith",
|
name: "Alice Smith",
|
||||||
|
@ -602,7 +486,6 @@ test("get_items_for_users", () => {
|
||||||
should_add_guest_user_indicator: false,
|
should_add_guest_user_indicator: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
faded: false,
|
|
||||||
href: "#narrow/dm/1003-Fred-Flintstone",
|
href: "#narrow/dm/1003-Fred-Flintstone",
|
||||||
is_current_user: false,
|
is_current_user: false,
|
||||||
name: "Fred Flintstone",
|
name: "Fred Flintstone",
|
||||||
|
|
|
@ -61,23 +61,12 @@ run_test("set_focused_recipient", ({override_rewire}) => {
|
||||||
subscribed: true,
|
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();
|
stream_data.clear_subscriptions();
|
||||||
assert.equal(compose_fade_helper.would_receive_message(bob.user_id), true);
|
|
||||||
|
|
||||||
stream_data.add_sub(sub);
|
stream_data.add_sub(sub);
|
||||||
compose_state.set_stream_id(sub.stream_id);
|
compose_state.set_stream_id(sub.stream_id);
|
||||||
peer_data.set_subscribers(sub.stream_id, [me.user_id, alice.user_id]);
|
peer_data.set_subscribers(sub.stream_id, [me.user_id, alice.user_id]);
|
||||||
compose_fade.set_focused_recipient("stream");
|
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 = {
|
const good_msg = {
|
||||||
type: "stream",
|
type: "stream",
|
||||||
stream_id: 101,
|
stream_id: 101,
|
||||||
|
|
|
@ -9,7 +9,6 @@ const blueslip = require("./lib/zblueslip");
|
||||||
const $ = require("./lib/zjquery");
|
const $ = require("./lib/zjquery");
|
||||||
|
|
||||||
const color_data = mock_esm("../src/color_data");
|
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_color_events = mock_esm("../src/stream_color_events");
|
||||||
const stream_list = mock_esm("../src/stream_list");
|
const stream_list = mock_esm("../src/stream_list");
|
||||||
const stream_muting = mock_esm("../src/stream_muting");
|
const stream_muting = mock_esm("../src/stream_muting");
|
||||||
|
@ -454,9 +453,6 @@ test("process_subscriber_update", ({override}) => {
|
||||||
const subsStub = make_stub();
|
const subsStub = make_stub();
|
||||||
stream_settings_ui.update_subscribers_ui = subsStub.f;
|
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);
|
override(user_profile, "update_user_profile_streams_list_for_users", noop);
|
||||||
// Sample user IDs
|
// Sample user IDs
|
||||||
const userIds = [104, 2, 3];
|
const userIds = [104, 2, 3];
|
||||||
|
@ -468,7 +464,4 @@ test("process_subscriber_update", ({override}) => {
|
||||||
|
|
||||||
// Assert that update_subscribers_ui is called for each stream ID
|
// Assert that update_subscribers_ui is called for each stream ID
|
||||||
assert.equal(subsStub.num_calls, streamIds.length);
|
assert.equal(subsStub.num_calls, streamIds.length);
|
||||||
|
|
||||||
// Assert that update_faded_users is called once
|
|
||||||
assert.equal(fadedUsersStub.num_calls, 1);
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue