statuses.go (6900B)
1 // GoToSocial 2 // Copyright (C) GoToSocial Authors admin@gotosocial.org 3 // SPDX-License-Identifier: AGPL-3.0-or-later 4 // 5 // This program is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU Affero General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // This program is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU Affero General Public License for more details. 14 // 15 // You should have received a copy of the GNU Affero General Public License 16 // along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18 package accounts 19 20 import ( 21 "errors" 22 "fmt" 23 "net/http" 24 "strconv" 25 26 "github.com/gin-gonic/gin" 27 apiutil "github.com/superseriousbusiness/gotosocial/internal/api/util" 28 "github.com/superseriousbusiness/gotosocial/internal/gtserror" 29 "github.com/superseriousbusiness/gotosocial/internal/oauth" 30 ) 31 32 // AccountStatusesGETHandler swagger:operation GET /api/v1/accounts/{id}/statuses accountStatuses 33 // 34 // See statuses posted by the requested account. 35 // 36 // The statuses will be returned in descending chronological order (newest first), with sequential IDs (bigger = newer). 37 // 38 // --- 39 // tags: 40 // - accounts 41 // 42 // produces: 43 // - application/json 44 // 45 // parameters: 46 // - 47 // name: id 48 // type: string 49 // description: Account ID. 50 // in: path 51 // required: true 52 // - 53 // name: limit 54 // type: integer 55 // description: Number of statuses to return. 56 // default: 30 57 // in: query 58 // required: false 59 // - 60 // name: exclude_replies 61 // type: boolean 62 // description: Exclude statuses that are a reply to another status. 63 // default: false 64 // in: query 65 // required: false 66 // - 67 // name: exclude_reblogs 68 // type: boolean 69 // description: Exclude statuses that are a reblog/boost of another status. 70 // default: false 71 // in: query 72 // required: false 73 // - 74 // name: max_id 75 // type: string 76 // description: >- 77 // Return only statuses *OLDER* than the given max status ID. 78 // The status with the specified ID will not be included in the response. 79 // in: query 80 // - 81 // name: min_id 82 // type: string 83 // description: >- 84 // Return only statuses *NEWER* than the given min status ID. 85 // The status with the specified ID will not be included in the response. 86 // in: query 87 // required: false 88 // - 89 // name: pinned_only 90 // type: boolean 91 // description: Show only pinned statuses. In other words, exclude statuses that are not pinned to the given account ID. 92 // default: false 93 // in: query 94 // required: false 95 // - 96 // name: only_media 97 // type: boolean 98 // description: Show only statuses with media attachments. 99 // default: false 100 // in: query 101 // required: false 102 // - 103 // name: only_public 104 // type: boolean 105 // description: Show only statuses with a privacy setting of 'public'. 106 // default: false 107 // in: query 108 // required: false 109 // 110 // security: 111 // - OAuth2 Bearer: 112 // - read:accounts 113 // 114 // responses: 115 // '200': 116 // name: statuses 117 // description: Array of statuses. 118 // schema: 119 // type: array 120 // items: 121 // "$ref": "#/definitions/status" 122 // '400': 123 // description: bad request 124 // '401': 125 // description: unauthorized 126 // '404': 127 // description: not found 128 // '406': 129 // description: not acceptable 130 // '500': 131 // description: internal server error 132 func (m *Module) AccountStatusesGETHandler(c *gin.Context) { 133 authed, err := oauth.Authed(c, false, false, false, false) 134 if err != nil { 135 apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1) 136 return 137 } 138 139 if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { 140 apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1) 141 return 142 } 143 144 targetAcctID := c.Param(IDKey) 145 if targetAcctID == "" { 146 err := errors.New("no account id specified") 147 apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1) 148 return 149 } 150 151 limit := 30 152 limitString := c.Query(LimitKey) 153 if limitString != "" { 154 i, err := strconv.ParseInt(limitString, 10, 32) 155 if err != nil { 156 err := fmt.Errorf("error parsing %s: %s", LimitKey, err) 157 apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1) 158 return 159 } 160 limit = int(i) 161 } 162 163 excludeReplies := false 164 excludeRepliesString := c.Query(ExcludeRepliesKey) 165 if excludeRepliesString != "" { 166 i, err := strconv.ParseBool(excludeRepliesString) 167 if err != nil { 168 err := fmt.Errorf("error parsing %s: %s", ExcludeRepliesKey, err) 169 apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1) 170 return 171 } 172 excludeReplies = i 173 } 174 175 excludeReblogs := false 176 excludeReblogsString := c.Query(ExcludeReblogsKey) 177 if excludeReblogsString != "" { 178 i, err := strconv.ParseBool(excludeReblogsString) 179 if err != nil { 180 err := fmt.Errorf("error parsing %s: %s", ExcludeReblogsKey, err) 181 apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1) 182 return 183 } 184 excludeReblogs = i 185 } 186 187 maxID := "" 188 maxIDString := c.Query(MaxIDKey) 189 if maxIDString != "" { 190 maxID = maxIDString 191 } 192 193 minID := "" 194 minIDString := c.Query(MinIDKey) 195 if minIDString != "" { 196 minID = minIDString 197 } 198 199 pinnedOnly := false 200 pinnedString := c.Query(PinnedKey) 201 if pinnedString != "" { 202 i, err := strconv.ParseBool(pinnedString) 203 if err != nil { 204 err := fmt.Errorf("error parsing %s: %s", PinnedKey, err) 205 apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1) 206 return 207 } 208 pinnedOnly = i 209 } 210 211 mediaOnly := false 212 mediaOnlyString := c.Query(OnlyMediaKey) 213 if mediaOnlyString != "" { 214 i, err := strconv.ParseBool(mediaOnlyString) 215 if err != nil { 216 err := fmt.Errorf("error parsing %s: %s", OnlyMediaKey, err) 217 apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1) 218 return 219 } 220 mediaOnly = i 221 } 222 223 publicOnly := false 224 publicOnlyString := c.Query(OnlyPublicKey) 225 if publicOnlyString != "" { 226 i, err := strconv.ParseBool(publicOnlyString) 227 if err != nil { 228 err := fmt.Errorf("error parsing %s: %s", OnlyPublicKey, err) 229 apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1) 230 return 231 } 232 publicOnly = i 233 } 234 235 resp, errWithCode := m.processor.Account().StatusesGet(c.Request.Context(), authed.Account, targetAcctID, limit, excludeReplies, excludeReblogs, maxID, minID, pinnedOnly, mediaOnly, publicOnly) 236 if errWithCode != nil { 237 apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1) 238 return 239 } 240 241 if resp.LinkHeader != "" { 242 c.Header("Link", resp.LinkHeader) 243 } 244 c.JSON(http.StatusOK, resp.Items) 245 }