Commit 37835fb9cc4700a293c1f52f9d3f12566b8efdda

Authored by Francisco Marcelo de Araújo Lima Júnior
1 parent e3f170d0

#community_dashboard - fixes

plugins/community_hub/controllers/public/community_hub_plugin_public_controller.rb
... ... @@ -50,14 +50,12 @@ class CommunityHubPluginPublicController < PublicController
50 50 mediation_data = {}
51 51 mediation_data.merge!(params[:article]) if params[:article]
52 52  
53   - mediation = TinyMceArticle.new(mediation_data)
  53 + mediation = CommunityHubPlugin::Mediation.new(mediation_data)
  54 + mediation.name = CommunityHubPlugin::Mediation.timestamp
54 55 mediation.profile = profile
55 56 mediation.last_changed_by = user
56   - mediation.name = mediation_timestamp
57   - mediation.notify_comments = false
58   - mediation.type = 'TinyMceArticle'
59   - mediation.advertise = false
60 57 mediation.created_by_id = user.id
  58 + mediation.source = 'local'
61 59  
62 60 if mediation && mediation.save
63 61 render :text => {'ok' => true}.to_json, :content_type => 'application/json'
... ... @@ -113,7 +111,7 @@ class CommunityHubPluginPublicController < PublicController
113 111 def newer_articles
114 112 latest_post = params[:latest_post]
115 113 hub = Article.find(params[:hub])
116   - posts = Article.find(:all, :order => "id desc", :conditions => ["id > :id and type = :type and parent_id = :hub", { :id => latest_post, :type => 'TinyMceArticle', :hub => hub.id }])
  114 + posts = CommunityHubPlugin::Mediation.find(:all, :order => "id desc", :conditions => ["id > :id and parent_id = :hub", { :id => latest_post, :hub => hub.id }])
117 115  
118 116 if !posts.empty?
119 117 oldest_post = posts.last.id
... ... @@ -158,11 +156,13 @@ class CommunityHubPluginPublicController < PublicController
158 156 def pin_message
159 157 if logged_in?
160 158 if (!params[:hub].blank? && !params[:message].blank?)
  159 +
161 160 begin
162 161 hub = Article.find(params[:hub])
163 162 rescue
164 163 hub = nil
165 164 end
  165 +
166 166 if hub && hub.mediator?(user)
167 167 begin
168 168 message = Comment.find(params[:message])
... ... @@ -171,42 +171,37 @@ class CommunityHubPluginPublicController < PublicController
171 171 end
172 172  
173 173 if message
174   - mediation = TinyMceArticle.new
175   - mediation.profile = hub.profile
176   - mediation.parent = hub
177   -
178 174 author = message.author.blank? ? user : message.author
179 175  
  176 + mediation = CommunityHubPlugin::Mediation.new
  177 + mediation.name = CommunityHubPlugin::Mediation.timestamp
  178 +
  179 + mediation.profile = hub.profile
180 180 mediation.last_changed_by = author
181 181 mediation.created_by_id = author.id
182   -
183   - mediation.name = mediation_timestamp
184 182 mediation.body = message.body
185   - mediation.notify_comments = false
186   - mediation.type = 'TinyMceArticle'
187   - mediation.advertise = false
  183 + mediation.parent_id = hub.id
188 184 mediation.source = 'local'
189 185  
190   - if mediation.save
  186 + if mediation && mediation.save
191 187  
192 188 if ( message.title == 'hub-message-twitter' )
193 189 mediation.source = 'twitter'
194 190 mediation.author_name = message.name
195   - mediation.external_link = message.profile_picture
196   - elsif ( message.title == 'hub-message-facebook' )
197   - mediation.source = 'facebook'
198   - mediation.author_name = message.name
  191 + mediation.profile_picture = message.profile_picture
  192 + mediation.save
199 193 end
200 194  
201   - mediation.save
202   -
203 195 hub.pinned_messages += [message.id] unless hub.pinned_messages.include?(message.id)
204 196 hub.pinned_mediations += [mediation.id] unless hub.pinned_mediations.include?(mediation.id)
205   - if hub.save
  197 +
  198 + if hub && hub.save
206 199 render :text => {'ok' => true}.to_json, :content_type => 'application/json'
207 200 return true
208 201 end
  202 +
209 203 end
  204 +
210 205 end
211 206 end
212 207 end
... ... @@ -217,11 +212,6 @@ class CommunityHubPluginPublicController < PublicController
217 212  
218 213 protected
219 214  
220   - def mediation_timestamp
221   - "hub-mediation-#{(Time.now.to_f * 1000).to_i}"
222   - end
223   -
224   -
225 215 def message_timestamp
226 216 "hub-message-#{(Time.now.to_f * 1000).to_i}"
227 217 end
... ...
plugins/community_hub/lib/community_hub_plugin/mediation.rb 0 → 100644
... ... @@ -0,0 +1,15 @@
  1 +class CommunityHubPlugin::Mediation < Article
  2 +
  3 + before_save do |mediation|
  4 + mediation.advertise = false
  5 + mediation.notify_comments = false
  6 + nil
  7 + end
  8 +
  9 + settings_items :profile_picture, :type => :string, :default => ""
  10 +
  11 + def self.timestamp
  12 + "hub-mediation-#{(Time.now.to_f * 1000).to_i}"
  13 + end
  14 +
  15 +end
... ...
plugins/community_hub/views/community_hub_plugin_public/_mediation.rhtml
... ... @@ -7,7 +7,7 @@
7 7  
8 8 <li class="avatar">
9 9 <% if mediation.source == 'twitter' %>
10   - <%= image_tag(mediation.external_link, :alt => "Twitter") %>
  10 + <%= image_tag(mediation.profile_picture, :alt => "Twitter") %>
11 11 <% elsif mediation.source == 'facebook' %>
12 12 <%= image_tag('/plugins/community_hub/icons/logo_facebook_50x50.png', :alt => "Facebook") %>
13 13 <% else %>
... ...
plugins/community_hub/views/community_hub_plugin_public/_post.rhtml
... ... @@ -14,7 +14,7 @@
14 14 </li>
15 15 <li class="message"><span class="author"><%= post.author_name %>:</span> <%= post.body %></li>
16 16  
17   - <% if mediator?(hub) %>
  17 + <% if mediator?(hub) && post.title != 'hub-message-facebook' %>
18 18 <li class="mediation-bar">
19 19 <ul>
20 20 <li class="pin">
... ...