Allow message topic changing to propagate backwards

(imported from commit 470178ef5f7aaf09d4528c88ae6e33f17538fcaf)
This commit is contained in:
Leo Franchi 2013-09-13 12:12:29 -04:00
parent c417f3323d
commit c588c7938c
6 changed files with 67 additions and 19 deletions

View File

@ -15,9 +15,9 @@ exports.save = function (row) {
if (new_topic !== message.subject && new_topic.trim() !== "") {
request.subject = new_topic;
if (feature_flags.propagate_topic_edits &&
row.find(".message_edit_topic_propagate>input").is(":checked")) {
request.propagate_subject = true;
if (feature_flags.propagate_topic_edits) {
var selected_topic_propagation = row.find("select.message_edit_topic_propagate").val();
request.propagate_mode = selected_topic_propagation;
}
changed = true;
}
@ -78,6 +78,8 @@ function edit_message (row, raw_content) {
content: raw_content}));
var edit_obj = {form: form, raw_content: raw_content};
var original_topic = message.subject;
current_msg_list.show_edit_message(row, edit_obj);
form.keydown(handle_edit_keydown);
@ -98,7 +100,11 @@ function edit_message (row, raw_content) {
viewport.scrollTop(viewport.scrollTop() + scroll_by);
if (feature_flags.propagate_topic_edits) {
row.find('.message_edit_topic_propagate').show();
var topic_input = edit_row.find(".message_edit_topic");
topic_input.keyup( function () {
var new_topic = topic_input.val();
row.find('.message_edit_topic_propagate').toggle(new_topic !== original_topic);
});
}
}

View File

@ -1180,6 +1180,9 @@ table.focused_table {
}
.message_edit_topic_propagate{
display: inline-block;
height: 20px;
width: 400px;
}
.message_content.condensed {

View File

@ -6,9 +6,11 @@
<label class="control-label edit-control-label" for="message_edit_topic">Topic</label>
<div class="controls edit-controls">
<input type="text" value="{{topic}}" class="message_edit_topic" id="message_edit_topic">
<label class='message_edit_topic_propagate' style='display:none;'>
<input type="checkbox"> Change all later messages on this topic
</label>
<select class='message_edit_topic_propagate' style='display:none;'>
<option selected="selected" value="change_one"> Change only this message topic</option>
<option value="change_later"> Change later messages to this topic</option>
<option value="change_all"> Change previous and following messages to this topic</option>
</select>
</div>
</div>
{{/if}}

View File

@ -20,7 +20,7 @@ from django.core.exceptions import ValidationError
from django.utils.importlib import import_module
from django.template import loader
from django.core.mail import EmailMultiAlternatives, EmailMessage
from django.utils.timezone import utc, is_naive
from django.utils.timezone import utc, is_naive, now
from confirmation.models import Confirmation
@ -1191,7 +1191,7 @@ def do_update_onboarding_steps(user_profile, steps):
users=[user_profile.id])
tornado_callbacks.send_notification(notice)
def do_update_message(user_profile, message_id, subject, propagate_subject, content):
def do_update_message(user_profile, message_id, subject, propagate_mode, content):
try:
message = Message.objects.select_related().get(id=message_id)
except Message.DoesNotExist:
@ -1257,12 +1257,20 @@ def do_update_message(user_profile, message_id, subject, propagate_subject, cont
event['subject_links'] = bugdown.subject_links(message.sender.realm.domain.lower(), subject)
edit_history_event["prev_subject"] = orig_subject
if propagate_subject:
messages = Message.objects.filter(
recipient = message.recipient,
subject = orig_subject,
id__gt = message.id
).select_related()
if propagate_mode in ["change_later", "change_all"]:
propagate_query = Q(recipient = message.recipient, subject = orig_subject)
# We only change messages up to 2 days in the past, to avoid hammering our
# DB by changing an unbounded amount of messages
if propagate_mode == 'change_all':
before_bound = now() - datetime.timedelta(days=2)
propagate_query = propagate_query & ~Q(id = message.id) & \
Q(pub_date__range=(before_bound, now()))
if propagate_mode == 'change_later':
propagate_query = propagate_query & Q(id__gt = message.id)
messages = Message.objects.filter(propagate_query).select_related();
# Evaluate the query before running the update
messages_list = list(messages)

View File

@ -1542,7 +1542,7 @@ class EditMessageTest(AuthedTestCase):
self.assert_json_success(result)
self.check_message(msg_id, subject="edited")
def test_propagate_topic(self):
def test_propagate_topic_forward(self):
self.login("hamlet@zulip.com")
id1 = self.send_message("hamlet@zulip.com", "Scotland", Recipient.STREAM,
subject="topic1")
@ -1558,7 +1558,7 @@ class EditMessageTest(AuthedTestCase):
result = self.client.post("/json/update_message", {
'message_id': id1,
'subject': 'edited',
'propagate_subject': True
'propagate_mode': 'change_later'
})
self.assert_json_success(result)
@ -1568,6 +1568,35 @@ class EditMessageTest(AuthedTestCase):
self.check_message(id4, subject="topic2")
self.check_message(id5, subject="edited")
def test_propagate_all_topics(self):
self.login("hamlet@zulip.com")
id1 = self.send_message("hamlet@zulip.com", "Scotland", Recipient.STREAM,
subject="topic1")
id2 = self.send_message("hamlet@zulip.com", "Scotland", Recipient.STREAM,
subject="topic1")
id3 = self.send_message("iago@zulip.com", "Rome", Recipient.STREAM,
subject="topic1")
id4 = self.send_message("hamlet@zulip.com", "Scotland", Recipient.STREAM,
subject="topic2")
id5 = self.send_message("iago@zulip.com", "Scotland", Recipient.STREAM,
subject="topic1")
id6 = self.send_message("iago@zulip.com", "Scotland", Recipient.STREAM,
subject="topic3")
result = self.client.post("/json/update_message", {
'message_id': id2,
'subject': 'edited',
'propagate_mode': 'change_all'
})
self.assert_json_success(result)
self.check_message(id1, subject="edited")
self.check_message(id2, subject="edited")
self.check_message(id3, subject="topic1")
self.check_message(id4, subject="topic2")
self.check_message(id5, subject="edited")
self.check_message(id6, subject="topic3")
class InviteUserTest(AuthedTestCase):
def invite(self, users, streams):

View File

@ -1277,11 +1277,11 @@ def json_fetch_raw_message(request, user_profile,
def update_message_backend(request, user_profile,
message_id=REQ(converter=to_non_negative_int),
subject=REQ(default=None),
propagate_subject=REQ(default=False),
propagate_mode=REQ(default="change-one"),
content=REQ(default=None)):
if subject is None and content is None:
return json_error("Nothing to change")
do_update_message(user_profile, message_id, subject, propagate_subject, content)
do_update_message(user_profile, message_id, subject, propagate_mode, content)
return json_success()
# We do not @require_login for send_message_backend, since it is used