Permalink
Browse files

Mod: 邀请回答限制重复发邮件(同一个问题对一个用户最多两次),并限制用户不可邀请自己

  • Loading branch information...
huacnlee committed Apr 13, 2011
1 parent c6559df commit 37fc5cb027b5f90cba322f8cfe77f934d4808d8c
@@ -219,7 +219,12 @@ def invite_to_answer
result = AskInvite.cancel(params[:i_id], current_user.id)
render :text => "1"
else
- @invite = AskInvite.invite(params[:id], params[:user_id], current_user.id)
+ if (current_user.id.to_s != params[:user_id].to_s)
+ @invite = AskInvite.invite(params[:id], params[:user_id], current_user.id)
+ @success = true
+ else
+ @success = false
+ end
end
end
View
@@ -35,8 +35,16 @@ def self.invite(ask_id,user_id,invitor_id)
return item if item.invitor_ids.include?(invitor_id)
item.invitor_ids << invitor_id
item.count += 1
+
+ # 发送邮件
+ if(item.mail_sent <= 1)
+ UserMailer.invite_to_answer(item.ask_id, item.user_id, item.invitor_ids).deliver
+ item.mail_sent += 1
+ end
+
item.save
- UserMailer.invite_to_answer(item.ask_id, item.user_id, item.invitor_ids).deliver
+
+ # 插入 Log 和 Notification
insert_log(ask_id, user_id, invitor_id)
item
end
@@ -1,8 +1,10 @@
+<% if @success %>
i = $("#ask_invite_<%= @invite.id %>");
if(i.length == 0){
$("#ask_invited_users").append('<%= escape_javascript(render("invited_user", :item => @invite)) %>');
}
else{
$(".count",i).text('<%= @invite.count %>');
}
+<% end %>
App.loading(false);
View
@@ -1,5 +1,2 @@
namespace :mailer do
- task :ask_invite => :environment do
- AskInvite.check_to_send
- end
end
View
@@ -1,3 +1,4 @@
+# VVERBOSE=1 QUEUE=mailer rake resque:work
# RAILS_ENV=production VVERBOSE=1 QUEUE=mailer COUNT=5 rake resque:workers >> log/resque.log 2>&1 &
RAILS_ENV=production VVERBOSE=1 QUEUE=mailer COUNT=3 rake resque:workers >> log/resque.log 2>&1 &

0 comments on commit 37fc5cb

Please sign in to comment.