Browse Source

Automatically follow a user after tagging her

feature/tags
Bèr Kessels 10 months ago
parent
commit
65cf5e3c55

+ 2
- 0
app/aggregates/member.rb View File

@@ -32,6 +32,8 @@ module Aggregates

apply MemberInvited do |event|
end
apply FollowerAdded do |event|
end

apply MemberBioUpdated do |event|
write_attributes(event.body.slice('bio'))

+ 5
- 0
app/events/follower_added.rb View File

@@ -0,0 +1,5 @@
# frozen_string_literal: true

##
# A follower was added to a member
FollowerAdded = Class.new(EventSourcery::Event)

+ 23
- 0
app/projections/updates/projector.rb View File

@@ -79,6 +79,21 @@ module Projections
text: update.text
)
end

project FollowerAdded do |event|
author = Roost.repository.load(
Aggregates::Member, event.body['follower_id']
)
update = FollowsUpdate.new(event.body.merge(author: author))
recipient_id = event.aggregate_id

table.insert(
for: recipient_id,
author: author.handle.to_s,
posted_at: DateTime.now,
text: update.text
)
end
end

##
@@ -111,5 +126,13 @@ module Projections
"#{author_name} added you to their contacts"
end
end

##
# Respresents an update that X is now following you
class FollowsUpdate < UpdateRecord
def text
"#{author_name} started following you"
end
end
end
end

+ 23
- 0
app/reactors/follower.rb View File

@@ -0,0 +1,23 @@
# frozen_string_literal: true

module Reactors
##
# Adds an actor to a members' followers on various Events
class Follower
include EventSourcery::Postgres::Reactor

processor_name :follower

emits_events FollowerAdded

process MemberTagAdded do |event|
emit_event(
FollowerAdded.new(
aggregate_id: event.aggregate_id,
body: { follower_id: event.body['author_id'] },
causation_id: event.uuid
)
)
end
end
end

+ 2
- 2
app/web/controllers/web/tags_controller.rb View File

@@ -26,8 +26,8 @@ module Web
)

# TODO: raise if no profile handle given
# TODO: remove the hardcoded tag.
flash[:success] = "#{profile.handle} was tagged as \"#{post_params['tag']}\""
flash[:success] = "#{profile.handle} was tagged as "\
"\"#{post_params['tag']}\""
redirect "/m/#{profile.handle}"
end


+ 1
- 0
config/environment.rb View File

@@ -76,6 +76,7 @@ class Roost
Reactors::InvitationMailer,
Reactors::ConfirmationMailer,
Reactors::MemberGenerator,
Reactors::Follower,
Projections::Contacts::Projector,
Projections::Invitations::Projector,
Projections::Members::Projector,

+ 16
- 0
test/integration/web/member_tags_member_test.rb View File

@@ -26,4 +26,20 @@ class MemberTagsMemberTest < Minitest::WebSpec

assert_selector('.tag.mine', text: 'friend')
end

it 'can only add a tag once per tagging member'
it 'can add a tag multiple times on one profile'

it 'follows the tagged member' do
# Determine that harry follows ron by checking the notification sent to
# ron. TODO: Change to check with my followings once we have that overview
as(ron)

# @INK: implementing a follow feature. Which:
# * sends a notification
# * introduces a Followers list.
# * adds me as follower.
main_menu('Updates').click
assert_content '@hpotter@example.com started following you'
end
end

+ 1
- 1
test/support/workflows/tags_member.rb View File

@@ -14,7 +14,7 @@ module Workflows
click_icon('plus')
end

process_events(%w[tag_added])
process_events(%w[member_tag_added follower_added])
end

def form_attributes

Loading…
Cancel
Save