Skip to content

Commit

Permalink
Track date for all the notifiable events
Browse files Browse the repository at this point in the history
A few event types used to track, in its payload, the date and time when
the event was triggered. The 'when' key was used for this. From now on,
all the notifiable event types track this value.

Now, when a notification is created, its timestaps fields (create_at and
updated_at) are set to the 'when' value. This way, we ensure they have
realistic date and time according to the moment when the event happened
and not when the notification was created (what usually happens some
time later).
  • Loading branch information
saraycp committed Apr 8, 2020
1 parent 4e434ed commit 3cd61dd
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/api/app/models/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ def event_parameters
commentable.event_parameters.merge!({ id: id,
commenter: user.login,
comment_body: body,
commenters: involved_users })
commenters: involved_users,
when: updated_at.strftime('%Y-%m-%dT%H:%M:%S') })
end

private
Expand Down
2 changes: 2 additions & 0 deletions src/api/app/models/event/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ def parameters_for_notification
{ event_type: eventtype,
event_payload: payload,
notifiable_id: payload['id'],
created_at: payload['when'].to_datetime,
updated_at: payload['when'].to_datetime,
title: subject_to_title }
end

Expand Down
2 changes: 1 addition & 1 deletion src/api/app/models/event/comment_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Event
module CommentEvent
def self.included(base)
base.class_eval do
payload_keys :id, :commenters, :commenter, :comment_body, :comment_title
payload_keys :id, :commenters, :commenter, :comment_body, :comment_title, :when
receiver_roles :commenter
shortenable_key :comment_body
end
Expand Down
18 changes: 9 additions & 9 deletions src/api/app/models/review.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,6 @@ def map_objects_to_ids(objs)
objs.map { |obj| { "#{obj.class.to_s.downcase}_id" => obj.id } }.uniq
end

def event_parameters(params = {})
params = params.merge(_get_attributes)
params[:id] = id
params[:comment] = reason
params[:reviewers] = map_objects_to_ids(users_and_groups_for_review)
params
end

def reviewable_by?(opts)
return by_user == opts[:by_user] if by_user
return by_group == opts[:by_group] if by_group
Expand Down Expand Up @@ -249,10 +241,18 @@ def matches_user?(user)
matches_maintainers?(user)
end

def event_parameters(params = {})
params = params.merge(_get_attributes)
params[:id] = id
params[:comment] = reason
params[:reviewers] = map_objects_to_ids(users_and_groups_for_review)
params[:when] = updated_at.strftime('%Y-%m-%dT%H:%M:%S')
params
end

def create_event(params = {})
params = event_parameters(params)

# send email later
Event::ReviewWanted.create(params)
end

Expand Down

0 comments on commit 3cd61dd

Please sign in to comment.