mirror of
https://github.com/zulip/zulip.git
synced 2025-11-18 04:43:58 +00:00
refactor: Call compose_fade without triggers.
We are trying to phase out the trigger-event way
of telling modules to do something.
In this case we not only remove the indirection
of the event handler, but we also get to remove
`compose_fade` from the `ui_init` startup sequence.
This also has us update `compose_fade` outside
the loop, although that's only a theoretical
improvement, since I don't think `peer_add` events
every actually include multiple streams.
To make the dispatch tests a little flatter, I
added a one-line change to zjsunit to add
`make_stub` to `global`.
To manually test:
* have Aaron reply to Denmark (keep compose box open)
* have Iago add Hamlet to Denmark
* have Hamlet unsubscribe
This commit is contained in:
@@ -646,6 +646,9 @@ with_overrides(function (override) {
|
||||
});
|
||||
});
|
||||
|
||||
const compose_fade_stub = global.make_stub();
|
||||
override('compose_fade.update_faded_users', compose_fade_stub.f);
|
||||
|
||||
event = event_fixtures.subscription__peer_add;
|
||||
global.with_stub(function (stub) {
|
||||
override('stream_data.add_subscriber', stub.f);
|
||||
@@ -654,6 +657,7 @@ with_overrides(function (override) {
|
||||
assert_same(args.sub, event.subscriptions[0]);
|
||||
assert_same(args.user_id, 555);
|
||||
});
|
||||
assert.equal(compose_fade_stub.num_calls, 1);
|
||||
|
||||
event = event_fixtures.subscription__peer_remove;
|
||||
global.with_stub(function (stub) {
|
||||
@@ -663,6 +667,7 @@ with_overrides(function (override) {
|
||||
assert_same(args.sub, event.subscriptions[0]);
|
||||
assert_same(args.user_id, 555);
|
||||
});
|
||||
assert.equal(compose_fade_stub.num_calls, 2);
|
||||
|
||||
event = event_fixtures.subscription__remove;
|
||||
let stream_id_looked_up;
|
||||
|
||||
@@ -108,7 +108,6 @@ zrequire('tutorial');
|
||||
zrequire('notifications');
|
||||
zrequire('pointer');
|
||||
zrequire('pm_conversations');
|
||||
zrequire('compose_fade');
|
||||
zrequire('pm_list');
|
||||
zrequire('list_cursor');
|
||||
zrequire('keydown_util');
|
||||
|
||||
@@ -44,6 +44,7 @@ global.to_$ = () => window;
|
||||
|
||||
// Set up stub helpers.
|
||||
const stub = require('./stub.js');
|
||||
global.make_stub = stub.make_stub;
|
||||
global.with_stub = stub.with_stub;
|
||||
|
||||
// Set up fake jQuery
|
||||
|
||||
@@ -239,11 +239,4 @@ exports.update_rendered_message_groups = function (message_groups, get_element)
|
||||
}
|
||||
};
|
||||
|
||||
exports.initialize = function () {
|
||||
$(document).on('peer_subscribe.zulip peer_unsubscribe.zulip', function () {
|
||||
exports.update_faded_users();
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
window.compose_fade = exports;
|
||||
|
||||
@@ -335,6 +335,7 @@ exports.dispatch_normal_event = function dispatch_normal_event(event) {
|
||||
blueslip.warn('Cannot process peer_add event');
|
||||
}
|
||||
}
|
||||
compose_fade.update_faded_users();
|
||||
} else if (event.op === 'peer_remove') {
|
||||
for (const sub of event.subscriptions) {
|
||||
if (stream_data.remove_subscriber(sub, event.user_id)) {
|
||||
@@ -343,6 +344,7 @@ exports.dispatch_normal_event = function dispatch_normal_event(event) {
|
||||
blueslip.warn('Cannot process peer_remove event.');
|
||||
}
|
||||
}
|
||||
compose_fade.update_faded_users();
|
||||
} else if (event.op === 'remove') {
|
||||
for (const rec of event.subscriptions) {
|
||||
const sub = stream_data.get_sub_by_id(rec.stream_id);
|
||||
|
||||
@@ -475,7 +475,6 @@ exports.initialize_everything = function () {
|
||||
presence.initialize(presence_params);
|
||||
activity.initialize();
|
||||
emoji_picker.initialize();
|
||||
compose_fade.initialize();
|
||||
pm_list.initialize();
|
||||
topic_list.initialize();
|
||||
topic_zoom.initialize();
|
||||
|
||||
Reference in New Issue
Block a user