diff options
| author | Kir | 2011-11-11 18:51:52 +0400 | 
|---|---|---|
| committer | Kir | 2011-11-11 18:51:52 +0400 | 
| commit | 61bd4dd67fdaee93af6994d539b86d46cd1c45f1 (patch) | |
| tree | 6e8a9d85aa372a98f32083a3968a9f9aefe2b3a3 | |
| parent | a9c97ba576f190c18544919af477753c419036cf (diff) | |
| download | inboxes-61bd4dd67fdaee93af6994d539b86d46cd1c45f1.tar.bz2 | |
Model updated, readme fixes
| -rw-r--r-- | README.md | 18 | ||||
| -rw-r--r-- | app/controllers/discussions_controller.rb | 2 | ||||
| -rw-r--r-- | app/models/discussion.rb | 20 | ||||
| -rw-r--r-- | app/models/discussion_view.rb | 7 | ||||
| -rw-r--r-- | app/models/speaker.rb | 6 | ||||
| -rw-r--r-- | config/locales/en.yml | 3 | ||||
| -rw-r--r-- | config/locales/ru.yml | 1 | ||||
| -rw-r--r-- | lib/generators/inboxes/templates/install.rb | 7 | 
8 files changed, 22 insertions, 42 deletions
| @@ -8,27 +8,27 @@ Inboxes is a young messaging system for Rails app. It:  ##Requirements and recommendations -Inboxes requires Rails 3.x and [Devise](https://github.com/plataformatec/devise) for user identification (surely, messaging system is not possible without users). +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. -We recommend to use Inboxes with [Faye](https://github.com/jcoglan/faye), because it's really useful with it. +We recommend to use Inboxes with [Faye](https://github.com/jcoglan/faye), because it's really sexy with it. -Remember that unfortunately, Inboxes reserve 3 model names: Discussion, DiscussionView, Message and Speaker and 2 controller names: Messages and Discussions. +Remember that unfortunately, Inboxes reserve 3 resources names: Discussion, Message and Speaker.  ##Installation  *Make sure that Devise is already installed and configured!* -1. Add `gem "inboxes", :git => git://github.com/kirs/inboxes.git` to your `Gemfile` and run `bundle install` -2. Run `rails generate inboxes:install`. This command will generate migration for messaging system. Don't forget to run migrations: `rake db:migrate` +1. Add `gem "inboxes"` to your `Gemfile` and run `bundle install` +2. Execute `rails generate inboxes:install`. This command will generate migration for messaging system. Don't forget to run migrations: `rake db:migrate`  3. Add `inboxes` to your User model like [here](https://gist.github.com/1330080) -4. Now Inboxes is ready to use. Open `http://yoursite.dev/discussions` to show discussions list. You can start new one. +4. Now Inboxes is ready to use. Open `http://yoursite.dev/discussions` to see the list of discussions. You can start new one. -Default Inboxes views are ugly, so you can copy it to your app and make anything with them: `rails generate inboxes:views` -If you have problems with installation if gem, you can check [demo app code](https://github.com/kirs/inboxes-app) +Default Inboxes views are ugly, so you can copy into your app and make anything with them: `rails generate inboxes:views` +If you have problems with installation, you can check [code of demo app](https://github.com/kirs/inboxes-app)  ## I18n -By default, this gem provides localized phrases for Russian and English languages. You can easily override any of them. [Here is](https://github.com/kirs/inboxes/blob/master/config/locales/en.yml) list of all I18n phrases. +By default, the gem provides localized phrases for Russian and English languages. You can easily override any of them. [Here is](https://github.com/kirs/inboxes/blob/master/config/locales/en.yml) list of all I18n phrases.  ##Todo diff --git a/app/controllers/discussions_controller.rb b/app/controllers/discussions_controller.rb index 48f6652..5e769fb 100644 --- a/app/controllers/discussions_controller.rb +++ b/app/controllers/discussions_controller.rb @@ -14,7 +14,7 @@ class DiscussionsController < ApplicationController      @discussion = Discussion.includes(:messages, :speakers).find(params[:id])      redirect_to discussions_url, :notice => t("inboxes.discussions.can_not_participate") unless @discussion.can_participate?(current_user) -    @discussion.mark_as_read_for(current_user) +    # @discussion.mark_as_read_for(current_user)    end    # GET /discussions/new diff --git a/app/models/discussion.rb b/app/models/discussion.rb index 7cab6f0..aa4ce3e 100644 --- a/app/models/discussion.rb +++ b/app/models/discussion.rb @@ -13,11 +13,10 @@ class Discussion < ActiveRecord::Base    has_many :users, :through => :speakers    # отметки о прочтении юзеров -  has_many :views, :dependent => :destroy, :class_name => "DiscussionView"    scope :unread_for, (lambda do |user_or_user_id|      user = user_or_user_id.is_a?(User) ? user_or_user_id.id : user_or_user_id -    joins(:views, :speakers).where("discussions.updated_at >= discussion_views.updated_at AND speakers.user_id = ? AND discussion_views.user_id = ?", user, user) +    joins(:speakers).where("discussions.updated_at >= speakers.updated_at AND speakers.user_id = ?", user)    end)    accepts_nested_attributes_for :messages @@ -26,7 +25,7 @@ class Discussion < ActiveRecord::Base    # добавляем записи об указанных собеседников    after_save(:on => :create) do -    Rails.logger.info("Repicients ids: #{recipient_ids.inspect}") +    # Rails.logger.info("Repicients ids: #{recipient_ids.inspect}")      if recipient_ids.kind_of?(Array)        recipient_ids.uniq! @@ -89,9 +88,9 @@ class Discussion < ActiveRecord::Base    # проверка, является ли дискуссия непрочитанной для пользователя    def unread_for?(user) -    flag = self.views.find_by_user_id(user.id) -    if flag -      self.updated_at >= flag.updated_at +    speaker = find_speaker_by_user(user) +    if speaker +      self.updated_at >= speaker.updated_at      else        true      end @@ -99,9 +98,9 @@ class Discussion < ActiveRecord::Base    # пометить как прочитанная    def mark_as_read_for(user) -    # true -    flag = DiscussionView.find_or_create_by_user_id_and_discussion_id(user.id, self.id) -    flag.touch +    speaker = Speaker.find_or_create_by_user_id_and_discussion_id(user.id, self.id) +    # flag.update_attributes(:updat => Time.zone.now) +    speaker.touch    end    def find_speaker_by_user user @@ -111,8 +110,7 @@ class Discussion < ActiveRecord::Base    private    def check_that_has_at_least_two_users -    Rails.logger.info self.recipient_ids -    errors.add :recipient_tokens, "Укажите хотя бы одного получателя" if !self.recipient_ids || self.recipient_ids.size < 2 +    errors.add :recipient_tokens, t("inboxes.discussions.choose_at_least_one_recipient") if !self.recipient_ids || self.recipient_ids.size < 2    end  end
\ No newline at end of file diff --git a/app/models/discussion_view.rb b/app/models/discussion_view.rb deleted file mode 100644 index 5714bb5..0000000 --- a/app/models/discussion_view.rb +++ /dev/null @@ -1,7 +0,0 @@ -class DiscussionView < ActiveRecord::Base -  belongs_to :user -  belongs_to :discussion -   -  validates :user, :discussion, :presence => true -  validates_uniqueness_of :user_id, :scope => :discussion_id -end diff --git a/app/models/speaker.rb b/app/models/speaker.rb index 86be7dc..0ed9cdd 100644 --- a/app/models/speaker.rb +++ b/app/models/speaker.rb @@ -5,16 +5,10 @@ class Speaker < ActiveRecord::Base    validates_uniqueness_of :user_id, :scope => :discussion_id    validates :user, :discussion, :presence => true -  after_destroy :destroy_discussion_view    after_destroy :destroy_discussion    private -  def destroy_discussion_view -    @view = DiscussionView.find_by_user_id_and_discussion_id(self.user_id, self.discussion_id) -    @view.destroy if @view -  end -      def destroy_discussion      self.discussion.destroy unless self.discussion.speakers.any?    end diff --git a/config/locales/en.yml b/config/locales/en.yml index e7013f5..3bcda3c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -11,4 +11,5 @@ en:        started: "Discussion started"        leaved: "You leaved the discussion"        exists: "Discussion between you and %{user} already exists" -      can_not_participate: "You are not listed in this discussion"
\ No newline at end of file +      can_not_participate: "You are not listed in this discussion" +      choose_at_least_one_recipient: "You should choose at least one recipient of discussion"
\ No newline at end of file diff --git a/config/locales/ru.yml b/config/locales/ru.yml index f0e4f04..7bcbbef 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -11,6 +11,7 @@ ru:        leaved: "Вы покинули дискуссию"        exists: "Дискуссия между вами и %{user} уже существует"        can_not_participate: "Вы не состоите в этой дискуссии" +      choose_at_least_one_recipient: "Укажите хотя бы одного получателя"      speakers:        added: "Участник дискуссии добавлен"        removed: "Участник дискуссии удален"
\ No newline at end of file diff --git a/lib/generators/inboxes/templates/install.rb b/lib/generators/inboxes/templates/install.rb index ff83b40..91fded7 100644 --- a/lib/generators/inboxes/templates/install.rb +++ b/lib/generators/inboxes/templates/install.rb @@ -1,11 +1,5 @@  class InstallInboxes < ActiveRecord::Migration    def self.up -    create_table :discussion_views do |t| -      t.references :user -      t.references :discussion -      t.timestamps -    end -      create_table :discussions do |t|        t.integer :messages_count, :default => 0 # counter cache        t.timestamps @@ -30,7 +24,6 @@ class InstallInboxes < ActiveRecord::Migration    def self.down      drop_table :speakers      drop_table :discussions -    drop_table :discussion_views      drop_table :messages    end  end
\ No newline at end of file | 
