mirror of
https://github.com/christianselig/apollo-backend
synced 2024-11-25 05:07:43 +00:00
get post ID from context
This commit is contained in:
parent
147f1e924c
commit
06465ebf19
2 changed files with 17 additions and 1 deletions
|
@ -460,7 +460,7 @@ func payloadFromMessage(acct *data.Account, msg *reddit.MessageData, badgeCount
|
|||
break
|
||||
case (msg.Kind == "t1" && msg.Type == "comment_reply"):
|
||||
title := fmt.Sprintf(`%s in “%s”`, msg.Author, postTitle)
|
||||
_, postID := reddit.SplitID(msg.ParentID)
|
||||
postID := reddit.PostIDFromContext(msg.Context)
|
||||
payload = payload.
|
||||
AlertTitle(title).
|
||||
Category("inbox-comment-reply").
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptrace"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -34,6 +35,21 @@ func SplitID(id string) (string, string) {
|
|||
return "", ""
|
||||
}
|
||||
|
||||
func PostIDFromContext(context string) string {
|
||||
exps := []*regexp.Regexp{
|
||||
regexp.MustCompile(`\/r\/[^\/]*\/comments\/([^\/]*)\/.*`),
|
||||
}
|
||||
|
||||
for _, exp := range exps {
|
||||
matches := exp.FindStringSubmatch(context)
|
||||
if len(matches) != 2 {
|
||||
continue
|
||||
}
|
||||
return matches[1]
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func NewClient(id, secret string, statsd *statsd.Client) *Client {
|
||||
tracer := &httptrace.ClientTrace{
|
||||
GotConn: func(info httptrace.GotConnInfo) {
|
||||
|
|
Loading…
Reference in a new issue