Last active
September 10, 2015 17:08
-
-
Save lorenjohnson/c357c5b73bb93d55524d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Notifications::NotifyMentioned | |
include Service | |
include Virtus.model | |
attribute :instance | |
attribute :get_stream_client | |
attribute :get_stream_activity_builder | |
def call | |
# LEJ: Disabling mention notifications until | |
# better solution is found to mention actions | |
# showing in activity of main feed (not just notifications) | |
@get_stream_client ||= StreamRails.client | |
@get_stream_activity_builder ||= Feed::BuildGetStreamActivityHash | |
activity = get_stream_activity_builder.call(instance: instance) | |
activity[:verb] = 'mention' | |
if instance.respond_to?(:mentioned_users) | |
instance.mentioned_users.each do |user| | |
feed = get_stream_client.feed('notification', user.id) | |
feed.add_activity(activity) | |
end | |
end | |
end | |
end | |
class Feed::BuildGetStreamActivityHash | |
include Service | |
include Virtus.model | |
attribute :instance | |
def call | |
activity = { | |
:actor => instance.activity_actor_id, | |
:verb => instance.activity_verb, | |
:object => instance.activity_object_id, | |
:foreign_id => instance.activity_foreign_id, | |
:time => instance.activity_time | |
} | |
activity.merge!(instance.activity_extra_data) | |
return activity | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment