@@ -6,23 +6,22 @@ import (
6
6
"github.com/thecsw/mira/models"
7
7
)
8
8
9
- // // c is the channel with all unread messages
10
- // // stop is the channel to stop the stream. Do stop <- true to stop the loop
9
+ // c is the channel with all unread messages
10
+ // stop is the channel to stop the stream. Do stop <- true to stop the loop
11
11
func (r * Reddit ) StreamCommentReplies () (<- chan * models.Comment , chan bool ) {
12
12
c := make (chan * models.Comment , 25 )
13
13
stop := make (chan bool , 1 )
14
14
go func () {
15
15
for {
16
16
stop <- false
17
17
un , _ := r .Me ().ListUnreadMessages ()
18
+ un = onlyReplies (un )
18
19
for _ , v := range un {
19
20
// Only process comment replies and
20
21
// mark them as read.
21
- if v .IsCommentReply () {
22
- c <- & v
23
- // You can read the message with
24
- r .Me ().ReadMessage (v .GetId ())
25
- }
22
+ c <- & v
23
+ // You can read the message with
24
+ r .Me ().ReadMessage (v .GetId ())
26
25
}
27
26
time .Sleep (r .Stream .CommentListInterval * time .Second )
28
27
if <- stop {
@@ -33,23 +32,22 @@ func (r *Reddit) StreamCommentReplies() (<-chan *models.Comment, chan bool) {
33
32
return c , stop
34
33
}
35
34
36
- // // c is the channel with all unread messages
37
- // // stop is the channel to stop the stream. Do stop <- true to stop the loop
35
+ // c is the channel with all unread messages
36
+ // stop is the channel to stop the stream. Do stop <- true to stop the loop
38
37
func (r * Reddit ) StreamMentions () (<- chan * models.Comment , chan bool ) {
39
38
c := make (chan * models.Comment , 25 )
40
39
stop := make (chan bool , 1 )
41
40
go func () {
42
41
for {
43
42
stop <- false
44
43
un , _ := r .Me ().ListUnreadMessages ()
44
+ un = onlyMentions (un )
45
45
for _ , v := range un {
46
46
// Only process comment replies and
47
47
// mark them as read.
48
- if v .IsMention () {
49
- c <- & v
50
- // You can read the message with
51
- r .Me ().ReadMessage (v .GetId ())
52
- }
48
+ c <- & v
49
+ // You can read the message with
50
+ r .Me ().ReadMessage (v .GetId ())
53
51
}
54
52
time .Sleep (r .Stream .CommentListInterval * time .Second )
55
53
if <- stop {
@@ -60,8 +58,8 @@ func (r *Reddit) StreamMentions() (<-chan *models.Comment, chan bool) {
60
58
return c , stop
61
59
}
62
60
63
- // // c is the channel with all comments
64
- // // stop is the channel to stop the stream. Do stop <- true to stop the loop
61
+ // c is the channel with all comments
62
+ // stop is the channel to stop the stream. Do stop <- true to stop the loop
65
63
func (r * Reddit ) StreamComments () (<- chan * models.Comment , chan bool , error ) {
66
64
name , ttype , err := r .checkType ("subreddit" , "redditor" )
67
65
if err != nil {
@@ -209,3 +207,23 @@ func (r *Reddit) streamRedditorSubmissions(redditor string) (<-chan *models.Post
209
207
}()
210
208
return c , stop , nil
211
209
}
210
+
211
+ func onlyMentions (comments []models.Comment ) []models.Comment {
212
+ newComments := make ([]models.Comment , 0 , 8 )
213
+ for _ , v := range comments {
214
+ if v .IsMention () {
215
+ newComments = append (newComments , v )
216
+ }
217
+ }
218
+ return newComments
219
+ }
220
+
221
+ func onlyReplies (comments []models.Comment ) []models.Comment {
222
+ newComments := make ([]models.Comment , 0 , 8 )
223
+ for _ , v := range comments {
224
+ if v .IsCommentReply () {
225
+ newComments = append (newComments , v )
226
+ }
227
+ }
228
+ return newComments
229
+ }
0 commit comments