Skip to content

Commit

Permalink
Merge branch 'private_messages'
Browse files Browse the repository at this point in the history
Conflicts:
	app/controllers/status_messages_controller.rb
	app/models/data_point.rb
	app/models/status_message.rb
	db/schema.rb
	lib/fake.rb
	public/stylesheets/sass/application.sass
	spec/models/mention_spec.rb
  • Loading branch information
danielgrippi committed Mar 9, 2011
2 parents 5f841b9 + 81f0cd7 commit 1f5edb1
Show file tree
Hide file tree
Showing 113 changed files with 2,682 additions and 625 deletions.
14 changes: 7 additions & 7 deletions Gemfile.lock
Expand Up @@ -119,14 +119,14 @@ GEM
erubis
extlib
highline
json (>= 1.4.4, <= 1.4.6)
json (<= 1.4.6, >= 1.4.4)
mixlib-authentication (>= 1.1.0)
mixlib-cli (>= 1.1.0)
mixlib-config (>= 1.1.2)
mixlib-log (>= 1.2.0)
moneta
ohai (>= 0.5.7)
rest-client (>= 1.0.4, < 1.7.0)
rest-client (< 1.7.0, >= 1.0.4)
uuidtools
childprocess (0.1.7)
ffi (~> 0.6.3)
Expand Down Expand Up @@ -163,7 +163,7 @@ GEM
faraday (0.5.4)
addressable (~> 2.2.2)
multipart-post (~> 1.1.0)
rack (>= 1.1.0, < 2)
rack (< 2, >= 1.1.0)
faraday_middleware (0.3.2)
faraday (~> 0.5.4)
fastercsv (1.5.4)
Expand Down Expand Up @@ -271,7 +271,7 @@ GEM
multi_json (~> 0.0.4)
ohai (0.5.8)
extlib
json (>= 1.4.4, <= 1.4.6)
json (<= 1.4.6, >= 1.4.4)
mixlib-cli
mixlib-config
mixlib-log
Expand Down Expand Up @@ -344,17 +344,17 @@ GEM
rubyntlm (0.1.1)
rubyzip (0.9.4)
selenium-client (1.2.18)
selenium-rc (2.3.1)
selenium-rc (2.3.2)
selenium-client (>= 1.2.18)
selenium-webdriver (0.1.3)
childprocess (~> 0.1.5)
ffi (~> 0.6.3)
json_pure
rubyzip
simple_oauth (0.1.4)
sinatra (1.1.3)
sinatra (1.2.0)
rack (~> 1.1)
tilt (>= 1.2.2, < 2.0)
tilt (< 2.0, >= 1.2.2)
subexec (0.0.4)
systemu (1.2.0)
term-ansicolor (1.0.5)
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/application_controller.rb
Expand Up @@ -7,7 +7,7 @@ class ApplicationController < ActionController::Base
protect_from_forgery :except => :receive

before_filter :ensure_http_referer_is_set
before_filter :set_contacts_notifications_and_status, :except => [:create, :update]
before_filter :set_contacts_notifications_unread_count_and_status, :except => [:create, :update]
before_filter :count_requests
before_filter :set_invites
before_filter :set_locale
Expand All @@ -22,12 +22,13 @@ def ensure_http_referer_is_set
request.env['HTTP_REFERER'] ||= '/aspects'
end

def set_contacts_notifications_and_status
def set_contacts_notifications_unread_count_and_status
if user_signed_in?
@aspect = nil
@object_aspect_ids = []
@all_aspects = current_user.aspects.includes(:aspect_memberships, :post_visibilities)
@notification_count = Notification.for(current_user, :unread =>true).count
@unread_message_count = ConversationVisibility.sum(:unread, :conditions => "person_id = #{current_user.person.id}")
@user_id = current_user.id
end
end
Expand Down
15 changes: 2 additions & 13 deletions app/controllers/aspect_memberships_controller.rb
Expand Up @@ -3,20 +3,10 @@
# the COPYRIGHT file.
#

class AspectMembershipsController < ApplicationController
class AspectMembershipsController < ApplicationController
before_filter :authenticate_user!

def new
render :nothing => true
end

def index
raise
end



def destroy
def destroy
#note :id is garbage

@person_id = params[:person_id]
Expand Down Expand Up @@ -58,7 +48,6 @@ def create
@aspect = current_user.aspects.where(:id => params[:aspect_id]).first
@contact = current_user.contact_for(@person)


current_user.add_contact_to_aspect(@contact, @aspect)

flash.now[:notice] = I18n.t 'aspects.add_to_aspect.success'
Expand Down
3 changes: 1 addition & 2 deletions app/controllers/comments_controller.rb
Expand Up @@ -18,8 +18,7 @@ def create

if @comment.save
Rails.logger.info("event=create type=comment user=#{current_user.diaspora_handle} status=success comment=#{@comment.id} chars=#{params[:text].length}")

