preferences.go (2076B)
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 processing 19 20 import ( 21 "context" 22 23 apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model" 24 "github.com/superseriousbusiness/gotosocial/internal/gtserror" 25 "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" 26 ) 27 28 func (p *Processor) PreferencesGet(ctx context.Context, accountID string) (*apimodel.Preferences, gtserror.WithCode) { 29 act, err := p.state.DB.GetAccountByID(ctx, accountID) 30 if err != nil { 31 return nil, gtserror.NewErrorInternalError(err) 32 } 33 34 return &apimodel.Preferences{ 35 PostingDefaultVisibility: mastoPrefVisibility(act.Privacy), 36 PostingDefaultSensitive: *act.Sensitive, 37 PostingDefaultLanguage: act.Language, 38 // The Reading* preferences don't appear to actually be settable by the 39 // client, so forcing some sensible defaults here 40 ReadingExpandMedia: "default", 41 ReadingExpandSpoilers: false, 42 ReadingAutoPlayGifs: false, 43 }, nil 44 } 45 46 func mastoPrefVisibility(vis gtsmodel.Visibility) string { 47 switch vis { 48 case gtsmodel.VisibilityPublic, gtsmodel.VisibilityDirect: 49 return string(vis) 50 case gtsmodel.VisibilityUnlocked: 51 return "unlisted" 52 default: 53 // this will catch gtsmodel.VisibilityMutualsOnly and other types Mastodon doesn't 54 // have and map them to the most restrictive state 55 return "private" 56 } 57 }