Allow anyone to edit a "no topic" message

This change would allow anyone in the realm to set a topic for a "no topic"
message. As soon as the message topic is set, only the sender can change it again.

(imported from commit 0a91a93b8fd14549965cedc79f45ffd869d82307)
This commit is contained in:
acrefoot
2013-08-16 17:45:13 -04:00
parent e8e5cc37b7
commit 395aaae994
9 changed files with 92 additions and 30 deletions

View File

@@ -2,14 +2,17 @@ var message_edit = (function () {
var exports = {};
var currently_editing_messages = {};
//returns true if the edit task should end.
exports.save = function (row) {
var msg_list = current_msg_list;
var message = current_msg_list.get(rows.id(row));
var new_subject = row.find(".message_edit_subject").val();
var new_topic = row.find(".message_edit_topic").val();
var new_content = row.find(".message_edit_content").val();
var request = {message_id: message.id};
if (new_subject !== message.subject) {
request.subject = new_subject;
if (new_topic !== message.subject && new_topic.trim() !== "") {
request.subject = new_topic;
}
if (new_content !== message.raw_content) {
request.content = new_content;
@@ -17,7 +20,7 @@ exports.save = function (row) {
if (request.subject === undefined &&
request.content === undefined) {
// If they didn't change anything, just cancel it.
return message_edit.end(row);
return true;
}
$.ajax({
type: 'POST',
@@ -26,12 +29,12 @@ exports.save = function (row) {
dataType: 'json',
success: function (data) {
if (msg_list === current_msg_list) {
message_edit.end(row);
return true;
}
},
error: function (xhr, error_type, xhn) {
var message = util.xhr_error_message("Error saving edit", xhr);
row.find(".message_edit_error").text(message).show();
row.find(".edit_error").text(message).show();
}
});
// The message will automatically get replaced when it arrives.
@@ -43,7 +46,13 @@ function handle_edit_keydown(e) {
if (e.target.id === "message_edit_content" && code === 13 &&
(e.metaKey || e.ctrlKey)) {
row = $(".message_edit_content").filter(":focus").closest(".message_row");
message_edit.save(row);
if (message_edit.save(row) === true) {
message_edit.end(row);
}
} else if (e.target.id === "message_edit_topic" && code === 13) {
//hitting enter in topic field isn't so great.
e.stopPropagation();
e.preventDefault();
}
}
@@ -55,7 +64,7 @@ function edit_message (row, raw_content) {
var edit_row = row.find(".message_edit");
var form = $(templates.render('message_edit_form',
{is_stream: message.is_stream,
subject: message.subject,
topic: message.subject,
content: raw_content}));
var edit_obj = {form: form, raw_content: raw_content};
@@ -65,7 +74,7 @@ function edit_message (row, raw_content) {
currently_editing_messages[message.id] = edit_obj;
if (message.subject === compose.empty_subject_placeholder()) {
edit_row.find(".message_edit_subject").focus();
edit_row.find(".message_edit_topic").focus();
} else {
edit_row.find(".message_edit_content").focus();
}
@@ -96,6 +105,13 @@ exports.start = function (row) {
});
};
exports.start_topic_edit = function (recipient_row) {
var form = $(templates.render('topic_edit_form'));
current_msg_list.show_edit_topic(recipient_row, form);
form.keydown(handle_edit_keydown);
form.find(".message_edit_topic").focus();
};
exports.is_editing = function (id) {
return currently_editing_messages[id] !== undefined;
};

View File

@@ -295,6 +295,17 @@ MessageList.prototype = {
row.find(".message_edit").hide();
},
show_edit_topic: function MessageList_show_edit_topic(recipient_row, form) {
recipient_row.find(".topic_edit_form").empty().append(form);
recipient_row.find(".stream_topic").hide();
recipient_row.find(".topic_edit").show();
},
hide_edit_topic: function MessageList_hide_edit_topic(recipient_row) {
recipient_row.find(".stream_topic").show();
recipient_row.find(".topic_edit").hide();
},
show_message_as_read: function (message, options) {
var row = this.get_row(message.id);
if (options.from === 'pointer' && feature_flags.mark_read_at_bottom) {

View File

@@ -1318,14 +1318,30 @@ $(function () {
popovers.hide_all();
});
$('body').on('click', '.edit_subject', function (e) {
var row = current_msg_list.get_row(rows.id($(this).closest(".recipient_row")));
message_edit.start(row);
var recipient_row = $(this).closest(".recipient_row");
message_edit.start_topic_edit(recipient_row);
e.stopPropagation();
popovers.hide_all();
});
$("body").on("click", ".topic_edit_save", function (e) {
var recipient_row = $(this).closest(".recipient_row");
if (message_edit.save(recipient_row) === true) {
current_msg_list.hide_edit_topic(recipient_row);
}
e.stopPropagation();
popovers.hide_all();
});
$("body").on("click", ".topic_edit_cancel", function (e) {
var recipient_row = $(this).closest(".recipient_row");
current_msg_list.hide_edit_topic(recipient_row);
e.stopPropagation();
popovers.hide_all();
});
$("body").on("click", ".message_edit_save", function (e) {
var row = $(this).closest(".message_row");
message_edit.save(row);
if (message_edit.save(row) === true) {
message_edit.end(row);
}
e.stopPropagation();
popovers.hide_all();
});

View File

@@ -554,13 +554,10 @@ function add_message_metadata(message) {
involved_people = [{'full_name': message.sender_full_name,
'email': message.sender_email}];
if ((message.subject === compose.empty_subject_placeholder()) &&
message.sent_by_me) {
// You can only edit messages you sent, so only show the edit hint
// for empty subjects on messages you sent.
message.your_empty_subject = true;
if (message.subject === compose.empty_subject_placeholder()) {
message.empty_subject = true;
} else {
message.your_empty_subject = false;
message.empty_subject = false;
}
break;
@@ -736,9 +733,9 @@ function update_messages(events) {
msg.subject = event.subject;
msg.subject_links = event.subject_links;
if (msg.subject === compose.empty_subject_placeholder()) {
msg.your_empty_subject = true;
msg.empty_subject = true;
} else {
msg.your_empty_subject = false;
msg.empty_subject = false;
}
// Add the recent subjects entry for the new subject; must
// be called after we update msg.subject

View File

@@ -2214,6 +2214,10 @@ div.edit_bot {
margin-bottom: 5px;
}
#topic_edit_form {
display: inline;
}
.message_edit_notice {
font-size: 11px;
}

View File

@@ -55,10 +55,17 @@
<span class="message_label_clickable narrows_by_recipient stream_label"
title="Narrow to stream &quot;{{display_recipient}}&quot;">{{display_recipient}}</span>
&nbsp;<i class="icon-vector-narrow icon-vector-small"></i><span class="copy-paste-text">&gt;</span>&nbsp;
<span class="message_label_clickable narrows_by_subject"
title="Narrow to stream &quot;{{display_recipient}}&quot;, topic &quot;{{subject}}&quot;">{{#if ../../../../use_match_properties}}{{{match_subject}}}{{else}}{{subject}}{{/if}}</span>
{{#if your_empty_subject}}<i class="icon-vector-pencil edit_subject"></i>{{/if}}
{{#each subject_links}}<a href="{{this}}" target="_blank"><i class="icon-vector-external-link-sign"></i>{{/each}}
<span class="stream_topic">
<span class="message_label_clickable narrows_by_subject"
title="Narrow to stream &quot;{{display_recipient}}&quot;, topic &quot;{{subject}}&quot;">{{#if ../../../../use_match_properties}}{{{match_subject}}}{{else}}{{subject}}{{/if}}</span>
{{#if empty_subject}}
<i class="icon-vector-pencil edit_subject"></i>
{{/if}}
{{#each subject_links}}<a href="{{this}}" target="_blank"><i class="icon-vector-external-link-sign"></i>{{/each}}
</span>
<span class="topic_edit">
<span class="topic_edit_form" id="{{id}}"></span>
</span>
</td>
</tr>
{{else}}

View File

@@ -3,9 +3,9 @@
<form id="message_edit_form" class="form-horizontal">
{{#if is_stream}}
<div class="control-group">
<label class="control-label edit-control-label" for="message_edit_subject">Topic</label>
<label class="control-label edit-control-label" for="message_edit_topic">Topic</label>
<div class="controls edit-controls">
<input type="text" value="{{subject}}" class="message_edit_subject" id="message_edit_subject">
<input type="text" value="{{topic}}" class="message_edit_topic" id="message_edit_topic">
</div>
</div>
{{/if}}
@@ -16,9 +16,9 @@
</div>
<div class="control-group">
<div class="controls edit-controls">
<button type="button" class="message_edit_save btn btn-primary btn-small">Save</a>
<button type="button" class="message_edit_cancel btn btn-small">Cancel</a>
<button type="button" class="message_edit_save btn btn-primary btn-small">Save</button>
<button type="button" class="message_edit_cancel btn btn-small">Cancel</button>
</div>
</div>
<div class="alert alert-error message_edit_error hide"></div>
<div class="alert alert-error edit_error hide"></div>
</form>

View File

@@ -0,0 +1,10 @@
{{! Client-side Mustache template for rendering the topic edit form. }}
<form id="topic_edit_form" class="form-horizontal">
{{! <div class="controls edit-controls"> }}
<input type="text" value="" class="message_edit_topic" id="message_edit_topic">
<button type="button" class="topic_edit_save btn btn-primary btn-small">Save</button>
<button type="button" class="topic_edit_cancel btn btn-small">Cancel</button>
{{! </div> }}
<div class="alert alert-error edit_error hide"></div>
</form>

View File

@@ -963,7 +963,8 @@ def do_update_message(user_profile, message_id, subject, content):
edit_history_event = {}
if message.sender != user_profile:
raise JsonableError("Message was not sent by you")
if not (message.subject == "(no topic)" and content is None):
raise JsonableError("Message was not sent by you")
# Set first_rendered_content to be the oldest version of the
# rendered content recorded; which is the current version if the