current_user.dispatch_comment(@comment)
Postzord::Dispatch.new(current_user, @comment).post

respond_to do |format|
format.js{
Expand Down
19 changes: 19 additions & 0 deletions app/controllers/conversation_visibilities_controller.rb
@@ -0,0 +1,19 @@
# Copyright (c) 2010, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
#

class ConversationVisibilitiesController < ApplicationController
before_filter :authenticate_user!

def destroy
@vis = ConversationVisibility.where(:person_id => current_user.person.id,
:conversation_id => params[:conversation_id]).first
if @vis
if @vis.destroy
flash[:notice] = "Conversation successfully removed"
end
end
redirect_to conversations_path
end
end
66 changes: 66 additions & 0 deletions app/controllers/conversations_controller.rb
@@ -0,0 +1,66 @@
class ConversationsController < ApplicationController
before_filter :authenticate_user!

respond_to :html, :json

def index
@conversations = Conversation.joins(:conversation_visibilities).where(
:conversation_visibilities => {:person_id => current_user.person.id}).paginate(
:page => params[:page], :per_page => 15, :order => 'updated_at DESC')

@visibilities = ConversationVisibility.where( :person_id => current_user.person.id ).paginate(
:page => params[:page], :per_page => 15, :order => 'updated_at DESC')

@unread_counts = {}
@visibilities.each{|v| @unread_counts[v.conversation_id] = v.unread}

@authors = {}
@conversations.each{|c| @authors[c.id] = c.last_author}

@conversation = Conversation.joins(:conversation_visibilities).where(
:conversation_visibilities => {:person_id => current_user.person.id, :conversation_id => params[:conversation_id]}).first
end

def create
person_ids = Contact.where(:id => params[:contact_ids].split(',')).map! do |contact|
contact.person_id
end

params[:conversation][:participant_ids] = person_ids | [current_user.person.id]
params[:conversation][:author] = current_user.person

if @conversation = Conversation.create(params[:conversation])
Postzord::Dispatch.new(current_user, @conversation).post

flash[:notice] = "Message sent"
if params[:profile]
redirect_to person_path(params[:profile])
else
redirect_to conversations_path(:conversation_id => @conversation.id)
end
end
end

def show
@conversation = Conversation.joins(:conversation_visibilities).where(:id => params[:id],
:conversation_visibilities => {:person_id => current_user.person.id}).first

if @visibility = ConversationVisibility.where(:conversation_id => params[:id], :person_id => current_user.person.id).first
@visibility.unread = 0
@visibility.save
end

if @conversation
render :layout => false
else
redirect_to conversations_path
end
end

def new
@all_contacts_and_ids = current_user.contacts.map{|c| {:value => c.id, :name => c.person.name}}
@contact = current_user.contacts.find(params[:contact_id]) if params[:contact_id]
render :layout => false
end

end
32 changes: 32 additions & 0 deletions app/controllers/messages_controller.rb
@@ -0,0 +1,32 @@
# Copyright (c) 2010, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.

class MessagesController < ApplicationController
include ApplicationHelper
before_filter :authenticate_user!

respond_to :html, :mobile
respond_to :json, :only => :show

def create
cnv = Conversation.joins(:conversation_visibilities).where(:id => params[:conversation_id],
:conversation_visibilities => {:person_id => current_user.person.id}).first

if cnv
message = Message.new(:conversation_id => cnv.id, :text => params[:message][:text], :author => current_user.person)

if message.save
Rails.logger.info("event=create type=comment user=#{current_user.diaspora_handle} status=success message=#{message.id} chars=#{params[:message][:text].length}")
Postzord::Dispatch.new(current_user, message).post

redirect_to conversations_path(:conversation_id => cnv.id)
else
render :nothing => true, :status => 406
end
else
render :nothing => true, :status => 406
end
end

end
12 changes: 6 additions & 6 deletions app/controllers/photos_controller.rb
Expand Up @@ -30,7 +30,7 @@ def index
end

@posts = current_user.visible_photos.where(
:person_id => @person.id
:author_id => @person.id
).paginate(:page => params[:page])

render 'people/show'
Expand Down Expand Up @@ -94,8 +94,8 @@ def create
end

def make_profile_photo
person_id = current_user.person.id
@photo = Photo.where(:id => params[:photo_id], :person_id => person_id).first
author_id = current_user.person.id
@photo = Photo.where(:id => params[:photo_id], :author_id => author_id).first

if @photo
profile_hash = {:image_url => @photo.url(:thumb_large),
Expand All @@ -108,7 +108,7 @@ def make_profile_photo
:image_url => @photo.url(:thumb_large),
:image_url_medium => @photo.url(:thumb_medium),
:image_url_small => @photo.url(:thumb_small),
:person_id => person_id},
:author_id => author_id},
:status => 201}
end
else
Expand Down Expand Up @@ -139,8 +139,8 @@ def destroy
end

