mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	This commit prefixes stream names in urls with stream ids, so that the urls don't break when we rename streams. strean name: foo bar.com% before: #narrow/stream/foo.20bar.2Ecom.25 after: #narrow/stream/20-foo-bar.2Ecom.25 For new realms, everything is simple under the new scheme, since we just parse out the stream id every time to figure out where to narrow. For old realms, any old URLs will still work under the new scheme, assuming the stream hasn't been renamed (and of course old urls wouldn't have survived stream renaming in the first place). The one exception is the hopefully rare case of a stream name starting with something like "99-" and colliding with another stream whose id is 99. The way that we enocde the stream name portion of the URL is kind of unimportant now, since we really only look at the stream id, but we still want a safe encoding of the name that is mostly human readable, so we now convert spaces to dashes in the stream name. Also, we try to ensure more code on both sides (frontend and backend) calls common functions to do the encoding. Fixes #4713
		
			
				
	
	
		
			104 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			104 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
set_global('$', global.make_zjquery());
 | 
						|
set_global('i18n', global.stub_i18n);
 | 
						|
 | 
						|
set_global('narrow_state', {});
 | 
						|
set_global('stream_data', {});
 | 
						|
set_global('unread', {});
 | 
						|
set_global('muting', {});
 | 
						|
set_global('stream_popover', {});
 | 
						|
set_global('templates', {});
 | 
						|
 | 
						|
zrequire('hash_util');
 | 
						|
zrequire('narrow');
 | 
						|
zrequire('stream_data');
 | 
						|
zrequire('topic_data');
 | 
						|
zrequire('topic_list');
 | 
						|
 | 
						|
(function test_topic_list_build_widget() {
 | 
						|
    var stream_id = 555;
 | 
						|
 | 
						|
    topic_data.reset();
 | 
						|
    topic_data.add_message({
 | 
						|
        stream_id: stream_id,
 | 
						|
        topic_name: 'coding',
 | 
						|
        message_id: 400,
 | 
						|
    });
 | 
						|
 | 
						|
    stream_popover.hide_topic_popover = function () {};
 | 
						|
 | 
						|
    narrow_state.topic = function () {
 | 
						|
        return 'testing';
 | 
						|
    };
 | 
						|
 | 
						|
    unread.num_unread_for_topic = function () {
 | 
						|
        return 3;
 | 
						|
    };
 | 
						|
 | 
						|
    stream_data.get_sub_by_id = function (stream_id) {
 | 
						|
        assert.equal(stream_id, 555);
 | 
						|
        return {
 | 
						|
            name: 'devel',
 | 
						|
        };
 | 
						|
    };
 | 
						|
 | 
						|
    var checked_mutes;
 | 
						|
    var rendered;
 | 
						|
 | 
						|
    templates.render = function (name, info) {
 | 
						|
        assert.equal(name, 'topic_list_item');
 | 
						|
        var expected = {
 | 
						|
            topic_name: 'coding',
 | 
						|
            unread: 3,
 | 
						|
            is_zero: false,
 | 
						|
            is_muted: false,
 | 
						|
            url: '#narrow/stream/devel/subject/coding',
 | 
						|
        };
 | 
						|
        assert.deepEqual(info, expected);
 | 
						|
        rendered = true;
 | 
						|
        return '<topic list item>';
 | 
						|
    };
 | 
						|
 | 
						|
    muting.is_topic_muted = function (stream_name, topic_name) {
 | 
						|
        assert.equal(stream_name, 'devel');
 | 
						|
        assert.equal(topic_name, 'coding');
 | 
						|
        checked_mutes = true;
 | 
						|
        return false;
 | 
						|
    };
 | 
						|
 | 
						|
    var ul = $('<ul class="topic-list">');
 | 
						|
 | 
						|
    var list_items = [];
 | 
						|
 | 
						|
    ul.append = function (item) {
 | 
						|
        list_items.push(item);
 | 
						|
    };
 | 
						|
 | 
						|
    var parent_elem = $.create('parent_elem');
 | 
						|
    var attached_to_parent;
 | 
						|
 | 
						|
    parent_elem.append = function (child) {
 | 
						|
        assert.equal(child, ul);
 | 
						|
        attached_to_parent = true;
 | 
						|
    };
 | 
						|
 | 
						|
    assert.equal(topic_list.active_stream_id(), undefined);
 | 
						|
 | 
						|
    var widget = topic_list.widget(parent_elem, stream_id);
 | 
						|
 | 
						|
    widget.build_more_topics_section = function () {
 | 
						|
        return $('<more topics>');
 | 
						|
    };
 | 
						|
 | 
						|
    widget.build();
 | 
						|
 | 
						|
    assert(widget.is_for_stream(stream_id));
 | 
						|
    assert.equal(widget.get_parent(), parent_elem);
 | 
						|
 | 
						|
    assert(checked_mutes);
 | 
						|
    assert(rendered);
 | 
						|
    assert.equal(list_items[0].html(), '<topic list item>');
 | 
						|
    assert.equal(list_items[1].html(), '<more topics>');
 | 
						|
    assert(attached_to_parent);
 | 
						|
 | 
						|
}());
 |