Modified: branches/event_logging/app/helpers/application_helper.rb (2031 => 2032)
--- branches/event_logging/app/helpers/application_helper.rb 2008-12-04 16:28:27 UTC (rev 2031)
+++ branches/event_logging/app/helpers/application_helper.rb 2008-12-04 18:09:51 UTC (rev 2032)
@@ -1784,32 +1784,27 @@
# END DEBUG
- # events are within the corerct timeframe, potentially can be grouped
- if ((["Tagging"].include? new_event.activity_loggable_type) && new_event.action == "create" &&
- new_event.action == base_event.action && new_event.activity_loggable_type == base_event.activity_loggable_type &&
- new_event.culprit_type == base_event.culprit_type && new_event.culprit_id == base_event.culprit_id &&
- new_event.referenced_type == base_event.referenced_type && new_event.referenced_id == base_event.referenced_id)
+ # events are within the correct timeframe, potentially can be grouped
+ if group_event_with_base?(true, new_event, base_event)
- # DEBUG
- puts "grouping should happen"
- # END DEBUG
+ # DEBUG
+ puts "grouping should happen"
+ # END DEBUG
+
+ seq_timestamp = [new_event.created_at, new_event.updated_at]
+ related_activity_loggable_ids << new_event.activity_loggable_id
+ array_ids_to_delete << i
+
+ grouping_happened = true
+ reset_required = false
+
+ elsif group_event_with_base?(false, new_event, base_event)
seq_timestamp = [new_event.created_at, new_event.updated_at]
- related_activity_loggable_ids << new_event.activity_loggable_id
array_ids_to_delete << i
grouping_happened = true
reset_required = false
- elsif ((["Profile"].include? new_event.activity_loggable_type) && new_event.action == "update" &&
- new_event.action == base_event.action && new_event.activity_loggable_type == base_event.activity_loggable_type &&
- new_event.culprit_type == base_event.culprit_type && new_event.culprit_id == base_event.culprit_id &&
- new_event.referenced_type == base_event.referenced_type && new_event.referenced_id == base_event.referenced_id)
-
- seq_timestamp = [new_event.created_at, new_event.updated_at]
- array_ids_to_delete << i
-
- grouping_happened = true
- reset_required = false
end
end
@@ -2544,6 +2539,50 @@
return [instance, path]
end
+
+ # this method assumes that the two events are within a certain timeframe and decides if
+ # these can be grouped or not;
+ # "should_have_accummulated_ids" parameter chooses between two types of grouping behaviour:
+ # -- one option is to pick the latest of all events (because they don't add any new information) (false)
+ # -- another option is to accummulate the items the news entries are pointing to and present them as one (true)
+ def group_event_with_base?(should_have_accummulated_ids, new_event, base_event)
+ ans = false
+
+ if should_have_accummulated_ids
+ # action "create" && "Tagging" && ActivityLoggableType match (IDs can vary) && CulpritType/CulpritID match && ReferencedType/ReferencedID match
+ if ((["Tagging"].include? new_event.activity_loggable_type) && new_event.action == "create" &&
+ new_event.action == base_event.action && new_event.activity_loggable_type == base_event.activity_loggable_type &&
+ new_event.culprit_type == base_event.culprit_type && new_event.culprit_id == base_event.culprit_id &&
+ new_event.referenced_type == base_event.referenced_type && new_event.referenced_id == base_event.referenced_id)
+ ans = true
+
+ # action "create" && "Bookmark" && ActivityLoggableType match (IDs can vary) && CulpritType/CulpritID match --> Referenced :: Any type / ID
+ elsif ((["Bookmark"].include? new_event.activity_loggable_type) && new_event.action == "create" &&
+ new_event.action == base_event.action && new_event.activity_loggable_type == base_event.activity_loggable_type &&
+ new_event.culprit_type == base_event.culprit_type && new_event.culprit_id == base_event.culprit_id)
+ ans = true
+
+ # action "create" && "Creditation|Attribution" && ActivityLoggableType match (IDs can vary) && CulpritType/CulpritID match --> Referenced :: Any type / ID
+ # but need to add more strict check on the timestamp - will attempt to group only creditations / attributions at exact same date / time
+ elsif ((["Creditation", "Attribution"].include? new_event.activity_loggable_type) && new_event.action == "create" &&
+ new_event.action == base_event.action && new_event.activity_loggable_type == base_event.activity_loggable_type &&
+ new_event.culprit_type == base_event.culprit_type && new_event.culprit_id == base_event.culprit_id &&
+ new_event.created_at == base_event.created_at && new_event.updated_at == base_event.updated_at)
+ ans = true
+ end
+ else
+ # action "update" && "Profile" && ActivityLoggableType match && CulpritType/CulpritID match && ReferencedType/ReferencedID match
+ if ((["Profile"].include? new_event.activity_loggable_type) && new_event.action == "update" &&
+ new_event.action == base_event.action && new_event.activity_loggable_type == base_event.activity_loggable_type &&
+ new_event.culprit_type == base_event.culprit_type && new_event.culprit_id == base_event.culprit_id &&
+ new_event.referenced_type == base_event.referenced_type && new_event.referenced_id == base_event.referenced_id)
+ ans = true
+ end
+ end
+
+ return ans
+ end
+
######################################################
def permissions_categorised(permissions)