Permalink
Browse files

SOC-13 & SOC-14 starting to work with messages. Can send and receive …

…messages to specific users from profile pages
  • Loading branch information...
1 parent 09e3634 commit 9cad976a510eb0c85a0f65fc532a63eca6367e0d Eric Ryan Jones committed Nov 16, 2013
View
@@ -14,7 +14,8 @@ gem "simple_form", ">= 2.1.0"
gem "country_select", "~> 1.1.3"
gem "figaro", ">= 0.5.0"
gem "acts-as-taggable-on", ">= 2.4.1"
-gem "friendly_id", "~> 4.0.9"
+gem "friendly_id", "~> 4.0.10.1"
+gem "acts-as-messageable", "~> 0.4.8"
group :assets do
gem 'sass-rails', '~> 3.2.3'
View
@@ -28,13 +28,20 @@ GEM
activesupport (3.2.13)
i18n (= 0.6.1)
multi_json (~> 1.0)
+ acts-as-messageable (0.4.8)
+ activerecord (>= 3.0.0)
+ activesupport (>= 3.0.0)
+ ancestry (~> 1.3.0)
+ railties (>= 3.0.0)
acts-as-taggable-on (2.4.1)
rails (>= 3, < 5)
acts_as_commentable_with_threading (1.1.3)
activerecord (>= 3.0)
activesupport (~> 3.0)
awesome_nested_set (>= 2.0)
addressable (2.3.4)
+ ancestry (1.3.0)
+ activerecord (>= 2.3.14)
arel (3.0.2)
awesome_nested_set (2.1.6)
activerecord (>= 3.0.0)
@@ -95,7 +102,8 @@ GEM
figaro (0.6.4)
bundler (~> 1.0)
rails (>= 3, < 5)
- friendly_id (4.0.9)
+ friendly_id (4.0.10.1)
+ activerecord (>= 3.0, < 4.0)
geocoder (1.1.8)
gherkin (2.12.0)
multi_json (~> 1.3)
@@ -189,6 +197,7 @@ PLATFORMS
ruby
DEPENDENCIES
+ acts-as-messageable (~> 0.4.8)
acts-as-taggable-on (>= 2.4.1)
acts_as_commentable_with_threading
better_errors (>= 0.2.0)
@@ -204,7 +213,7 @@ DEPENDENCIES
email_spec (>= 1.4.0)
factory_girl_rails (>= 4.1.0)
figaro (>= 0.5.0)
- friendly_id (~> 4.0.9)
+ friendly_id (~> 4.0.10.1)
geocoder
jquery-rails
launchy (>= 2.1.2)
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
@@ -0,0 +1,3 @@
+// Place all the styles related to the messages controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
@@ -3,7 +3,7 @@ class DashboardController < ApplicationController
def index
@my_topics = Topic.find_all_by_user_id(current_user.id)
-
+ @myNearGuides = current_user.nearbys(15)
if params[:search].present?
@user_search = User.near(params[:search], 50, :order => :distance)
else
@@ -0,0 +1,31 @@
+class MessagesController < ApplicationController
+ def index
+ @messages = current_user.received_messages
+ end
+
+ def outbox
+ @messages = current_user.sent_messages
+ end
+
+ def show
+ @message = current_user.messages.find(params[:id])
+ end
+
+ def destroy
+ @message = current_user.messages.find(params[:id])
+ if @message.destroy
+ flash[:notice] = "All ok"
+ else
+ flash[:error] = "Fail"
+ end
+ end
+
+ def new
+ @message = ActsAsMessageable::Message.new
+ end
+
+ def create
+ @to = User.find_by_id(params[:message][:to])
+ current_user.send_message(@to, params[:message][:topic], params[:message][:body])
+ end
+end
@@ -8,6 +8,7 @@ def index
def show
@user = User.find(params[:id])
+ @message = ActsAsMessageable::Message.new
end
def update
@@ -0,0 +1,2 @@
+module MessagesHelper
+end
View
@@ -7,6 +7,7 @@ class User < ActiveRecord::Base
acts_as_tagger
acts_as_taggable
acts_as_taggable_on :interest
+ acts_as_messageable :dependent => :destroy, :group_messages => true
after_validation :geocode, :if => :address_changed?
@@ -28,25 +28,31 @@
</div>
<div class="row-fluid">
<div class="span12">
+ <% if @myNearGuides.count() > 0 %>
+ <h3>Guides within 15 miles of you:</h3>
+ <% for guides in @myNearGuides %>
+ <li><%= link_to guides.name, guides %> (<%= guides.distance.round(2) %> miles)</li>
+ <% end %>
+ <% end %>
<div class="user-search-form">
- <h3>Search for Users</h3>
+ <h3>Search for Guides</h3>
<%= form_tag '', :method => :get do %>
<p>
<%= text_field_tag :search, params[:search] %>
<%= submit_tag "Search Near", :name => nil %>
</p>
<% end %>
<% if params[:search].present? %>
- <h3>Nearby guides</h3>
- <ul class="guideSearchResults">
- <% if @user_search.count() > 0 %>
- <% for guides in @user_search %>
- <li><%= link_to guides.address, guides %> (<%= guides.distance.round(2) %> miles)</li>
- <% end %>
- <% else %>
- <li class="noneFound">Sorry <%= @user_search.count() %> guides could be found at this time.</li>
- <% end %>
- </ul>
+ <h3>Nearby guides</h3>
+ <ul class="guideSearchResults">
+ <% if @user_search.count() > 0 %>
+ <% for guides in @user_search %>
+ <li><%= link_to guides.name, guides %> (<%= guides.distance.round(2) %> miles)</li>
+ <% end %>
+ <% else %>
+ <li class="noneFound">Sorry <%= @user_search.count() %> guides could be found at this time.</li>
+ <% end %>
+ </ul>
<% end %>
</div>
</div>
@@ -0,0 +1,10 @@
+<% if @messages.count > 0 %>
+ <div class="message" id="message-#{message.id}">
+ <hr>
+ <%= link_to "×", message_path(message), :method => :delete, :remote => true, :confirm => "Are you sure you want to remove this message?", :disable_with => "×", :class => 'close' %>
+ <h4 class="messageTopic"><%= message.topic %></h4>
+ <div class="messageBody"><%= message.body %></div>
+ </div>
+<% else %>
+ <div class="noMessages">No messages sent.</div>
+<% end %>
@@ -0,0 +1,10 @@
+<% if @messages.count > 0 %>
+ <div class="message" id="message-#{message.id}">
+ <hr>
+ <%= link_to "×", message_path(message), :method => :delete, :remote => true, :confirm => "Are you sure you want to remove this message?", :disable_with => "×", :class => 'close' %>
+ <h4 class="messageTopic"><%= message.topic %></h4>
+ <div class="messageBody"><%= message.body %></div>
+ </div>
+<% else %>
+ <div class="noMessages">No messages received.</div>
+<% end %>
@@ -0,0 +1 @@
+<h1>Message Created!</h1>
@@ -0,0 +1,5 @@
+<h1>Messages</h1>
+<h2>Recieved Messages</h2>
+<div class="messagesOutbox">
+ <%= render :partial => 'messages/recieved', :collection => @messages, :as => :message %>
+</div>
@@ -0,0 +1,3 @@
+<div class="messagesOutbox">
+ <%= render :partial => 'messages/outbox', :collection => @messages, :as => :message %>
+</div>
@@ -0,0 +1,6 @@
+<%= simple_form_for :message, :url => messages_path, :method => :post do |f| %>
+ <%= f.input :topic %>
+ <%= f.input :body %>
+ <%= f.input :to, as: :hidden, input_html: { value: @user.id }%>
+ <%= f.button :submit %>
+<% end %>
@@ -1,3 +1,6 @@
-<h3>User</h3>
+<h2>User</h2>
<p>User: <%= @user.name %></p>
-<p>Email: <%= @user.email if @user.email %></p>
+<p>Email: <%= @user.email if @user.email %></p>
+<p>Address: <%= @user.address if @user.address %></p>
+<h3>Send Me A Message</h3>
+<%= render "users/form", :locals => { :message => @message } %>
@@ -4,5 +4,5 @@
# Dynamic shortcuts for User class (user.is_admin? like methods). Default is: false
# Enable this feature _after_ running rake db:migrate as it relies on the roles table
- # config.use_dynamic_shortcuts
+ config.use_dynamic_shortcuts
end
View
@@ -8,13 +8,18 @@
root :to => "home#index"
+ get "messages/recieved" => "messages#recieved", :as => :messages
+ get "messages/outbox" => "messages#outbox", :as => :messages
+ get "messages/outbox" => "messages#destroy", :as => :messages
+ get "topics/keywords" => "topics#keywords", :as => :keywords
+
resources :users
resources :topics
resources :comments, :only => [:create, :destroy]
resources :dashboard
resources :tags
+ resources :messages
- get "topics/keywords" => "topics#keywords", :as => :keywords
end
@@ -0,0 +1,24 @@
+class CreateMessagesTable < ActiveRecord::Migration
+ def self.up
+ create_table :messages do |t|
+ t.string :topic
+ t.text :body
+ t.references :received_messageable, :polymorphic => true
+ t.references :sent_messageable, :polymorphic => true
+ t.boolean :opened, :default => false
+ t.boolean :recipient_delete, :default => false
+ t.boolean :sender_delete, :default => false
+ t.timestamps
+
+ # ancestry
+ t.string :ancestry
+ end
+
+ add_index :messages, [:sent_messageable_id, :received_messageable_id], :name => "acts_as_messageable_ids"
+ add_index :messages, :ancestry
+ end
+
+ def self.down
+ drop_table :messages
+ end
+end
@@ -0,0 +1,11 @@
+class AddRecipientPermanentDeleteAndSenderPermanentDeleteToMessages < ActiveRecord::Migration
+ def self.up
+ add_column :messages, :recipient_permanent_delete, :boolean, :default => false
+ add_column :messages, :sender_permanent_delete, :boolean, :default => false
+ end
+
+ def self.down
+ remove_column :messages, :recipient_permanent_delete
+ remove_column :messages, :sender_permanent_delete
+ end
+end
View
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20130727194240) do
+ActiveRecord::Schema.define(:version => 20131026002220) do
create_table "comments", :force => true do |t|
t.integer "commentable_id", :default => 0
@@ -30,6 +30,26 @@
add_index "comments", ["commentable_id", "commentable_type"], :name => "index_comments_on_commentable_id_and_commentable_type"
add_index "comments", ["user_id"], :name => "index_comments_on_user_id"
+ create_table "messages", :force => true do |t|
+ t.string "topic"
+ t.text "body"
+ t.integer "received_messageable_id"
+ t.string "received_messageable_type"
+ t.integer "sent_messageable_id"
+ t.string "sent_messageable_type"
+ t.boolean "opened", :default => false
+ t.boolean "recipient_delete", :default => false
+ t.boolean "sender_delete", :default => false
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ t.string "ancestry"
+ t.boolean "recipient_permanent_delete", :default => false
+ t.boolean "sender_permanent_delete", :default => false
+ end
+
+ add_index "messages", ["ancestry"], :name => "index_messages_on_ancestry"
+ add_index "messages", ["sent_messageable_id", "received_messageable_id"], :name => "acts_as_messageable_ids"
+
create_table "roles", :force => true do |t|
t.string "name"
t.integer "resource_id"
@@ -0,0 +1,5 @@
+require 'spec_helper'
+
+describe MessagesController do
+
+end
@@ -0,0 +1,15 @@
+require 'spec_helper'
+
+# Specs in this file have access to a helper object that includes
+# the MessagesHelper. For example:
+#
+# describe MessagesHelper do
+# describe "string concat" do
+# it "concats two strings with spaces" do
+# helper.concat_strings("this","that").should == "this that"
+# end
+# end
+# end
+describe MessagesHelper do
+ pending "add some examples to (or delete) #{__FILE__}"
+end

0 comments on commit 9cad976

Please sign in to comment.