Permalink
Browse files

Refactor: change map to reduce. Remove no-op block for unknown origin.

  • Loading branch information...
Pistos committed Mar 29, 2013
1 parent 673cb18 commit 044fa449517edceaf9753f7f0d6941b4eacb28be
Showing with 6 additions and 9 deletions.
  1. +6 −9 lib/libertree/server/responder/message.rb
@@ -18,22 +18,19 @@ def rsp_message(params)
return
end
member_ids = params['recipients'].map { |recipient|
member_ids = params['recipients'].reduce([]) { |ids, recipient|
origin = Model::Server[ 'public_key' => recipient['public_key'] ]
if origin
member = Model::Member['username' => recipient['username'], 'server_id' => origin.id]
member.id if member
elsif origin.nil? && recipient['public_key'] != @public_key
# TODO: respond somehow
nil
elsif origin.nil?
# origin is supposedly this local server
ids << member.id if member
elsif origin.nil? && recipient['public_key'] == @public_key
# origin is this local server
account = Model::Account['username' => recipient['username']]
if account
account.member.id
ids << account.member.id
end
end
}.compact
}
message = Libertree::Model::Message.create_with_recipients(
sender_member_id: sender_member.id,

0 comments on commit 044fa44

Please sign in to comment.