mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 22:43:42 +00:00
Use stream_id for by_stream_topic_uri().
This commit is contained in:
@@ -20,12 +20,12 @@ var hamlet = {
|
|||||||
|
|
||||||
people.add_in_realm(hamlet);
|
people.add_in_realm(hamlet);
|
||||||
|
|
||||||
var sub = {
|
var frontend = {
|
||||||
stream_id: 99,
|
stream_id: 99,
|
||||||
name: 'frontend',
|
name: 'frontend',
|
||||||
};
|
};
|
||||||
|
|
||||||
stream_data.add_sub(sub.name, sub);
|
stream_data.add_sub('frontend', frontend);
|
||||||
|
|
||||||
run_test('hash_util', () => {
|
run_test('hash_util', () => {
|
||||||
// Test encodeHashComponent
|
// Test encodeHashComponent
|
||||||
@@ -131,7 +131,7 @@ run_test('test_stream_edit_uri', () => {
|
|||||||
run_test('test_by_conversation_and_time_uri', () => {
|
run_test('test_by_conversation_and_time_uri', () => {
|
||||||
var message = {
|
var message = {
|
||||||
type: 'stream',
|
type: 'stream',
|
||||||
stream: 'frontend',
|
stream_id: frontend.stream_id,
|
||||||
subject: 'testing',
|
subject: 'testing',
|
||||||
id: 42,
|
id: 42,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -43,6 +43,14 @@ exports.encode_operand = function (operator, operand) {
|
|||||||
return exports.encodeHashComponent(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) {
|
exports.encode_stream_name = function (operand) {
|
||||||
// stream_data prefixes the stream id, but it does not do the
|
// stream_data prefixes the stream id, but it does not do the
|
||||||
// URI encoding piece
|
// URI encoding piece
|
||||||
@@ -76,8 +84,8 @@ exports.by_stream_uri = function (stream) {
|
|||||||
return "#narrow/stream/" + exports.encode_stream_name(stream);
|
return "#narrow/stream/" + exports.encode_stream_name(stream);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.by_stream_topic_uri = function (stream, subject) {
|
exports.by_stream_topic_uri = function (stream_id, subject) {
|
||||||
return "#narrow/stream/" + exports.encode_stream_name(stream) +
|
return "#narrow/stream/" + exports.encode_stream_id(stream_id) +
|
||||||
"/subject/" + exports.encodeHashComponent(subject);
|
"/subject/" + exports.encodeHashComponent(subject);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -132,7 +140,7 @@ exports.by_conversation_and_time_uri = function (message) {
|
|||||||
|
|
||||||
if (message.type === "stream") {
|
if (message.type === "stream") {
|
||||||
return absolute_url +
|
return absolute_url +
|
||||||
exports.by_stream_topic_uri(message.stream, message.subject) +
|
exports.by_stream_topic_uri(message.stream_id, message.subject) +
|
||||||
suffix;
|
suffix;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -243,7 +243,7 @@ MessageListView.prototype = {
|
|||||||
hash_util.by_stream_uri(message_container.msg.stream);
|
hash_util.by_stream_uri(message_container.msg.stream);
|
||||||
message_container.topic_url =
|
message_container.topic_url =
|
||||||
hash_util.by_stream_topic_uri(
|
hash_util.by_stream_topic_uri(
|
||||||
message_container.msg.stream,
|
message_container.msg.stream_id,
|
||||||
message_container.msg.subject);
|
message_container.msg.subject);
|
||||||
} else {
|
} else {
|
||||||
message_container.pm_with_url =
|
message_container.pm_with_url =
|
||||||
|
|||||||
@@ -97,6 +97,16 @@ exports.get_sub_by_name = function (name) {
|
|||||||
return subs_by_stream_id.get(stream_id);
|
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) {
|
exports.name_to_slug = function (name) {
|
||||||
var stream_id = exports.get_stream_id(name);
|
var stream_id = exports.get_stream_id(name);
|
||||||
|
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ exports.widget = function (parent_elem, my_stream_id) {
|
|||||||
unread: num_unread,
|
unread: num_unread,
|
||||||
is_zero: num_unread === 0,
|
is_zero: num_unread === 0,
|
||||||
is_muted: muting.is_topic_muted(my_stream_id, topic_name),
|
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));
|
var li = $(templates.render('topic_list_item', topic_info));
|
||||||
self.topic_items.set(topic_name, li);
|
self.topic_items.set(topic_name, li);
|
||||||
|
|||||||
Reference in New Issue
Block a user