@@ -11,6 +11,7 @@ var Tag = models.Tag;
11
11
var Topic = models . Topic ;
12
12
var TopicTag = models . TopicTag ;
13
13
var TopicCollect = models . TopicCollect ;
14
+ var Relation = models . Relation ;
14
15
var check = require ( 'validator' ) . check ;
15
16
var sanitize = require ( 'validator' ) . sanitize ;
16
17
var at_ctrl = require ( './at' ) ;
@@ -33,12 +34,13 @@ exports.index = function(req, res, next) {
33
34
if ( topic_id . length !== 24 ) {
34
35
return res . render ( 'notify/notify' , { error : '此话题不存在或已被删除。' } ) ;
35
36
}
36
- var events = [ 'topic' , 'other_topics' , 'no_reply_topics' , '@user' ] ;
37
- var ep = EventProxy . create ( events , function ( topic , other_topics , no_reply_topics ) {
37
+ var events = [ 'topic' , 'other_topics' , 'no_reply_topics' , 'get_relation' , ' @user' ] ;
38
+ var ep = EventProxy . create ( events , function ( topic , other_topics , no_reply_topics , relation ) {
38
39
res . render ( 'topic/index' , {
39
40
topic : topic ,
40
41
author_other_topics : other_topics ,
41
- no_reply_topics : no_reply_topics
42
+ no_reply_topics : no_reply_topics ,
43
+ relation : relation
42
44
} ) ;
43
45
} ) ;
44
46
ep . on ( 'error' , function ( err ) {
@@ -59,6 +61,7 @@ exports.index = function(req, res, next) {
59
61
return res . render ( 'notify/notify' , { error : message } ) ;
60
62
}
61
63
64
+
62
65
at_ctrl . link_at_who ( topic . content , function ( err , content ) {
63
66
if ( err ) return ep . emit ( 'error' , err ) ;
64
67
topic . content = content ;
@@ -91,12 +94,23 @@ exports.index = function(req, res, next) {
91
94
}
92
95
} ) ;
93
96
97
+ //get author's relationship
98
+ if ( ! req . session . user . _id ) {
99
+ ep . emit ( 'get_relation' , null ) ;
100
+ } else {
101
+
102
+ Relation . findOne ( { user_id :req . session . user . _id , follow_id : topic . author_id } , function ( err , relation ) {
103
+ if ( err ) return ep . emit ( 'error' , err ) ;
104
+ ep . emit ( 'get_relation' , relation ) ;
105
+ } ) ;
106
+ }
107
+
94
108
// get author other topics
95
109
var options = { limit : 5 , sort : [ [ 'last_reply_at' , 'desc' ] ] } ;
96
110
var query = { author_id : topic . author_id , _id : { '$nin' : [ topic . _id ] } } ;
97
111
get_topics_by_query ( query , options , function ( err , topics ) {
98
112
if ( err ) return ep . emit ( 'error' , err ) ;
99
- ep . emit ( 'other_topics' , topics ) ;
113
+ ep . emit ( 'other_topics' , topics ) ;
100
114
} ) ;
101
115
102
116
// get no reply topics
@@ -545,12 +559,13 @@ function get_full_topic(id,cb){
545
559
return cb ( null , '话题的作者丢了。' ) ;
546
560
}
547
561
proxy . trigger ( 'author' , author ) ;
548
- } ) ;
562
+ } ) ;
549
563
550
564
reply_ctrl . get_replies_by_topic_id ( topic . _id , function ( err , replies ) {
551
565
if ( err ) return cb ( err ) ;
552
566
proxy . trigger ( 'replies' , replies ) ;
553
567
} ) ;
568
+
554
569
} ) ;
555
570
556
571
}
0 commit comments