Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Defer users and channels creation #56

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions lib/lita/adapters/slack/rtm_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class RTMConnection

class << self
def build(robot, config)
new(robot, config, API.new(config).rtm_start)
team_data = API.new(config).rtm_start
new(robot, config, team_data)
end
end

Expand All @@ -28,8 +29,12 @@ def initialize(robot, config, team_data)
@websocket_url = team_data.websocket_url
@robot_id = team_data.self.id

UserCreator.create_users(team_data.users, robot, robot_id)
RoomCreator.create_rooms(team_data.channels, robot)
defer do
log.debug("Inserting #{team_data.users.size} users")
UserCreator.create_users(team_data.users, robot, robot_id)
log.debug("Inserting #{team_data.channels.size} channels")
RoomCreator.create_rooms(team_data.channels, robot)
end
end

def im_for(user_id)
Expand Down Expand Up @@ -81,6 +86,10 @@ def shut_down
attr_reader :websocket
attr_reader :websocket_url

def defer(&block)
Thread.new(&block)
end

def log
Lita.logger
end
Expand Down
2 changes: 2 additions & 0 deletions spec/lita/adapters/slack/rtm_connection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@ def with_websocket(subject, queue)

it "creates users with the results of rtm.start data" do
expect(Lita::Adapters::Slack::UserCreator).to receive(:create_users)
expect_any_instance_of(described_class).to receive(:defer).and_yield

described_class.build(robot, config)
end

it "creates rooms with the results of rtm.start data" do
expect(Lita::Adapters::Slack::RoomCreator).to receive(:create_rooms)
expect_any_instance_of(described_class).to receive(:defer).and_yield

described_class.build(robot, config)
end
Expand Down