Skip to content
Extraits de code Groupes Projets
Valider 9a3f653c rédigé par Benjamin Neff's avatar Benjamin Neff
Parcourir les fichiers

fix sender for messages for old pods

Send a second message to remote recipients with conversation-author
as salmon author if the conversation-author is local.

The first dispatch will fail on old pods. New pods will ignore the
second message, if the guid already exist.
parent 9a033c7f
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -15,9 +15,17 @@ class MessagesController < ApplicationController
message = current_user.build_message(conversation, opts)
if message.save
logger.info "event=create type=comment user=#{current_user.diaspora_handle} status=success " \
logger.info "event=create type=message user=#{current_user.diaspora_handle} status=success " \
"message=#{message.id} chars=#{params[:message][:text].length}"
Diaspora::Federation::Dispatcher.defer_dispatch(current_user, message)
# TODO: can be removed when messages are not relayed anymore
conversation_owner = conversation.author.owner
if conversation_owner && conversation_owner != current_user
remote_subs = conversation.participants.remote.ids
opts = {subscriber_ids: remote_subs}
Diaspora::Federation::Dispatcher.defer_dispatch(conversation_owner, message, opts) unless remote_subs.empty?
end
else
flash[:error] = I18n.t('conversations.new_conversation.fail')
end
......
......@@ -39,6 +39,11 @@ describe MessagesController, :type => :controller do
expect(response.status).to eq(302)
expect(response).to redirect_to(conversations_path(:conversation_id => @conversation))
end
it "dispatches the message" do
expect(Diaspora::Federation::Dispatcher).to receive(:defer_dispatch).with(alice, instance_of(Message))
post :create, @message_params
end
end
context "with an empty message" do
......@@ -94,6 +99,24 @@ describe MessagesController, :type => :controller do
post :create, @message_params
expect(old_message.reload.text).to eq('hello')
end
it "dispatches the message" do
expect(Diaspora::Federation::Dispatcher).to receive(:defer_dispatch).with(alice, instance_of(Message))
post :create, @message_params
end
it "dispatches the message twice if the conversation author is local and it has remote users" do
@conversation_params[:participant_ids] = [bob.person.id, alice.person.id, remote_raphael.id]
conversation = Conversation.create!(@conversation_params)
@message_params[:conversation_id] = conversation.id
expect(Diaspora::Federation::Dispatcher).to receive(:defer_dispatch).with(alice, instance_of(Message))
expect(Diaspora::Federation::Dispatcher).to receive(:defer_dispatch).with(
bob, instance_of(Message), subscriber_ids: [remote_raphael.id]
)
post :create, @message_params
end
end
context 'on a post from a stranger' do
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter