Skip to content

Commit

Permalink
Merge pull request #34 from scalableinternetservices/jc-profile-chat
Browse files Browse the repository at this point in the history
added chat to profile
  • Loading branch information
HououinKyouma-2036 authored Nov 25, 2024
2 parents 83c833d + 79b5bda commit 5369251
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
4 changes: 4 additions & 0 deletions app/controllers/chats_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ def create
elsif otherUser.id == @current_user.id
puts chats_path
redirect_back(fallback_location:posts_path, alert: 'You cannot chat with yourself')
elsif Chat.where(user1_id: @current_user.id, user2_id: otherUser.id).exists?
redirect_to Chat.where(user1_id: @current_user.id, user2_id: otherUser.id).first
elsif Chat.where(user1_id: otherUser.id, user2_id: @current_user.id).exists?
redirect_to Chat.where(user1_id: otherUser.id, user2_id: @current_user.id).first
else
@chat = Chat.new(:user1_id => @current_user.id, :user2_id => otherUser.id)
if @chat.save
Expand Down
15 changes: 9 additions & 6 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,21 @@ def index
@newmessages = @unresponded_chats.map do |chat|
Message.find(chat.last_message_id)
end.flatten

end

def show
@user = User.find_by(username: params[:username])
if @user
@meetings = @user.meetings
@posts = @user.posts.order(created_at: :desc)
@chats = Chat.where("user1_id = ? OR user2_id = ?", @user.id, @user.id)
@unresponded_chats = @chats.where("last_message_user_id != ?", @user.id)
@newmessages = @unresponded_chats.map do |chat|
Message.find(chat.last_message_id)
end.flatten
if (@user.id < @current_user.id)
@chats = Chat.where("user1_id = ? OR user2_id = ?", @user.id, @current_user.id)
else
@chats = Chat.where("user1_id = ? OR user2_id = ?", @current_user.id, @user.id)
end
else
redirect_to root_path, alert: 'User not found'
end
end

Expand All @@ -29,7 +32,7 @@ def create
if User.exists?(username: params[:username])
redirect_to signup_path, alert: 'Username already taken'
return
end
end

# Check password length
if params[:password].length < 8
Expand Down
24 changes: 24 additions & 0 deletions app/views/users/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,28 @@
details[open] .expand-icon {
transform: rotate(180deg);
}
.chat-container{
display: flex;
flex-direction: column;
align-text: center;
}
.chat-card {
display: inline-block;
max-width: 600px;
margin: 20px auto;
background: white;
border-radius: 8px;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
padding: 5px 20px;
height: auto;
text-decoration:none;
color: inherit;

}

.chat-card:hover{
cursor: pointer;
}

.attendees-list {
border-top: 1px solid #eee;
Expand Down Expand Up @@ -304,6 +326,8 @@
Their Role: <span class="role-badge"><%= @user.role.capitalize %></span>
</div>
</div>
<div class="chat-container">
<%= link_to "Chat with #{@user.username}", chats_path(query:@user.username), method: :post, class: "chat-card", data: { turbo_method: :post} %> </div>
</div>

<h2 class="sub-profile-title"> <%= @user.username%>'s Meetings</h2>
Expand Down

0 comments on commit 5369251

Please sign in to comment.