Permalink
Browse files

Join/leave conversations.

You can now join a conversation without posting to it; that should prevent "I'm just posting to join the conversation" posts, which would be really annoying.
  • Loading branch information...
1 parent f854727 commit 50563b804bee5493a8f153791a00ea9819ae88bf @sirsean committed Aug 24, 2010
Showing with 45 additions and 1 deletion.
  1. +8 −0 model/Conversation.rb
  2. +30 −1 server.rb
  3. +7 −0 views/conversation.haml
@@ -4,4 +4,12 @@ class Conversation
key :post_ids, :index => true
key :user_ids, :index => true
key :created_at
+
+ def add_user(user_id)
+ @user_ids.push(user_id).uniq!
+ end
+
+ def remove_user(user_id)
+ @user_ids.delete(user_id)
+ end
end
View
@@ -351,7 +351,6 @@
:in_reply_to => params["in_reply_to"]
})
- #redirect session.delete("redirect_url") or "/home/"
flash "Emission posted"
redirect_back "/home/"
else
@@ -370,9 +369,39 @@
@conversation_users = User.get_by_user_ids(@conversation.user_ids)
@emissions = Post.get_by_post_ids(@conversation.post_ids)
+ if @logged_in_user
+ @is_participating = @conversation.user_ids.include?(@logged_in_user.id)
+ end
+
haml :conversation
end
+get "/conversation/:conversation_id/join/?" do |conversation_id|
+ if @logged_in_user
+ conversation = Conversation.find(conversation_id)
+ conversation.add_user(@logged_in_user.id)
+ conversation.save
+
+ flash "Joined conversation"
+ redirect_back "/conversation/#{conversation.id}/"
+ else
+ redirect "/login/"
+ end
+end
+
+get "/conversation/:conversation_id/leave/?" do |conversation_id|
+ if @logged_in_user
+ conversation = Conversation.find(conversation_id)
+ conversation.remove_user(@logged_in_user.id)
+ conversation.save
+
+ flash "You are no longer participating in this conversation"
+ redirect_back "/conversation/#{conversation.id}/"
+ else
+ redirect "/login/"
+ end
+end
+
get "/search/?" do
set_redirect
@term = params["term"]
@@ -1,5 +1,12 @@
%h2="Conversation"
+- if @is_participating
+ %p
+ %a{:href => "/conversation/#{@conversation.id}/leave/"}="Leave"
+- else
+ %p
+ %a{:href => "/conversation/#{@conversation.id}/join/"}="Join"
+
- if not @emissions.empty?
#emission_list
- @emissions.each do |emission|

0 comments on commit 50563b8

Please sign in to comment.