Skip to content

Commit

Permalink
Add built-in methods to streams
Browse files Browse the repository at this point in the history
- `ParentURL` and `GrandparentURL`
  • Loading branch information
benpate committed Sep 23, 2024
1 parent 88f23ec commit eedbf35
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions model/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package model

import (
"math"
"net/url"
"time"

"github.com/EmissarySocial/emissary/tools/id"
Expand Down Expand Up @@ -400,6 +401,16 @@ func (stream *Stream) HasParent() bool {
return !stream.ParentID.IsZero()
}

// ParentURL returns the URL for the parent object
func (stream *Stream) ParentURL() string {
if streamURL, err := url.Parse(stream.URL); err == nil {
streamURL.Path = stream.ParentID.Hex()
return streamURL.String()
}

return ""
}

// HasGrandparent returns TRUE if this Stream has a GrandparentID
func (stream *Stream) HasGrandparent() bool {
return len(stream.ParentIDs) > 1
Expand All @@ -414,6 +425,19 @@ func (stream *Stream) GrandparentID() primitive.ObjectID {
return primitive.NilObjectID
}

// GrandparentURL returns the URL of the parent of the parent of this Stream (if it exists)
func (stream *Stream) GrandparentURL() string {

if grandparentID := stream.GrandparentID(); !grandparentID.IsZero() {
if streamURL, err := url.Parse(stream.URL); err == nil {
streamURL.Path = grandparentID.Hex()
return streamURL.String()
}
}

return ""
}

// SetAttributedTo sets the list of people that this Stream is attributed to
func (stream *Stream) SetAttributedTo(person PersonLink) {
stream.AttributedTo = person
Expand Down

0 comments on commit eedbf35

Please sign in to comment.