inboxes 0.1.5 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +29 -9
 - data/app/controllers/inboxes/base_controller.rb +2 -2
 - data/app/controllers/inboxes/discussions_controller.rb +8 -8
 - data/app/controllers/inboxes/messages_controller.rb +3 -3
 - data/app/controllers/inboxes/speakers_controller.rb +2 -2
 - data/app/models/discussion.rb +22 -27
 - data/app/models/inboxes/ability.rb +3 -3
 - data/app/models/message.rb +9 -10
 - data/app/models/speaker.rb +5 -5
 - data/app/views/inboxes/discussions/_form.html.haml +1 -1
 - data/app/views/inboxes/discussions/index.html.haml +6 -3
 - data/app/views/inboxes/discussions/show.html.haml +3 -3
 - data/config/locales/en.yml +1 -1
 - data/config/routes.rb +2 -2
 - data/lib/generators/inboxes/install_generator.rb +3 -7
 - data/lib/generators/inboxes/templates/install.rb +5 -4
 - data/lib/generators/inboxes/templates/upgrade_discussible.rb +9 -0
 - data/lib/generators/inboxes/upgrade_discussible_generator.rb +36 -0
 - data/lib/generators/inboxes/views_generator.rb +1 -1
 - data/lib/inboxes/ability.rb +3 -3
 - data/lib/inboxes/active_record_extension.rb +3 -3
 - data/lib/inboxes/engine.rb +1 -1
 - data/lib/inboxes/railtie.rb +2 -2
 - data/lib/inboxes/version.rb +1 -1
 - data/lib/inboxes.rb +4 -4
 - metadata +38 -61
 
    
        data/README.md
    CHANGED
    
    | 
         @@ -6,6 +6,10 @@ Inboxes is a young messaging system for Rails app. It: 
     | 
|
| 
       6 
6 
     | 
    
         
             
            - read/unread discussions counter
         
     | 
| 
       7 
7 
     | 
    
         
             
            - any user can be invited to discussion by the member of this discussion, so you can chat with unlimited number of users
         
     | 
| 
       8 
8 
     | 
    
         | 
| 
      
 9 
     | 
    
         
            +
            ##Upgrading from 0.1 to current version (0.2)
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            **Run `rails generate inboxes:upgrade_discussible` and then roll up the migration. Your DB is upgraded!**
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
       9 
13 
     | 
    
         
             
            ##Requirements and recommendations
         
     | 
| 
       10 
14 
     | 
    
         | 
| 
       11 
