myexperiment-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myexperiment-hackers] [1899] branches/event_logging/app/helpers/applica


From: noreply
Subject: [myexperiment-hackers] [1899] branches/event_logging/app/helpers/application_helper.rb: Work on news generation.
Date: Thu, 30 Oct 2008 06:34:03 -0400 (EDT)

Revision
1899
Author
alekses6
Date
2008-10-30 06:34:02 -0400 (Thu, 30 Oct 2008)

Log Message

Work on news generation. 

Fix: profile updates now shown to friends, not only to users themself.

Bug-fix: user's networks' events now shown in the news feed on home page (i.e. where not only current user's events are); on user's profile page along with all regular events, news entries regarding their actions as network admin are added.

Modified Paths

Diff

Modified: branches/event_logging/app/helpers/application_helper.rb (1898 => 1899)


--- branches/event_logging/app/helpers/application_helper.rb	2008-10-29 16:58:52 UTC (rev 1898)
+++ branches/event_logging/app/helpers/application_helper.rb	2008-10-30 10:34:02 UTC (rev 1899)
@@ -1419,6 +1419,7 @@
     # - members of networks, where current user is admin of;
     
     events = []
+    events_as_admin = []
     related_contributors = []
     
     case contributor.class.to_s.downcase
@@ -1427,8 +1428,10 @@
           # ..add friends
           related_contributors.concat(contributor.friends)
           
-          # ..add members of networks, where contributor is admin AND where contributor is member of
+          # ..add networks AND members of networks, where contributor is admin AND where contributor is member of
+          # (adding networks will provide with events like "network X credited for workflow Y", etc)
           contributor.networks.concat(contributor.networks_owned).each do |network|
+            related_contributors.concat(network)
             related_contributors.concat(network.members)
           end
           
@@ -1437,6 +1440,24 @@
           
           # remove the contributor from the list of related contributors to avoid double processing
           related_contributors.delete(contributor)
+        else
+          # fetch events initiated by networks (i.e. where network is a culprit) belonging to contributor;
+          # NB! this works on assumption that networks have only one admin -> therefore, events initiated by
+          # the network are the ones done by contributor as he's the admin!!
+          #
+          # -----------------------------------------------------------------------
+          # this is executed when "contributor events only" are requested, because
+          # these are things done by the current contributor which is a User -
+          # and should be displayed along with all the other user's events;
+          #
+          # when news for "related contributors" are requested as well this piece is
+          # not needed, because all events for user's networks will be added - both
+          # where they are member and admin of
+          # -----------------------------------------------------------------------
+          contributor.networks_owned.each do |network|
+            network_events = ActivityLog.find(:all, :conditions => ["created_at > ? AND created_at < ? AND (culprit_type = ? AND culprit_id = ?)", after, before, network.class.to_s, network.id]) 
+            events_as_admin.concat(network_events)
+          end
         end
       when "network"
         # UNCOMMENT THE NEXT LINE TO GET NEWS OF GROUP'S MEMBERS IN THE GROUP'S NEWS FEED
@@ -1452,19 +1473,8 @@
     # (no need to impose order on the DB query, as more queries will be run [for "related_contributors"]
     #  and subsequent sorting will be required anyway)
     events = ActivityLog.find(:all, :conditions => ["created_at > ? AND created_at < ? AND ((activity_loggable_type = ? AND activity_loggable_id = ?) OR (culprit_type = ? AND culprit_id = ?) OR (referenced_type = ? AND referenced_id = ?))", after, before, contributor.class.to_s, contributor.id, contributor.class.to_s, contributor.id, contributor.class.to_s, contributor.id])
+    events.concat(events_as_admin) unless events_as_admin.empty?
     
-    
-    # fetch events initiated by networks (i.e. where network is a culprit) belonging to contributor;
-    # NB! this works on assumption that networks have only one admin -> therefore, events initiated by
-    # the network are the ones done by contributor as he's the admin!!
-    if contributor.class.to_s.downcase == "user"
-      contributor.networks_owned.each do |network|
-        events_as_admin = ActivityLog.find(:all, :conditions => ["created_at > ? AND created_at < ? AND (culprit_type = ? AND culprit_id = ?)", after, before, network.class.to_s, network.id]) 
-        events.concat(events_as_admin)
-      end
-    end
-    
-    
     # if any "related_contributors", get events for each
     # (can't use the "limit" parameter just yet, because events for "related_contributors" may be newer
     #  than some of the contributor in the original query)
@@ -1979,9 +1989,8 @@
           # in the news we're only interested in "update" action for profiles,
           # as these are created / deleted along with the user account
           when "update"
-            # TODO: who can view profile updates?
-            # for now only show this to the user themself
-            if my_event
+            # only friends of the user will see this event
+            if my_event || current_viewer.friend?(log_entry.culprit_id)
               rtn << [timestamp, "#{culprit_link} has updated their #{link_to "profile", user_path(log_entry.culprit_id)}"]
             end
         end
@@ -1992,11 +2001,14 @@
             # anyone can see new users joining myExperiment
             rtn << [timestamp, "#{name(log_entry.activity_loggable.id)} joined #{link_to "myExperiment", "/"}."]
           when "update"
-            # TODO: who can view account updates?
-            # for now only show this to the user themself
-            if log_entry.activity_loggable_id == current_viewer.id
-              rtn << [timestamp, "#{name(log_entry.activity_loggable_id)} updated their #{link_to "account", user_path(log_entry.activity_loggable_id)} settings."]
-            end
+            # for now this event is not shown to anyone - event to the user themself,
+            # partly because every time when user logs in "last seen" field is set, which
+            # which triggers this event
+            # DISABLED FRAGMENT
+            #if log_entry.activity_loggable_id == current_viewer.id
+            #  rtn << [timestamp, "#{name(log_entry.activity_loggable_id)} updated their #{link_to "account", user_path(log_entry.activity_loggable_id)} settings."]
+            #end
+            # END OF DISABLED FRAGMENT
         end
       
       when "Announcement"

reply via email to

[Prev in Thread] Current Thread [Next in Thread]