Welcome to mirror list, hosted at ThFree Co, Russian Federation.

fetch_profile_photo.rb « workers « app - github.com/diaspora/diaspora.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8eb370ecb631c4f12b3c74138b96442bb3f49047 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#   Copyright (c) 2010-2011, Diaspora Inc.  This file is
#   licensed under the Affero General Public License version 3 or later.  See
#   the COPYRIGHT file.


module Workers
  class FetchProfilePhoto < Base
    sidekiq_options queue: :medium

    def perform(user_id, service_id, fallback_image_url = nil)
      service = Service.find(service_id)

      image_url = service.profile_photo_url
      image_url ||= fallback_image_url

      return unless image_url

      user = User.find(user_id)

      @photo = Photo.diaspora_initialize(:author => user.person, :image_url => image_url, :pending => true)
      @photo.save!
      
      profile_params = {:image_url => @photo.url(:thumb_large),
                       :image_url_medium => @photo.url(:thumb_medium),
                       :image_url_small => @photo.url(:thumb_small)}
      user.update_profile(profile_params)
    end
  end
end