Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7055cf6

Browse files
committed
浏览增加活跃
1 parent ac91c68 commit 7055cf6

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

src/logic/view.go

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package logic
88

99
import (
10+
"fmt"
1011
"net/http"
1112
"strconv"
1213
"strings"
@@ -81,7 +82,7 @@ func newViews() *views {
8182
}
8283

8384
// TODO: 用户登录了,应该用用户标识,而不是IP
84-
func (this *views) Incr(req *http.Request, objtype, objid int) {
85+
func (this *views) Incr(req *http.Request, objtype, objid int, uids ...int) {
8586
ua := req.UserAgent()
8687
spiders := config.ConfigFile.MustValueArray("global", "spider", ",")
8788
for _, spider := range spiders {
@@ -90,28 +91,34 @@ func (this *views) Incr(req *http.Request, objtype, objid int) {
9091
}
9192
}
9293

93-
user := goutils.Ip2long(goutils.RemoteIp(req))
94-
9594
key := strconv.Itoa(objtype) + strconv.Itoa(objid)
9695

96+
var userKey string
97+
98+
if len(uids) > 0 {
99+
userKey = fmt.Sprintf("%s_uid_%d", key, uids[0])
100+
} else {
101+
userKey = fmt.Sprintf("%s_ip_%d", key, goutils.Ip2long(goutils.RemoteIp(req)))
102+
}
103+
97104
this.locker.Lock()
98105
defer this.locker.Unlock()
99106

100-
if user != 0 {
101-
userKey := key + strconv.FormatUint(uint64(user), 10)
102-
103-
if _, ok := this.users[userKey]; ok {
104-
return
105-
} else {
106-
this.users[userKey] = true
107-
}
107+
if _, ok := this.users[userKey]; ok {
108+
return
109+
} else {
110+
this.users[userKey] = true
108111
}
109112

110113
if _, ok := this.data[key]; !ok {
111114
this.data[key] = newView(objtype, objid)
112115
}
113116

114117
this.data[key].incr()
118+
119+
if len(uids) > 0 {
120+
viewObservable.NotifyObservers(uids[0], objtype, objid)
121+
}
115122
}
116123

117124
func (this *views) Flush() {

template/common/comment.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
</div>
1515
<div class="sub row">
1616
<ul class="help-block col-md-10">
17+
<li>请尽量让自己的回复能够对别人有帮助</li>
1718
<li class="markdown_tip">支持 Markdown 格式, <strong>**粗体**</strong>、~~删除线~~、<code>`单行代码`</code></li>
1819
<li>支持 @ 本站用户;支持表情(输入 : 提示),见 <a href="http://www.emoji-cheat-sheet.com/" target="_blank">Emoji cheat sheet</a></li>
1920
</ul>

0 commit comments

Comments
 (0)