def show
@photo = current_user.visible_photos.where(:id => params[:id]).includes(:person, :status_message => :photos).first
@photo ||= Photo.where(:public => true, :id => params[:id]).includes(:person, :status_message => :photos).first
@photo = current_user.visible_photos.where(:id => params[:id]).includes(:author, :status_message => :photos).first
@photo ||= Photo.where(:public => true, :id => params[:id]).includes(:author, :status_message => :photos).first
if @photo
@parent = @photo.status_message

Expand Down
6 changes: 3 additions & 3 deletions app/controllers/posts_controller.rb
Expand Up @@ -3,19 +3,19 @@
# the COPYRIGHT file.

class PostsController < ApplicationController
skip_before_filter :set_contacts_notifications_and_status
skip_before_filter :set_contacts_notifications_unread_count_and_status
skip_before_filter :count_requests
skip_before_filter :set_invites
skip_before_filter :set_locale
skip_before_filter :which_action_and_user
skip_before_filter :set_grammatical_gender

def show
@post = Post.where(:id => params[:id], :public => true).includes(:person, :comments => :person).first
@post = Post.where(:id => params[:id], :public => true).includes(:author, :comments => :author).first

if @post
@landing_page = true
@person = @post.person
@person = @post.author
if @person.owner_id
I18n.locale = @person.owner.language
render "posts/#{@post.class.to_s.underscore}", :layout => true
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/profiles_controller.rb
Expand Up @@ -14,7 +14,7 @@ def update
# upload and set new profile photo
params[:profile] ||= {}
params[:profile][:searchable] ||= false
params[:profile][:photo] = Photo.where(:person_id => current_user.person.id,
params[:profile][:photo] = Photo.where(:author_id => current_user.person.id,
:id => params[:photo_id]).first if params[:photo_id]

if current_user.update_profile params[:profile]
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/publics_controller.rb
Expand Up @@ -6,7 +6,7 @@ class PublicsController < ApplicationController
require File.join(Rails.root, '/lib/diaspora/parser')
include Diaspora::Parser

skip_before_filter :set_contacts_notifications_and_status, :except => [:create, :update]
skip_before_filter :set_contacts_notifications_unread_count_and_status, :except => [:create, :update]
skip_before_filter :count_requests
skip_before_filter :set_invites
skip_before_filter :set_locale
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/status_messages_controller.rb
Expand Up @@ -52,7 +52,7 @@ def create
photos.update_all(:status_message_id => nil)
end
respond_to do |format|
format.js { render :json =>{:errors => @status_message.errors.full_messages}, :status => 406 }
format.js { render :json =>{:errors => @status_message.errors.full_messages}, :status => 406 }
format.html {redirect_to :back}
end
end
Expand Down
9 changes: 4 additions & 5 deletions app/helpers/application_helper.rb
Expand Up @@ -13,11 +13,10 @@ def timeago(time, options = {})
def page_title text=nil
title = ""
if text.blank?
title = "#{current_user.name} | " if current_user
title = "#{current_user.name}" if current_user
else
title = "#{text} | "
title = "#{text}"
end
title += "DIASPORA*"
end

def aspects_with_post aspects, post
Expand Down Expand Up @@ -133,8 +132,8 @@ def person_image_tag(person, size=:thumb_small)
"<img alt=\"#{h(person.name)}\" class=\"avatar\" #{("data-owner_id="+@user_id.to_s) if @user_id} data-person_id=\"#{person.id}\" src=\"#{person.profile.image_url(size)}\" title=\"#{h(person.name)}\">".html_safe
end

def person_link(person)
"<a href='/people/#{person.id}'>
def person_link(person, opts={})
"<a href='/people/#{person.id}' class='#{opts[:class]}'>
#{h(person.name)}
</a>".html_safe
end
Expand Down
9 changes: 9 additions & 0 deletions app/helpers/conversations_helper.rb
@@ -0,0 +1,9 @@
module ConversationsHelper
def new_message_text(count)
if count > 0
t('new_messages', :count => count)
else
t('no_new_messages')
end
end
end
2 changes: 1 addition & 1 deletion app/helpers/notifications_helper.rb
Expand Up @@ -22,7 +22,7 @@ def object_link(note)
elsif note.instance_of?(Notifications::AlsoCommented)
post = Post.where(:id => note.target_id).first
if post
"#{translation(target_type, post.person.name)} #{link_to t('notifications.post'), object_path(post)}".html_safe
"#{translation(target_type, post.author.name)} #{link_to t('notifications.post'), object_path(post)}".html_safe
else
t('notifications.also_commented_deleted')
end
Expand Down
2 changes: 2 additions & 0 deletions app/helpers/private_messages_helper.rb
@@ -0,0 +1,2 @@
module PrivateMessagesHelper
end

0 comments on commit 1f5edb1

Please sign in to comment.