15 
     | 
    
         
             
            Inboxes requires Rails 3.x and [Devise](https://github.com/plataformatec/devise) for user identification (surely, messaging system is not possible without users). Now the gem is tested only with Ruby 1.8.7 and REE.
         
     | 
| 
         @@ -14,13 +18,15 @@ We recommend to use Inboxes with [Faye](https://github.com/jcoglan/faye), becaus 
     | 
|
| 
       14 
18 
     | 
    
         | 
| 
       15 
19 
     | 
    
         
             
            Remember that unfortunately, Inboxes reserve 3 resources names: Discussion, Message and Speaker.
         
     | 
| 
       16 
20 
     | 
    
         | 
| 
      
 21 
     | 
    
         
            +
            Since version 0.2.0, it is possible to add `has_inboxes` option to any model. For instance, it can be `Person` or `Teacher`.
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
       17 
23 
     | 
    
         
             
            ##Installation
         
     | 
| 
       18 
24 
     | 
    
         | 
| 
       19 
25 
     | 
    
         
             
            *Make sure that Devise is already installed and configured in your app!*
         
     | 
| 
       20 
26 
     | 
    
         | 
| 
       21 
27 
     | 
    
         
             
            1. Add `gem "inboxes", "~> 0.1.2"` to the `Gemfile` and run `bundle install`
         
     | 
| 
       22 
28 
     | 
    
         
             
            2. Execute `rails generate inboxes:install`. This command will generate migration for messaging system. Don't forget to run migrations: `rake db:migrate`
         
     | 
| 
       23 
     | 
    
         
            -
            3. Add ` 
     | 
| 
      
 29 
     | 
    
         
            +
            3. Add `has_inboxes` to your User model like [here](https://gist.github.com/1330080).
         
     | 
| 
       24 
30 
     | 
    
         
             
            4. Now Inboxes are ready to use. Open `http://yoursite.dev/discussions` to see the list of discussions. You can start new one.
         
     | 
| 
       25 
31 
     | 
    
         | 
| 
       26 
32 
     | 
    
         
             
            Default Inboxes views are ugly, so you can copy into your app and make anything with them: `rails generate inboxes:views`
         
     | 
| 
         @@ -35,26 +41,40 @@ By default, the gem provides localized phrases for Russian and English languages 
     | 
|
| 
       35 
41 
     | 
    
         
             
            You can watch the demo of integration [on YouTube](http://youtu.be/c12gey9DvyU)
         
     | 
| 
       36 
42 
     | 
    
         | 
| 
       37 
43 
     | 
    
         
             
            1. Add `gem "faye"` to your Gemfile and run `bundle install`. Install Faye by [the screencast](http://railscasts.com/episodes/260-messaging-with-faye)
         
     | 
| 
       38 
     | 
    
         
            -
            2. Create `messaging.js` in `app/assets/javascripts/` with  
     | 
| 
      
 44 
     | 
    
         
            +
            2. Create `messaging.js` in `app/assets/javascripts/` with this line: `//= require inboxes/faye`
         
     | 
| 
       39 
45 
     | 
    
         | 
| 
       40 
46 
     | 
    
         
             
            3. Copy or replace 2 views from Inboxes example app to your application: [app/views/inboxes/messages/_form](https://github.com/kirs/inboxes-app/blob/master/app/views/inboxes/messages/_form.html.haml) and [app/views/inboxes/messages/create](https://github.com/kirs/inboxes-app/blob/master/app/views/inboxes/messages/create.js.erb)
         
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
       42 
48 
     | 
    
         
             
            4. Add config parameters to your application config (last 2 are not necessary):
         
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 51 
     | 
    
         
            +
            config.inboxes.faye_enabled = true
         
     | 
| 
      
 52 
     | 
    
         
            +
            config.inboxes.faye_host = "inboxes-app.dev" # localhost by default
         
     | 
| 
      
 53 
     | 
    
         
            +
            config.inboxes.faye_port = 9292 # 9292 by default
         
     | 
| 
      
 54 
     | 
    
         
            +
            ```
         
     | 
| 
       47 
55 
     | 
    
         | 
| 
       48 
56 
     | 
    
         
             
            5. Faye installation is finished. If you have any troubles, check the [example app](https://github.com/kirs/inboxes-app/)
         
     | 
| 
       49 
57 
     | 
    
         | 
| 
       50 
58 
     | 
    
         
             
            *While testing Inboxes with Faye, don't forget to run it: `rackup faye.ru -s thin -E production`*
         
     | 
| 
      
 59 
     | 
    
         
            +
            You can read more about Faye on it's [official page](http://faye.jcoglan.com/).
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
      
 61 
     | 
    
         
            +
            ### Hints
         
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
      
 63 
     | 
    
         
            +
            1. If you want to add breadcrumbs to Inboxes pages, we recommend you to use [crummy gem](https://github.com/zachinglis/crummy). It allows to define breadcrumbs in views.
         
     | 
| 
       51 
64 
     | 
    
         | 
| 
       52 
65 
     | 
    
         
             
            ##Todo
         
     | 
| 
       53 
66 
     | 
    
         | 
| 
       54 
67 
     | 
    
         
             
            - Add RSpec tests
         
     | 
| 
      
 68 
     | 
    
         
            +
            - Add ability to inherit Inboxes controllers
         
     | 
| 
      
 69 
     | 
    
         
            +
            - Add Pusher capability
         
     | 
| 
      
 70 
     | 
    
         
            +
            - Email notifications and the ability to answer received emails like in Github issues (#7)
         
     | 
| 
       55 
71 
     | 
    
         | 
| 
       56 
     | 
    
         
            -
            ## 
     | 
| 
      
 72 
     | 
    
         
            +
            ##Contributors
         
     | 
| 
       57 
73 
     | 
    
         | 
| 
       58 
74 
     | 
    
         
             
            - [Kir Shatrov](https://github.com/kirs/) (Evrone Company)
         
     | 
| 
      
 75 
     | 
    
         
            +
            - [Andrey Ognevsky](https://github.com/ognevsy/) (Evrone Company)
         
     | 
| 
      
 76 
     | 
    
         
            +
            - [Alexander Brodyanoj](https://github.com/dom1nga)
         
     | 
| 
      
 77 
     | 
    
         
            +
            - [Dmitriy Kiriyenko](https://github.com/dmitriy-kiriyenko)
         
     | 
| 
      
 78 
     | 
    
         
            +
            - [Alexey Poimtsev](https://github.com/alec-c4) ([http://progress-engine.ru/](Progress Engine))
         
     | 
| 
       59 
79 
     | 
    
         | 
| 
       60 
     | 
    
         
            -
            ##Feel free for pull requests!
         
     | 
| 
      
 80 
     | 
    
         
            +
            ##Feel free for pull requests!
         
     | 
| 
         @@ -1,10 +1,10 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            class Inboxes::BaseController < ApplicationController
         
     | 
| 
       2 
2 
     | 
    
         
             
              private
         
     | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
       4 
4 
     | 
    
         
             
              def init_discussion
         
     | 
| 
       5 
5 
     | 
    
         
             
                @discussion = Discussion.find(params[:discussion_id])
         
     | 
| 
       6 
6 
     | 
    
         
             
              end
         
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
       8 
8 
     | 
    
         
             
              # Needs to be overriden so that we use Spree's Ability rather than anyone else's.
         
     | 
| 
       9 
9 
     | 
    
         
             
              def current_ability
         
     | 
| 
       10 
10 
     | 
    
         
             
                # raise "Loading Ability"
         
     | 
| 
         @@ -3,7 +3,7 @@ class Inboxes::DiscussionsController < Inboxes::BaseController 
     | 
|
| 
       3 
3 
     | 
    
         
             
              # before_filter :authenticate_user!
         
     | 
| 
       4 
4 
     | 
    
         
             
              # before_filter :init_and_check_permissions, :only => :show
         
     | 
| 
       5 
5 
     | 
    
         
             
              before_filter :load_and_check_discussion_recipient, :only => [:create, :new]
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
       7 
7 
     | 
    
         
             
              def index
         
     | 
| 
       8 
8 
     | 
    
         
             
                @discussions = current_user.discussions
         
     | 
| 
       9 
9 
     | 
    
         
             
              end
         
     | 
| 
         @@ -21,37 +21,37 @@ class Inboxes::DiscussionsController < Inboxes::BaseController 
     | 
|
| 
       21 
21 
     | 
    
         
             
                # @discussion = Discussion.new
         
     | 
| 
       22 
22 
     | 
    
         
             
                @discussion.messages.build
         
     | 
| 
       23 
23 
     | 
    
         
             
              end
         
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
       25 
25 
     | 
    
         
             
              # POST /discussions
         
     | 
| 
       26 
26 
     | 
    
         
             
              # POST /discussions.json
         
     | 
| 
       27 
27 
     | 
    
         
             
              def create
         
     | 
| 
       28 
28 
     | 
    
         
             
                # @discussion = Discussion.new(params[:discussion])
         
     | 
| 
       29 
29 
     | 
    
         
             
                @discussion.add_recipient_token current_user.id
         
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
       31 
31 
     | 
    
         
             
                @discussion.messages.each do |m|
         
     | 
| 
       32 
32 
     | 
    
         
             
                  m.discussion = @discussion
         
     | 
| 
       33 
33 
     | 
    
         
             
                  m.user = current_user
         
     | 
| 
       34 
34 
     | 
    
         
             
                end
         
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
       36 
36 
     | 
    
         
             
                if @discussion.save
         
     | 
| 
       37 
37 
     | 
    
         
             
                  redirect_to @discussion, :notice => t("inboxes.discussions.started")
         
     | 
| 
       38 
38 
     | 
    
         
             
                else
         
     | 
| 
       39 
39 
     | 
    
         
             
                  render :action => "new"
         
     | 
| 
       40 
40 
     | 
    
         
             
                end
         
     | 
| 
       41 
41 
     | 
    
         
             
              end
         
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
       43 
43 
     | 
    
         
             
              private
         
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
       45 
45 
     | 
    
         
             
              # def init_and_check_permissions
         
     | 
| 
       46 
46 
     | 
    
         
             
              #   @discussion = Discussion.includes(:messages, :speakers).find(params[:id])
         
     | 
| 
       47 
47 
     | 
    
         
             
              #   redirect_to discussions_url, :notice => t("inboxes.discussions.can_not_participate") unless @discussion.can_participate?(current_user)
         
     | 
| 
       48 
48 
     | 
    
         
             
              # end
         
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
       50 
50 
     | 
    
         
             
              def load_and_check_discussion_recipient
         
     | 
| 
       51 
51 
     | 
    
         
             
                # initializing model for new and create actions
         
     | 
| 
       52 
52 
     | 
    
         
             
                @discussion = Discussion.new(params[:discussion].presence || {})
         
     | 
| 
       53 
53 
     | 
    
         
             
                # @discussion.recipient_tokens = params[:recipients] if params[:recipients] # pre-population
         
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
       55 
55 
     | 
    
         
             
                # checking if discussion with this user already exists
         
     | 
| 
       56 
56 
     | 
    
         
             
                if @discussion.recipient_ids && @discussion.recipient_ids.size == 1
         
     | 
| 
       57 
57 
     | 
    
         
             
                  user = User.find(@discussion.recipient_ids.first)
         
     | 
| 
         @@ -3,12 +3,12 @@ class Inboxes::MessagesController < Inboxes::BaseController 
     | 
|
| 
       3 
3 
     | 
    
         
             
              # load_and_authorize_resource
         
     | 
| 
       4 
4 
     | 
    
         
             
              load_and_authorize_resource :discussion
         
     | 
| 
       5 
5 
     | 
    
         
             
              load_resource :message, :through => :discussion, :shallow => true
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
       7 
7 
     | 
    
         
             
              def create
         
     | 
| 
       8 
8 
     | 
    
         
             
                @message.user = current_user
         
     | 
| 
       9 
9 
     | 
    
         
             
                @message.discussion = @discussion
         
     | 
| 
       10 
10 
     | 
    
         
             
                @message.save
         
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
       12 
12 
     | 
    
         
             
                respond_to do |format|
         
     | 
| 
       13 
13 
     | 
    
         
             
                  format.html { redirect_to @message.discussion }
         
     | 
| 
       14 
14 
     | 
    
         
             
                  format.js
         
     | 
| 
         @@ -16,7 +16,7 @@ class Inboxes::MessagesController < Inboxes::BaseController 
     | 
|
| 
       16 
16 
     | 
    
         
             
              end
         
     | 
| 
       17 
17 
     | 
    
         | 
| 
       18 
18 
     | 
    
         
             
              # private
         
     | 
| 
       19 
     | 
    
         
            -
              # 
     | 
| 
      
 19 
     | 
    
         
            +
              #
         
     | 
| 
       20 
20 
     | 
    
         
             
              # def init_and_check_permissions
         
     | 
| 
       21 
21 
     | 
    
         
             
              #   @discussion = Discussion.find(params[:discussion_id])
         
     | 
| 
       22 
22 
     | 
    
         
             
              #   redirect_to discussions_url, :notice => t("inboxes.discussions.can_not_participate") unless @discussion.can_participate?(current_user)
         
     | 
| 
         @@ -3,14 +3,14 @@ class Inboxes::SpeakersController < Inboxes::BaseController 
     | 
|
| 
       3 
3 
     | 
    
         
             
              load_and_authorize_resource :discussion
         
     | 
| 
       4 
4 
     | 
    
         
             
              load_resource :speaker, :through => :discussion, :shallow => true
         
     | 
| 
       5 
5 
     | 
    
         
             
              # load_and_authorize_resource
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
       7 
7 
     | 
    
         
             
              def create
         
     | 
| 
       8 
8 
     | 
    
         
             
                raise ActiveRecord::RecordNotFound unless params[:speaker] && params[:speaker][:user_id]
         
     | 
| 
       9 
9 
     | 
    
         
             
                @user = User.find(params[:speaker][:user_id])
         
     | 
| 
       10 
10 
     | 
    
         
             
                flash[:notice] = t("inboxes.speakers.added") if @discussion.add_speaker(@user)
         
     | 
| 
       11 
11 
     | 
    
         
             
                redirect_to @discussion
         
     | 
| 
       12 
12 
     | 
    
         
             
              end
         
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
       14 
14 
     | 
    
         
             
              def destroy
         
     | 
| 
       15 
15 
     | 
    
         
             
                @speaker = Speaker.find(params[:id])
         
     | 
| 
       16 
16 
     | 
    
         
             
                @speaker.destroy
         
     | 
    
        data/app/models/discussion.rb
    CHANGED
    
    | 
         @@ -1,19 +1,19 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
             
     | 
| 
       2 
1 
     | 
    
         
             
            class Discussion < ActiveRecord::Base
         
     | 
| 
       3 
2 
     | 
    
         
             
              attr_accessor :recipient_tokens, :recipient_ids
         
     | 
| 
       4 
3 
     | 
    
         
             
              attr_reader :recipient_ids
         
     | 
| 
       5 
4 
     | 
    
         | 
| 
       6 
5 
     | 
    
         
             
              # paginates_per 10
         
     | 
| 
       7 
6 
     | 
    
         | 
| 
       8 
     | 
    
         
            -
              #  
     | 
| 
      
 7 
     | 
    
         
            +
              # creater
         
     | 
| 
       9 
8 
     | 
    
         
             
              has_many :messages, :dependent => :destroy
         
     | 
| 
       10 
9 
     | 
    
         | 
| 
       11 
     | 
    
         
            -
               
     | 
| 
      
 10 
     | 
    
         
            +
              belongs_to :discussable, :polymorphic => true
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
              # participants of discussion (speakers)
         
     | 
| 
       12 
13 
     | 
    
         
             
              has_many :speakers, :dependent => :destroy
         
     | 
| 
       13 
14 
     | 
    
         
             
              has_many :users, :through => :speakers
         
     | 
| 
       14 
15 
     | 
    
         | 
| 
       15 
     | 
    
         
            -
              #  
     | 
| 
       16 
     | 
    
         
            -
              
         
     | 
| 
      
 16 
     | 
    
         
            +
              # marks about read/unread
         
     | 
| 
       17 
17 
     | 
    
         
             
              scope :unread_for, (lambda do |user_or_user_id|
         
     | 
| 
       18 
18 
     | 
    
         
             
                user = user_or_user_id.is_a?(User) ? user_or_user_id.id : user_or_user_id
         
     | 
| 
       19 
19 
     | 
    
         
             
                joins(:speakers).where("discussions.updated_at >= speakers.updated_at AND speakers.user_id = ?", user)
         
     | 
| 
         @@ -21,12 +21,10 @@ class Discussion < ActiveRecord::Base 
     | 
|
| 
       21 
21 
     | 
    
         | 
| 
       22 
22 
     | 
    
         
             
              accepts_nested_attributes_for :messages
         
     | 
| 
       23 
23 
     | 
    
         | 
| 
       24 
     | 
    
         
            -
              validate :check_that_has_at_least_two_users #  
     | 
| 
      
 24 
     | 
    
         
            +
              validate :check_that_has_at_least_two_users # don't allow to create discussion, if there is no creator
         
     | 
| 
       25 
25 
     | 
    
         | 
| 
       26 
     | 
    
         
            -
              #  
     | 
| 
      
 26 
     | 
    
         
            +
              # mark as read
         
     | 
| 
       27 
27 
     | 
    
         
             
              after_save(:on => :create) do
         
     | 
| 
       28 
     | 
    
         
            -
                # Rails.logger.info("Repicients ids: #{recipient_ids.inspect}")
         
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
28 
     | 
    
         
             
                if recipient_ids.kind_of?(Array)
         
     | 
| 
       31 
29 
     | 
    
         
             
                  recipient_ids.uniq!
         
     | 
| 
       32 
30 
     | 
    
         
             
                  recipient_ids.each do |id|
         
     | 
| 
         @@ -55,38 +53,30 @@ class Discussion < ActiveRecord::Base 
     | 
|
| 
       55 
53 
     | 
    
         
             
              end
         
     | 
| 
       56 
54 
     | 
    
         | 
| 
       57 
55 
     | 
    
         
             
              def user_invited_at(user)
         
     | 
| 
       58 
     | 
    
         
            -
                 
     | 
| 
       59 
     | 
    
         
            -
                speaker.created_at
         
     | 
| 
      
 56 
     | 
    
         
            +
                find_speaker_by_user(user).created_at
         
     | 
| 
       60 
57 
     | 
    
         
             
              end
         
     | 
| 
       61 
58 
     | 
    
         | 
| 
       62 
59 
     | 
    
         
             
              def can_participate?(user)
         
     | 
| 
       63 
     | 
    
         
            -
                 
     | 
| 
       64 
     | 
    
         
            -
                speaker ? true : false
         
     | 
| 
      
 60 
     | 
    
         
            +
                !!find_speaker_by_user(user)
         
     | 
| 
       65 
61 
     | 
    
         
             
              end
         
     | 
| 
       66 
62 
     | 
    
         | 
| 
       67 
     | 
    
         
            -
              #  
     | 
| 
       68 
     | 
    
         
            -
              # TODO  
     | 
| 
      
 63 
     | 
    
         
            +
              # don't allow to create discussion with user, if discussion with this user already exists
         
     | 
| 
      
 64 
     | 
    
         
            +
              # TODO move to separated method and return boolean value
         
     | 
| 
       69 
65 
     | 
    
         
             
              def self.find_between_users(user, user2)
         
     | 
| 
       70 
66 
     | 
    
         
             
                dialog = nil
         
     | 
| 
       71 
67 
     | 
    
         
             
                discussions = self.joins(:speakers).includes(:users).where("speakers.user_id = ?", user.id)
         
     | 
| 
       72 
68 
     | 
    
         
             
                Rails.logger.info "Searching for ids: #{user.id}, #{user2.id}"
         
     | 
| 
       73 
69 
     | 
    
         
             
                discussions.each do |discussion|
         
     | 
| 
       74 
     | 
    
         
            -
                  dialog = discussion if discussion.private? && ( 
     | 
| 
      
 70 
     | 
    
         
            +
                  dialog = discussion if discussion.private? && ([discussion.users.first, discussion.users.last] - [user, user2]).empty?
         
     | 
| 
       75 
71 
     | 
    
         
             
                end
         
     | 
| 
       76 
72 
     | 
    
         
             
                dialog
         
     | 
| 
       77 
73 
     | 
    
         
             
              end
         
     | 
| 
       78 
74 
     | 
    
         | 
| 
       79 
     | 
    
         
            -
              #  
     | 
| 
      
 75 
     | 
    
         
            +
              # private/group discussion
         
     | 
| 
       80 
76 
     | 
    
         
             
              def private?
         
     | 
| 
       81 
77 
     | 
    
         
             
                self.users.size <= 2
         
     | 
| 
       82 
78 
     | 
    
         
             
              end
         
     | 
| 
       83 
79 
     | 
    
         | 
| 
       84 
     | 
    
         
            -
              # дата последнего сообщения в дискуссии
         
     | 
| 
       85 
     | 
    
         
            -
              # def last_message_at
         
     | 
| 
       86 
     | 
    
         
            -
              #   self.messages.last ? self.messages.last.created_at : nil
         
     | 
| 
       87 
     | 
    
         
            -
              # end
         
     | 
| 
       88 
     | 
    
         
            -
             
     | 
| 
       89 
     | 
    
         
            -
              # проверка, является ли дискуссия непрочитанной для пользователя
         
     | 
| 
       90 
80 
     | 
    
         
             
              def unread_for?(user)
         
     | 
| 
       91 
81 
     | 
    
         
             
                speaker = find_speaker_by_user(user)
         
     | 
| 
       92 
82 
     | 
    
         
             
                if speaker
         
     | 
| 
         @@ -96,21 +86,26 @@ class Discussion < ActiveRecord::Base 
     | 
|
| 
       96 
86 
     | 
    
         
             
                end
         
     | 
| 
       97 
87 
     | 
    
         
             
              end
         
     | 
| 
       98 
88 
     | 
    
         | 
| 
       99 
     | 
    
         
            -
              #  
     | 
| 
      
 89 
     | 
    
         
            +
              # return amount of unreaded messages for current discussion
         
     | 
| 
      
 90 
     | 
    
         
            +
              def unread_messages_count_for(user)
         
     | 
| 
      
 91 
     | 
    
         
            +
                speaker = find_speaker_by_user(user)
         
     | 
| 
      
 92 
     | 
    
         
            +
                messages.where("updated_at > ?", speaker.updated_at ).where("user_id != ?", speaker.id ).count
         
     | 
| 
      
 93 
     | 
    
         
            +
              end
         
     | 
| 
      
 94 
     | 
    
         
            +
             
     | 
| 
       100 
95 
     | 
    
         
             
              def mark_as_read_for(user)
         
     | 
| 
       101 
96 
     | 
    
         
             
                speaker = Speaker.find_or_create_by_user_id_and_discussion_id(user.id, self.id)
         
     | 
| 
       102 
97 
     | 
    
         
             
                # flag.update_attributes(:updat => Time.zone.now)
         
     | 
| 
       103 
98 
     | 
    
         
             
                speaker.touch
         
     | 
| 
       104 
99 
     | 
    
         
             
              end
         
     | 
| 
       105 
     | 
    
         
            -
             
     | 
| 
      
 100 
     | 
    
         
            +
             
     | 
| 
       106 
101 
     | 
    
         
             
              def find_speaker_by_user user
         
     | 
| 
       107 
102 
     | 
    
         
             
                Speaker.find_by_discussion_id_and_user_id(self.id, user.id)
         
     | 
| 
       108 
103 
     | 
    
         
             
              end
         
     | 
| 
       109 
     | 
    
         
            -
             
     | 
| 
      
 104 
     | 
    
         
            +
             
     | 
| 
       110 
105 
     | 
    
         
             
              private
         
     | 
| 
       111 
106 
     | 
    
         | 
| 
       112 
107 
     | 
    
         
             
              def check_that_has_at_least_two_users
         
     | 
| 
       113 
108 
     | 
    
         
             
                errors.add :recipient_tokens, t("inboxes.discussions.choose_at_least_one_recipient") if !self.recipient_ids || self.recipient_ids.size < 2
         
     | 
| 
       114 
109 
     | 
    
         
             
              end
         
     | 
| 
       115 
110 
     | 
    
         | 
| 
       116 
     | 
    
         
            -
            end
         
     | 
| 
      
 111 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -15,20 +15,20 @@ module Inboxes 
     | 
|
| 
       15 
15 
     | 
    
         
             
                # and therefore should be easy to test in isolation.
         
     | 
| 
       16 
16 
     | 
    
         
             
                def self.register_ability(ability)
         
     | 
| 
       17 
17 
     | 
    
         
             
                  self.abilities.add(ability)
         
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
       19 
19 
     | 
    
         
             
                end
         
     | 
| 
       20 
20 
     | 
    
         | 
| 
       21 
21 
     | 
    
         
             
                def initialize(user)
         
     | 
| 
       22 
22 
     | 
    
         
             
                  # raise "Initializing 3rd patry"
         
     | 
| 
       23 
23 
     | 
    
         
             
                  # self.clear_aliased_actions
         
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
       25 
25 
     | 
    
         
             
                  # can [:index, :create], Discussion
         
     | 
| 
       26 
26 
     | 
    
         
             
                  # can :read, Discussion do |discussion|
         
     | 
| 
       27 
27 
     | 
    
         
             
                  #   discussion.can_participate?(user)
         
     | 
| 
       28 
28 
     | 
    
         
             
                  # end
         
     | 
| 
       29 
29 
     | 
    
         | 
| 
       30 
30 
     | 
    
         
             
                  #include any abilities registered by extensions, etc.
         
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
       32 
32 
     | 
    
         
             
                  Ability.abilities.each do |clazz|
         
     | 
| 
       33 
33 
     | 
    
         
             
                    ability = clazz.send(:new, user)
         
     | 
| 
       34 
34 
     | 
    
         
             
                    @rules = rules + ability.send(:rules)
         
     | 
    
        data/app/models/message.rb
    CHANGED
    
    | 
         @@ -1,22 +1,21 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            class Message < ActiveRecord::Base
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
              default_scope order(:created_at)
         
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
              belongs_to :discussion, :counter_cache => true
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
              belongs_to :discussion, :counter_cache => true, :touch => true
         
     | 
| 
       6 
6 
     | 
    
         
             
              belongs_to :user
         
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
       8 
8 
     | 
    
         
             
              validates :user, :discussion, :body, :presence => true
         
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
              after_save : 
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
              after_save :mark_discussion_as_read
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
       12 
12 
     | 
    
         
             
              def visible_for? user
         
     | 
| 
       13 
13 
     | 
    
         
             
                self.created_at.to_i >= self.discussion.user_invited_at(user).to_i
         
     | 
| 
       14 
14 
     | 
    
         
             
              end
         
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
       16 
16 
     | 
    
         
             
              private
         
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
              def  
     | 
| 
       19 
     | 
    
         
            -
                self.discussion.touch
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
              def mark_discussion_as_read
         
     | 
| 
       20 
19 
     | 
    
         
             
                self.discussion.mark_as_read_for(self.user)
         
     | 
| 
       21 
20 
     | 
    
         
             
              end
         
     | 
| 
       22 
21 
     | 
    
         
             
            end
         
     | 
    
        data/app/models/speaker.rb
    CHANGED
    
    | 
         @@ -1,16 +1,16 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            class Speaker < ActiveRecord::Base
         
     | 
| 
       2 
2 
     | 
    
         
             
              belongs_to :user
         
     | 
| 
       3 
3 
     | 
    
         
             
              belongs_to :discussion
         
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
       5 
5 
     | 
    
         
             
              validates_uniqueness_of :user_id, :scope => :discussion_id
         
     | 
| 
       6 
6 
     | 
    
         
             
              validates :user, :discussion, :presence => true
         
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
       8 
8 
     | 
    
         
             
              after_destroy :destroy_discussion
         
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
       10 
10 
     | 
    
         
             
              private
         
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
       12 
12 
     | 
    
         
             
              def destroy_discussion
         
     | 
| 
       13 
13 
     | 
    
         
             
                self.discussion.destroy unless self.discussion.speakers.any?
         
     | 
| 
       14 
14 
     | 
    
         
             
              end
         
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
       16 
16 
     | 
    
         
             
            end
         
     | 
| 
         @@ -11,7 +11,10 @@ 
     | 
|
| 
       11 
11 
     | 
    
         
             
                  %td
         
     | 
| 
       12 
12 
     | 
    
         
             
                    = link_to discussion.users.collect{|u| u[Inboxes::config.user_name]}.join(', '), discussion
         
     | 
| 
       13 
13 
     | 
    
         
             
                  %td
         
     | 
| 
       14 
     | 
    
         
            -
                     
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
      
 14 
     | 
    
         
            +
                    - if discussion.unread_for?(current_user)
         
     | 
| 
      
 15 
     | 
    
         
            +
                      = pluralize(discussion.unread_messages_count_for(current_user), "message")
         
     | 
| 
      
 16 
     | 
    
         
            +
                    - else
         
     | 
| 
      
 17 
     | 
    
         
            +
                      No unread messages
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
       16 
19 
     | 
    
         
             
            %p
         
     | 
| 
       17 
     | 
    
         
            -
              = link_to "Create new", new_discussion_path
         
     | 
| 
      
 20 
     | 
    
         
            +
              = link_to "Create new", new_discussion_path
         
     | 
| 
         @@ -16,13 +16,13 @@ 
     | 
|
| 
       16 
16 
     | 
    
         
             
                = f.label :user_id, "Add speaker"
         
     | 
| 
       17 
17 
     | 
    
         
             
                = f.collection_select :user_id, available_users, :id, :name
         
     | 
| 
       18 
18 
     | 
    
         
             
                = f.submit "Add"
         
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
       21 
21 
     | 
    
         
             
            %h3 Messages
         
     | 
| 
       22 
22 
     | 
    
         | 
| 
       23 
23 
     | 
    
         
             
            #messages_box
         
     | 
| 
       24 
24 
     | 
    
         
             
              = render @discussion.messages, :as => :message
         
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
       26 
26 
     | 
    
         
             
            %h3 Add message
         
     | 
| 
       27 
27 
     | 
    
         
             
            = render "inboxes/messages/form"
         
     | 
| 
       28 
28 
     | 
    
         | 
    
        data/config/locales/en.yml
    CHANGED
    
    | 
         @@ -9,7 +9,7 @@ en: 
     | 
|
| 
       9 
9 
     | 
    
         
             
                  removed: "Speaker was removed from discussion"
         
     | 
| 
       10 
10 
     | 
    
         
             
                discussions:
         
     | 
| 
       11 
11 
     | 
    
         
             
                  started: "Discussion started"
         
     | 
| 
       12 
     | 
    
         
            -
                  leaved: "You  
     | 
| 
      
 12 
     | 
    
         
            +
                  leaved: "You leave the discussion"
         
     | 
| 
       13 
13 
     | 
    
         
             
                  exists: "Discussion between you and %{user} already exists"
         
     | 
| 
       14 
14 
     | 
    
         
             
                  can_not_participate: "You are not listed in this discussion"
         
     | 
| 
       15 
15 
     | 
    
         
             
                  choose_at_least_one_recipient: "You should choose at least one recipient of discussion"
         
     | 
    
        data/config/routes.rb
    CHANGED
    
    | 
         @@ -1,5 +1,5 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            Rails.application.routes.draw do
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       3 
3 
     | 
    
         
             
              resources :discussions, :except => :edit, :module => :inboxes do
         
     | 
| 
       4 
4 
     | 
    
         
             
                resources :messages, :only => [:create, :index]
         
     | 
| 
       5 
5 
     | 
    
         
             
                resources :speakers, :only => [:create, :destroy]
         
     | 
| 
         @@ -7,5 +7,5 @@ Rails.application.routes.draw do 
     | 
|
| 
       7 
7 
     | 
    
         
             
                  post 'leave'
         
     | 
| 
       8 
8 
     | 
    
         
             
                end
         
     | 
| 
       9 
9 
     | 
    
         
             
              end
         
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
       11 
11 
     | 
    
         
             
            end
         
     | 
| 
         @@ -5,19 +5,15 @@ module Inboxes 
     | 
|
| 
       5 
5 
     | 
    
         
             
              module Generators
         
     | 
| 
       6 
6 
     | 
    
         
             
                class InstallGenerator < Rails::Generators::Base
         
     | 
| 
       7 
7 
     | 
    
         
             
                  include Rails::Generators::Migration
         
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
       9 
9 
     | 
    
         
             
                  source_root File.expand_path("../templates", __FILE__)
         
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
                   
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                  desc "Generates migration for Inboxes"
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
       13 
13 
     | 
    
         
             
                  def self.orm
         
     | 
| 
       14 
14 
     | 
    
         
             
                    Rails::Generators.options[:rails][:orm]
         
     | 
| 
       15 
15 
     | 
    
         
             
                  end
         
     | 
| 
       16 
16 
     | 
    
         | 
| 
       17 
     | 
    
         
            -
                  # def self.source_root
         
     | 
| 
       18 
     | 
    
         
            -
                    # File.join(File.dirname(__FILE__), 'templates', (orm.to_s unless orm.class.eql?(String)) )
         
     | 
| 
       19 
     | 
    
         
            -
                  # end
         
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
17 
     | 
    
         
             
                  def self.orm_has_migration?
         
     | 
| 
       22 
18 
     | 
    
         
             
                    [:active_record].include? orm
         
     | 
| 
       23 
19 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -2,6 +2,7 @@ class InstallInboxes < ActiveRecord::Migration 
     | 
|
| 
       2 
2 
     | 
    
         
             
              def self.up
         
     | 
| 
       3 
3 
     | 
    
         
             
                create_table :discussions do |t|
         
     | 
| 
       4 
4 
     | 
    
         
             
                  t.integer :messages_count, :default => 0 # counter cache
         
     | 
| 
      
 5 
     | 
    
         
            +
                  t.references :discussable
         
     | 
| 
       5 
6 
     | 
    
         
             
                  t.timestamps
         
     | 
| 
       6 
7 
     | 
    
         
             
                end
         
     | 
| 
       7 
8 
     | 
    
         | 
| 
         @@ -9,14 +10,14 @@ class InstallInboxes < ActiveRecord::Migration 
     | 
|
| 
       9 
10 
     | 
    
         
             
                  t.references :user
         
     | 
| 
       10 
11 
     | 
    
         
             
                  t.references :discussion
         
     | 
| 
       11 
12 
     | 
    
         
             
                  t.text :body
         
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
       13 
14 
     | 
    
         
             
                  t.timestamps
         
     | 
| 
       14 
15 
     | 
    
         
             
                end
         
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
       16 
17 
     | 
    
         
             
                create_table :speakers do |t|
         
     | 
| 
       17 
18 
     | 
    
         
             
                  t.references :user
         
     | 
| 
       18 
19 
     | 
    
         
             
                  t.references :discussion
         
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
       20 
21 
     | 
    
         
             
                  t.timestamps
         
     | 
| 
       21 
22 
     | 
    
         
             
                end
         
     | 
| 
       22 
23 
     | 
    
         
             
              end
         
     | 
| 
         @@ -26,4 +27,4 @@ class InstallInboxes < ActiveRecord::Migration 
     | 
|
| 
       26 
27 
     | 
    
         
             
                drop_table :discussions
         
     | 
| 
       27 
28 
     | 
    
         
             
                drop_table :messages
         
     | 
| 
       28 
29 
     | 
    
         
             
              end
         
     | 
| 
       29 
     | 
    
         
            -
            end
         
     | 
| 
      
 30 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,36 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'rails/generators'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'rails/generators/migration'
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            module Inboxes
         
     | 
| 
      
 5 
     | 
    
         
            +
              module Generators
         
     | 
| 
      
 6 
     | 
    
         
            +
                class UpgradeDiscussibleGenerator < Rails::Generators::Base
         
     | 
| 
      
 7 
     | 
    
         
            +
                  include Rails::Generators::Migration
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
                  source_root File.expand_path("../templates", __FILE__)
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                  desc "Generates migration for Inboxes 0.2.0 update"
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                  def self.orm
         
     | 
| 
      
 14 
     | 
    
         
            +
                    Rails::Generators.options[:rails][:orm]
         
     | 
| 
      
 15 
     | 
    
         
            +
                  end
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                  def self.orm_has_migration?
         
     | 
| 
      
 18 
     | 
    
         
            +
                    [:active_record].include? orm
         
     | 
| 
      
 19 
     | 
    
         
            +
                  end
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                  def self.next_migration_number(dirname)
         
     | 
| 
      
 22 
     | 
    
         
            +
                    if ActiveRecord::Base.timestamped_migrations
         
     | 
| 
      
 23 
     | 
    
         
            +
                      migration_number = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
         
     | 
| 
      
 24 
     | 
    
         
            +
                      migration_number += 1
         
     | 
| 
      
 25 
     | 
    
         
            +
                      migration_number.to_s
         
     | 
| 
      
 26 
     | 
    
         
            +
                    else
         
     | 
| 
      
 27 
     | 
    
         
            +
                      "%.3d" % (current_migration_number(dirname) + 1)
         
     | 
| 
      
 28 
     | 
    
         
            +
                    end
         
     | 
| 
      
 29 
     | 
    
         
            +
                  end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                  def copy_migration
         
     | 
| 
      
 32 
     | 
    
         
            +
                    migration_template 'upgrade_discussible.rb', 'db/migrate/upgrade_discussible_inboxes.rb'
         
     | 
| 
      
 33 
     | 
    
         
            +
                  end
         
     | 
| 
      
 34 
     | 
    
         
            +
                end
         
     | 
| 
      
 35 
     | 
    
         
            +
              end
         
     | 
| 
      
 36 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -5,7 +5,7 @@ module Inboxes 
     | 
|
| 
       5 
5 
     | 
    
         
             
                class ViewsGenerator < Rails::Generators::Base
         
     | 
| 
       6 
6 
     | 
    
         
             
                  source_root File.expand_path('../../../../app/views', __FILE__)
         
     | 
| 
       7 
7 
     | 
    
         
             
                  #class_option :template_engine, :type => :string, :aliases => '-e', :desc => 'Template engine for the views. Available options are "erb" and "haml".'
         
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
       9 
9 
     | 
    
         
             
                  # TODO support of both haml and erb
         
     | 
| 
       10 
10 
     | 
    
         
             
                  def copy_or_fetch
         
     | 
| 
       11 
11 
     | 
    
         
             
                    filename_pattern = File.join self.class.source_root, "*" #/*.html.#{template_engine}"
         
     | 
    
        data/lib/inboxes/ability.rb
    CHANGED
    
    | 
         @@ -13,17 +13,17 @@ module Inboxes 
     | 
|
| 
       13 
13 
     | 
    
         
             
                      discussion.can_participate?(user)
         
     | 
| 
       14 
14 
     | 
    
         
             
                    end
         
     | 
| 
       15 
15 
     | 
    
         
             
                  end
         
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
       17 
17 
     | 
    
         
             
                  # Message
         
     | 
| 
       18 
18 
     | 
    
         
             
                  # can :create, Message do |message|
         
     | 
| 
       19 
19 
     | 
    
         
             
                  #   message.discussion.can_participate?(user)
         
     | 
| 
       20 
20 
     | 
    
         
             
                  # end
         
     | 
| 
       21 
     | 
    
         
            -
                  # 
     | 
| 
      
 21 
     | 
    
         
            +
                  #
         
     | 
| 
       22 
22 
     | 
    
         
             
                  # # Speaker
         
     | 
| 
       23 
23 
     | 
    
         
             
                  # can [:create, :destroy], Speaker do |speaker|
         
     | 
| 
       24 
24 
     | 
    
         
             
                  #   speaker.discussion.can_participate?(user)
         
     | 
| 
       25 
25 
     | 
    
         
             
                  # end
         
     | 
| 
       26 
26 
     | 
    
         
             
                end
         
     | 
| 
       27 
27 
     | 
    
         
             
              end
         
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
       29 
29 
     | 
    
         
             
            end
         
     | 
| 
         @@ -3,9 +3,9 @@ module Inboxes 
     | 
|
| 
       3 
3 
     | 
    
         
             
                def has_inboxes(options = {})
         
     | 
| 
       4 
4 
     | 
    
         
             
                  # field  = options[:as]     || name
         
     | 
| 
       5 
5 
     | 
    
         
             
                  # prefix = options[:prefix] || "with"
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
       7 
7 
     | 
    
         
             
                  has_many :speakers, :dependent => :destroy
         
     | 
| 
       8 
     | 
    
         
            -
                  has_many :discussions, :through => :speakers
         
     | 
| 
      
 8 
     | 
    
         
            +
                  has_many :discussions, :as => :discussable, :through => :speakers
         
     | 
| 
       9 
9 
     | 
    
         
             
                end
         
     | 
| 
       10 
10 
     | 
    
         
             
              end
         
     | 
| 
       11 
     | 
    
         
            -
            end
         
     | 
| 
      
 11 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/inboxes/engine.rb
    CHANGED
    
    
    
        data/lib/inboxes/railtie.rb
    CHANGED
    
    | 
         @@ -4,7 +4,7 @@ require "inboxes/ability" 
     | 
|
| 
       4 
4 
     | 
    
         
             
            module Inboxes
         
     | 
| 
       5 
5 
     | 
    
         
             
              class Railtie < ::Rails::Railtie
         
     | 
| 
       6 
6 
     | 
    
         
             
                config.inboxes = ActiveSupport::OrderedOptions.new
         
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
       8 
8 
     | 
    
         
             
                initializer "inboxes.configure" do |app|
         
     | 
| 
       9 
9 
     | 
    
         
             
                  Inboxes.configure do |config|
         
     | 
| 
       10 
10 
     | 
    
         
             
                    config.user_name = app.config.inboxes[:user_name] || "email"
         
     | 
| 
         @@ -15,7 +15,7 @@ module Inboxes 
     | 
|
| 
       15 
15 
     | 
    
         | 
| 
       16 
16 
     | 
    
         
             
                  # app.config.middleware.insert_before "::Rails::Rack::Logger", "Inboxes::Middleware"
         
     | 
| 
       17 
17 
     | 
    
         
             
                end
         
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
       19 
19 
     | 
    
         
             
                # def self.activate
         
     | 
| 
       20 
20 
     | 
    
         
             
                #   Ability.register_ability(InboxesAbility)
         
     | 
| 
       21 
21 
     | 
    
         
             
                # end
         
     | 
    
        data/lib/inboxes/version.rb
    CHANGED
    
    
    
        data/lib/inboxes.rb
    CHANGED
    
    | 
         @@ -6,7 +6,7 @@ require "inboxes/active_record_extension" 
     | 
|
| 
       6 
6 
     | 
    
         | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
8 
     | 
    
         
             
            module Inboxes
         
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
       10 
10 
     | 
    
         
             
              def self.configure(&block)
         
     | 
| 
       11 
11 
     | 
    
         
             
                yield @config ||= Inboxes::Configuration.new
         
     | 
| 
       12 
12 
     | 
    
         
             
              end
         
     | 
| 
         @@ -25,11 +25,11 @@ module Inboxes 
     | 
|
| 
       25 
25 
     | 
    
         
             
                config_accessor :faye_enabled
         
     | 
| 
       26 
26 
     | 
    
         | 
| 
       27 
27 
     | 
    
         
             
                def param_name
         
     | 
| 
       28 
     | 
    
         
            -
                  config.param_name.respond_to?(:call) ? config.param_name.call() : config.param_name 
     | 
| 
      
 28 
     | 
    
         
            +
                  config.param_name.respond_to?(:call) ? config.param_name.call() : config.param_name
         
     | 
| 
       29 
29 
     | 
    
         
             
                end
         
     | 
| 
       30 
30 
     | 
    
         
             
              end
         
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
       32 
32 
     | 
    
         
             
              # adding method inboxes for models
         
     | 
| 
       33 
33 
     | 
    
         
             
              ActiveRecord::Base.extend(Inboxes::ActiveRecordExtension)
         
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
       35 
35 
     | 
    
         
             
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,60 +1,45 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            --- !ruby/object:Gem::Specification 
     | 
| 
      
 1 
     | 
    
         
            +
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: inboxes
         
     | 
| 
       3 
     | 
    
         
            -
            version: !ruby/object:Gem::Version 
     | 
| 
       4 
     | 
    
         
            -
               
     | 
| 
      
 3 
     | 
    
         
            +
            version: !ruby/object:Gem::Version
         
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.2.0
         
     | 
| 
       5 
5 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       6 
     | 
    
         
            -
              segments: 
         
     | 
| 
       7 
     | 
    
         
            -
              - 0
         
     | 
| 
       8 
     | 
    
         
            -
              - 1
         
     | 
| 
       9 
     | 
    
         
            -
              - 5
         
     | 
| 
       10 
     | 
    
         
            -
              version: 0.1.5
         
     | 
| 
       11 
6 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       12 
     | 
    
         
            -
            authors: 
     | 
| 
      
 7 
     | 
    
         
            +
            authors:
         
     | 
| 
       13 
8 
     | 
    
         
             
            - Kir Shatrov
         
     | 
| 
       14 
9 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       15 
10 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       16 
11 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
            - !ruby/object:Gem::Dependency 
         
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2012-01-17 00:00:00.000000000 Z
         
     | 
| 
      
 13 
     | 
    
         
            +
            dependencies:
         
     | 
| 
      
 14 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
       21 
15 
     | 
    
         
             
              name: haml-rails
         
     | 
| 
       22 
     | 
    
         
            -
               
     | 
| 
       23 
     | 
    
         
            -
              requirement: &id001 !ruby/object:Gem::Requirement 
         
     | 
| 
      
 16 
     | 
    
         
            +
              requirement: &70128130356540 !ruby/object:Gem::Requirement
         
     | 
| 
       24 
17 
     | 
    
         
             
                none: false
         
     | 
| 
       25 
     | 
    
         
            -
                requirements: 
     | 
| 
       26 
     | 
    
         
            -
                - -  
     | 
| 
       27 
     | 
    
         
            -
                  - !ruby/object:Gem::Version 
     | 
| 
       28 
     | 
    
         
            -
                     
     | 
| 
       29 
     | 
    
         
            -
                    segments: 
         
     | 
| 
       30 
     | 
    
         
            -
                    - 0
         
     | 
| 
       31 
     | 
    
         
            -
                    version: "0"
         
     | 
| 
      
 18 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 19 
     | 
    
         
            +
                - - ! '>='
         
     | 
| 
      
 20 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 21 
     | 
    
         
            +
                    version: '0'
         
     | 
| 
       32 
22 
     | 
    
         
             
              type: :runtime
         
     | 
| 
       33 
     | 
    
         
            -
              version_requirements: *id001
         
     | 
| 
       34 
     | 
    
         
            -
            - !ruby/object:Gem::Dependency 
         
     | 
| 
       35 
     | 
    
         
            -
              name: cancan
         
     | 
| 
       36 
23 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       37 
     | 
    
         
            -
               
     | 
| 
      
 24 
     | 
    
         
            +
              version_requirements: *70128130356540
         
     | 
| 
      
 25 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 26 
     | 
    
         
            +
              name: cancan
         
     | 
| 
      
 27 
     | 
    
         
            +
              requirement: &70128130355760 !ruby/object:Gem::Requirement
         
     | 
| 
       38 
28 
     | 
    
         
             
                none: false
         
     | 
| 
       39 
     | 
    
         
            -
                requirements: 
     | 
| 
       40 
     | 
    
         
            -
                - -  
     | 
| 
       41 
     | 
    
         
            -
                  - !ruby/object:Gem::Version 
     | 
| 
       42 
     | 
    
         
            -
                     
     | 
| 
       43 
     | 
    
         
            -
                    segments: 
         
     | 
| 
       44 
     | 
    
         
            -
                    - 0
         
     | 
| 
       45 
     | 
    
         
            -
                    version: "0"
         
     | 
| 
      
 29 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 30 
     | 
    
         
            +
                - - ! '>='
         
     | 
| 
      
 31 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 32 
     | 
    
         
            +
                    version: '0'
         
     | 
| 
       46 
33 
     | 
    
         
             
              type: :runtime
         
     | 
| 
       47 
     | 
    
         
            -
               
     | 
| 
      
 34 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 35 
     | 
    
         
            +
              version_requirements: *70128130355760
         
     | 
| 
       48 
36 
     | 
    
         
             
            description: Messaging system for Rails 3 app
         
     | 
| 
       49 
     | 
    
         
            -
            email: 
     | 
| 
      
 37 
     | 
    
         
            +
            email:
         
     | 
| 
       50 
38 
     | 
    
         
             
            - shatrov@me.com
         
     | 
| 
       51 
39 
     | 
    
         
             
            executables: []
         
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
40 
     | 
    
         
             
            extensions: []
         
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
41 
     | 
    
         
             
            extra_rdoc_files: []
         
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
            files: 
         
     | 
| 
      
 42 
     | 
    
         
            +
            files:
         
     | 
| 
       58 
43 
     | 
    
         
             
            - .gitignore
         
     | 
| 
       59 
44 
     | 
    
         
             
            - Gemfile
         
     | 
| 
       60 
45 
     | 
    
         
             
            - README.md
         
     | 
| 
         @@ -80,6 +65,8 @@ files: 
     | 
|
| 
       80 
65 
     | 
    
         
             
            - inboxes.gemspec
         
     | 
| 
       81 
66 
     | 
    
         
             
            - lib/generators/inboxes/install_generator.rb
         
     | 
| 
       82 
67 
     | 
    
         
             
            - lib/generators/inboxes/templates/install.rb
         
     | 
| 
      
 68 
     | 
    
         
            +
            - lib/generators/inboxes/templates/upgrade_discussible.rb
         
     | 
| 
      
 69 
     | 
    
         
            +
            - lib/generators/inboxes/upgrade_discussible_generator.rb
         
     | 
| 
       83 
70 
     | 
    
         
             
            - lib/generators/inboxes/views_generator.rb
         
     | 
| 
       84 
71 
     | 
    
         
             
            - lib/inboxes.rb
         
     | 
| 
       85 
72 
     | 
    
         
             
            - lib/inboxes/ability.rb
         
     | 
| 
         @@ -91,36 +78,26 @@ files: 
     | 
|
| 
       91 
78 
     | 
    
         
             
            - vendor/assets/javascripts/inboxes/faye/init.js.coffee
         
     | 
| 
       92 
79 
     | 
    
         
             
            homepage: http://evrone.com/
         
     | 
| 
       93 
80 
     | 
    
         
             
            licenses: []
         
     | 
| 
       94 
     | 
    
         
            -
             
     | 
| 
       95 
81 
     | 
    
         
             
            post_install_message: 
         
     | 
| 
       96 
82 
     | 
    
         
             
            rdoc_options: []
         
     | 
| 
       97 
     | 
    
         
            -
             
     | 
| 
       98 
     | 
    
         
            -
            require_paths: 
         
     | 
| 
      
 83 
     | 
    
         
            +
            require_paths:
         
     | 
| 
       99 
84 
     | 
    
         
             
            - lib
         
     | 
| 
       100 
     | 
    
         
            -
            required_ruby_version: !ruby/object:Gem::Requirement 
     | 
| 
      
 85 
     | 
    
         
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         
     | 
| 
       101 
86 
     | 
    
         
             
              none: false
         
     | 
| 
       102 
     | 
    
         
            -
              requirements: 
     | 
| 
       103 
     | 
    
         
            -
              - -  
     | 
| 
       104 
     | 
    
         
            -
                - !ruby/object:Gem::Version 
     | 
| 
       105 
     | 
    
         
            -
                   
     | 
| 
       106 
     | 
    
         
            -
             
     | 
| 
       107 
     | 
    
         
            -
                  - 0
         
     | 
| 
       108 
     | 
    
         
            -
                  version: "0"
         
     | 
| 
       109 
     | 
    
         
            -
            required_rubygems_version: !ruby/object:Gem::Requirement 
         
     | 
| 
      
 87 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 88 
     | 
    
         
            +
              - - ! '>='
         
     | 
| 
      
 89 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 90 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 91 
     | 
    
         
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
       110 
92 
     | 
    
         
             
              none: false
         
     | 
| 
       111 
     | 
    
         
            -
              requirements: 
     | 
| 
       112 
     | 
    
         
            -
              - -  
     | 
| 
       113 
     | 
    
         
            -
                - !ruby/object:Gem::Version 
     | 
| 
       114 
     | 
    
         
            -
                   
     | 
| 
       115 
     | 
    
         
            -
                  segments: 
         
     | 
| 
       116 
     | 
    
         
            -
                  - 0
         
     | 
| 
       117 
     | 
    
         
            -
                  version: "0"
         
     | 
| 
      
 93 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 94 
     | 
    
         
            +
              - - ! '>='
         
     | 
| 
      
 95 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 96 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
       118 
97 
     | 
    
         
             
            requirements: []
         
     | 
| 
       119 
     | 
    
         
            -
             
     | 
| 
       120 
98 
     | 
    
         
             
            rubyforge_project: inboxes
         
     | 
| 
       121 
     | 
    
         
            -
            rubygems_version: 1.8. 
     | 
| 
      
 99 
     | 
    
         
            +
            rubygems_version: 1.8.10
         
     | 
| 
       122 
100 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       123 
101 
     | 
    
         
             
            specification_version: 3
         
     | 
| 
       124 
102 
     | 
    
         
             
            summary: Messaging system for Rails 3 app
         
     | 
| 
       125 
103 
     | 
    
         
             
            test_files: []
         
     | 
| 
       126 
     | 
    
         
            -
             
     |