2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-11-30 23:46:45 +01:00
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
|
2020-12-01 00:53:02 +01:00
|
|
|
const {set_global, 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
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
zrequire("stream_data");
|
2020-08-20 21:24:06 +02:00
|
|
|
const people = zrequire("people");
|
2020-07-15 01:29:15 +02:00
|
|
|
zrequire("compose_fade");
|
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,
|
2018-03-19 05:52:37 +01:00
|
|
|
can_access_subscribers: true,
|
2017-02-23 23:39:43 +01:00
|
|
|
};
|
2020-02-09 22:02:55 +01:00
|
|
|
stream_data.add_sub(sub);
|
2017-02-23 23:39:43 +01:00
|
|
|
stream_data.set_subscribers(sub, [me.user_id, alice.user_id]);
|
|
|
|
|
2020-12-01 00:53:02 +01:00
|
|
|
set_global("$", (selector) => {
|
2017-02-23 23:39:43 +01:00
|
|
|
switch (selector) {
|
2020-07-15 00:34:28 +02:00
|
|
|
case "#stream_message_recipient_stream":
|
|
|
|
return {
|
2020-07-20 22:18:43 +02:00
|
|
|
val() {
|
2020-07-15 00:34:28 +02:00
|
|
|
return "social";
|
|
|
|
},
|
|
|
|
};
|
|
|
|
case "#stream_message_recipient_topic":
|
|
|
|
return {
|
2020-07-20 22:18:43 +02:00
|
|
|
val() {
|
2020-07-15 00:34:28 +02:00
|
|
|
return "lunch";
|
|
|
|
},
|
|
|
|
};
|
2020-09-24 07:50:36 +02:00
|
|
|
default:
|
|
|
|
throw new Error(`Unknown selector ${selector}`);
|
2017-02-23 23:39:43 +01:00
|
|
|
}
|
2020-12-01 00:53:02 +01:00
|
|
|
});
|
2017-02-23 23:39:43 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
compose_fade.set_focused_recipient("stream");
|
2017-02-23 23:39:43 +01:00
|
|
|
|
2020-06-05 19:49:16 +02:00
|
|
|
assert.equal(compose_fade.would_receive_message(me.user_id), true);
|
|
|
|
assert.equal(compose_fade.would_receive_message(alice.user_id), true);
|
|
|
|
assert.equal(compose_fade.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
|
|
|
};
|
|
|
|
assert(!compose_fade.should_fade_message(good_msg));
|
|
|
|
assert(compose_fade.should_fade_message(bad_msg));
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|