mirror of https://github.com/zulip/zulip.git
Remove obsolete code for stream subscribe buttons.
In 18e43895ff
we replaced
stream subscribe buttons with stream links. The new feature
has been well tested and well received for over a year now,
so it's safe to remove the older feature at this point.
Older sites will have super old messages that still have the
rendered markup; this commit does not attempt to address those
situations. Most likely, clicking on an old button in the old
message will either do nothing or look like a message reply.
This commit is contained in:
parent
d32d7a9b4d
commit
4f05cefb32
|
@ -1,126 +0,0 @@
|
|||
var custom_markdown = (function () {
|
||||
|
||||
var exports = {};
|
||||
|
||||
(function () {
|
||||
// Javascript for bugdown.StreamSubscribeButton
|
||||
|
||||
// A map of stream names to ids to select inline subscribe node without
|
||||
// needing to escape the CSS selectors.
|
||||
var inline_subscribe_id_map = {};
|
||||
|
||||
function add_sub(stream_name, $status_message) {
|
||||
channel.post({
|
||||
url: '/json/users/me/subscriptions',
|
||||
data: {
|
||||
subscriptions: JSON.stringify([{name: stream_name}]),
|
||||
},
|
||||
}).then(
|
||||
function (data) {
|
||||
if (!$.isEmptyObject(data.already_subscribed)) {
|
||||
// Display the canonical stream capitalization.
|
||||
var my_email = people.my_current_email();
|
||||
var true_stream_name = data.already_subscribed[my_email][0];
|
||||
ui_report.success(i18n.t("Already subscribed to __stream__", {stream: true_stream_name}),
|
||||
$status_message);
|
||||
}
|
||||
}, function (xhr) {
|
||||
ui_report.error(i18n.t("Error adding subscription"), xhr, $status_message);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function remove_sub(stream_name, $status_message) {
|
||||
channel.del({
|
||||
url: '/json/users/me/subscriptions',
|
||||
data: {
|
||||
subscriptions: JSON.stringify([stream_name]),
|
||||
},
|
||||
}).then(
|
||||
function () {
|
||||
$status_message.hide();
|
||||
}, function (xhr) {
|
||||
ui_report.error(i18n.t("Error removing subscription"), xhr, $status_message);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function display_subscribe($button, stream_name) {
|
||||
$button.text(i18n.t('Subscribe to __stream__', {stream: stream_data.canonicalized_name(stream_name)}))
|
||||
.removeClass('btn-success')
|
||||
.addClass('btn-default');
|
||||
}
|
||||
|
||||
function display_unsubscribe($button, stream_name) {
|
||||
$button.text(i18n.t('Unsubscribe from __stream__', {stream: stream_data.canonicalized_name(stream_name)}))
|
||||
.removeClass('btn-default')
|
||||
.addClass('btn-success');
|
||||
}
|
||||
|
||||
function update_button_display($button, stream_name) {
|
||||
if (stream_data.is_subscribed(stream_name)) {
|
||||
display_unsubscribe($button, stream_name);
|
||||
} else {
|
||||
display_subscribe($button, stream_name);
|
||||
}
|
||||
}
|
||||
|
||||
$(function () {
|
||||
$('#main_div').on('click', '.inline-subscribe-button', function (e) {
|
||||
var $button = $(e.target);
|
||||
var stream_name = $button.closest('.inline-subscribe').attr('data-stream-name');
|
||||
var $status_message = $button.siblings('.inline-subscribe-error');
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
if (stream_data.is_subscribed(stream_name)) {
|
||||
remove_sub(stream_name, $status_message);
|
||||
} else {
|
||||
add_sub(stream_name, $status_message);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$(document).on('message_rendered.zulip', function (e) {
|
||||
var $inline_subscribe;
|
||||
var $button;
|
||||
var stream_name;
|
||||
var id;
|
||||
$inline_subscribe = $(e.target).find('.inline-subscribe');
|
||||
if ($inline_subscribe.length === 0) {
|
||||
return;
|
||||
}
|
||||
stream_name = $inline_subscribe.attr('data-stream-name');
|
||||
$button = $inline_subscribe.find('.inline-subscribe-button');
|
||||
|
||||
if (inline_subscribe_id_map[stream_name]) {
|
||||
id = inline_subscribe_id_map[stream_name];
|
||||
} else {
|
||||
id = _.uniqueId('inline-subscribe-id-');
|
||||
inline_subscribe_id_map[stream_name] = id;
|
||||
}
|
||||
// Can not use data here, jQuery only stores into expando so our jQuery
|
||||
// selectors will not be able to find it.
|
||||
$inline_subscribe.attr('data-stream-ui-id', id);
|
||||
|
||||
update_button_display($button, stream_name);
|
||||
});
|
||||
|
||||
var sub_event_handler = function (e) {
|
||||
var stream_name = e.sub.name;
|
||||
var id = inline_subscribe_id_map[stream_name];
|
||||
var $button = $('#main_div').
|
||||
find('.inline-subscribe[data-stream-ui-id="'+ id + '"] .inline-subscribe-button');
|
||||
update_button_display($button, stream_name);
|
||||
};
|
||||
$(document).on('subscription_add_done.zulip', sub_event_handler);
|
||||
$(document).on('subscription_remove_done.zulip', sub_event_handler);
|
||||
}());
|
||||
|
||||
|
||||
return exports;
|
||||
|
||||
}());
|
||||
if (typeof module !== 'undefined') {
|
||||
module.exports = custom_markdown;
|
||||
}
|
|
@ -566,19 +566,6 @@
|
|||
"expected_output": "<p><code>!gravatar(username@example.com)</code></p>",
|
||||
"text_content": "!gravatar(username@example.com)"
|
||||
},
|
||||
{
|
||||
"name": "stream_subscribe_button",
|
||||
"input": "!_stream_subscribe_button(streamname)",
|
||||
"expected_output": "<p><span class=\"inline-subscribe\" data-stream-name=\"streamname\"><button class=\"inline-subscribe-button btn\">Subscribe to streamname</button><span class=\"inline-subscribe-error\"></span></span></p>",
|
||||
"marked_expected_output": "<p>!_stream_subscribe_button(streamname)</p>",
|
||||
"text_content": "Subscribe to streamname"
|
||||
},
|
||||
{
|
||||
"name": "stream_subscribe_button_escaped",
|
||||
"input": "`!_stream_subscribe_button(streamname)`",
|
||||
"expected_output": "<p><code>!_stream_subscribe_button(streamname)</code></p>",
|
||||
"text_content": "!_stream_subscribe_button(streamname)"
|
||||
},
|
||||
{
|
||||
"name": "tex_inline",
|
||||
"input": "$$1 \\oplus 0 = 1$$",
|
||||
|
|
|
@ -1054,26 +1054,6 @@ class Emoji(markdown.inlinepatterns.Pattern):
|
|||
def content_has_emoji_syntax(content: Text) -> bool:
|
||||
return re.search(EMOJI_REGEX, content) is not None
|
||||
|
||||
class StreamSubscribeButton(markdown.inlinepatterns.Pattern):
|
||||
# This markdown extension has required javascript in
|
||||
# static/js/custom_markdown.js
|
||||
def handleMatch(self, match: Match[Text]) -> Element:
|
||||
stream_name = match.group('stream_name')
|
||||
stream_name = stream_name.replace('\\)', ')').replace('\\\\', '\\')
|
||||
|
||||
span = markdown.util.etree.Element('span')
|
||||
span.set('class', 'inline-subscribe')
|
||||
span.set('data-stream-name', stream_name)
|
||||
|
||||
button = markdown.util.etree.SubElement(span, 'button')
|
||||
button.text = 'Subscribe to ' + stream_name
|
||||
button.set('class', 'inline-subscribe-button btn')
|
||||
|
||||
error = markdown.util.etree.SubElement(span, 'span')
|
||||
error.set('class', 'inline-subscribe-error')
|
||||
|
||||
return span
|
||||
|
||||
class ModalLink(markdown.inlinepatterns.Pattern):
|
||||
"""
|
||||
A pattern that allows including in-app modal links in messages.
|
||||
|
@ -1585,11 +1565,6 @@ class Bugdown(markdown.Extension):
|
|||
md.inlinePatterns.add('avatar', Avatar(AVATAR_REGEX), '>backtick')
|
||||
md.inlinePatterns.add('gravatar', Avatar(GRAVATAR_REGEX), '>backtick')
|
||||
|
||||
md.inlinePatterns.add(
|
||||
'stream_subscribe_button',
|
||||
StreamSubscribeButton(
|
||||
r'!_stream_subscribe_button\((?P<stream_name>(?:[^)\\]|\\\)|\\)*)\)'),
|
||||
'>backtick')
|
||||
md.inlinePatterns.add(
|
||||
'modal_link',
|
||||
ModalLink(r'!modal_link\((?P<relative_url>[^)]*), (?P<text>[^)]*)\)'),
|
||||
|
|
|
@ -1067,58 +1067,6 @@ class BugdownTest(ZulipTestCase):
|
|||
'<p>There #<strong>Nonexistentstream</strong></p>')
|
||||
self.assertEqual(msg.mentions_user_ids, set())
|
||||
|
||||
def test_stream_subscribe_button_simple(self) -> None:
|
||||
msg = '!_stream_subscribe_button(simple)'
|
||||
converted = bugdown_convert(msg)
|
||||
self.assertEqual(
|
||||
converted,
|
||||
'<p>'
|
||||
'<span class="inline-subscribe" data-stream-name="simple">'
|
||||
'<button class="inline-subscribe-button btn">Subscribe to simple</button>'
|
||||
'<span class="inline-subscribe-error"></span>'
|
||||
'</span>'
|
||||
'</p>'
|
||||
)
|
||||
|
||||
def test_stream_subscribe_button_in_name(self) -> None:
|
||||
msg = '!_stream_subscribe_button(simple (not\\))'
|
||||
converted = bugdown_convert(msg)
|
||||
self.assertEqual(
|
||||
converted,
|
||||
'<p>'
|
||||
'<span class="inline-subscribe" data-stream-name="simple (not)">'
|
||||
'<button class="inline-subscribe-button btn">Subscribe to simple (not)</button>'
|
||||
'<span class="inline-subscribe-error"></span>'
|
||||
'</span>'
|
||||
'</p>'
|
||||
)
|
||||
|
||||
def test_stream_subscribe_button_after_name(self) -> None:
|
||||
msg = '!_stream_subscribe_button(simple) (not)'
|
||||
converted = bugdown_convert(msg)
|
||||
self.assertEqual(
|
||||
converted,
|
||||
'<p>'
|
||||
'<span class="inline-subscribe" data-stream-name="simple">'
|
||||
'<button class="inline-subscribe-button btn">Subscribe to simple</button>'
|
||||
'<span class="inline-subscribe-error"></span>'
|
||||
'</span>'
|
||||
' (not)</p>'
|
||||
)
|
||||
|
||||
def test_stream_subscribe_button_slash(self) -> None:
|
||||
msg = '!_stream_subscribe_button(simple\\\\)'
|
||||
converted = bugdown_convert(msg)
|
||||
self.assertEqual(
|
||||
converted,
|
||||
'<p>'
|
||||
'<span class="inline-subscribe" data-stream-name="simple\\">'
|
||||
'<button class="inline-subscribe-button btn">Subscribe to simple\\</button>'
|
||||
'<span class="inline-subscribe-error"></span>'
|
||||
'</span>'
|
||||
'</p>'
|
||||
)
|
||||
|
||||
def test_in_app_modal_link(self) -> None:
|
||||
msg = '!modal_link(#settings, Settings page)'
|
||||
converted = bugdown_convert(msg)
|
||||
|
|
|
@ -1144,7 +1144,6 @@ JS_SPECS = {
|
|||
'js/admin.js',
|
||||
'js/tab_bar.js',
|
||||
'js/emoji.js',
|
||||
'js/custom_markdown.js',
|
||||
'js/bot_data.js',
|
||||
'js/reactions.js',
|
||||
'js/typing.js',
|
||||
|
|
Loading…
Reference in New Issue