-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Messages and Friendships have relationship through Activity
- Loading branch information
1 parent
e128cff
commit c827cfa
Showing
25 changed files
with
213 additions
and
474 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,7 @@ | ||
class ActivitiesController < ApplicationController | ||
before_action :set_activity, only: [:show, :edit, :update, :destroy] | ||
|
||
# GET /activities | ||
# GET /activities.json | ||
def index | ||
@activities = current_user.activities.order created_at: :desc | ||
end | ||
|
||
# GET /activities/1 | ||
# GET /activities/1.json | ||
def show | ||
end | ||
|
||
# GET /activities/new | ||
def new | ||
@activity = Activity.new | ||
end | ||
|
||
# GET /activities/1/edit | ||
def edit | ||
end | ||
|
||
# POST /activities | ||
# POST /activities.json | ||
def create | ||
@activity = Activity.new(activity_params) | ||
|
||
respond_to do |format| | ||
if @activity.save | ||
format.html { redirect_to @activity, notice: 'Activity was successfully created.' } | ||
format.json { render :show, status: :created, location: @activity } | ||
else | ||
format.html { render :new } | ||
format.json { render json: @activity.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# PATCH/PUT /activities/1 | ||
# PATCH/PUT /activities/1.json | ||
def update | ||
respond_to do |format| | ||
if @activity.update(activity_params) | ||
format.html { redirect_to @activity, notice: 'Activity was successfully updated.' } | ||
format.json { render :show, status: :ok, location: @activity } | ||
else | ||
format.html { render :edit } | ||
format.json { render json: @activity.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# DELETE /activities/1 | ||
# DELETE /activities/1.json | ||
def destroy | ||
@activity.destroy | ||
respond_to do |format| | ||
format.html { redirect_to activities_url, notice: 'Activity was successfully destroyed.' } | ||
format.json { head :no_content } | ||
end | ||
end | ||
|
||
private | ||
|
||
# Use callbacks to share common setup or constraints between actions. | ||
def set_activity | ||
@activity = Activity.find(params[:id]) | ||
end | ||
|
||
# Never trust parameters from the scary internet, only allow the white list through. | ||
def activity_params | ||
params.require(:activity).permit(:user_id, :message_id, :type) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,30 @@ | ||
class ActivityDecorator < Draper::Decorator | ||
delegate :id, :user, :message, :type | ||
delegate :id, :user, :actionable, :type, :actionable_type | ||
|
||
decorates_association :user | ||
decorates_association :message | ||
decorates_association :actionable | ||
|
||
def reciprocate_message | ||
actionable.unacknowledged_message_for_sender_reciprocation | ||
end | ||
|
||
def acknowledge_message | ||
actionable.acknowledged_message_for_recipient | ||
end | ||
|
||
def activity_message | ||
# hashtag uhg. | ||
if object.type == 'sent' | ||
if message.acknowledged_at | ||
acknowledged_message_for_sender | ||
if actionable.acknowledged_at | ||
actionable.acknowledged_message_for_sender | ||
else | ||
unacknowledged_message_for_sender | ||
actionable.unacknowledged_message_for_sender | ||
end | ||
else | ||
if message.acknowledged_at | ||
acknowledged_message_for_recipient | ||
if actionable.acknowledged_at | ||
actionable.acknowledged_message_for_recipient | ||
else | ||
unacknowledged_message_for_recipient | ||
actionable.unacknowledged_message_for_recipient | ||
end | ||
end | ||
end | ||
|
||
def reciprocate_message | ||
unacknowledged_message_for_sender_reciprocation | ||
end | ||
|
||
def acknowledge_message | ||
acknowledged_message_for_recipient | ||
end | ||
|
||
private | ||
|
||
def acknowledged_message_for_sender | ||
"You #{ message.conjugate_verb(:past, :perfective) } #{ message.recipient.first_name }." # past tense | ||
end | ||
|
||
def acknowledged_message_for_recipient | ||
"#{ message.sender.first_name } #{ message.conjugate_verb(:past, :perfective) } you." # past tense | ||
end | ||
|
||
def unacknowledged_message_for_sender | ||
"You tried to #{ message.verb } #{ message.recipient.first_name }." # present | ||
end | ||
|
||
def unacknowledged_message_for_recipient | ||
"#{ message.sender.first_name } wants to #{ message.verb } you." # present | ||
end | ||
|
||
def unacknowledged_message_for_sender_reciprocation | ||
"You tried to #{ message.verb } #{ message.sender.first_name }." # present | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,50 @@ | ||
class FriendshipDecorator < Draper::Decorator | ||
delegate_all | ||
|
||
# Define presentation-specific methods here. Helpers are accessed through | ||
# `helpers` (aka `h`). You can override attributes, for example: | ||
# | ||
# def created_at | ||
# helpers.content_tag :span, class: 'time' do | ||
# object.created_at.strftime("%a %m/%d/%y") | ||
# end | ||
# end | ||
def created_at | ||
object.created_at.to_time.to_i | ||
end | ||
|
||
def created_at_in_words | ||
helpers.time_ago_in_words object.created_at | ||
end | ||
|
||
def acknowledged_at | ||
return nil unless object.approved | ||
object.approved.to_time.to_i | ||
end | ||
|
||
def acknowledged_at_in_words | ||
return nil unless object.approved | ||
helpers.time_ago_in_words object.approved | ||
end | ||
|
||
def reciprocate_message | ||
unacknowledged_message_for_sender_reciprocation | ||
end | ||
|
||
def acknowledge_message | ||
acknowledged_message_for_recipient | ||
end | ||
|
||
def acknowledged_message_for_sender | ||
"#{ friend.first_name } accepted your friendship." | ||
end | ||
|
||
def acknowledged_message_for_recipient | ||
"You accepted #{ user.first_name } friendship." # past tense | ||
end | ||
|
||
def unacknowledged_message_for_sender | ||
"You offered friendship to #{ friend.first_name }." # present | ||
end | ||
|
||
def unacknowledged_message_for_recipient | ||
"#{ user.first_name } offers friendship." # present | ||
end | ||
|
||
def unacknowledged_message_for_sender_reciprocation | ||
# TODO: How to handle this case? | ||
'' # present | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,17 @@ | ||
class Friendship < ActiveRecord::Base | ||
belongs_to :user | ||
belongs_to :friend, class_name: 'User' | ||
has_many :activities, as: :actionable, dependent: :destroy | ||
|
||
after_create :create_activity_entries | ||
|
||
def accept | ||
update approved: Time.now | ||
end | ||
|
||
private | ||
|
||
def create_activity_entries | ||
Activity.activities_for_friendship self | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.