Browse Source

Cleanup of avatar use from third party systems.

Martin Edenhofer 9 years ago
parent
commit
060381e0db
2 changed files with 14 additions and 13 deletions
  1. 13 12
      app/models/authorization.rb
  2. 1 1
      app/models/avatar.rb

+ 13 - 12
app/models/authorization.rb

@@ -42,8 +42,9 @@ class Authorization < ApplicationModel
         )
 
         # update user link
-        if avatar
-          user.update_column( :image, avatar.store_hash )
+        if avatar && user.image != avatar.store_hash
+          user.image = avatar.store_hash
+          user.save
         end
       end
     end
@@ -51,9 +52,13 @@ class Authorization < ApplicationModel
   end
 
   def self.create_from_hash(hash, user = nil)
-    if user
 
-      # save/update avatar
+    if !user
+      user = User.create_from_hash!(hash)
+    end
+
+    # save/update avatar
+    if hash['info']['image']
       avatar = Avatar.add(
         object: 'User',
         o_id: user.id,
@@ -65,15 +70,10 @@ class Authorization < ApplicationModel
       )
 
       # update user link
-      if avatar
-        user.update_column( :image, avatar.store_hash )
+      if avatar && user.image != avatar.store_hash
+        user.image = avatar.store_hash
+        user.save
       end
-
-      # fillup empty attributes
-      # TODO
-
-    else
-      user = User.create_from_hash!(hash)
     end
 
     Authorization.create(
@@ -89,6 +89,7 @@ class Authorization < ApplicationModel
   private
 
   def delete_user_cache
+    return if !user
     user.touch
   end
 

+ 1 - 1
app/models/avatar.rb

@@ -102,7 +102,7 @@ add a avatar
       # twitter workaround to get bigger avatar images
       # see also https://dev.twitter.com/overview/general/user-profile-images-and-banners
       if data[:url] =~ %r{//pbs.twimg.com/}i
-        data[:url].sub!(/normal\.png$/, 'bigger.png')
+        data[:url].sub!(/normal\.(png|jpg|gif)$/, 'bigger.\1')
       end
 
       # fetch image