home.go (4361B)
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 timelines 19 20 import ( 21 "net/http" 22 23 "github.com/gin-gonic/gin" 24 apiutil "github.com/superseriousbusiness/gotosocial/internal/api/util" 25 "github.com/superseriousbusiness/gotosocial/internal/gtserror" 26 "github.com/superseriousbusiness/gotosocial/internal/oauth" 27 ) 28 29 // HomeTimelineGETHandler swagger:operation GET /api/v1/timelines/home homeTimeline 30 // 31 // See statuses/posts by accounts you follow. 32 // 33 // The statuses will be returned in descending chronological order (newest first), with sequential IDs (bigger = newer). 34 // 35 // The returned Link header can be used to generate the previous and next queries when scrolling up or down a timeline. 36 // 37 // Example: 38 // 39 // ``` 40 // <https://example.org/api/v1/timelines/home?limit=20&max_id=01FC3GSQ8A3MMJ43BPZSGEG29M>; rel="next", <https://example.org/api/v1/timelines/home?limit=20&min_id=01FC3KJW2GYXSDDRA6RWNDM46M>; rel="prev" 41 // ```` 42 // 43 // --- 44 // tags: 45 // - timelines 46 // 47 // produces: 48 // - application/json 49 // 50 // parameters: 51 // - 52 // name: max_id 53 // type: string 54 // description: >- 55 // Return only statuses *OLDER* than the given max status ID. 56 // The status with the specified ID will not be included in the response. 57 // in: query 58 // required: false 59 // - 60 // name: since_id 61 // type: string 62 // description: >- 63 // Return only statuses *newer* than the given since status ID. 64 // The status with the specified ID will not be included in the response. 65 // in: query 66 // - 67 // name: min_id 68 // type: string 69 // description: >- 70 // Return only statuses *immediately newer* than the given since status ID. 71 // The status with the specified ID will not be included in the response. 72 // in: query 73 // required: false 74 // - 75 // name: limit 76 // type: integer 77 // description: Number of statuses to return. 78 // default: 20 79 // in: query 80 // required: false 81 // - 82 // name: local 83 // type: boolean 84 // description: Show only statuses posted by local accounts. 85 // default: false 86 // in: query 87 // required: false 88 // 89 // security: 90 // - OAuth2 Bearer: 91 // - read:statuses 92 // 93 // responses: 94 // '200': 95 // name: statuses 96 // description: Array of statuses. 97 // schema: 98 // type: array 99 // items: 100 // "$ref": "#/definitions/status" 101 // headers: 102 // Link: 103 // type: string 104 // description: Links to the next and previous queries. 105 // '401': 106 // description: unauthorized 107 // '400': 108 // description: bad request 109 func (m *Module) HomeTimelineGETHandler(c *gin.Context) { 110 authed, err := oauth.Authed(c, true, true, true, true) 111 if err != nil { 112 apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1) 113 return 114 } 115 116 if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { 117 apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1) 118 return 119 } 120 121 limit, errWithCode := apiutil.ParseLimit(c.Query(apiutil.LimitKey), 20, 40, 1) 122 if errWithCode != nil { 123 apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1) 124 return 125 } 126 127 local, errWithCode := apiutil.ParseLocal(c.Query(apiutil.LocalKey), false) 128 if errWithCode != nil { 129 apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1) 130 return 131 } 132 133 resp, errWithCode := m.processor.Timeline().HomeTimelineGet( 134 c.Request.Context(), 135 authed, 136 c.Query(MaxIDKey), 137 c.Query(SinceIDKey), 138 c.Query(MinIDKey), 139 limit, 140 local, 141 ) 142 if errWithCode != nil { 143 apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1) 144 return 145 } 146 147 if resp.LinkHeader != "" { 148 c.Header("Link", resp.LinkHeader) 149 } 150 c.JSON(http.StatusOK, resp.Items) 151 }