2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-11-30 23:46:45 +01:00
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
|
2021-06-16 15:58:34 +02:00
|
|
|
const {mock_jquery, zrequire} = require("../zjsunit/namespace");
|
2020-12-01 00:39:47 +01:00
|
|
|
const {run_test} = require("../zjsunit/test");
|
2020-12-01 00:02:16 +01:00
|
|
|
|
2021-06-16 15:58:34 +02:00
|
|
|
mock_jquery((selector) => {
|
2020-12-01 23:21:38 +01:00
|
|
|
switch (selector) {
|
|
|
|
case "#stream_message_recipient_stream":
|
|
|
|
return {
|
|
|
|
val() {
|
|
|
|
return "social";
|
|
|
|
},
|
|
|
|
};
|
|
|
|
case "#stream_message_recipient_topic":
|
|
|
|
return {
|
|
|
|
val() {
|
|
|
|
return "lunch";
|
|
|
|
},
|
|
|
|
};
|
|
|
|
default:
|
|
|
|
throw new Error(`Unknown selector ${selector}`);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-02-10 04:53:22 +01:00
|
|
|
const stream_data = zrequire("stream_data");
|
2021-01-12 21:38:01 +01:00
|
|
|
const peer_data = zrequire("peer_data");
|
2020-08-20 21:24:06 +02:00
|
|
|
const people = zrequire("people");
|
2021-02-10 04:53:22 +01:00
|
|
|
const compose_fade = zrequire("compose_fade");
|
2021-03-19 14:38:22 +01:00
|
|
|
const compose_fade_helper = zrequire("compose_fade_helper");
|
2017-02-23 23:39:43 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const me = {
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "me@example.com",
|
2017-02-23 23:39:43 +01:00
|
|
|
user_id: 30,
|
2020-07-15 01:29:15 +02:00
|
|
|
full_name: "Me Myself",
|
2017-02-23 23:39:43 +01:00
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const alice = {
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "alice@example.com",
|
2017-02-23 23:39:43 +01:00
|
|
|
user_id: 31,
|
2020-07-15 01:29:15 +02:00
|
|
|
full_name: "Alice",
|
2017-02-23 23:39:43 +01:00
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const bob = {
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "bob@example.com",
|
2017-02-23 23:39:43 +01:00
|
|
|
user_id: 32,
|
2020-07-15 01:29:15 +02:00
|
|
|
full_name: "Bob",
|
2017-02-23 23:39:43 +01:00
|
|
|
};
|
|
|
|
|
2020-05-26 22:34:15 +02:00
|
|
|
people.add_active_user(me);
|
2017-02-23 23:39:43 +01:00
|
|
|
people.initialize_current_user(me.user_id);
|
|
|
|
|
2020-05-26 22:34:15 +02:00
|
|
|
people.add_active_user(alice);
|
|
|
|
people.add_active_user(bob);
|
2017-02-23 23:39:43 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("set_focused_recipient", () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const sub = {
|
2017-02-23 23:39:43 +01:00
|
|
|
stream_id: 101,
|
2020-07-15 01:29:15 +02:00
|
|
|
name: "social",
|
2017-02-23 23:39:43 +01:00
|
|
|
subscribed: true,
|
|
|
|
};
|
2021-03-19 14:38:22 +01:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2020-02-09 22:02:55 +01:00
|
|
|
stream_data.add_sub(sub);
|
2021-01-13 22:03:25 +01:00
|
|
|
peer_data.set_subscribers(sub.stream_id, [me.user_id, alice.user_id]);
|
2020-07-15 01:29:15 +02:00
|
|
|
compose_fade.set_focused_recipient("stream");
|
2017-02-23 23:39:43 +01:00
|
|
|
|
2021-03-19 14:38:22 +01:00
|
|
|
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);
|
2017-02-24 01:20:49 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const good_msg = {
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "stream",
|
2017-02-23 03:53:02 +01:00
|
|
|
stream_id: 101,
|
2020-07-15 01:29:15 +02:00
|
|
|
topic: "lunch",
|
2017-02-24 01:20:49 +01:00
|
|
|
};
|
2019-11-02 00:06:25 +01:00
|
|
|
const bad_msg = {
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "stream",
|
2017-02-23 03:53:02 +01:00
|
|
|
stream_id: 999,
|
2020-07-15 01:29:15 +02:00
|
|
|
topic: "lunch",
|
2017-02-24 01:20:49 +01:00
|
|
|
};
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(!compose_fade_helper.should_fade_message(good_msg));
|
|
|
|
assert.ok(compose_fade_helper.should_fade_message(bad_msg));
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|