mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 14:03:30 +00:00
Use data-user-ids-string in Private Messages sidebar.
This commit also changed message_store.recent_private_messages to use user_ids_string instead of reply_to.
This commit is contained in:
@@ -5,6 +5,7 @@ add_dependencies({
|
||||
templates: 'js/templates',
|
||||
muting: 'js/muting',
|
||||
narrow: 'js/narrow',
|
||||
people: 'js/people',
|
||||
stream_color: 'js/stream_color',
|
||||
stream_data: 'js/stream_data',
|
||||
subs: 'js/subs',
|
||||
@@ -33,15 +34,27 @@ global.compile_template('sidebar_private_message_list');
|
||||
global.compile_template('stream_sidebar_row');
|
||||
global.compile_template('stream_privacy');
|
||||
|
||||
var alice = {
|
||||
email: 'alice@zulip.com',
|
||||
user_id: 101,
|
||||
full_name: 'Alice'
|
||||
};
|
||||
var bob = {
|
||||
email: 'bob@zulip.com',
|
||||
user_id: 102,
|
||||
full_name: 'Bob'
|
||||
};
|
||||
global.people.add_in_realm(alice);
|
||||
global.people.add_in_realm(bob);
|
||||
|
||||
(function test_build_private_messages_list() {
|
||||
var reply_tos = "alice@zulip.com,bob@zulip.com";
|
||||
var active_conversation = "Alice, Bob";
|
||||
var active_conversation = "alice@zulip.com,bob@zulip.com";
|
||||
var max_conversations = 5;
|
||||
|
||||
|
||||
var conversations = {reply_to: reply_tos,
|
||||
display_reply_to: active_conversation,
|
||||
timestamp: 0 };
|
||||
var conversations = {user_ids_string: '101,102',
|
||||
display_reply_to: active_conversation,
|
||||
timestamp: 0 };
|
||||
global.message_store.recent_private_messages.push(conversations);
|
||||
|
||||
global.unread.num_unread_for_person = function () {
|
||||
|
||||
@@ -42,13 +42,20 @@ exports.get_private_message_recipient = function (message, attr, fallback_attr)
|
||||
exports.process_message_for_recent_private_messages = function process_message_for_recent_private_messages(message, remove_message) {
|
||||
var current_timestamp = 0;
|
||||
|
||||
var user_ids_string = people.emails_strings_to_user_ids_string(message.reply_to);
|
||||
|
||||
if (!user_ids_string) {
|
||||
blueslip.warn('Unknown reply_to in message: ' + user_ids_string);
|
||||
return;
|
||||
}
|
||||
|
||||
// If this conversation is already tracked, we'll replace with new timestamp,
|
||||
// so remove it from the current list.
|
||||
exports.recent_private_messages = _.filter(exports.recent_private_messages, function (recent_pm) {
|
||||
return recent_pm.reply_to !== message.reply_to;
|
||||
return recent_pm.user_ids_string !== user_ids_string;
|
||||
});
|
||||
|
||||
var new_conversation = {reply_to: message.reply_to,
|
||||
var new_conversation = {user_ids_string: user_ids_string,
|
||||
display_reply_to: message.display_reply_to,
|
||||
timestamp: Math.max(message.timestamp, current_timestamp)};
|
||||
|
||||
|
||||
@@ -29,8 +29,17 @@ function set_count(type, name, count) {
|
||||
|
||||
exports.get_conversation_li = function (conversation) {
|
||||
// conversation is something like "foo@example.com,bar@example.com"
|
||||
var user_ids_string = people.emails_strings_to_user_ids_string(conversation);
|
||||
if (!user_ids_string) {
|
||||
blueslip.warn('Unknown conversation: ' + conversation);
|
||||
return;
|
||||
}
|
||||
return exports.get_li_for_user_ids_string(user_ids_string);
|
||||
};
|
||||
|
||||
exports.get_li_for_user_ids_string = function (user_ids_string) {
|
||||
var pm_li = get_filter_li();
|
||||
var convo_li = pm_li.find("li[data-name='" + conversation + "']");
|
||||
var convo_li = pm_li.find("li[data-user-ids-string='" + user_ids_string + "']");
|
||||
return convo_li;
|
||||
};
|
||||
|
||||
@@ -65,13 +74,20 @@ exports._build_private_messages_list = function (active_conversation, max_privat
|
||||
var display_messages = [];
|
||||
var hiding_messages = false;
|
||||
|
||||
// SHIM
|
||||
if (active_conversation) {
|
||||
active_conversation = people.emails_strings_to_user_ids_string(active_conversation);
|
||||
}
|
||||
|
||||
_.each(private_messages, function (private_message_obj, idx) {
|
||||
var recipients_string = private_message_obj.display_reply_to;
|
||||
var replies_to = private_message_obj.reply_to;
|
||||
var num_unread = unread.num_unread_for_person(private_message_obj.reply_to);
|
||||
var user_ids_string = private_message_obj.user_ids_string;
|
||||
var reply_to = people.user_ids_string_to_emails_string(user_ids_string);
|
||||
|
||||
var num_unread = unread.num_unread_for_person(reply_to);
|
||||
|
||||
var always_visible = (idx < max_private_messages) || (num_unread > 0)
|
||||
|| (replies_to === active_conversation);
|
||||
|| (user_ids_string === active_conversation);
|
||||
|
||||
if (!always_visible) {
|
||||
hiding_messages = true;
|
||||
@@ -79,11 +95,11 @@ exports._build_private_messages_list = function (active_conversation, max_privat
|
||||
|
||||
var display_message = {
|
||||
recipients: recipients_string,
|
||||
reply_to: replies_to,
|
||||
user_ids_string: user_ids_string,
|
||||
unread: num_unread,
|
||||
is_zero: num_unread === 0,
|
||||
zoom_out_hide: !always_visible,
|
||||
url: narrow.pm_with_uri(private_message_obj.reply_to)
|
||||
url: narrow.pm_with_uri(reply_to)
|
||||
};
|
||||
display_messages.push(display_message);
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<ul class='expanded_private_messages' data-name='private'>
|
||||
{{#each messages}}
|
||||
<li class='{{#if is_zero}}zero-subject-unreads{{/if}} {{#if zoom_out_hide}}zoom-out-hide{{/if}} expanded_private_message' data-name='{{reply_to}}'>
|
||||
<li class='{{#if is_zero}}zero-subject-unreads{{/if}} {{#if zoom_out_hide}}zoom-out-hide{{/if}} expanded_private_message' data-user-ids-string='{{user_ids_string}}'>
|
||||
<span class='pm-box'>
|
||||
<a href='{{url}}' class="conversation-partners">
|
||||
{{recipients}}
|
||||
|
||||
Reference in New Issue
Block a user