Skip to content
This repository has been archived by the owner on Mar 6, 2018. It is now read-only.

Commit

Permalink
Add: 用户可选择对推荐话题和用户'不感兴趣',以后将不再推荐
Browse files Browse the repository at this point in the history
  • Loading branch information
huacnlee committed Apr 26, 2011
1 parent 92a00f4 commit 2ad3f0c
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 3 deletions.
7 changes: 6 additions & 1 deletion app/controllers/home_controller.rb
@@ -1,6 +1,6 @@
# coding: utf-8
class HomeController < ApplicationController
before_filter :require_user_text, :only => [:update_in_place]
before_filter :require_user_text, :only => [:update_in_place,:mute_suggest_item]
before_filter :require_user, :except => [:about,:index]

def index
Expand Down Expand Up @@ -171,4 +171,9 @@ def report
redirect_to params[:url]
end

def mute_suggest_item
UserSuggestItem.mute(current_user.id, params[:type].strip.titleize, params[:id])
render :text => "1"
end

end
3 changes: 3 additions & 0 deletions app/models/user.rb
Expand Up @@ -312,8 +312,11 @@ def refresh_suggest_items
saved_count = 0
# 先删除就的缓存
UserSuggestItem.delete_all(self.id)
mutes = UserSuggestItem.get_mutes(self.id)
items.shuffle.each do |item|
klass = item.class.to_s
# 跳过 mute 的信息
next if mutes.include?({"type" => klass, "id" => item.id.to_s})
# 跳过删除的用户
next if klass == "User" and item.deleted == 1
usi = UserSuggestItem.new(:user_id => self.id,
Expand Down
24 changes: 24 additions & 0 deletions app/models/user_suggest_item.rb
Expand Up @@ -102,4 +102,28 @@ def self.gets(user_id, options = {})
result
end

# 取得不感兴趣的列表
def self.get_mutes(user_id)
key = "#{UserSuggestItem.gkey(user_id)}:mutes"
$redis.llen(key)
max = $redis.llen(key)
items = $redis.lrange(key, 0, max)
result = []
items.each do |item|
json = JSON.parse(item)
result << json
end
result
end

# 不感兴趣
def self.mute(user_id, type, id)
# TODO: 需要防止重复插入
key = "#{UserSuggestItem.gkey(user_id)}:mutes"
val = { :type => type, :id => id }
$redis.rpush(key,val.to_json)
UserSuggestItem.delete(user_id, type, id)
true
end

end
3 changes: 3 additions & 0 deletions app/views/asks/_sidebar.html.erb
Expand Up @@ -51,6 +51,9 @@
<% end %>
</ul>
</div>
<script type="text/javascript">
$("ul.followed-item li").mouseenter(function(){ $(this).find(".mute").show(); }).mouseleave(function(){ $(this).find(".mute").hide(); });
</script>
<% end %>
<% end %>
<% end %>
3 changes: 3 additions & 0 deletions app/views/home/_recommended_topic.html.erb
@@ -1,4 +1,7 @@
<li>
<div class="mute">
<a href="#" title="不感兴趣" onclick="Users.mute_suggest_item(this,'Topic','<%= topic.id %>');"></a>
</div>
<div class="item">
<div class="left">
<%= topic_cover_tag(topic,:small) %>
Expand Down
3 changes: 3 additions & 0 deletions app/views/home/_recommended_user.html.erb
@@ -1,4 +1,7 @@
<li>
<div class="mute">
<a href="#" title="不感兴趣" onclick="Users.mute_suggest_item(this,'User','<%= follower.id %>');"></a>
</div>
<div class="item">
<div class="left">
<%= user_avatar_tag(follower,:small) %>
Expand Down
2 changes: 1 addition & 1 deletion config/environments/development.rb
Expand Up @@ -12,7 +12,7 @@
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_view.debug_rjs = true
config.action_controller.perform_caching = true
config.action_controller.perform_caching = false

# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = false
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Expand Up @@ -8,6 +8,7 @@
match "/followed" => "home#followed"
match "/recommended" => "home#recommended"
match "/mark_notifies_as_read" => "home#mark_notifies_as_read"
match "/mute_suggest_item" => "home#mute_suggest_item"
match "/report" => "home#report"
match "/about" => "home#about"
match "/doing" => "logs#index"
Expand Down
10 changes: 10 additions & 0 deletions public/javascripts/users.js
Expand Up @@ -17,5 +17,15 @@ var Users = {
});
return false;
},

/* 不感兴趣推荐的用户或话题 */
mute_suggest_item : function(el, type, id){
$(el).parent().parent().fadeOut("fast");
$.get("/mute_suggest_item", { type : type, id : id },function(res){
App.requireUser(res);
});
return false;
},

varsion : function(){}
}
2 changes: 1 addition & 1 deletion public/stylesheets/front.css
Expand Up @@ -23,7 +23,7 @@ body { text-align:center; }
.left_wrapper { float:left; width:630px; }
#footer .left_wrapper ,
#main .left_wrapper { margin-left:70px; margin-right:20px; width:605px; }
.sidebar { float:right; width:210px; overflow:hidden; _width:190px; }
.sidebar { float:right; width:210px; _width:190px; }
.sidebar .box { margin-bottom:20px; }
.sidebar .box h2 { border-top: 1px dotted silver; padding: 15px 0 3px; color: #333; font-size: 1.2em; margin-bottom: 3px; }
.leftbox .box h2 { border-top: 1px dotted silver; padding: 15px 0 3px; color: #333; font-size: 1.2em; margin-bottom: 3px; }
Expand Down
7 changes: 7 additions & 0 deletions public/stylesheets/users.css
Expand Up @@ -50,6 +50,7 @@
margin: 10px 0 10px 10px;
}

/* 向用户推荐感兴趣的内容 */
.followed-item {
padding: 0;
margin: 0;
Expand All @@ -59,8 +60,14 @@
.followed-item li {
list-style: none;
padding: 10px 0;
height: 45px;
border-top: 1px dotted #C8C8C8;
}
.followed-item li .mute { padding-top:4px; float:left; position:relative; margin-left: -22px; padding-right:5px;
width:17px; height:45px; display:none; }
.followed-item li .mute a { background:#DFEAF4 url(/images/x.gif) -2px -1px no-repeat; display:block;
height: 15px; width: 15px;margin-bottom:1px;
-moz-border-radius: 3px; -webkit-border-radius: 3px; }

.topic-listing li, .followers-listing li {
border-top: none;
Expand Down

0 comments on commit 2ad3f0c

Please sign in to comment.