diff options
-rw-r--r-- | OutboxPost.go | 4 | ||||
-rw-r--r-- | main.go | 59 |
2 files changed, 47 insertions, 16 deletions
diff --git a/OutboxPost.go b/OutboxPost.go index 61175be..cb0f988 100644 --- a/OutboxPost.go +++ b/OutboxPost.go @@ -55,9 +55,9 @@ func ParseOutboxRequest(w http.ResponseWriter, r *http.Request, db *sql.DB) { op := len(nObj.InReplyTo) - 1 if op >= 0 { if nObj.InReplyTo[op].Id == "" { - id = nObj.Id + id = nObj.Id } else { - id = nObj.InReplyTo[op].Id + id = nObj.InReplyTo[0].Id + "|" + nObj.Id } } @@ -1930,31 +1930,65 @@ func GetActorCollectionReq(r *http.Request, collection string) Collection { func shortURL(actorName string, url string) string { - re := regexp.MustCompile(`outbox`) + re := regexp.MustCompile(`.+\/`) + + actor := re.FindString(actorName) + + urlParts := strings.Split(url, "|") + + op := urlParts[0] + + var reply string + + if len(urlParts) > 1 { + reply = urlParts[1] + } - actor := re.ReplaceAllString(actorName, "") - re = regexp.MustCompile(`\w+$`) - temp := re.ReplaceAllString(url, "") + temp := re.ReplaceAllString(op, "") if(temp == actor){ - short := StripTransferProtocol(url) + id := localShort(op) - re := regexp.MustCompile(`\w+$`) + re := regexp.MustCompile(`.+\/`) + replyCheck := re.FindString(reply) - id := re.FindString(short); + if(reply != "" && replyCheck == actor){ + id = id + "#" + localShort(reply) + } else if reply != "" { + id = id + "#" + remoteShort(reply) + } return id; }else{ - short := StripTransferProtocol(url) + id := remoteShort(op) + + re := regexp.MustCompile(`.+\/`) + replyCheck := re.FindString(reply) + + if(reply != "" && replyCheck == actor){ + id = id + "#" + localShort(reply) + } else if reply != "" { + id = id + "#" + remoteShort(reply) + } + + return id; + } +} +func localShort(url string) string { re := regexp.MustCompile(`\w+$`) + return re.FindString(StripTransferProtocol(url)); +} - id := re.FindString(short); +func remoteShort(url string) string { + re := regexp.MustCompile(`\w+$`) + + id := re.FindString(StripTransferProtocol(url)); re = regexp.MustCompile(`.+/.+/`) - actorurl := re.FindString(short) + actorurl := re.FindString(StripTransferProtocol(url)) re = regexp.MustCompile(`/.+/`) @@ -1962,8 +1996,5 @@ func shortURL(actorName string, url string) string { actorname = strings.Replace(actorname, "/", "", -1) - id = "f" + actorname + "-" + id - - return id; - } + return "f" + actorname + "-" + id } |