status.go (4122B)
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 statuses 19 20 import ( 21 "net/http" 22 23 "github.com/gin-gonic/gin" 24 "github.com/superseriousbusiness/gotosocial/internal/processing" 25 ) 26 27 const ( 28 // IDKey is for status UUIDs 29 IDKey = "id" 30 // BasePath is the base path for serving the statuses API, minus the 'api' prefix 31 BasePath = "/v1/statuses" 32 // BasePathWithID is just the base path with the ID key in it. 33 // Use this anywhere you need to know the ID of the status being queried. 34 BasePathWithID = BasePath + "/:" + IDKey 35 36 // FavouritedPath is for seeing who's faved a given status 37 FavouritedPath = BasePathWithID + "/favourited_by" 38 // FavouritePath is for posting a fave on a status 39 FavouritePath = BasePathWithID + "/favourite" 40 // UnfavouritePath is for removing a fave from a status 41 UnfavouritePath = BasePathWithID + "/unfavourite" 42 43 // RebloggedPath is for seeing who's boosted a given status 44 RebloggedPath = BasePathWithID + "/reblogged_by" 45 // ReblogPath is for boosting/reblogging a given status 46 ReblogPath = BasePathWithID + "/reblog" 47 // UnreblogPath is for undoing a boost/reblog of a given status 48 UnreblogPath = BasePathWithID + "/unreblog" 49 50 // BookmarkPath is for creating a bookmark on a given status 51 BookmarkPath = BasePathWithID + "/bookmark" 52 // UnbookmarkPath is for removing a bookmark from a given status 53 UnbookmarkPath = BasePathWithID + "/unbookmark" 54 55 // MutePath is for muting a given status so that notifications will no longer be received about it. 56 MutePath = BasePathWithID + "/mute" 57 // UnmutePath is for undoing an existing mute 58 UnmutePath = BasePathWithID + "/unmute" 59 60 // PinPath is for pinning a status to an account profile so that it's the first thing people see 61 PinPath = BasePathWithID + "/pin" 62 // UnpinPath is for undoing a pin and returning a status to the ever-swirling drain of time and entropy 63 UnpinPath = BasePathWithID + "/unpin" 64 65 // ContextPath is used for fetching context of posts 66 ContextPath = BasePathWithID + "/context" 67 ) 68 69 type Module struct { 70 processor *processing.Processor 71 } 72 73 func New(processor *processing.Processor) *Module { 74 return &Module{ 75 processor: processor, 76 } 77 } 78 79 func (m *Module) Route(attachHandler func(method string, path string, f ...gin.HandlerFunc) gin.IRoutes) { 80 // create / get / delete status 81 attachHandler(http.MethodPost, BasePath, m.StatusCreatePOSTHandler) 82 attachHandler(http.MethodGet, BasePathWithID, m.StatusGETHandler) 83 attachHandler(http.MethodDelete, BasePathWithID, m.StatusDELETEHandler) 84 85 // fave stuff 86 attachHandler(http.MethodPost, FavouritePath, m.StatusFavePOSTHandler) 87 attachHandler(http.MethodPost, UnfavouritePath, m.StatusUnfavePOSTHandler) 88 attachHandler(http.MethodGet, FavouritedPath, m.StatusFavedByGETHandler) 89 90 // pin stuff 91 attachHandler(http.MethodPost, PinPath, m.StatusPinPOSTHandler) 92 attachHandler(http.MethodPost, UnpinPath, m.StatusUnpinPOSTHandler) 93 94 // reblog stuff 95 attachHandler(http.MethodPost, ReblogPath, m.StatusBoostPOSTHandler) 96 attachHandler(http.MethodPost, UnreblogPath, m.StatusUnboostPOSTHandler) 97 attachHandler(http.MethodGet, RebloggedPath, m.StatusBoostedByGETHandler) 98 attachHandler(http.MethodPost, BookmarkPath, m.StatusBookmarkPOSTHandler) 99 attachHandler(http.MethodPost, UnbookmarkPath, m.StatusUnbookmarkPOSTHandler) 100 101 // context / status thread 102 attachHandler(http.MethodGet, ContextPath, m.StatusContextGETHandler) 103 }