mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-20 17:37:29 -06:00
refining status views etc
This commit is contained in:
parent
3868803ff1
commit
eb9de53776
14 changed files with 184 additions and 90 deletions
|
|
@ -34,6 +34,15 @@ import (
|
|||
const (
|
||||
// LimitKey is for setting the return amount limit for eg., requesting an account's statuses
|
||||
LimitKey = "limit"
|
||||
// ExcludeRepliesKey is for specifying whether to exclude replies in a list of returned statuses by an account.
|
||||
ExcludeRepliesKey = "exclude_replies"
|
||||
// PinnedKey is for specifying whether to include pinned statuses in a list of returned statuses by an account.
|
||||
PinnedKey = "pinned"
|
||||
// MaxIDKey is for specifying the maximum ID of the status to retrieve.
|
||||
MaxIDKey = "max_id"
|
||||
// MediaOnlyKey is for specifying that only statuses with media should be returned in a list of returned statuses by an account.
|
||||
MediaOnlyKey = "only_media"
|
||||
|
||||
// IDKey is the key to use for retrieving account ID in requests
|
||||
IDKey = "id"
|
||||
// BasePath is the base API path for this module
|
||||
|
|
|
|||
|
|
@ -27,15 +27,27 @@ import (
|
|||
)
|
||||
|
||||
// AccountStatusesGETHandler serves the statuses of the requested account, if they're visible to the requester.
|
||||
//
|
||||
// Several different filters might be passed into this function in the query:
|
||||
//
|
||||
// limit -- show only limit number of statuses
|
||||
// exclude_replies -- exclude statuses that are a reply to another status
|
||||
// max_id -- the maximum ID of the status to show
|
||||
// pinned -- show only pinned statuses
|
||||
// media_only -- show only statuses that have media attachments
|
||||
func (m *Module) AccountStatusesGETHandler(c *gin.Context) {
|
||||
l := m.log.WithField("func", "AccountStatusesGETHandler")
|
||||
|
||||
authed, err := oauth.Authed(c, false, false, false, false)
|
||||
if err != nil {
|
||||
l.Debugf("error authing: %s", err)
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthorized"})
|
||||
return
|
||||
}
|
||||
|
||||
targetAcctID := c.Param(IDKey)
|
||||
if targetAcctID == "" {
|
||||
l.Debug("no account id specified in query")
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "no account id specified"})
|
||||
return
|
||||
}
|
||||
|
|
@ -43,16 +55,60 @@ func (m *Module) AccountStatusesGETHandler(c *gin.Context) {
|
|||
limit := 30
|
||||
limitString := c.Query(LimitKey)
|
||||
if limitString != "" {
|
||||
l, err := strconv.ParseInt(limitString, 10, 64)
|
||||
i, err := strconv.ParseInt(limitString, 10, 64)
|
||||
if err != nil {
|
||||
l.Debugf("error parsing limit string: %s", err)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "couldn't parse limit query param"})
|
||||
return
|
||||
}
|
||||
limit = int(l)
|
||||
limit = int(i)
|
||||
}
|
||||
|
||||
statuses, errWithCode := m.processor.AccountStatusesGet(authed, targetAcctID, limit)
|
||||
excludeReplies := false
|
||||
excludeRepliesString := c.Query(ExcludeRepliesKey)
|
||||
if excludeRepliesString != "" {
|
||||
i, err := strconv.ParseBool(excludeRepliesString)
|
||||
if err != nil {
|
||||
l.Debugf("error parsing replies string: %s", err)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "couldn't parse exclude replies query param"})
|
||||
return
|
||||
}
|
||||
excludeReplies = i
|
||||
}
|
||||
|
||||
maxID := ""
|
||||
maxIDString := c.Query(MaxIDKey)
|
||||
if maxIDString != "" {
|
||||
maxID = maxIDString
|
||||
}
|
||||
|
||||
pinned := false
|
||||
pinnedString := c.Query(PinnedKey)
|
||||
if pinnedString != "" {
|
||||
i, err := strconv.ParseBool(pinnedString)
|
||||
if err != nil {
|
||||
l.Debugf("error parsing pinned string: %s", err)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "couldn't parse pinned query param"})
|
||||
return
|
||||
}
|
||||
pinned = i
|
||||
}
|
||||
|
||||
mediaOnly := false
|
||||
mediaOnlyString := c.Query(MediaOnlyKey)
|
||||
if mediaOnlyString != "" {
|
||||
i, err := strconv.ParseBool(mediaOnlyString)
|
||||
if err != nil {
|
||||
l.Debugf("error parsing media only string: %s", err)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "couldn't parse media only query param"})
|
||||
return
|
||||
}
|
||||
mediaOnly = i
|
||||
}
|
||||
|
||||
statuses, errWithCode := m.processor.AccountStatusesGet(authed, targetAcctID, limit, excludeReplies, maxID, pinned, mediaOnly)
|
||||
if errWithCode != nil {
|
||||
l.Debugf("error from processor account statuses get: %s", errWithCode)
|
||||
c.JSON(errWithCode.Code(), gin.H{"error": errWithCode.Safe()})
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue