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

Commit

Permalink
Merge pull request #116 from shimomura1004/id/115
Browse files Browse the repository at this point in the history
add some info to chat view refs #115
  • Loading branch information
mallowlabs committed Jul 25, 2013
2 parents b53b34c + eb5098b commit a9fdfc0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
9 changes: 9 additions & 0 deletions app/helpers/chat_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ def cache_message(message, has_class, &block)
end
end

def current_info(room)
{
:user => current_user && current_user.screen_name,
:room => room.id,
:public => room.is_public,
:member => room.owner_and_members.map{|user| user._id}
}
end

private
def publish_message(event, message, room)
data = if event == :delete
Expand Down
5 changes: 4 additions & 1 deletion app/models/room.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ def self.all_live(user = nil)
end

def owner_and_members
[self.user] + self.members
if self.is_public
then []
else [self.user] + self.members
end
end

def messages(offset, order = nil)
Expand Down
5 changes: 1 addition & 4 deletions app/views/chat/room.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@
= javascript_include_tag "room"
:javascript
var AsakusaSatellite = {
current : {
user : "#{current_user && current_user.screen_name}",
room : "#{@room.id}"
},
current : #{current_info(@room).to_json},
pusher : #{AsakusaSatellite::MessagePusher.jsClass},
form_auth : "#{form_authenticity_token}",
url : {
Expand Down
6 changes: 6 additions & 0 deletions spec/models/room_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@
@member = User.create
@room = Room.create(:title => 'room private', :user => @user, :is_public => false)
@room.members << @member
@public_room = Room.create(:title => 'room public', :user => @user, :is_public => true)
end

context "user" do
Expand All @@ -228,6 +229,11 @@
subject { @room.owner_and_members.to_set }
it { should == [@user].to_set }
end

context "public room" do
subject { @public_room.owner_and_members }
it { should == [] }
end
end
end

Expand Down

0 comments on commit a9fdfc0

Please sign in to comment.