messaging stuff

This commit is contained in:
Nick Black 2007-05-05 12:29:44 +00:00
parent 20ae3232cd
commit 078301a780
7 changed files with 76 additions and 15 deletions

View file

@ -1,2 +1,25 @@
class MessageController < ApplicationController
layout 'site'
# before_filter :authorize
before_filter :authorize_web
before_filter :require_user
def new
if params[:message]
body = params[:message][:body]
title = params[:message][:title]
message = Message.new
message.body = body
message.title = title
message.to_user_id = User.find_by_display_name(params[:display_name]).id
message.from_user_id = @user.id
message.sent_on = Time.now
if message.save
flash[:notice] = 'Message sent'
else
@message.errors.add("Sending message failed")
end
end
end
end

View file

@ -53,7 +53,7 @@ class UserController < ApplicationController
end
def lost_password
if params['user']['email']
if params[:user][:email]
user = User.find_by_email(params['user']['email'])
if user
user.token = User.make_token
@ -162,15 +162,10 @@ class UserController < ApplicationController
def diary
@this_user = User.find_by_display_name(params[:display_name])
end
def contact_others(user_id, message_body)
@to = User.find_by_id(user_id)
@to.messages.new = body
if @to.save
flash[:notice] = Message sent
def make_friend
if params[:display_name]
end
#Send a message to other users - maybe there's a rails messaging plugin
end
end

View file

@ -1,2 +1,3 @@
class Message < ActiveRecord::Base
belongs_to :user
end

View file

@ -4,6 +4,7 @@ class User < ActiveRecord::Base
has_many :traces
has_many :diary_entries
has_many :messages, :foreign_key => :to_user_id
validates_confirmation_of :pass_crypt, :message => 'Password must match the confirmation password'
validates_uniqueness_of :display_name, :allow_nil => true
@ -64,6 +65,23 @@ class User < ActiveRecord::Base
return nearby
end
def self.has_messages?
if Message.fdhjklsafind_by_to_user_id(self.id)
return true
else
return false
end
end
def get_new_messages
messages = Message.find(:all, :conditions => "message_read = 0")
return messages
end
def get_all_messages
messages = Message.find(:all, :conditions => "message_read = 0")
return messages
end
end

View file

@ -1,8 +1,28 @@
<h2><%= @this_user.display_name %></h2>
<% if @user and @this_user.id == @user.id %>
<% if @user.has_messages? %>
<p>You have <%=@user.get_new_messages.length %> new messages and <%=@user.get_all_messages.length - @user.get_new_messages.length %> old messages.</p>
<table class="messages">
<th>from<th>
<th>title<th>
<th>received on<th>
<th><th>
<% @user.get_new_messages.each do |message| %>
<tr><td><%= link_to User.find(message.from_user_id).display_name , :controller => 'user', :action => User.find(message.from_user_id).display_name %></td>
<td><%= link_to message.title , :controller => 'message', :action => 'read', :message_id => message.id %></td>
<td><%= message.sent_on %></td>
<td><%= link_to 'reply', :controller => 'message', :action => 'new', :display_name => User.find(message.from_user_id).display_name %></td>
</tr>
<%end%>
</table>
<%end%>
<br />
<%= link_to 'go to your account page', :controller => 'user', :action => 'account', :display_name => @user.display_name %><br /><br />
<% else %>
<%= link_to 'send message', :controller => 'user', :action => 'message', :display_name => @this_user.display_name %><br /><br /> |
<%= link_to 'send message', :controller => 'message', :action => 'new', :display_name => @this_user.display_name %><br /><br />
<%= link_to 'Add as friend', :controller => 'user', :action => 'make_friend', :display_name => @this_user.display_name %><br /><br />
<% end %>

View file

@ -79,6 +79,10 @@ ActionController::Routing::Routes.draw do |map|
map.connect '/geocoder/search/', :controller => 'geocoder', :action => 'search'
map.connect '/geocoder/results/', :controller => 'geocoder', :action => 'results'
map.connect '/postcode/:postcode/', :controller => 'geocoder', :action => 'search'
# messages
map.connect '/message/new/:display_name', :controller => 'message', :action => 'new'
# fall through
map.connect ':controller/:id/:action'

View file

@ -39,10 +39,10 @@ create table diary_entries(id bigint not null auto_increment, user_id bigint not
alter table diary_entries add created_at datetime;
alter table diary_entries add updated_at datetime;
alter table users add column (home_lat double default 1);
alter table users add column (home_lon double default 1);
alter table users add column (home_lat double default 0);
alter table users add column (home_lon double default 0);
alter table users add column home_zoom int(2) default 3);
alter table users add column within_lon double default null;
alter table users add column within_lat double default null;
alter table users add column within_lon double default 2;
alter table users add column within_lat double default 2;
create table messages (id bigint not null auto_increment, user_id bigint(20) not null, title varchar(255), body text, sent_on datetime, message_read boolean default 0, primary key(id));
create table messages (id bigint not null auto_increment, user_id bigint(20) not null, from_user_id bigint(20) not null, title varchar(255), body text, sent_on datetime, message_read boolean default 0, primary key(id));