use conversation_id, not conversation_participant_id
also fixed a bug around adding new messages Change-Id: I55d318e2b814213cf1d14e858169b397e05e5450 Reviewed-on: https://gerrit.instructure.com/4882 Tested-by: Hudson <hudson@instructure.com> Reviewed-by: Jacob Fugal <jacob@instructure.com>
This commit is contained in:
parent
62c25dac5b
commit
d169efb400
|
@ -524,8 +524,11 @@ I18n.scoped 'conversations', (I18n) ->
|
|||
hash[decodeURIComponent(key)] = decodeURIComponent(value)
|
||||
hash
|
||||
|
||||
is_selected = ($conversation) ->
|
||||
$selected_conversation && $selected_conversation.attr('id') == $conversation?.attr('id')
|
||||
|
||||
select_conversation = ($conversation) ->
|
||||
if $selected_conversation && $selected_conversation.attr('id') == $conversation?.attr('id')
|
||||
if is_selected($conversation)
|
||||
$selected_conversation.removeClass 'inactive'
|
||||
$message_list.find('li.selected').removeClass 'selected'
|
||||
return
|
||||
|
@ -553,7 +556,7 @@ I18n.scoped 'conversations', (I18n) ->
|
|||
!$('#menu_actions').parent().find('ul[style*="block"]').length
|
||||
|
||||
if $selected_conversation
|
||||
location.hash = $selected_conversation.attr('id').replace('conversation_', '/messages/')
|
||||
location.hash = '/messages/' + $selected_conversation.data('id')
|
||||
else
|
||||
if match = location.hash.match(/^#\/messages\?(.*)$/)
|
||||
params = parse_query_string(match[1])
|
||||
|
@ -605,14 +608,14 @@ I18n.scoped 'conversations', (I18n) ->
|
|||
$pm_action = $message.find('a.send_private_message')
|
||||
pm_url = $.replaceTags($pm_action.attr('href'), 'user_id', data.author_id)
|
||||
pm_url = $.replaceTags(pm_url, 'user_name', encodeURIComponent(user_name))
|
||||
pm_url = $.replaceTags(pm_url, 'from_conversation_id', $selected_conversation.attr('id').replace('conversation_', ''))
|
||||
pm_url = $.replaceTags(pm_url, 'from_conversation_id', $selected_conversation.data('id'))
|
||||
$pm_action.attr('href', pm_url).click =>
|
||||
setTimeout =>
|
||||
select_conversation()
|
||||
$message
|
||||
|
||||
inbox_action_url_for = ($action) ->
|
||||
$.replaceTags $action.attr('href'), 'id', $selected_conversation.attr('id').replace('conversation_', '')
|
||||
$.replaceTags $action.attr('href'), 'id', $selected_conversation.data('id')
|
||||
|
||||
inbox_action = ($action, options) ->
|
||||
defaults =
|
||||
|
@ -636,6 +639,7 @@ I18n.scoped 'conversations', (I18n) ->
|
|||
|
||||
add_conversation = (data, append) ->
|
||||
$conversation = $("#conversation_blank").clone(true).attr('id', 'conversation_' + data.id)
|
||||
$conversation.data('id', data.id)
|
||||
if data.avatar_url
|
||||
$conversation.prepend $('<img />').attr('src', data.avatar_url).addClass('avatar')
|
||||
$conversation[if append then 'appendTo' else 'prependTo']($conversation_list).click (e) ->
|
||||
|
@ -643,6 +647,7 @@ I18n.scoped 'conversations', (I18n) ->
|
|||
select_conversation $(this)
|
||||
update_conversation($conversation, data, true)
|
||||
$conversation.hide().slideDown('fast') unless append
|
||||
$conversation
|
||||
|
||||
update_conversation = ($conversation, data, no_move) ->
|
||||
$a = $conversation.find('a')
|
||||
|
@ -715,12 +720,12 @@ I18n.scoped 'conversations', (I18n) ->
|
|||
$(this).loadingImage()
|
||||
success: (data) ->
|
||||
$(this).loadingImage 'remove'
|
||||
build_message(data.message.conversation_message).prependTo($message_list).slideDown 'fast'
|
||||
$conversation = $('#conversation_' + data.conversation.id)
|
||||
if $conversation.length
|
||||
update_conversation($conversation, data.conversation)
|
||||
build_message(data.message.conversation_message).prependTo($message_list).slideDown 'fast' if is_selected($conversation)
|
||||
else
|
||||
add_conversation(data.conversation)
|
||||
select_conversation add_conversation(data.conversation)
|
||||
reset_message_form()
|
||||
error: (data) ->
|
||||
$form.find('.token_input').errorBox(I18n.t('recipient_error', 'The course or group you have selected has no valid recipients'))
|
||||
|
|
|
@ -216,7 +216,7 @@ class ConversationsController < ApplicationController
|
|||
end
|
||||
|
||||
def get_conversation
|
||||
@conversation = @current_user.conversations.find(params[:id] || params[:conversation_id] || 0)
|
||||
@conversation = @current_user.conversations.find_by_conversation_id(params[:id] || params[:conversation_id] || 0)
|
||||
end
|
||||
|
||||
def jsonify_conversation(conversation)
|
||||
|
|
|
@ -36,8 +36,8 @@ class ConversationParticipant < ActiveRecord::Base
|
|||
|
||||
def as_json(options = {})
|
||||
latest = messages.human.first
|
||||
super.merge(
|
||||
:id => id,
|
||||
{
|
||||
:id => conversation_id,
|
||||
:participants => participants(private?),
|
||||
:workflow_state => workflow_state,
|
||||
:last_message => latest ? truncate_text(latest.body, :max_length => 100) : nil,
|
||||
|
@ -45,7 +45,7 @@ class ConversationParticipant < ActiveRecord::Base
|
|||
:subscribed => subscribed?,
|
||||
:private => private?,
|
||||
:flags => flags
|
||||
)
|
||||
}
|
||||
end
|
||||
|
||||
[:attachments, :media_objects].each do |association|
|
||||
|
|
|
@ -664,7 +664,7 @@
|
|||
}
|
||||
};
|
||||
I18n.scoped('conversations', function(I18n) {
|
||||
var add_conversation, build_message, close_menus, html_name_for_user, inbox_action, inbox_action_url_for, open_menu, parse_query_string, remove_conversation, reposition_conversation, reset_message_form, select_conversation, set_conversation_state, show_message_form, update_conversation;
|
||||
var add_conversation, build_message, close_menus, html_name_for_user, inbox_action, inbox_action_url_for, is_selected, open_menu, parse_query_string, remove_conversation, reposition_conversation, reset_message_form, select_conversation, set_conversation_state, show_message_form, update_conversation;
|
||||
show_message_form = function() {
|
||||
var newMessage;
|
||||
newMessage = !($selected_conversation != null);
|
||||
|
@ -709,9 +709,12 @@
|
|||
}
|
||||
return hash;
|
||||
};
|
||||
is_selected = function($conversation) {
|
||||
return $selected_conversation && $selected_conversation.attr('id') === ($conversation != null ? $conversation.attr('id') : void 0);
|
||||
};
|
||||
select_conversation = function($conversation) {
|
||||
var $c, match, params;
|
||||
if ($selected_conversation && $selected_conversation.attr('id') === ($conversation != null ? $conversation.attr('id') : void 0)) {
|
||||
if (is_selected($conversation)) {
|
||||
$selected_conversation.removeClass('inactive');
|
||||
$message_list.find('li.selected').removeClass('selected');
|
||||
return;
|
||||
|
@ -741,7 +744,7 @@
|
|||
$('#menu_actions').triggerHandler('prepare_menu');
|
||||
$('#menu_actions').toggleClass('disabled', !$('#menu_actions').parent().find('ul[style*="block"]').length);
|
||||
if ($selected_conversation) {
|
||||
location.hash = $selected_conversation.attr('id').replace('conversation_', '/messages/');
|
||||
location.hash = '/messages/' + $selected_conversation.data('id');
|
||||
} else {
|
||||
if (match = location.hash.match(/^#\/messages\?(.*)$/)) {
|
||||
params = parse_query_string(match[1]);
|
||||
|
@ -845,7 +848,7 @@
|
|||
$pm_action = $message.find('a.send_private_message');
|
||||
pm_url = $.replaceTags($pm_action.attr('href'), 'user_id', data.author_id);
|
||||
pm_url = $.replaceTags(pm_url, 'user_name', encodeURIComponent(user_name));
|
||||
pm_url = $.replaceTags(pm_url, 'from_conversation_id', $selected_conversation.attr('id').replace('conversation_', ''));
|
||||
pm_url = $.replaceTags(pm_url, 'from_conversation_id', $selected_conversation.data('id'));
|
||||
$pm_action.attr('href', pm_url).click(__bind(function() {
|
||||
return setTimeout(__bind(function() {
|
||||
return select_conversation();
|
||||
|
@ -854,7 +857,7 @@
|
|||
return $message;
|
||||
};
|
||||
inbox_action_url_for = function($action) {
|
||||
return $.replaceTags($action.attr('href'), 'id', $selected_conversation.attr('id').replace('conversation_', ''));
|
||||
return $.replaceTags($action.attr('href'), 'id', $selected_conversation.data('id'));
|
||||
};
|
||||
inbox_action = function($action, options) {
|
||||
var defaults, _ref;
|
||||
|
@ -888,6 +891,7 @@
|
|||
add_conversation = function(data, append) {
|
||||
var $conversation;
|
||||
$conversation = $("#conversation_blank").clone(true).attr('id', 'conversation_' + data.id);
|
||||
$conversation.data('id', data.id);
|
||||
if (data.avatar_url) {
|
||||
$conversation.prepend($('<img />').attr('src', data.avatar_url).addClass('avatar'));
|
||||
}
|
||||
|
@ -897,8 +901,9 @@
|
|||
});
|
||||
update_conversation($conversation, data, true);
|
||||
if (!append) {
|
||||
return $conversation.hide().slideDown('fast');
|
||||
$conversation.hide().slideDown('fast');
|
||||
}
|
||||
return $conversation;
|
||||
};
|
||||
update_conversation = function($conversation, data, no_move) {
|
||||
var $a, $p, flag, move_direction;
|
||||
|
@ -1017,12 +1022,14 @@
|
|||
success: function(data) {
|
||||
var $conversation;
|
||||
$(this).loadingImage('remove');
|
||||
build_message(data.message.conversation_message).prependTo($message_list).slideDown('fast');
|
||||
$conversation = $('#conversation_' + data.conversation.id);
|
||||
if ($conversation.length) {
|
||||
update_conversation($conversation, data.conversation);
|
||||
if (is_selected($conversation)) {
|
||||
build_message(data.message.conversation_message).prependTo($message_list).slideDown('fast');
|
||||
}
|
||||
} else {
|
||||
add_conversation(data.conversation);
|
||||
select_conversation(add_conversation(data.conversation));
|
||||
}
|
||||
return reset_message_form();
|
||||
},
|
||||
|
|
|
@ -45,7 +45,7 @@ describe ConversationsController do
|
|||
|
||||
get 'index'
|
||||
response.should be_success
|
||||
assigns[:conversations].map{|c|c[:id]}.should == @user.conversations.map(&:id)
|
||||
assigns[:conversations].map{|c|c[:id]}.should == @user.conversations.map(&:conversation_id)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -54,7 +54,7 @@ describe ConversationsController do
|
|||
course_with_student_logged_in(:active_all => true)
|
||||
conversation
|
||||
|
||||
get 'show', :id => @conversation.id
|
||||
get 'show', :id => @conversation.conversation_id
|
||||
response.should be_success
|
||||
assigns[:conversation].should == @conversation
|
||||
end
|
||||
|
@ -79,7 +79,7 @@ describe ConversationsController do
|
|||
course_with_student_logged_in(:active_all => true)
|
||||
conversation.mark_as_unread
|
||||
|
||||
post 'update', :id => @conversation.id, :conversation => {:subscribed => "0"}
|
||||
post 'update', :id => @conversation.conversation_id, :conversation => {:subscribed => "0"}
|
||||
response.should be_success
|
||||
@conversation.reload.subscribed?.should be_false
|
||||
end
|
||||
|
@ -90,7 +90,7 @@ describe ConversationsController do
|
|||
course_with_student_logged_in(:active_all => true)
|
||||
conversation
|
||||
|
||||
post 'workflow_event', :conversation_id => @conversation.id, :event => "mark_as_unread"
|
||||
post 'workflow_event', :conversation_id => @conversation.conversation_id, :event => "mark_as_unread"
|
||||
response.should be_success
|
||||
@conversation.unread?.should be_true
|
||||
end
|
||||
|
@ -101,7 +101,7 @@ describe ConversationsController do
|
|||
course_with_student_logged_in(:active_all => true)
|
||||
conversation
|
||||
|
||||
post 'add_message', :conversation_id => @conversation.id, :body => "hello world"
|
||||
post 'add_message', :conversation_id => @conversation.conversation_id, :body => "hello world"
|
||||
response.should be_success
|
||||
@conversation.messages.size.should == 2
|
||||
end
|
||||
|
@ -116,7 +116,7 @@ describe ConversationsController do
|
|||
enrollment = @course.enroll_student(new_user)
|
||||
enrollment.workflow_state = 'active'
|
||||
enrollment.save
|
||||
post 'add_recipients', :conversation_id => @conversation.id, :recipients => [new_user.id.to_s]
|
||||
post 'add_recipients', :conversation_id => @conversation.conversation_id, :recipients => [new_user.id.to_s]
|
||||
response.should be_success
|
||||
@conversation.participants.size.should == 3 # doesn't include @user
|
||||
end
|
||||
|
@ -127,7 +127,7 @@ describe ConversationsController do
|
|||
course_with_student_logged_in(:active_all => true)
|
||||
message = conversation.add_message('another')
|
||||
|
||||
post 'remove_messages', :conversation_id => @conversation.id, :remove => [message.id.to_s]
|
||||
post 'remove_messages', :conversation_id => @conversation.conversation_id, :remove => [message.id.to_s]
|
||||
response.should be_success
|
||||
@conversation.messages.size.should == 1
|
||||
end
|
||||
|
@ -138,7 +138,7 @@ describe ConversationsController do
|
|||
course_with_student_logged_in(:active_all => true)
|
||||
conversation
|
||||
|
||||
delete 'destroy', :id => @conversation.id
|
||||
delete 'destroy', :id => @conversation.conversation_id
|
||||
response.should be_success
|
||||
@user.conversations.should be_blank # the conversation_participant is no longer there
|
||||
@conversation.conversation.should_not be_nil # though the conversation is
|
||||
|
|
Loading…
Reference in New Issue