Permalink
Browse files

added private messaging, needs refactoring

  • Loading branch information...
1 parent 48b8400 commit 338e9657999fe4618ac3d24e8b8d4c1012e52bb4 Taylor Redden committed Aug 12, 2008
View
@@ -0,0 +1 @@
+*.log
@@ -6,7 +6,7 @@ class ApplicationController < ActionController::Base
include AuthenticatedSystem
# See ActionController::RequestForgeryProtection for details
# Uncomment the :secret if you're not using the cookie session store
- protect_from_forgery # :secret => '9d0e7799e103d6e78392724afa979f3a'
+ #protect_from_forgery # :secret => '9d0e7799e103d6e78392724afa979f3a'
# See ActionController::Base for details
# Uncomment this to filter the contents of submitted sensitive data parameters
@@ -1,5 +1,5 @@
class ChatRoomsController < ApplicationController
- before_filter :is_logged_in?, :except => :index
+ before_filter :is_logged_in?
# GET /chat_rooms
# GET /chat_rooms.xml
def index
@@ -2,21 +2,15 @@ class ConnectionsController < ApplicationController
around_filter :update_user_list
def login
- render :juggernaut => {:type => :send_to_channels, :channels => @channels } do |page|
- page.insert_html :bottom, 'chat_room', "<p style='color:green;font-size:20px;'>#{@user.login} has entered the room</p>"
- page.call :scrollChatPanel
- end
+ update_chat_room("entered") unless @channels.include? 0
- #render :nothing => true
+ render :nothing => true
end
def logout
Juggernaut.remove_channels_from_clients(@user.id, @channels)
- render :juggernaut => {:type => :send_to_channels, :channels => @channels } do |page|
- page.insert_html :bottom, 'chat_room', "<p style='color:green;font-size:20px;'>#{@user.login} has left the room</p>"
- page.call :scrollChatPanel
- end
+ update_chat_room("left") unless @channels.include? 0
render :nothing => true
end
@@ -26,16 +20,23 @@ def logout
def update_user_list
@user = User.find(params[:client_id])
- @channels = params[:channels].collect{|channel| channel.to_i }
+ @channels = params[:channels].collect{|channel| channel.to_i } if params[:channels]
yield
Thread.new do
users = User.find(Juggernaut.show_users_for_channels(@channels).collect{ |user| user["id"] })
render :juggernaut => {:type => :send_to_channels, :channels => @channels } do |page|
- page.replace_html 'user_list', users.collect{ |user| "<li>#{user.login}</li>" }.join
+ page.replace_html 'user_list', users.collect{ |user| "<li>"+ link_to_remote(user.login, :url => "/messages/new_private_message/#{user.id}")+"</li>" }.join
end
end
end
+
+ def update_chat_room(action)
+ render :juggernaut => {:type => :send_to_channels, :channels => @channels } do |page|
+ page.insert_html :bottom, 'chat_room', "<p style='color:green;font-size:20px;'>#{@user.login} has #{action} the room</p>"
+ page.call :scrollChatPanel
+ end
+ end
end
@@ -0,0 +1,24 @@
+class MessagesController < ApplicationController
+ def new_private_message
+ @client_ids = [ current_user.id, params[:id].to_i ]
+ puts @client_ids
+ end
+
+ def send_private_message
+ @client_ids = params[:client_ids].collect{|client_id| client_id.to_i } if params[:client_ids]
+
+ puts @client_ids
+
+ render :juggernaut => {:type => :send_to_clients, :client_ids => @client_ids } do |page|
+
+ page << "if ( $('private_chat_room') == null) {"
+ page.insert_html :bottom, 'private_messages', create_private_message(@client_ids)
+ page << "}"
+
+ page.insert_html :bottom, 'private_chat_room', "<p>#{current_user.login}: #{h params[:chat_input]}</p>"
+ page.call :scrollChatPanel, "private_chat_room"
+ end
+
+ render :nothing => true
+ end
+end
@@ -0,0 +1,15 @@
+module MessagesHelper
+ def create_private_message(client_ids)
+ top ="<div class='private_message'><div id='private_chat_room' class='private_chat_room scroller'></div><div id='chat_form'>"
+
+ form = form_remote_tag(:url => { :action => :send_private_message, :client_ids => client_ids }, :complete => "$('chat_input').value = ''" )
+
+ text = text_field_tag( 'chat_input', '', { :size => '50', :id => 'chat_input'} )
+
+ submit = submit_tag "Chat"
+
+ bottom ="</form></div><div"
+
+ top+form+text+submit+bottom
+ end
+end
@@ -1,3 +1,5 @@
+<%= juggernaut(:channels => [0], :client_id => session[:user_id]) %>
+
<h1>Listing chat_rooms</h1>
<table>
@@ -22,3 +24,9 @@
<br />
<%= link_to 'New chat_room', new_chat_room_path %>
+
+<br />
+
+<div id="user_list"></div>
+
+<div id="private_messages"></div>
@@ -1,12 +1,5 @@
<%= juggernaut(:channels => [@chat_room.id], :client_id => session[:user_id]) %>
-<script type="text/javascript">
-function scrollChatPanel(){
- div = $('chat_room');
- div.scrollTop = 0xffff;
-}
-</script>
-
<p><%= link_to 'Back', chat_rooms_path %></p>
<h1><%=h @chat_room.name %></h1>
@@ -7,6 +7,12 @@
<title>ChatRooms: <%= controller.action_name %></title>
<%= javascript_include_tag 'prototype', :juggernaut %>
<%= stylesheet_link_tag 'scaffold' %>
+ <script type="text/javascript">
+ function scrollChatPanel(room){
+ div = $(room);
+ div.scrollTop = 0xffff;
+ }
+ </script>
</head>
<body>
@@ -0,0 +1 @@
+page.insert_html :bottom, 'private_messages', create_private_message(@client_ids)
View
@@ -32,7 +32,7 @@
#
:allowed_ips:
- 127.0.0.1
- # - 192.168.0.1
+ #- 192.168.0.6
# 2) Via HTTP request
#
@@ -64,6 +64,18 @@ a:hover { color: #fff; background-color:#000; }
scrollbar-3dlight-color:B1D0F0;
}
+.scroller{
+ border:1px solid black;
+ overflow-y: scroll;
+ scrollbar-arrow-color:000000;
+ scrollbar-track-color:000000;
+ scrollbar-shadow-color:B1D0F0;
+ scrollbar-face-color:B1D0F0;
+ scrollbar-highlight-color:B1D0F0;
+ scrollbar-darkshadow-color:B1D0F0;
+ scrollbar-3dlight-color:B1D0F0;
+}
+
#chat_room
{
float: left;
@@ -90,4 +102,16 @@ a:hover { color: #fff; background-color:#000; }
margin-top: 10px;
font-size: 15px;
border: 1px solid black;
+}
+
+.private_message{
+ margin-left :10px;
+ float: left;
+ height: 400px;
+ padding: 10px;
+ border: 1px solid black;
+}
+
+.private_chat_room{
+ height: 350px;
}
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class MessagesControllerTest < ActionController::TestCase
+ # Replace this with your real tests.
+ def test_truth
+ assert true
+ end
+end

0 comments on commit 338e965

Please sign in to comment.