Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Faye support, refactoring

  • Loading branch information...
commit 1e475008504da06087fc691ff717f9d77d1954ca 1 parent 59cf234
Kir Shatrov authored November 16, 2011
1  Gemfile
@@ -13,6 +13,7 @@ gem 'devise'
13 13
 gem 'haml-rails'
14 14
 
15 15
 gem 'json'
  16
+gem 'faye'
16 17
 
17 18
 # gem 'inboxes', :path => "/Users/kir/Sites/rails/inboxes-app/gems/inboxes"
18 19
 gem 'inboxes', :path => "/Users/Kir/Sites/gems/inboxes"# :git => "git://github.com/kirs/inboxes.git"
23  Gemfile.lock
@@ -35,6 +35,7 @@ GEM
35 35
       activesupport (= 3.1.1)
36 36
     activesupport (3.1.1)
37 37
       multi_json (~> 1.0)
  38
+    addressable (2.2.6)
38 39
     arel (2.2.1)
39 40
     bcrypt-ruby (3.0.1)
40 41
     builder (3.0.0)
@@ -45,13 +46,29 @@ GEM
45 46
       coffee-script-source
46 47
       execjs
47 48
     coffee-script-source (1.1.2)
  49
+    daemons (1.1.4)
48 50
     devise (1.4.9)
49 51
       bcrypt-ruby (~> 3.0)
50 52
       orm_adapter (~> 0.0.3)
51 53
       warden (~> 1.0.3)
  54
+    em-hiredis (0.1.0)
  55
+      hiredis (~> 0.3.0)
  56
+    em-http-request (0.3.0)
  57
+      addressable (>= 2.0.0)
  58
+      escape_utils
  59
+      eventmachine (>= 0.12.9)
52 60
     erubis (2.7.0)
  61
+    escape_utils (0.2.4)
  62
+    eventmachine (0.12.10)
53 63
     execjs (1.2.9)
54 64
       multi_json (~> 1.0)
  65
+    faye (0.6.7)
  66
+      em-hiredis (>= 0.0.1)
  67
+      em-http-request (~> 0.3)
  68
+      eventmachine (~> 0.12.0)
  69
+      json (>= 1.0)
  70
+      rack (>= 1.0)
  71
+      thin (~> 1.2)
55 72
     haml (3.1.3)
56 73
     haml-rails (0.3.4)
57 74
       actionpack (~> 3.0)
@@ -59,6 +76,7 @@ GEM
59 76
       haml (~> 3.0)
60 77
       railties (~> 3.0)
61 78
     hike (1.2.1)
  79
+    hiredis (0.3.2)
62 80
     i18n (0.6.0)
63 81
     jquery-rails (1.0.16)
64 82
       railties (~> 3.0)
@@ -114,6 +132,10 @@ GEM
114 132
       rack (~> 1.0)
115 133
       tilt (~> 1.1, != 1.3.0)
116 134
     sqlite3 (1.3.4)
  135
+    thin (1.3.1)
  136
+      daemons (>= 1.0.9)
  137
+      eventmachine (>= 0.12.6)
  138
+      rack (>= 1.0.0)
117 139
     thor (0.14.6)
118 140
     tilt (1.3.3)
119 141
     treetop (1.4.10)
@@ -132,6 +154,7 @@ PLATFORMS
132 154
 DEPENDENCIES
133 155
   coffee-rails (~> 3.1.1)
134 156
   devise
  157
+  faye
135 158
   haml-rails
136 159
   inboxes!
137 160
   jquery-rails
3  app/assets/javascripts/messaging.js
... ...
@@ -0,0 +1,3 @@
  1
+/*
  2
+= require inboxes/faye
  3
+*/
8  app/controllers/application_controller.rb
... ...
@@ -1,3 +1,11 @@
1 1
 class ApplicationController < ActionController::Base
2 2
   protect_from_forgery
  3
+  
  4
+  before_filter :assign_unread_discussions
  5
+  
  6
+  private
  7
+  
  8
+  def assign_unread_discussions
  9
+    @unread_discussions_count = Discussion.unread_for(current_user).count if user_signed_in?
  10
+  end
3 11
 end
7  app/views/inboxes/messages/_form.html.haml
... ...
@@ -0,0 +1,7 @@
  1
+.message_form
  2
+  = form_for Message.new, :url => discussion_messages_path(@discussion.id), :method => :post, :remote => true do |f|
  3
+    %p
  4
+      = f.label :body
  5
+      %br
  6
+      = f.text_area :body
  7
+    %p= f.submit
4  app/views/inboxes/messages/create.js.erb
... ...
@@ -0,0 +1,4 @@
  1
+<% inboxes_faye_broadcast "/discussions/#{@message.discussion.id}" do %> 
  2
+  $("#messages_box").append("<%= escape_javascript render(@message) %>");
  3
+  $("#new_message")[0].reset();
  4
+<% end %>
2  app/views/layouts/application.html.erb
@@ -13,6 +13,8 @@
13 13
         <%= content_tag :div, msg, :id => "flash_#{name}" %>
14 14
       <% end %>
15 15
       <%= content_tag :h1, yield(:title) if show_title? %>
  16
+      Unread messages: <%= @unread_discussions_count %>
  17
+        
16 18
       <%= yield %>
17 19
     </div>
18 20
   </body>
3  config/application.rb
@@ -46,5 +46,8 @@ class Application < Rails::Application
46 46
     config.assets.version = '1.0'
47 47
     
48 48
     config.inboxes.user_name = :name
  49
+    config.inboxes.faye_enabled = true
  50
+    config.inboxes.faye_host = "inboxes-app.dev"
  51
+    # config.inboxes.faye_port = 9292 # by default
49 52
   end
50 53
 end
4  faye.ru
... ...
@@ -0,0 +1,4 @@
  1
+require 'faye'
  2
+
  3
+faye_server = Faye::RackAdapter.new(:mount => '/faye', :timeout => 25)
  4
+run faye_server

0 notes on commit 1e47500

Please sign in to comment.
Something went wrong with that request. Please try again.