Skip to content

Commit

Permalink
Don't send JOIN messages twice if a user is already present. Fixes ze…
Browse files Browse the repository at this point in the history
…rowidthgh-4.

As a side effect, this prevents a bug wherein an existing CamperVan::User was
being created with a CamperVan::User as the source rather than a FireRing::User,
causing a crash.
  • Loading branch information
zerowidth committed Jan 22, 2012
1 parent f64b049 commit 5ac4ebb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/camper_van/channel.rb
Expand Up @@ -297,8 +297,10 @@ def map_message_to_irc(message)
end

when "Enter"
client.campfire_reply :join, name, channel
users[user.id] = User.new(user)
unless users[user.id]
client.campfire_reply :join, name, channel
users[user.id] = User.new(user)
end

when "Leave", "Kick" # kick is used for idle timeouts
client.campfire_reply :part, name, channel, "Leaving..."
Expand Down
8 changes: 8 additions & 0 deletions spec/camper_van/channel_spec.rb
Expand Up @@ -403,6 +403,14 @@ def msg(type, attributes={})
@client.sent.last.must_match %r/:joe\S+ JOIN #test/
end

it "does not resend a join command when a user enters the room twice" do
@channel.map_message_to_irc msg("Enter")
@client.sent.clear
@client.sent.last.must_equal nil
@channel.map_message_to_irc msg("Enter")
@client.sent.last.must_equal nil
end

it "adds the user to the internal tracking list when a user joins" do
@channel.map_message_to_irc msg("Enter")
@client.sent.last.must_match %r/:joe\S+ JOIN #test/
Expand Down

0 comments on commit 5ac4ebb

Please sign in to comment.