Use stream_id for by_stream_topic_uri().

This commit is contained in:
Steve Howell
2018-12-14 18:02:26 +00:00
committed by Tim Abbott
parent 7a22d47338
commit aea074e744
5 changed files with 26 additions and 8 deletions

View File

@@ -20,12 +20,12 @@ var hamlet = {
people.add_in_realm(hamlet);
var sub = {
var frontend = {
stream_id: 99,
name: 'frontend',
};
stream_data.add_sub(sub.name, sub);
stream_data.add_sub('frontend', frontend);
run_test('hash_util', () => {
// Test encodeHashComponent
@@ -131,7 +131,7 @@ run_test('test_stream_edit_uri', () => {
run_test('test_by_conversation_and_time_uri', () => {
var message = {
type: 'stream',
stream: 'frontend',
stream_id: frontend.stream_id,
subject: 'testing',
id: 42,
};

View File

@@ -43,6 +43,14 @@ exports.encode_operand = function (operator, operand) {
return exports.encodeHashComponent(operand);
};
exports.encode_stream_id = function (stream_id) {
// stream_data appends the stream name, but it does not do the
// URI encoding piece
var slug = stream_data.id_to_slug(stream_id);
return exports.encodeHashComponent(slug);
};
exports.encode_stream_name = function (operand) {
// stream_data prefixes the stream id, but it does not do the
// URI encoding piece
@@ -76,8 +84,8 @@ exports.by_stream_uri = function (stream) {
return "#narrow/stream/" + exports.encode_stream_name(stream);
};
exports.by_stream_topic_uri = function (stream, subject) {
return "#narrow/stream/" + exports.encode_stream_name(stream) +
exports.by_stream_topic_uri = function (stream_id, subject) {
return "#narrow/stream/" + exports.encode_stream_id(stream_id) +
"/subject/" + exports.encodeHashComponent(subject);
};
@@ -132,7 +140,7 @@ exports.by_conversation_and_time_uri = function (message) {
if (message.type === "stream") {
return absolute_url +
exports.by_stream_topic_uri(message.stream, message.subject) +
exports.by_stream_topic_uri(message.stream_id, message.subject) +
suffix;
}

View File

@@ -243,7 +243,7 @@ MessageListView.prototype = {
hash_util.by_stream_uri(message_container.msg.stream);
message_container.topic_url =
hash_util.by_stream_topic_uri(
message_container.msg.stream,
message_container.msg.stream_id,
message_container.msg.subject);
} else {
message_container.pm_with_url =

View File

@@ -97,6 +97,16 @@ exports.get_sub_by_name = function (name) {
return subs_by_stream_id.get(stream_id);
};
exports.id_to_slug = function (stream_id) {
var name = exports.maybe_get_stream_name(stream_id) || 'unknown';
// The name part of the URL doesn't really matter, so we try to
// make it pretty.
name = name.replace(' ', '-');
return stream_id + '-' + name;
};
exports.name_to_slug = function (name) {
var stream_id = exports.get_stream_id(name);

View File

@@ -87,7 +87,7 @@ exports.widget = function (parent_elem, my_stream_id) {
unread: num_unread,
is_zero: num_unread === 0,
is_muted: muting.is_topic_muted(my_stream_id, topic_name),
url: hash_util.by_stream_topic_uri(my_stream_name, topic_name),
url: hash_util.by_stream_topic_uri(my_stream_id, topic_name),
};
var li = $(templates.render('topic_list_item', topic_info));
self.topic_items.set(topic_name, li);