mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 05:23:35 +00:00
Add narrow_state.pm_string().
This commit is contained in:
@@ -212,3 +212,44 @@ function set_filter(operators) {
|
||||
assert.equal(narrow_state.stream(), undefined);
|
||||
}());
|
||||
|
||||
(function test_pm_string() {
|
||||
// This function will return undefined unless we're clearly
|
||||
// narrowed to a specific PM (including huddles) with real
|
||||
// users.
|
||||
narrow_state.set_current_filter(undefined);
|
||||
assert.equal(narrow_state.pm_string(), undefined);
|
||||
|
||||
set_filter([['stream', 'Foo'], ['topic', 'Bar']]);
|
||||
assert.equal(narrow_state.pm_string(), undefined);
|
||||
|
||||
set_filter([['pm-with', '']]);
|
||||
assert.equal(narrow_state.pm_string(), undefined);
|
||||
|
||||
var called = false;
|
||||
blueslip.warn = function (error) {
|
||||
assert.equal(error, 'Unknown emails: bogus@foo.com');
|
||||
called = true;
|
||||
};
|
||||
|
||||
set_filter([['pm-with', 'bogus@foo.com']]);
|
||||
assert.equal(narrow_state.pm_string(), undefined);
|
||||
assert(called);
|
||||
|
||||
var alice = {
|
||||
email: 'alice@foo.com',
|
||||
user_id: 444,
|
||||
full_name: 'Alice',
|
||||
};
|
||||
|
||||
var bob = {
|
||||
email: 'bob@foo.com',
|
||||
user_id: 555,
|
||||
full_name: 'Bob',
|
||||
};
|
||||
|
||||
people.add(alice);
|
||||
people.add(bob);
|
||||
|
||||
set_filter([['pm-with', 'bob@foo.com,alice@foo.com']]);
|
||||
assert.equal(narrow_state.pm_string(), '444,555');
|
||||
}());
|
||||
|
||||
@@ -120,6 +120,30 @@ exports.topic = function () {
|
||||
return undefined;
|
||||
};
|
||||
|
||||
exports.pm_string = function () {
|
||||
// If you are narrowed to a PM conversation
|
||||
// with users 4, 5, and 99, this will return "4,5,99"
|
||||
|
||||
if (current_filter === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
var operands = current_filter.operands("pm-with");
|
||||
if (operands.length !== 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
var emails_string = operands[0];
|
||||
|
||||
if (!emails_string) {
|
||||
return;
|
||||
}
|
||||
|
||||
var user_ids_string = people.emails_strings_to_user_ids_string(emails_string);
|
||||
|
||||
return user_ids_string;
|
||||
};
|
||||
|
||||
// Are we narrowed to PMs: all PMs or PMs with particular people.
|
||||
exports.narrowed_to_pms = function () {
|
||||
if (current_filter === undefined) {
|
||||
|
||||
Reference in New Issue
Block a user