Compare commits

...

9 commits

Author SHA1 Message Date
Victor Dyotte 924a2a86b3
Merge 40c33ccc49 into 58af95a1d5 2024-09-26 17:36:49 -04:00
kim 58af95a1d5
[chore] bump go-byteutil v1.2.0 -> v1.3.0 (#3356)
* bump go-byteutil v1.2.0 -> v1.3.0 which has safer (as in long-term API consistency) byte <-> string conversions

* fix test relying on byteutil exported type no longer existing
2024-09-26 19:50:08 +00:00
kim f3e2d36d64
[chore] update go-sched pkg (#3357)
* update go-sched to v1.2.4 which removes some now unused dependencies

* whoops, remove test output
2024-09-26 19:23:41 +00:00
tobi 82b9515a9d
[chore] Fix some contrast issues in themes; performance tweaks (#3358) 2024-09-26 17:00:13 +02:00
vdyotte 40c33ccc49
Fix: update swagger doc 2024-09-24 16:13:49 -04:00
Victor Dyotte 90b773ae2a
Merge branch 'main' into profile-boosts 2024-09-24 15:51:41 -04:00
vdyotte 4b7d7f9b8b
Feat: document new hide boots setting 2024-09-24 15:49:56 -04:00
vdyotte af5a766f62
Feat: display boosts on public profile 2024-09-24 15:22:10 -04:00
S0yKaf d9e59820ed Feat: add "HideBoots" option to account settings 2024-09-23 12:53:21 -04:00
57 changed files with 387 additions and 5148 deletions

View file

@ -284,6 +284,12 @@ definitions:
example: https://example.org/media/some_user/header/static/header.png
type: string
x-go-name: HeaderStatic
hide_boosts:
description: |-
Account has opted to hide boosts from their profile.
Key/value omitted if false.
type: boolean
x-go-name: HideBoosts
hide_collections:
description: |-
Account has opted to hide their followers/following collections.
@ -2284,6 +2290,12 @@ definitions:
example: https://example.org/media/some_user/header/static/header.png
type: string
x-go-name: HeaderStatic
hide_boosts:
description: |-
Account has opted to hide boosts from their profile.
Key/value omitted if false.
type: boolean
x-go-name: HideBoosts
hide_collections:
description: |-
Account has opted to hide their followers/following collections.

View file

@ -88,9 +88,9 @@ This setting does not affect visibility of your posts over the ActivityPub proto
!!! warning
Be aware that changes to this setting also apply retroactively.
That is, if you previously made a post on Unlisted visibility, while set to show only Public posts on your profile, and you change this setting to show Public and Unlisted, then the Unlisted post you previously made will be visible on your profile alongside your Public posts.
Likewise, if you change this setting to show no posts, then all your posts will be hidden from your profile, regardless of when you created them, and what this option was set to at the time. This will apply until you change this setting again.
!!! tip
@ -134,6 +134,11 @@ This feed only includes posts set as 'Public' (see [Privacy Settings](./posts.md
!!! warning
Exposing your RSS feed allows *anyone* to subscribe to updates on your Public posts anonymously, bypassing follows and follow requests.
#### Hide boosts from your public page
By default, GoToSocial will display posts boosted by you on your public web profile. If you do not wish to display them, You can hide them by checking this box.
#### Hide Who You Follow / Are Followed By
By default, GoToSocial shows your following/followers counts on your public web profile, and allows others to see who you follow and are followed by. This can be useful for account discovery purposes. However, for privacy + safety reasons you may wish to hide these counts, and to hide your following/followers lists from other accounts. You can do this by checking this box.
@ -196,7 +201,7 @@ If you want to reset all your policies to the initial defaults, you can click on
!!! danger
While GoToSocial respects interaction policies, it is not guaranteed that other server softwares will, and it is possible that accounts on other servers will still send out replies and boosts of your post to their followers, even if your instance forbids these interactions.
As more ActivityPub servers roll out support for interaction policies, this issue will hopefully diminish, but in the meantime GoToSocial can offer only a "best effort" attempt to restrict interactions with your posts according to the policies you have set.
## Email & Password

8
go.mod
View file

@ -7,7 +7,7 @@ replace modernc.org/sqlite => gitlab.com/NyaaaWhatsUpDoc/sqlite v1.29.9-concurre
require (
codeberg.org/gruf/go-bytes v1.0.2
codeberg.org/gruf/go-bytesize v1.0.3
codeberg.org/gruf/go-byteutil v1.2.0
codeberg.org/gruf/go-byteutil v1.3.0
codeberg.org/gruf/go-cache/v3 v3.5.7
codeberg.org/gruf/go-debug v1.3.0
codeberg.org/gruf/go-errors/v2 v2.3.2
@ -19,8 +19,8 @@ require (
codeberg.org/gruf/go-mempool v0.0.0-20240507125005-cef10d64a760
codeberg.org/gruf/go-mimetypes v1.2.0
codeberg.org/gruf/go-mutexes v1.5.1
codeberg.org/gruf/go-runners v1.6.2
codeberg.org/gruf/go-sched v1.2.3
codeberg.org/gruf/go-runners v1.6.3
codeberg.org/gruf/go-sched v1.2.4
codeberg.org/gruf/go-storage v0.2.0
codeberg.org/gruf/go-structr v0.8.9
codeberg.org/superseriousbusiness/exif-terminator v0.9.0
@ -85,8 +85,6 @@ require (
)
require (
codeberg.org/gruf/go-atomics v1.1.0 // indirect
codeberg.org/gruf/go-bitutil v1.1.0 // indirect
codeberg.org/gruf/go-fastpath/v2 v2.0.0 // indirect
codeberg.org/gruf/go-mangler v1.4.1 // indirect
codeberg.org/gruf/go-maps v1.0.3 // indirect

18
go.sum
View file

@ -30,22 +30,16 @@ cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0Zeo
cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk=
cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs=
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
codeberg.org/gruf/go-atomics v1.1.0 h1:ni9QXYoRUFYQMXE3akWaUb1wMcPBDc05Md6Rgml7W58=
codeberg.org/gruf/go-atomics v1.1.0/go.mod h1:a/4/y/LgvjxjQVnpoy1VVkOSzLS1W9i1g4SJ0nflAa4=
codeberg.org/gruf/go-bitutil v1.0.0/go.mod h1:sb8IjlDnjVTz8zPK/8lmHesKxY0Yb3iqHWjUM/SkphA=
codeberg.org/gruf/go-bitutil v1.1.0 h1:U1Q+A1mtnPk+npqYrlRBc9ar2C5hYiBd17l1Wrp2Bt8=
codeberg.org/gruf/go-bitutil v1.1.0/go.mod h1:rGibFevYTQfYKcPv0Df5KpG8n5xC3AfD4d/UgYeoNy0=
codeberg.org/gruf/go-bytes v1.0.2 h1:malqE42Ni+h1nnYWBUAJaDDtEzF4aeN4uPN8DfMNNvo=
codeberg.org/gruf/go-bytes v1.0.2/go.mod h1:1v/ibfaosfXSZtRdW2rWaVrDXMc9E3bsi/M9Ekx39cg=
codeberg.org/gruf/go-bytesize v1.0.3 h1:Tz8tCxhPLeyM5VryuBNjUHgKmLj4Bx9RbPaUSA3qg6g=
codeberg.org/gruf/go-bytesize v1.0.3/go.mod h1:n/GU8HzL9f3UNp/mUKyr1qVmTlj7+xacpp0OHfkvLPs=
codeberg.org/gruf/go-byteutil v1.2.0 h1:YoxkpUOoHS82BcPXfiIcWLe/YhS8QhpNUHdfuhN09QM=
codeberg.org/gruf/go-byteutil v1.2.0/go.mod h1:cWM3tgMCroSzqoBXUXMhvxTxYJp+TbCr6ioISRY5vSU=
codeberg.org/gruf/go-byteutil v1.3.0 h1:nRqJnCcRQ7xbfU6azw7zOzJrSMDIJHBqX6FL9vEMYmU=
codeberg.org/gruf/go-byteutil v1.3.0/go.mod h1:chgnZz1LUcfaObaIFglxF5MRYQkJGjQf4WwVz95ccCM=
codeberg.org/gruf/go-cache/v3 v3.5.7 h1:5hut49a8Wp3hdwrCEJYj6pHY2aRR1hyTmkK4+wHVYq4=
codeberg.org/gruf/go-cache/v3 v3.5.7/go.mod h1:Thahfuf3PgHSv2+1zHpvhRdX97tx1WXurVNGWpZucAM=
codeberg.org/gruf/go-debug v1.3.0 h1:PIRxQiWUFKtGOGZFdZ3Y0pqyfI0Xr87j224IYe2snZs=
codeberg.org/gruf/go-debug v1.3.0/go.mod h1:N+vSy9uJBQgpQcJUqjctvqFz7tBHJf+S/PIjLILzpLg=
codeberg.org/gruf/go-errors/v2 v2.0.0/go.mod h1:ZRhbdhvgoUA3Yw6e56kd9Ox984RrvbEFC2pOXyHDJP4=
codeberg.org/gruf/go-errors/v2 v2.3.2 h1:8ItWaOMfhDaqrJK1Pw8MO0Nu+o/tVcQtR5cJ58Vc4zo=
codeberg.org/gruf/go-errors/v2 v2.3.2/go.mod h1:LfzD9nkAAJpEDbkUqOZQ2jdaQ8VrK0pnR36zLOMFq6Y=
codeberg.org/gruf/go-fastcopy v1.1.3 h1:Jo9VTQjI6KYimlw25PPc7YLA3Xm+XMQhaHwKnM7xD1g=
@ -72,10 +66,10 @@ codeberg.org/gruf/go-mimetypes v1.2.0 h1:3rZGXY/SkNYbamiddWXs2gETXIBkGIeWYnbWpp2
codeberg.org/gruf/go-mimetypes v1.2.0/go.mod h1:YiUWRj/nAdJQc+UFRvcsL6xXZsbc6b6Ic739ycEO8Yg=
codeberg.org/gruf/go-mutexes v1.5.1 h1:xICU0WXhWr6wf+Iror4eE3xT+xnXNPrO6o77D/G6QuY=
codeberg.org/gruf/go-mutexes v1.5.1/go.mod h1:rPEqQ/y6CmGITaZ3GPTMQVsoZAOzbsAHyIaLsJcOqVE=
codeberg.org/gruf/go-runners v1.6.2 h1:oQef9niahfHu/wch14xNxlRMP8i+ABXH1Cb9PzZ4oYo=
codeberg.org/gruf/go-runners v1.6.2/go.mod h1:Tq5PrZ/m/rBXbLZz0u5if+yP3nG5Sf6S8O/GnyEePeQ=
codeberg.org/gruf/go-sched v1.2.3 h1:H5ViDxxzOBR3uIyGBCf0eH8b1L8wMybOXcdtUUTXZHk=
codeberg.org/gruf/go-sched v1.2.3/go.mod h1:vT9uB6KWFIIwnG9vcPY2a0alYNoqdL1mSzRM8I+PK7A=
codeberg.org/gruf/go-runners v1.6.3 h1:To/AX7eTrWuXrTkA3RA01YTP5zha1VZ68LQ+0D4RY7E=
codeberg.org/gruf/go-runners v1.6.3/go.mod h1:oXAaUmG2VxoKttpCqZGv5nQBeSvZSR2BzIk7h1yTRlU=
codeberg.org/gruf/go-sched v1.2.4 h1:ddBB9o0D/2oU8NbQ0ldN5aWxogpXPRBATWi58+p++Hw=
codeberg.org/gruf/go-sched v1.2.4/go.mod h1:wad6l+OcYGWMA2TzNLMmLObsrbBDxdJfEy5WvTgBjNk=
codeberg.org/gruf/go-storage v0.2.0 h1:mKj3Lx6AavEkuXXtxqPhdq+akW9YwrnP16yQBF7K5ZI=
codeberg.org/gruf/go-storage v0.2.0/go.mod h1:o3GzMDE5QNUaRnm/daUzFqvuAaC4utlgXDXYO79sWKU=
codeberg.org/gruf/go-structr v0.8.9 h1:OyiSspWYCeJOm356fFPd+bDRumPrard2VAUXAPqZiJ0=

View file

@ -348,6 +348,7 @@ func parseUpdateAccountForm(c *gin.Context) (*apimodel.UpdateCredentialsRequest,
form.Theme == nil &&
form.CustomCSS == nil &&
form.EnableRSS == nil &&
form.HideBoosts == nil &&
form.HideCollections == nil &&
form.WebVisibility == nil) {
return nil, errors.New("empty form submitted")

View file

@ -104,6 +104,9 @@ type Account struct {
// Account has enabled RSS feed.
// Key/value omitted if false.
EnableRSS bool `json:"enable_rss,omitempty"`
// Account has opted to hide boosts from their profile.
// Key/value omitted if false.
HideBoosts bool `json:"hide_boosts,omitempty"`
// Account has opted to hide their followers/following collections.
// Key/value omitted if false.
HideCollections bool `json:"hide_collections,omitempty"`
@ -225,6 +228,8 @@ type UpdateCredentialsRequest struct {
CustomCSS *string `form:"custom_css" json:"custom_css"`
// Enable RSS feed of public toots for this account at /@[username]/feed.rss
EnableRSS *bool `form:"enable_rss" json:"enable_rss"`
// Hide boosts from this account's profile page.
HideBoosts *bool `form:"hide_boosts" json:"hide_boosts"`
// Hide this account's following/followers collections.
HideCollections *bool `form:"hide_collections" json:"hide_collections"`
// Visibility of statuses to show via the web view.

View file

@ -118,6 +118,10 @@ type WebStatus struct {
// Override API account with web account.
Account *WebAccount `json:"account"`
// Account that reblogged the status.
// needed to properly render reblogged statuses on profile pages.
ReblogAccount *WebAccount `json:"reblog_account"`
// Web version of media
// attached to this status.
MediaAttachments []*WebAttachment `json:"media_attachments"`

View file

@ -1017,6 +1017,7 @@ func (a *accountDB) GetAccountWebStatuses(
) ([]*gtsmodel.Status, error) {
// Check for an easy case: account exposes no statuses via the web.
webVisibility := account.Settings.WebVisibility
hideBoosts := *account.Settings.HideBoosts
if webVisibility == gtsmodel.VisibilityNone {
return nil, db.ErrNoEntries
}
@ -1035,9 +1036,12 @@ func (a *accountDB) GetAccountWebStatuses(
// Select only IDs from table
Column("status.id").
Where("? = ?", bun.Ident("status.account_id"), account.ID).
// Don't show replies or boosts.
Where("? IS NULL", bun.Ident("status.in_reply_to_uri")).
Where("? IS NULL", bun.Ident("status.boost_of_id"))
// Don't show replies.
Where("? IS NULL", bun.Ident("status.in_reply_to_uri"))
if hideBoosts {
q = q.Where("? IS NULL", bun.Ident("status.boost_of_id"))
}
// Select statuses for this account according
// to their web visibility preference.

View file

@ -0,0 +1,44 @@
// GoToSocial
// Copyright (C) GoToSocial Authors admin@gotosocial.org
// SPDX-License-Identifier: AGPL-3.0-or-later
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package migrations
import (
"context"
"strings"
"github.com/uptrace/bun"
)
func init() {
up := func(ctx context.Context, db *bun.DB) error {
_, err := db.ExecContext(ctx, "ALTER TABLE ? ADD COLUMN ? BOOLEAN DEFAULT FALSE", bun.Ident("account_settings"), bun.Ident("hide_boosts"))
if err != nil && !(strings.Contains(err.Error(), "already exists") || strings.Contains(err.Error(), "duplicate column name") || strings.Contains(err.Error(), "SQLSTATE 42701")) {
return err
}
return nil
}
down := func(ctx context.Context, db *bun.DB) error {
_, err := db.ExecContext(ctx, "ALTER TABLE ? DROP COLUMN ?", bun.Ident("account_settings"), bun.Ident("hide_boosts"))
return err
}
if err := Migrations.Register(up, down); err != nil {
panic(err)
}
}

View file

@ -33,6 +33,7 @@ type AccountSettings struct {
Theme string `bun:",nullzero"` // Preset CSS theme filename selected by this Account (empty string if nothing set).
CustomCSS string `bun:",nullzero"` // Custom CSS that should be displayed for this Account's profile and statuses.
EnableRSS *bool `bun:",nullzero,notnull,default:false"` // enable RSS feed subscription for this account's public posts at [URL]/feed
HideBoosts *bool `bun:",nullzero,notnull,default:false"` // Hide boosts from this accounts profile page.
HideCollections *bool `bun:",nullzero,notnull,default:false"` // Hide this account's followers/following collections.
WebVisibility Visibility `bun:",nullzero,notnull,default:public"` // Visibility level of statuses that visitors can view via the web profile.
InteractionPolicyDirect *InteractionPolicy `bun:""` // Interaction policy to use for new direct visibility statuses by this account. If null, assume default policy.

View file

@ -42,6 +42,16 @@ func (suite *GetRSSTestSuite) TestGetAccountRSSAdmin() {
<description>Posts from @admin@localhost:8080</description>
<pubDate>Wed, 20 Oct 2021 10:41:37 +0000</pubDate>
<lastBuildDate>Wed, 20 Oct 2021 10:41:37 +0000</lastBuildDate>
<item>
<title>introduction post</title>
<link>http://localhost:8080/@the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY</link>
<description>@the_mighty_zork@localhost:8080 made a new post: &#34;hello everyone!&#34;</description>
<content:encoded><![CDATA[hello everyone!]]></content:encoded>
<author>@the_mighty_zork@localhost:8080</author>
<guid isPermaLink="true">http://localhost:8080/@the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY</guid>
<pubDate>Wed, 20 Oct 2021 10:40:37 +0000</pubDate>
<source>http://localhost:8080/@the_mighty_zork/feed.rss</source>
</item>
<item>
<title>open to see some puppies</title>
<link>http://localhost:8080/@admin/statuses/01F8MHAAY43M6RJ473VQFCVH37</link>

View file

@ -274,6 +274,11 @@ func (p *Processor) Update(ctx context.Context, account *gtsmodel.Account, form
settingsColumns = append(settingsColumns, "enable_rss")
}
if form.HideBoosts != nil {
account.Settings.HideBoosts = form.HideBoosts
settingsColumns = append(settingsColumns, "hide_boosts")
}
if form.HideCollections != nil {
account.Settings.HideCollections = form.HideCollections
settingsColumns = append(settingsColumns, "hide_collections")

View file

@ -18,6 +18,7 @@
package delivery_test
import (
"bytes"
"fmt"
"io"
"math/rand"
@ -27,7 +28,6 @@
"strings"
"testing"
"codeberg.org/gruf/go-byteutil"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/httpclient"
"github.com/superseriousbusiness/gotosocial/internal/queue"
@ -176,9 +176,9 @@ func requiresBody(method string) bool {
func (t *testrequest) Generate(addr string) *http.Request {
var body io.ReadCloser
if t.body != nil {
var b byteutil.ReadNopCloser
var b bytes.Reader
b.Reset(t.body)
body = &b
body = io.NopCloser(&b)
}
req, err := http.NewRequest(t.method, addr+t.uri, body)
if err != nil {

View file

@ -302,7 +302,7 @@ func (c *Converter) accountToAPIAccountPublic(ctx context.Context, a *gtsmodel.A
// Bits that vary between remote + local accounts:
// - Account (acct) string.
// - Role.
// - Settings things (enableRSS, theme, customCSS, hideCollections).
// - Settings things (enableRSS, theme, customCSS, hideBoosts ,hideCollections).
var (
acct string
@ -310,6 +310,7 @@ func (c *Converter) accountToAPIAccountPublic(ctx context.Context, a *gtsmodel.A
enableRSS bool
theme string
customCSS string
hideBoosts bool
hideCollections bool
)
@ -338,6 +339,7 @@ func (c *Converter) accountToAPIAccountPublic(ctx context.Context, a *gtsmodel.A
enableRSS = *a.Settings.EnableRSS
theme = a.Settings.Theme
customCSS = a.Settings.CustomCSS
hideBoosts = *a.Settings.HideBoosts
hideCollections = *a.Settings.HideCollections
}
@ -380,6 +382,7 @@ func (c *Converter) accountToAPIAccountPublic(ctx context.Context, a *gtsmodel.A
Theme: theme,
CustomCSS: customCSS,
EnableRSS: enableRSS,
HideBoosts: hideBoosts,
HideCollections: hideCollections,
Roles: roles,
}
@ -1092,7 +1095,15 @@ func (c *Converter) StatusToWebStatus(
ctx context.Context,
s *gtsmodel.Status,
) (*apimodel.WebStatus, error) {
apiStatus, err := c.statusToFrontend(ctx, s,
isBoost := s.BoostOf != nil
status := s
if isBoost {
status = s.BoostOf
}
apiStatus, err := c.statusToFrontend(ctx, status,
nil, // No authed requester.
statusfilter.FilterContextNone, // No filters.
nil, // No filters.
@ -1103,7 +1114,7 @@ func (c *Converter) StatusToWebStatus(
}
// Convert status author to web model.
acct, err := c.AccountToWebAccount(ctx, s.Account)
acct, err := c.AccountToWebAccount(ctx, status.Account)
if err != nil {
return nil, err
}
@ -1113,6 +1124,14 @@ func (c *Converter) StatusToWebStatus(
Account: acct,
}
if isBoost {
reblogAcct, err := c.AccountToWebAccount(ctx, s.Account)
if err != nil {
return nil, err
}
webStatus.ReblogAccount = reblogAcct
}
// Whack a newline before and after each "pre" to make it easier to outdent it.
webStatus.Content = strings.ReplaceAll(webStatus.Content, "<pre>", "\n<pre>")
webStatus.Content = strings.ReplaceAll(webStatus.Content, "</pre>", "</pre>\n")

View file

@ -1402,6 +1402,7 @@ func (suite *InternalToFrontendTestSuite) TestStatusToWebStatus() {
"emojis": [],
"fields": []
},
"reblog_account": null,
"media_attachments": [
{
"id": "01HE7Y3C432WRSNS10EZM86SA5",

View file

@ -39,6 +39,12 @@
func (c *Converter) StatusToRSSItem(ctx context.Context, s *gtsmodel.Status) (*feeds.Item, error) {
// see https://cyber.harvard.edu/rss/rss.html
// If status is a boost,
// display the boost instead.
if s.BoostOf != nil {
s = s.BoostOf
}
// Title -- The title of the item.
// example: Venice Film Festival Tries to Quit Sinking
var title string

View file

@ -657,6 +657,7 @@ func NewTestAccountSettings() map[string]*gtsmodel.AccountSettings {
Sensitive: util.Ptr(false),
Language: "en",
EnableRSS: util.Ptr(false),
HideBoosts: util.Ptr(false),
HideCollections: util.Ptr(false),
WebVisibility: gtsmodel.VisibilityPublic,
},
@ -668,6 +669,7 @@ func NewTestAccountSettings() map[string]*gtsmodel.AccountSettings {
Sensitive: util.Ptr(false),
Language: "en",
EnableRSS: util.Ptr(true),
HideBoosts: util.Ptr(false),
HideCollections: util.Ptr(false),
WebVisibility: gtsmodel.VisibilityPublic,
},
@ -679,6 +681,7 @@ func NewTestAccountSettings() map[string]*gtsmodel.AccountSettings {
Sensitive: util.Ptr(false),
Language: "en",
EnableRSS: util.Ptr(true),
HideBoosts: util.Ptr(false),
HideCollections: util.Ptr(false),
WebVisibility: gtsmodel.VisibilityUnlocked,
},
@ -690,6 +693,7 @@ func NewTestAccountSettings() map[string]*gtsmodel.AccountSettings {
Sensitive: util.Ptr(true),
Language: "fr",
EnableRSS: util.Ptr(false),
HideBoosts: util.Ptr(false),
HideCollections: util.Ptr(true),
WebVisibility: gtsmodel.VisibilityPublic,
},

View file

@ -1,9 +0,0 @@
MIT License
Copyright (c) 2022 gruf
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View file

@ -1,3 +0,0 @@
# go-atomics
This library provides a variety of types for atomic operations on common Go types.

View file

@ -1,57 +0,0 @@
package atomics
import (
"sync/atomic"
"unsafe"
)
// {{ .Name }} provides user-friendly means of performing atomic operations on {{ .Type }} types.
type {{ .Name }} struct{ ptr unsafe.Pointer }
// New{{ .Name }} will return a new {{ .Name }} instance initialized with zero value.
func New{{ .Name }}() *{{ .Name }} {
var v {{ .Type }}
return &{{ .Name }}{
ptr: unsafe.Pointer(&v),
}
}
// Store will atomically store {{ .Type }} value in address contained within v.
func (v *{{ .Name }}) Store(val {{ .Type }}) {
atomic.StorePointer(&v.ptr, unsafe.Pointer(&val))
}
// Load will atomically load {{ .Type }} value at address contained within v.
func (v *{{ .Name }}) Load() {{ .Type }} {
return *(*{{ .Type }})(atomic.LoadPointer(&v.ptr))
}
// CAS performs a compare-and-swap for a(n) {{ .Type }} value at address contained within v.
func (v *{{ .Name }}) CAS(cmp, swp {{ .Type }}) bool {
for {
// Load current value at address
ptr := atomic.LoadPointer(&v.ptr)
cur := *(*{{ .Type }})(ptr)
// Perform comparison against current
if !({{ call .Compare "cur" "cmp" }}) {
return false
}
// Attempt to replace pointer
if atomic.CompareAndSwapPointer(
&v.ptr,
ptr,
unsafe.Pointer(&swp),
) {
return true
}
}
}
// Swap atomically stores new {{ .Type }} value into address contained within v, and returns previous value.
func (v *{{ .Name }}) Swap(swp {{ .Type }}) {{ .Type }} {
ptr := unsafe.Pointer(&swp)
ptr = atomic.SwapPointer(&v.ptr, ptr)
return *(*{{ .Type }})(ptr)
}

View file

@ -1,60 +0,0 @@
package atomics_test
import (
"atomic"
"unsafe"
"testing"
"codeberg.org/gruf/go-atomics"
)
func Test{{ .Name }}StoreLoad(t *testing.T) {
for _, test := range {{ .Name }}Tests {
val := atomics.New{{ .Name }}()
val.Store(test.V1)
if !({{ call .Compare "val.Load()" "test.V1" }}) {
t.Fatalf("failed testing .Store and .Load: expect=%v actual=%v", val.Load(), test.V1)
}
val.Store(test.V2)
if !({{ call .Compare "val.Load()" "test.V2" }}) {
t.Fatalf("failed testing .Store and .Load: expect=%v actual=%v", val.Load(), test.V2)
}
}
}
func Test{{ .Name }}CAS(t *testing.T) {
for _, test := range {{ .Name }}Tests {
val := atomics.New{{ .Name }}()
val.Store(test.V1)
if val.CAS(test.V2, test.V1) {
t.Fatalf("failed testing negative .CAS: test=%+v state=%v", test, val.Load())
}
if !val.CAS(test.V1, test.V2) {
t.Fatalf("failed testing positive .CAS: test=%+v state=%v", test, val.Load())
}
}
}
func Test{{ .Name }}Swap(t *testing.T) {
for _, test := range {{ .Name }}Tests {
val := atomics.New{{ .Name }}()
val.Store(test.V1)
if !({{ call .Compare "val.Swap(test.V2)" "test.V1" }}) {
t.Fatal("failed testing .Swap")
}
if !({{ call .Compare "val.Swap(test.V1)" "test.V2" }}) {
t.Fatal("failed testing .Swap")
}
}
}

View file

@ -1,47 +0,0 @@
package atomics
import "sync/atomic"
// Bool provides user-friendly means of performing atomic operations on bool types.
type Bool uint32
// NewBool will return a new Bool instance initialized with zero value.
func NewBool() *Bool {
return new(Bool)
}
// Store will atomically store bool value in address contained within i.
func (b *Bool) Store(val bool) {
atomic.StoreUint32((*uint32)(b), fromBool(val))
}
// Load will atomically load bool value at address contained within i.
func (b *Bool) Load() bool {
return toBool(atomic.LoadUint32((*uint32)(b)))
}
// CAS performs a compare-and-swap for a(n) bool value at address contained within i.
func (b *Bool) CAS(cmp, swp bool) bool {
return atomic.CompareAndSwapUint32((*uint32)(b), fromBool(cmp), fromBool(swp))
}
// Swap atomically stores new bool value into address contained within i, and returns previous value.
func (b *Bool) Swap(swp bool) bool {
return toBool(atomic.SwapUint32((*uint32)(b), fromBool(swp)))
}
// toBool converts uint32 value to bool.
func toBool(u uint32) bool {
if u == 0 {
return false
}
return true
}
// fromBool converts from bool to uint32 value.
func fromBool(b bool) uint32 {
if b {
return 1
}
return 0
}

View file

@ -1,57 +0,0 @@
package atomics
import (
"sync/atomic"
"unsafe"
)
// Bytes provides user-friendly means of performing atomic operations on []byte types.
type Bytes struct{ ptr unsafe.Pointer }
// NewBytes will return a new Bytes instance initialized with zero value.
func NewBytes() *Bytes {
var v []byte
return &Bytes{
ptr: unsafe.Pointer(&v),
}
}
// Store will atomically store []byte value in address contained within v.
func (v *Bytes) Store(val []byte) {
atomic.StorePointer(&v.ptr, unsafe.Pointer(&val))
}
// Load will atomically load []byte value at address contained within v.
func (v *Bytes) Load() []byte {
return *(*[]byte)(atomic.LoadPointer(&v.ptr))
}
// CAS performs a compare-and-swap for a(n) []byte value at address contained within v.
func (v *Bytes) CAS(cmp, swp []byte) bool {
for {
// Load current value at address
ptr := atomic.LoadPointer(&v.ptr)
cur := *(*[]byte)(ptr)
// Perform comparison against current
if !(string(cur) == string(cmp)) {
return false
}
// Attempt to replace pointer
if atomic.CompareAndSwapPointer(
&v.ptr,
ptr,
unsafe.Pointer(&swp),
) {
return true
}
}
}
// Swap atomically stores new []byte value into address contained within v, and returns previous value.
func (v *Bytes) Swap(swp []byte) []byte {
ptr := unsafe.Pointer(&swp)
ptr = atomic.SwapPointer(&v.ptr, ptr)
return *(*[]byte)(ptr)
}

View file

@ -1,57 +0,0 @@
package atomics
import (
"sync/atomic"
"unsafe"
)
// Error provides user-friendly means of performing atomic operations on error types.
type Error struct{ ptr unsafe.Pointer }
// NewError will return a new Error instance initialized with zero value.
func NewError() *Error {
var v error
return &Error{
ptr: unsafe.Pointer(&v),
}
}
// Store will atomically store error value in address contained within v.
func (v *Error) Store(val error) {
atomic.StorePointer(&v.ptr, unsafe.Pointer(&val))
}
// Load will atomically load error value at address contained within v.
func (v *Error) Load() error {
return *(*error)(atomic.LoadPointer(&v.ptr))
}
// CAS performs a compare-and-swap for a(n) error value at address contained within v.
func (v *Error) CAS(cmp, swp error) bool {
for {
// Load current value at address
ptr := atomic.LoadPointer(&v.ptr)
cur := *(*error)(ptr)
// Perform comparison against current
if !(cur == cmp) {
return false
}
// Attempt to replace pointer
if atomic.CompareAndSwapPointer(
&v.ptr,
ptr,
unsafe.Pointer(&swp),
) {
return true
}
}
}
// Swap atomically stores new error value into address contained within v, and returns previous value.
func (v *Error) Swap(swp error) error {
ptr := unsafe.Pointer(&swp)
ptr = atomic.SwapPointer(&v.ptr, ptr)
return *(*error)(ptr)
}

View file

@ -1,97 +0,0 @@
package atomics
import (
"sync/atomic"
"codeberg.org/gruf/go-bitutil"
)
// Flags32 provides user-friendly means of performing atomic operations on bitutil.Flags32 types.
type Flags32 bitutil.Flags32
// NewFlags32 will return a new Flags32 instance initialized with zero value.
func NewFlags32() *Flags32 {
return new(Flags32)
}
// Get will atomically load a(n) bitutil.Flags32 value contained within f, and check if bit value is set.
func (f *Flags32) Get(bit uint8) bool {
return f.Load().Get(bit)
}
// Set performs a compare-and-swap for a(n) bitutil.Flags32 with bit value set, at address contained within f.
func (f *Flags32) Set(bit uint8) bool {
cur := f.Load()
return f.CAS(cur, cur.Set(bit))
}
// Unset performs a compare-and-swap for a(n) bitutil.Flags32 with bit value unset, at address contained within f.
func (f *Flags32) Unset(bit uint8) bool {
cur := f.Load()
return f.CAS(cur, cur.Unset(bit))
}
// Store will atomically store bitutil.Flags32 value in address contained within f.
func (f *Flags32) Store(val bitutil.Flags32) {
atomic.StoreUint32((*uint32)(f), uint32(val))
}
// Load will atomically load bitutil.Flags32 value at address contained within f.
func (f *Flags32) Load() bitutil.Flags32 {
return bitutil.Flags32(atomic.LoadUint32((*uint32)(f)))
}
// CAS performs a compare-and-swap for a(n) bitutil.Flags32 value at address contained within f.
func (f *Flags32) CAS(cmp, swp bitutil.Flags32) bool {
return atomic.CompareAndSwapUint32((*uint32)(f), uint32(cmp), uint32(swp))
}
// Swap atomically stores new bitutil.Flags32 value into address contained within f, and returns previous value.
func (f *Flags32) Swap(swp bitutil.Flags32) bitutil.Flags32 {
return bitutil.Flags32(atomic.SwapUint32((*uint32)(f), uint32(swp)))
}
// Flags64 provides user-friendly means of performing atomic operations on bitutil.Flags64 types.
type Flags64 bitutil.Flags64
// NewFlags64 will return a new Flags64 instance initialized with zero value.
func NewFlags64() *Flags64 {
return new(Flags64)
}
// Get will atomically load a(n) bitutil.Flags64 value contained within f, and check if bit value is set.
func (f *Flags64) Get(bit uint8) bool {
return f.Load().Get(bit)
}
// Set performs a compare-and-swap for a(n) bitutil.Flags64 with bit value set, at address contained within f.
func (f *Flags64) Set(bit uint8) bool {
cur := f.Load()
return f.CAS(cur, cur.Set(bit))
}
// Unset performs a compare-and-swap for a(n) bitutil.Flags64 with bit value unset, at address contained within f.
func (f *Flags64) Unset(bit uint8) bool {
cur := f.Load()
return f.CAS(cur, cur.Unset(bit))
}
// Store will atomically store bitutil.Flags64 value in address contained within f.
func (f *Flags64) Store(val bitutil.Flags64) {
atomic.StoreUint64((*uint64)(f), uint64(val))
}
// Load will atomically load bitutil.Flags64 value at address contained within f.
func (f *Flags64) Load() bitutil.Flags64 {
return bitutil.Flags64(atomic.LoadUint64((*uint64)(f)))
}
// CAS performs a compare-and-swap for a(n) bitutil.Flags64 value at address contained within f.
func (f *Flags64) CAS(cmp, swp bitutil.Flags64) bool {
return atomic.CompareAndSwapUint64((*uint64)(f), uint64(cmp), uint64(swp))
}
// Swap atomically stores new bitutil.Flags64 value into address contained within f, and returns previous value.
func (f *Flags64) Swap(swp bitutil.Flags64) bitutil.Flags64 {
return bitutil.Flags64(atomic.SwapUint64((*uint64)(f), uint64(swp)))
}

View file

@ -1,69 +0,0 @@
package atomics
import "sync/atomic"
// Int32 provides user-friendly means of performing atomic operations on int32 types.
type Int32 int32
// NewInt32 will return a new Int32 instance initialized with zero value.
func NewInt32() *Int32 {
return new(Int32)
}
// Add will atomically add int32 delta to value in address contained within i, returning new value.
func (i *Int32) Add(delta int32) int32 {
return atomic.AddInt32((*int32)(i), delta)
}
// Store will atomically store int32 value in address contained within i.
func (i *Int32) Store(val int32) {
atomic.StoreInt32((*int32)(i), val)
}
// Load will atomically load int32 value at address contained within i.
func (i *Int32) Load() int32 {
return atomic.LoadInt32((*int32)(i))
}
// CAS performs a compare-and-swap for a(n) int32 value at address contained within i.
func (i *Int32) CAS(cmp, swp int32) bool {
return atomic.CompareAndSwapInt32((*int32)(i), cmp, swp)
}
// Swap atomically stores new int32 value into address contained within i, and returns previous value.
func (i *Int32) Swap(swp int32) int32 {
return atomic.SwapInt32((*int32)(i), swp)
}
// Int64 provides user-friendly means of performing atomic operations on int64 types.
type Int64 int64
// NewInt64 will return a new Int64 instance initialized with zero value.
func NewInt64() *Int64 {
return new(Int64)
}
// Add will atomically add int64 delta to value in address contained within i, returning new value.
func (i *Int64) Add(delta int64) int64 {
return atomic.AddInt64((*int64)(i), delta)
}
// Store will atomically store int64 value in address contained within i.
func (i *Int64) Store(val int64) {
atomic.StoreInt64((*int64)(i), val)
}
// Load will atomically load int64 value at address contained within i.
func (i *Int64) Load() int64 {
return atomic.LoadInt64((*int64)(i))
}
// CAS performs a compare-and-swap for a(n) int64 value at address contained within i.
func (i *Int64) CAS(cmp, swp int64) bool {
return atomic.CompareAndSwapInt64((*int64)(i), cmp, swp)
}
// Swap atomically stores new int64 value into address contained within i, and returns previous value.
func (i *Int64) Swap(swp int64) int64 {
return atomic.SwapInt64((*int64)(i), swp)
}

View file

@ -1,57 +0,0 @@
package atomics
import (
"sync/atomic"
"unsafe"
)
// Interface provides user-friendly means of performing atomic operations on interface{} types.
type Interface struct{ ptr unsafe.Pointer }
// NewInterface will return a new Interface instance initialized with zero value.
func NewInterface() *Interface {
var v interface{}
return &Interface{
ptr: unsafe.Pointer(&v),
}
}
// Store will atomically store interface{} value in address contained within v.
func (v *Interface) Store(val interface{}) {
atomic.StorePointer(&v.ptr, unsafe.Pointer(&val))
}
// Load will atomically load interface{} value at address contained within v.
func (v *Interface) Load() interface{} {
return *(*interface{})(atomic.LoadPointer(&v.ptr))
}
// CAS performs a compare-and-swap for a(n) interface{} value at address contained within v.
func (v *Interface) CAS(cmp, swp interface{}) bool {
for {
// Load current value at address
ptr := atomic.LoadPointer(&v.ptr)
cur := *(*interface{})(ptr)
// Perform comparison against current
if !(cur == cmp) {
return false
}
// Attempt to replace pointer
if atomic.CompareAndSwapPointer(
&v.ptr,
ptr,
unsafe.Pointer(&swp),
) {
return true
}
}
}
// Swap atomically stores new interface{} value into address contained within v, and returns previous value.
func (v *Interface) Swap(swp interface{}) interface{} {
ptr := unsafe.Pointer(&swp)
ptr = atomic.SwapPointer(&v.ptr, ptr)
return *(*interface{})(ptr)
}

View file

@ -1,58 +0,0 @@
package atomics
import "sync"
// State provides user-friendly means of performing atomic-like
// operations on a uint32 state, and allowing callbacks on successful
// state change. This is a bit of a misnomer being where it is, as it
// actually uses a mutex under-the-hood.
type State struct {
mutex sync.Mutex
state uint32
}
// Store will update State value safely within mutex lock.
func (st *State) Store(val uint32) {
st.mutex.Lock()
st.state = val
st.mutex.Unlock()
}
// Load will get value of State safely within mutex lock.
func (st *State) Load() uint32 {
st.mutex.Lock()
state := st.state
st.mutex.Unlock()
return state
}
// WithLock performs fn within State mutex lock, useful if you want
// to just use State's mutex for locking instead of creating another.
func (st *State) WithLock(fn func()) {
st.mutex.Lock()
defer st.mutex.Unlock()
fn()
}
// Update performs fn within State mutex lock, with the current state
// value provided as an argument, and return value used to update state.
func (st *State) Update(fn func(state uint32) uint32) {
st.mutex.Lock()
defer st.mutex.Unlock()
st.state = fn(st.state)
}
// CAS performs a compare-and-swap on State, calling fn on success. Success value is also returned.
func (st *State) CAS(cmp, swp uint32, fn func()) (ok bool) {
// Acquire lock
st.mutex.Lock()
defer st.mutex.Unlock()
// Perform CAS operation, fn() on success
if ok = (st.state == cmp); ok {
st.state = swp
fn()
}
return
}

View file

@ -1,57 +0,0 @@
package atomics
import (
"sync/atomic"
"unsafe"
)
// String provides user-friendly means of performing atomic operations on string types.
type String struct{ ptr unsafe.Pointer }
// NewString will return a new String instance initialized with zero value.
func NewString() *String {
var v string
return &String{
ptr: unsafe.Pointer(&v),
}
}
// Store will atomically store string value in address contained within v.
func (v *String) Store(val string) {
atomic.StorePointer(&v.ptr, unsafe.Pointer(&val))
}
// Load will atomically load string value at address contained within v.
func (v *String) Load() string {
return *(*string)(atomic.LoadPointer(&v.ptr))
}
// CAS performs a compare-and-swap for a(n) string value at address contained within v.
func (v *String) CAS(cmp, swp string) bool {
for {
// Load current value at address
ptr := atomic.LoadPointer(&v.ptr)
cur := *(*string)(ptr)
// Perform comparison against current
if !(cur == cmp) {
return false
}
// Attempt to replace pointer
if atomic.CompareAndSwapPointer(
&v.ptr,
ptr,
unsafe.Pointer(&swp),
) {
return true
}
}
}
// Swap atomically stores new string value into address contained within v, and returns previous value.
func (v *String) Swap(swp string) string {
ptr := unsafe.Pointer(&swp)
ptr = atomic.SwapPointer(&v.ptr, ptr)
return *(*string)(ptr)
}

View file

@ -1,58 +0,0 @@
package atomics
import (
"sync/atomic"
"time"
"unsafe"
)
// Time provides user-friendly means of performing atomic operations on time.Time types.
type Time struct{ ptr unsafe.Pointer }
// NewTime will return a new Time instance initialized with zero value.
func NewTime() *Time {
var v time.Time
return &Time{
ptr: unsafe.Pointer(&v),
}
}
// Store will atomically store time.Time value in address contained within v.
func (v *Time) Store(val time.Time) {
atomic.StorePointer(&v.ptr, unsafe.Pointer(&val))
}
// Load will atomically load time.Time value at address contained within v.
func (v *Time) Load() time.Time {
return *(*time.Time)(atomic.LoadPointer(&v.ptr))
}
// CAS performs a compare-and-swap for a(n) time.Time value at address contained within v.
func (v *Time) CAS(cmp, swp time.Time) bool {
for {
// Load current value at address
ptr := atomic.LoadPointer(&v.ptr)
cur := *(*time.Time)(ptr)
// Perform comparison against current
if !(cur.Equal(cmp)) {
return false
}
// Attempt to replace pointer
if atomic.CompareAndSwapPointer(
&v.ptr,
ptr,
unsafe.Pointer(&swp),
) {
return true
}
}
}
// Swap atomically stores new time.Time value into address contained within v, and returns previous value.
func (v *Time) Swap(swp time.Time) time.Time {
ptr := unsafe.Pointer(&swp)
ptr = atomic.SwapPointer(&v.ptr, ptr)
return *(*time.Time)(ptr)
}

View file

@ -1,69 +0,0 @@
package atomics
import "sync/atomic"
// Uint32 provides user-friendly means of performing atomic operations on uint32 types.
type Uint32 uint32
// NewUint32 will return a new Uint32 instance initialized with zero value.
func NewUint32() *Uint32 {
return new(Uint32)
}
// Add will atomically add uint32 delta to value in address contained within i, returning new value.
func (u *Uint32) Add(delta uint32) uint32 {
return atomic.AddUint32((*uint32)(u), delta)
}
// Store will atomically store uint32 value in address contained within i.
func (u *Uint32) Store(val uint32) {
atomic.StoreUint32((*uint32)(u), val)
}
// Load will atomically load uint32 value at address contained within i.
func (u *Uint32) Load() uint32 {
return atomic.LoadUint32((*uint32)(u))
}
// CAS performs a compare-and-swap for a(n) uint32 value at address contained within i.
func (u *Uint32) CAS(cmp, swp uint32) bool {
return atomic.CompareAndSwapUint32((*uint32)(u), cmp, swp)
}
// Swap atomically stores new uint32 value into address contained within i, and returns previous value.
func (u *Uint32) Swap(swp uint32) uint32 {
return atomic.SwapUint32((*uint32)(u), swp)
}
// Uint64 provides user-friendly means of performing atomic operations on uint64 types.
type Uint64 uint64
// NewUint64 will return a new Uint64 instance initialized with zero value.
func NewUint64() *Uint64 {
return new(Uint64)
}
// Add will atomically add uint64 delta to value in address contained within i, returning new value.
func (u *Uint64) Add(delta uint64) uint64 {
return atomic.AddUint64((*uint64)(u), delta)
}
// Store will atomically store uint64 value in address contained within i.
func (u *Uint64) Store(val uint64) {
atomic.StoreUint64((*uint64)(u), val)
}
// Load will atomically load uint64 value at address contained within i.
func (u *Uint64) Load() uint64 {
return atomic.LoadUint64((*uint64)(u))
}
// CAS performs a compare-and-swap for a(n) uint64 value at address contained within i.
func (u *Uint64) CAS(cmp, swp uint64) bool {
return atomic.CompareAndSwapUint64((*uint64)(u), cmp, swp)
}
// Swap atomically stores new uint64 value into address contained within i, and returns previous value.
func (u *Uint64) Swap(swp uint64) uint64 {
return atomic.SwapUint64((*uint64)(u), swp)
}

View file

@ -1,9 +0,0 @@
MIT License
Copyright (c) 2022 gruf
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View file

@ -1,3 +0,0 @@
# go-bitutil
This library provides helpful methods and types for performing typical bitwise operations on integers, e.g. packing/unpacking, bit flags.

View file

@ -1,29 +0,0 @@
package bitutil
// Abs8 returns the absolute value of i (calculated without branching).
func Abs8(i int8) int8 {
const bits = 8
u := uint64(i >> (bits - 1))
return (i ^ int8(u)) + int8(u&1)
}
// Abs16 returns the absolute value of i (calculated without branching).
func Abs16(i int16) int16 {
const bits = 16
u := uint64(i >> (bits - 1))
return (i ^ int16(u)) + int16(u&1)
}
// Abs32 returns the absolute value of i (calculated without branching).
func Abs32(i int32) int32 {
const bits = 32
u := uint64(i >> (bits - 1))
return (i ^ int32(u)) + int32(u&1)
}
// Abs64 returns the absolute value of i (calculated without branching).
func Abs64(i int64) int64 {
const bits = 64
u := uint64(i >> (bits - 1))
return (i ^ int64(u)) + int64(u&1)
}

File diff suppressed because it is too large Load diff

View file

@ -1,117 +0,0 @@
package bitutil
import (
"strings"
"unsafe"
)
{{ range $idx, $size := . }}
// Flags{{ $size.Size }} is a type-casted unsigned integer with helper
// methods for easily managing up to {{ $size.Size }} bit-flags.
type Flags{{ $size.Size }} uint{{ $size.Size }}
// Get will fetch the flag bit value at index 'bit'.
func (f Flags{{ $size.Size }}) Get(bit uint8) bool {
mask := Flags{{ $size.Size }}(1) << bit
return (f & mask != 0)
}
// Set will set the flag bit value at index 'bit'.
func (f Flags{{ $size.Size }}) Set(bit uint8) Flags{{ $size.Size }} {
mask := Flags{{ $size.Size }}(1) << bit
return f | mask
}
// Unset will unset the flag bit value at index 'bit'.
func (f Flags{{ $size.Size }}) Unset(bit uint8) Flags{{ $size.Size }} {
mask := Flags{{ $size.Size }}(1) << bit
return f & ^mask
}
{{ range $idx := $size.Bits }}
// Get{{ $idx }} will fetch the flag bit value at index {{ $idx }}.
func (f Flags{{ $size.Size }}) Get{{ $idx }}() bool {
const mask = Flags{{ $size.Size }}(1) << {{ $idx }}
return (f & mask != 0)
}
// Set{{ $idx }} will set the flag bit value at index {{ $idx }}.
func (f Flags{{ $size.Size }}) Set{{ $idx }}() Flags{{ $size.Size }} {
const mask = Flags{{ $size.Size }}(1) << {{ $idx }}
return f | mask
}
// Unset{{ $idx }} will unset the flag bit value at index {{ $idx }}.
func (f Flags{{ $size.Size }}) Unset{{ $idx }}() Flags{{ $size.Size }} {
const mask = Flags{{ $size.Size }}(1) << {{ $idx }}
return f & ^mask
}
{{ end }}
// String returns a human readable representation of Flags{{ $size.Size }}.
func (f Flags{{ $size.Size }}) String() string {
var (
i int
val bool
buf []byte
)
// Make a prealloc est. based on longest-possible value
const prealloc = 1+(len("false ")*{{ $size.Size }})-1+1
buf = make([]byte, prealloc)
buf[i] = '{'
i++
{{ range $idx := .Bits }}
val = f.Get{{ $idx }}()
i += copy(buf[i:], bool2str(val))
buf[i] = ' '
i++
{{ end }}
buf[i-1] = '}'
buf = buf[:i]
return *(*string)(unsafe.Pointer(&buf))
}
// GoString returns a more verbose human readable representation of Flags{{ $size.Size }}.
func (f Flags{{ $size.Size }})GoString() string {
var (
i int
val bool
buf []byte
)
// Make a prealloc est. based on longest-possible value
const prealloc = len("bitutil.Flags{{ $size.Size }}{")+(len("{{ sub $size.Size 1 }}=false ")*{{ $size.Size }})-1+1
buf = make([]byte, prealloc)
i += copy(buf[i:], "bitutil.Flags{{ $size.Size }}{")
{{ range $idx := .Bits }}
val = f.Get{{ $idx }}()
i += copy(buf[i:], "{{ $idx }}=")
i += copy(buf[i:], bool2str(val))
buf[i] = ' '
i++
{{ end }}
buf[i-1] = '}'
buf = buf[:i]
return *(*string)(unsafe.Pointer(&buf))
}
{{ end }}
func bool2str(b bool) string {
if b {
return "true"
}
return "false"
}

View file

@ -1,98 +0,0 @@
package bitutil_test
import (
"strings"
"testing"
"codeberg.org/gruf/go-bytes"
)
{{ range $idx, $size := . }}
func TestFlags{{ $size.Size }}Get(t *testing.T) {
var mask, flags bitutil.Flags{{ $size.Size }}
{{ range $idx := $size.Bits }}
mask = bitutil.Flags{{ $size.Size }}(1) << {{ $idx }}
flags = 0
flags |= mask
if !flags.Get({{ $idx }}) {
t.Error("failed .Get() set Flags{{ $size.Size }} bit at index {{ $idx }}")
}
flags = ^bitutil.Flags{{ $size.Size }}(0)
flags &= ^mask
if flags.Get({{ $idx }}) {
t.Error("failed .Get() unset Flags{{ $size.Size }} bit at index {{ $idx }}")
}
flags = 0
flags |= mask
if !flags.Get{{ $idx }}() {
t.Error("failed .Get{{ $idx }}() set Flags{{ $size.Size }} bit at index {{ $idx }}")
}
flags = ^bitutil.Flags{{ $size.Size }}(0)
flags &= ^mask
if flags.Get{{ $idx }}() {
t.Error("failed .Get{{ $idx }}() unset Flags{{ $size.Size }} bit at index {{ $idx }}")
}
{{ end }}
}
func TestFlags{{ $size.Size }}Set(t *testing.T) {
var mask, flags bitutil.Flags{{ $size.Size }}
{{ range $idx := $size.Bits }}
mask = bitutil.Flags{{ $size.Size }}(1) << {{ $idx }}
flags = 0
flags = flags.Set({{ $idx }})
if flags & mask == 0 {
t.Error("failed .Set() Flags{{ $size.Size }} bit at index {{ $idx }}")
}
flags = 0
flags = flags.Set{{ $idx }}()
if flags & mask == 0 {
t.Error("failed .Set{{ $idx }}() Flags{{ $size.Size }} bit at index {{ $idx }}")
}
{{ end }}
}
func TestFlags{{ $size.Size }}Unset(t *testing.T) {
var mask, flags bitutil.Flags{{ $size.Size }}
{{ range $idx := $size.Bits }}
mask = bitutil.Flags{{ $size.Size }}(1) << {{ $idx }}
flags = ^bitutil.Flags{{ $size.Size }}(0)
flags = flags.Unset({{ $idx }})
if flags & mask != 0 {
t.Error("failed .Unset() Flags{{ $size.Size }} bit at index {{ $idx }}")
}
flags = ^bitutil.Flags{{ $size.Size }}(0)
flags = flags.Unset{{ $idx }}()
if flags & mask != 0 {
t.Error("failed .Unset{{ $idx }}() Flags{{ $size.Size }} bit at index {{ $idx }}")
}
{{ end }}
}
{{ end }}

View file

@ -1,85 +0,0 @@
package bitutil
// PackInt8s will pack two signed 8bit integers into an unsigned 16bit integer.
func PackInt8s(i1, i2 int8) uint16 {
const bits = 8
const mask = (1 << bits) - 1
return uint16(i1)<<bits | uint16(i2)&mask
}
// UnpackInt8s will unpack two signed 8bit integers from an unsigned 16bit integer.
func UnpackInt8s(i uint16) (int8, int8) {
const bits = 8
const mask = (1 << bits) - 1
return int8(i >> bits), int8(i & mask)
}
// PackInt16s will pack two signed 16bit integers into an unsigned 32bit integer.
func PackInt16s(i1, i2 int16) uint32 {
const bits = 16
const mask = (1 << bits) - 1
return uint32(i1)<<bits | uint32(i2)&mask
}
// UnpackInt16s will unpack two signed 16bit integers from an unsigned 32bit integer.
func UnpackInt16s(i uint32) (int16, int16) {
const bits = 16
const mask = (1 << bits) - 1
return int16(i >> bits), int16(i & mask)
}
// PackInt32s will pack two signed 32bit integers into an unsigned 64bit integer.
func PackInt32s(i1, i2 int32) uint64 {
const bits = 32
const mask = (1 << bits) - 1
return uint64(i1)<<bits | uint64(i2)&mask
}
// UnpackInt32s will unpack two signed 32bit integers from an unsigned 64bit integer.
func UnpackInt32s(i uint64) (int32, int32) {
const bits = 32
const mask = (1 << bits) - 1
return int32(i >> bits), int32(i & mask)
}
// PackUint8s will pack two unsigned 8bit integers into an unsigned 16bit integer.
func PackUint8s(u1, u2 uint8) uint16 {
const bits = 8
const mask = (1 << bits) - 1
return uint16(u1)<<bits | uint16(u2)&mask
}
// UnpackUint8s will unpack two unsigned 8bit integers from an unsigned 16bit integer.
func UnpackUint8s(u uint16) (uint8, uint8) {
const bits = 8
const mask = (1 << bits) - 1
return uint8(u >> bits), uint8(u & mask)
}
// PackUint16s will pack two unsigned 16bit integers into an unsigned 32bit integer.
func PackUint16s(u1, u2 uint16) uint32 {
const bits = 16
const mask = (1 << bits) - 1
return uint32(u1)<<bits | uint32(u2)&mask
}
// UnpackUint16s will unpack two unsigned 16bit integers from an unsigned 32bit integer.
func UnpackUint16s(u uint32) (uint16, uint16) {
const bits = 16
const mask = (1 << bits) - 1
return uint16(u >> bits), uint16(u & mask)
}
// PackUint32s will pack two unsigned 32bit integers into an unsigned 64bit integer.
func PackUint32s(u1, u2 uint32) uint64 {
const bits = 32
const mask = (1 << bits) - 1
return uint64(u1)<<bits | uint64(u2)&mask
}
// UnpackUint32s will unpack two unsigned 32bit integers from an unsigned 64bit integer.
func UnpackUint32s(u uint64) (uint32, uint32) {
const bits = 32
const mask = (1 << bits) - 1
return uint32(u >> bits), uint32(u & mask)
}

View file

@ -1,60 +0,0 @@
package atomics_test
import (
"atomic"
"unsafe"
"testing"
"codeberg.org/gruf/go-atomics"
)
func Test{{ .Name }}StoreLoad(t *testing.T) {
for _, test := range {{ .Name }}Tests {
val := atomics.New{{ .Name }}()
val.Store(test.V1)
if !({{ call .Compare "val.Load()" "test.V1" }}) {
t.Fatalf("failed testing .Store and .Load: expect=%v actual=%v", val.Load(), test.V1)
}
val.Store(test.V2)
if !({{ call .Compare "val.Load()" "test.V2" }}) {
t.Fatalf("failed testing .Store and .Load: expect=%v actual=%v", val.Load(), test.V2)
}
}
}
func Test{{ .Name }}CAS(t *testing.T) {
for _, test := range {{ .Name }}Tests {
val := atomics.New{{ .Name }}()
val.Store(test.V1)
if val.CAS(test.V2, test.V1) {
t.Fatalf("failed testing negative .CAS: test=%+v state=%v", test, val.Load())
}
if !val.CAS(test.V1, test.V2) {
t.Fatalf("failed testing positive .CAS: test=%+v state=%v", test, val.Load())
}
}
}
func Test{{ .Name }}Swap(t *testing.T) {
for _, test := range {{ .Name }}Tests {
val := atomics.New{{ .Name }}()
val.Store(test.V1)
if !({{ call .Compare "val.Swap(test.V2)" "test.V1" }}) {
t.Fatal("failed testing .Swap")
}
if !({{ call .Compare "val.Swap(test.V1)" "test.V2" }}) {
t.Fatal("failed testing .Swap")
}
}
}

View file

@ -1,7 +1,6 @@
package byteutil
import (
"reflect"
"unsafe"
)
@ -16,44 +15,13 @@ func Copy(b []byte) []byte {
}
// B2S returns a string representation of []byte without allocation.
//
// According to the Go spec strings are immutable and byte slices are not. The way this gets implemented is strings under the hood are:
//
// type StringHeader struct {
// Data uintptr
// Len int
// }
//
// while slices are:
//
// type SliceHeader struct {
// Data uintptr
// Len int
// Cap int
// }
//
// because being mutable, you can change the data, length etc, but the string has to promise to be read-only to all who get copies of it.
//
// So in practice when you do a conversion of `string(byteSlice)` it actually performs an allocation because it has to copy the contents of the byte slice into a safe read-only state.
//
// Being that the shared fields are in the same struct indices (no different offsets), means that if you have a byte slice you can "forcibly" cast it to a string. Which in a lot of situations can be risky, because then it means you have a string that is NOT immutable, as if someone changes the data in the originating byte slice then the string will reflect that change! Now while this does seem hacky, and it _kind_ of is, it is something that you see performed in the standard library. If you look at the definition for `strings.Builder{}.String()` you'll see this :)
// Since Go strings are immutable, the bytes passed to String must
// not be modified as long as the returned string value exists.
func B2S(b []byte) string {
return *(*string)(unsafe.Pointer(&b))
return unsafe.String(unsafe.SliceData(b), len(b))
}
// S2B returns a []byte representation of string without allocation (minus slice header).
// See B2S() code comment, and this function's implementation for a better understanding.
// S2B returns a []byte representation of string without allocation.
func S2B(s string) []byte {
var b []byte
// Get byte + string headers
bh := (*reflect.SliceHeader)(unsafe.Pointer(&b))
sh := (*reflect.StringHeader)(unsafe.Pointer(&s))
// Manually set bytes to string
bh.Data = sh.Data
bh.Len = sh.Len
bh.Cap = sh.Len
return b
return unsafe.Slice(unsafe.StringData(s), len(s))
}

View file

@ -1,36 +0,0 @@
package byteutil
import "bytes"
// Reader wraps a bytes.Reader{} to provide Rewind() capabilities.
type Reader struct {
B []byte
bytes.Reader
}
// NewReader returns a new Reader{} instance reset to b.
func NewReader(b []byte) *Reader {
r := &Reader{}
r.Reset(b)
return r
}
// Reset resets the Reader{} to be reading from b and sets Reader{}.B.
func (r *Reader) Reset(b []byte) {
r.B = b
r.Rewind()
}
// Rewind resets the Reader{} to be reading from the start of Reader{}.B.
func (r *Reader) Rewind() {
r.Reader.Reset(r.B)
}
// ReadNopCloser wraps a Reader{} to provide nop close method.
type ReadNopCloser struct {
Reader
}
func (*ReadNopCloser) Close() error {
return nil
}

View file

@ -4,9 +4,9 @@
"reflect"
"strconv"
"strings"
"sync/atomic"
"time"
"codeberg.org/gruf/go-atomics"
"unsafe"
)
// Job encapsulates logic for a scheduled job to be run according
@ -14,7 +14,7 @@
// holding onto a next execution time safely in a concurrent environment.
type Job struct {
id uint64
next atomics.Time
next unsafe.Pointer // *time.Time
timing Timing
call func(time.Time)
panic func(interface{})
@ -33,9 +33,6 @@ func NewJob(fn func(now time.Time)) *Job {
panic: func(i interface{}) { panic(i) },
}
// Init next time ptr
j.next.Store(zerotime)
return j
}
@ -99,14 +96,20 @@ func (job *Job) OnPanic(fn func(interface{})) *Job {
// Next returns the next time this Job is expected to run.
func (job *Job) Next() time.Time {
return job.next.Load()
return loadTime(&job.next)
}
// Run will execute this Job and pass through given now time.
func (job *Job) Run(now time.Time) {
defer func() {
if r := recover(); r != nil {
switch r := recover(); {
case r == nil:
// no panic
case job != nil &&
job.panic != nil:
job.panic(r)
default:
panic(r)
}
}()
job.call(now)
@ -120,10 +123,21 @@ func (job *Job) String() string {
buf.WriteString(strconv.FormatUint(job.id, 10))
buf.WriteByte(' ')
buf.WriteString("next=")
buf.WriteString(job.next.Load().Format(time.StampMicro))
buf.WriteString(loadTime(&job.next).Format(time.StampMicro))
buf.WriteByte(' ')
buf.WriteString("timing=")
buf.WriteString(reflect.TypeOf(job.timing).String())
buf.WriteByte('}')
return buf.String()
}
func loadTime(p *unsafe.Pointer) time.Time {
if p := atomic.LoadPointer(p); p != nil {
return *(*time.Time)(p)
}
return zerotime
}
func storeTime(p *unsafe.Pointer, t time.Time) {
atomic.StorePointer(p, unsafe.Pointer(&t))
}

View file

@ -225,7 +225,7 @@ func (sch *Scheduler) handle(v interface{}) {
// Update the next call time
next := v.timing.Next(now)
v.next.Store(next)
storeTime(&v.next, next)
// Append this job to queued
sch.jobs = append(sch.jobs, v)
@ -261,7 +261,7 @@ func (sch *Scheduler) schedule(now time.Time) {
// Update the next call time
next := job.timing.Next(now)
job.next.Store(next)
storeTime(&job.next, next)
if next.IsZero() {
// Zero time, this job is done and can be dropped

14
vendor/modules.txt vendored
View file

@ -1,17 +1,11 @@
# codeberg.org/gruf/go-atomics v1.1.0
## explicit; go 1.16
codeberg.org/gruf/go-atomics
# codeberg.org/gruf/go-bitutil v1.1.0
## explicit; go 1.19
codeberg.org/gruf/go-bitutil
# codeberg.org/gruf/go-bytes v1.0.2
## explicit; go 1.14
codeberg.org/gruf/go-bytes
# codeberg.org/gruf/go-bytesize v1.0.3
## explicit; go 1.17
codeberg.org/gruf/go-bytesize
# codeberg.org/gruf/go-byteutil v1.2.0
## explicit; go 1.16
# codeberg.org/gruf/go-byteutil v1.3.0
## explicit; go 1.20
codeberg.org/gruf/go-byteutil
# codeberg.org/gruf/go-cache/v3 v3.5.7
## explicit; go 1.19
@ -59,10 +53,10 @@ codeberg.org/gruf/go-mimetypes
# codeberg.org/gruf/go-mutexes v1.5.1
## explicit; go 1.22.2
codeberg.org/gruf/go-mutexes
# codeberg.org/gruf/go-runners v1.6.2
# codeberg.org/gruf/go-runners v1.6.3
## explicit; go 1.19
codeberg.org/gruf/go-runners
# codeberg.org/gruf/go-sched v1.2.3
# codeberg.org/gruf/go-sched v1.2.4
## explicit; go 1.19
codeberg.org/gruf/go-sched
# codeberg.org/gruf/go-storage v0.2.0

View file

@ -22,7 +22,7 @@
--blue3: var(--blurple3);
/* Basic page styling (background + foreground) */
--bg: linear-gradient(var(--blurple7), black);
--bg: var(--blurple7);
--bg-accent: var(--blurple6);
--fg: var(--blurple1);
--fg-reduced: var(--blurple2);
@ -44,6 +44,11 @@
--boxshadow-border: 0.08rem solid black;
}
/* Main page background */
body {
background: linear-gradient(var(--blurple7), black);
}
/* Scroll bar */
html, body {
scrollbar-color: var(--blurple4) var(--blurple7);

View file

@ -24,7 +24,7 @@
--blue3: var(--blurple6);
/* Basic page styling (background + foreground) */
--bg: linear-gradient(var(--blurple1), white);
--bg: var(--blurple1);
--bg-accent: var(--white2);
--fg: var(--gray1);
--fg-reduced: var(--gray2);
@ -46,6 +46,11 @@
--boxshadow-border: 0.08rem solid var(--blurple6);
}
/* Main page background */
body {
background: linear-gradient(var(--blurple1), white);
}
/* Scroll bar */
html, body {
scrollbar-color: var(--blurple5) var(--blurple2);

View file

@ -66,11 +66,7 @@
--blue3: var(--ecks-pee-white);
/* Basic page styling (background + foreground) */
--bg: radial-gradient(
circle closest-corner at 20% 20%,
var(--ecks-pee-lighter-blue),
var(--ecks-pee-light-blue)
);
--bg: var(--ecks-pee-light-blue);
--bg-accent: var(--ecks-pee-blue);
--fg: var(--ecks-pee-white);
--fg-reduced: var(--ecks-pee-lightest-blue);
@ -122,6 +118,15 @@
src: url(/assets/fonts/Atkinson-Hyperlegible-BoldItalic-102.woff) format('woff');
}
/* Main page background */
body {
background: radial-gradient(
circle closest-corner at 20% 20%,
var(--ecks-pee-lighter-blue),
var(--ecks-pee-light-blue)
);
}
/* Scroll bar */
html, body {
/* Try Atkinson, fall back to default GtS fonts */

View file

@ -19,8 +19,14 @@
--blue3: var(--acid-green);
}
/* Main page background */
body {
background: linear-gradient(90deg, var(--darkmagenta), black, var(--darkmagenta));
background: linear-gradient(
90deg,
var(--darkmagenta),
black,
var(--darkmagenta)
);
}
html, body {

View file

@ -8,21 +8,21 @@
v1.0 by xmgz at github */
:root {
/* color definitions */
--dgreen1: #003333;
--dgreen2: #196C41;
--dgreen3: #027C68;
--dgreen4: #009933;
--dblue1: #141E46; /* very dark blue */
--typecolor: #F8F4EC;
--linkcolor: #c0f0c0; /* very soft lime green */
--sunny: #FCDC2A;
--lesssunny: #FF7431; /* papaya */
/* wood/earth colors */
--codebg: #3A2722; /* darker caoba */
--quotebg: #800000; /* maroon */
/* water, post's date and stats. User stats */
--fg-reduced: #BBEBFF;
/* color definitions */
--dgreen1: #003333;
--dgreen2: #196C41;
--dgreen3: #027C68;
--dgreen4: #009933;
--dblue1: #141E46; /* very dark blue */
--typecolor: #F8F4EC;
--linkcolor: #c0f0c0; /* very soft lime green */
--sunny: #FCDC2A;
--lesssunny: #FF7431; /* papaya */
/* wood/earth colors */
--codebg: #3A2722; /* darker caoba */
--quotebg: #800000; /* maroon */
/* water, post's date and stats. User stats */
--fg-reduced: #BBEBFF;
/* Restyle basic colors */
--blue1: var(--dgreen2);
@ -43,12 +43,9 @@
--button-bg: var(--lesssunny);
--button-fg: var(--dblue1);
/* Used around statuses + other items */
--boxshadow: 0 0.4rem 0.7rem -0.1rem rgba(252,220,42,0.15); /* subtle status glow */
--boxshadow-border: 0.07rem solid var(--lesssunny); /* thin papaya border */
}

View file

@ -20,7 +20,7 @@
--br-inner: 0.4rem;
/* Basic page styling (background + foreground) */
--bg: linear-gradient(-90deg, var(--soft-blue), var(--soft-pink), white, var(--soft-pink), var(--soft-blue));
--bg: var(--soft-pink);
--bg-accent: var(--soft-pink-translucent);
--fg: var(--gray1);
--fg-reduced: var(--gray3);
@ -41,6 +41,18 @@
--boxshadow-border: 0.08rem solid var(--gray8);
}
/* Main page background */
body {
background: linear-gradient(
-90deg,
var(--soft-blue),
var(--soft-pink),
white,
var(--soft-pink),
var(--soft-blue)
);
}
/* Scroll bar */
html, body {
scrollbar-color: var(--orange2) var(--soft-pink);

View file

@ -29,40 +29,29 @@
:root {
/* Define solarized palette */
--base3: #002b36;
--base2: #073642;
--base1: #586e75;
--base0: #657b83;
--base00: #839496;
--base01: #93a1a1;
--base02: #eee8d5;
--base03: #fdf6e3;
--yellow: #b58900;
--orange: #cb4b16;
--red: #dc322f;
--magenta: #d33682;
--violet: #6c71c4;
--blue: #268bd2;
--cyan: #2aa198;
--green: #859900;
--base03: #002b36; /* Background. */
--base02: #073642; /* Background highlights. */
--base01: #586e75; /* Comments / secondary color. */
--base0: #839496; /* Body text / default code / primary content. */
--base1: #93a1a1; /* Optional emphasized content. */
--red: #dc322f; /* Trim. */
/* Override orange trim */
--orange2: var(--red);
/* Restyle basic colors to use Solarized */
--white1: var(--base3);
--white2: var(--base2);
--blue1: var(--cyan);
--blue2: var(--base03);
--blue3: var(--base02);
--white1: var(--base02);
--white2: var(--base03);
--blue2: var(--base0);
--blue3: var(--base1);
/* Basic page styling (background + foreground) */
--bg: var(--white1);
--bg-accent: var(--white2);
--fg: var(--base02);
--fg-reduced: var(--base01);
--fg-reduced: var(--base0);
--fg: var(--base1);
/* Profile page styling (light) */
/* Profile page styling */
--profile-bg: var(--white2);
/* Solarize buttons */
@ -76,10 +65,10 @@
--status-focus-info-bg: var(--white2);
/* Used around statuses + other items */
--boxshadow-border: 0.1rem solid var(--base1);
--boxshadow-border: 0.15rem solid var(--base01);
--plyr-video-control-color: var(--fg-reduced);
--plyr-video-control-color-hover: var(--fg);
--plyr-video-control-color: var(--fg);
--plyr-video-control-color-hover: var(--fg-reduced);
}
@font-face {
@ -108,7 +97,7 @@ html, body {
border: var(--boxshadow-border);
}
.status .media .media-wrapper details .unknown-attachment .placeholder {
color: var(--blue2);
color: var(--base01);
}
.status .media .media-wrapper details video.plyr-video {
background: transparent;
@ -126,22 +115,38 @@ html, body {
pre, pre[class*="language-"],
code, code[class*="language-"] {
background-color: black;
color: var(--base03);
color: #93a1a1;
}
/* Block quotes */
blockquote {
background-color: var(--bg-accent);
color: var(--fg);
background-color: var(--base03);
color: var(--base0);
}
button,
.button,
button, .button,
.status .text-spoiler > summary .button {
font-family: 'Noto Sans Mono', monospace;
}
.button {
color: var(--base0);
background: var(--base03);
border: var(--boxshadow-border);
}
.button:hover {
color: var(--base1);
background: var(--base02);
border: var(--boxshadow-border);
}
/* Ensure role badge readable */
.profile .profile-header .basic-info .namerole .role.admin {
color: var(--base03);
}
.col-header a {
font-size: 1.2rem;
font-weight: bold;
}

View file

@ -1,6 +1,6 @@
/*
theme-title: Solarized (light)
theme-description: Solarized sloth (light)
theme-title: Solarized (dark)
theme-description: Solarized sloth (dark)
*/
/*
@ -29,40 +29,29 @@
:root {
/* Define solarized palette */
--base03: #002b36;
--base02: #073642;
--base01: #586e75;
--base00: #657b83;
--base0: #839496;
--base1: #93a1a1;
--base2: #eee8d5;
--base3: #fdf6e3;
--yellow: #b58900;
--orange: #cb4b16;
--red: #dc322f;
--magenta: #d33682;
--violet: #6c71c4;
--blue: #268bd2;
--cyan: #2aa198;
--green: #859900;
--base3: #fdf6e3; /* Background. */
--base2: #eee8d5; /* Background highlights. */
--base1: #93a1a1; /* Comments / secondary color. */
--base00: #657b83; /* Body text / default code / primary content. */
--base01: #586e75; /* Optional emphasized content. */
--red: #cb4b16; /* Trim. */
/* Override orange trim */
--orange2: var(--orange);
--orange2: var(--red);
/* Restyle basic colors to use Solarized */
--white1: var(--base3);
--white2: var(--base2);
--blue1: var(--cyan);
--blue2: var(--base03);
--blue3: var(--base02);
--blue2: var(--base00);
--blue3: var(--base01);
/* Basic page styling (background + foreground) */
--bg: var(--white1);
--bg-accent: var(--white2);
--fg: var(--base02);
--fg-reduced: var(--base01);
--fg-reduced: var(--base00);
--fg: var(--base01);
/* Profile page styling (light) */
/* Profile page styling */
--profile-bg: var(--white2);
/* Solarize buttons */
@ -76,10 +65,10 @@
--status-focus-info-bg: var(--white2);
/* Used around statuses + other items */
--boxshadow-border: 0.1rem solid var(--base1);
--boxshadow-border: 0.15rem solid var(--base1);
--plyr-video-control-color: var(--fg-reduced);
--plyr-video-control-color-hover: var(--fg);
--plyr-video-control-color: var(--fg);
--plyr-video-control-color-hover: var(--fg-reduced);
}
@font-face {
@ -108,7 +97,7 @@ html, body {
border: var(--boxshadow-border);
}
.status .media .media-wrapper details .unknown-attachment .placeholder {
color: var(--blue2);
color: var(--base1);
}
.status .media .media-wrapper details video.plyr-video {
background: transparent;
@ -126,22 +115,38 @@ html, body {
pre, pre[class*="language-"],
code, code[class*="language-"] {
background-color: black;
color: var(--base3);
color: #93a1a1;
}
/* Block quotes */
blockquote {
background-color: var(--bg-accent);
color: var(--fg);
background-color: var(--base3);
color: var(--base00);
}
button,
.button,
button, .button,
.status .text-spoiler > summary .button {
font-family: 'Noto Sans Mono', monospace;
}
.button {
color: var(--base01);
background: var(--base2);
border: var(--boxshadow-border);
}
.button:hover {
color: var(--base00);
background: var(--base3);
border: var(--boxshadow-border);
}
/* Ensure role badge readable */
.profile .profile-header .basic-info .namerole .role.admin {
color: var(--base03);
color: var(--base3);
}
.col-header a {
font-size: 1.2rem;
font-weight: bold;
}

View file

@ -23,7 +23,7 @@
--orange2: var(--pink);
/* Basic page styling (background + foreground) */
--bg: linear-gradient(var(--eggplant1), var(--pink), var(--orange), var(--yellow), var(--eggshell));
--bg: var(--eggshell);
--bg-accent: var(--white2);
--fg: var(--eggplant4);
--fg-reduced: var(--eggplant3);
@ -45,6 +45,17 @@
--boxshadow-border: 0.08rem solid var(--orange);
}
/* Main page background */
body {
background: linear-gradient(
var(--eggplant1),
var(--pink),
var(--orange),
var(--yellow),
var(--eggshell)
);
}
/* Scroll bar */
html, body {
scrollbar-color: var(--pink) var(--eggshell);
@ -55,12 +66,6 @@ html, body {
color: var(--eggshell);
}
/* Role and bot badge backgrounds */
.profile .profile-header .basic-info .namerole .role,
.profile .profile-header .basic-info .namerole .bot-username-wrapper .bot-legend-wrapper {
background: var(--eggshell);
}
/* Profile fields */
.profile .about-user .fields .field {
border-bottom: 0.1rem solid var(--orange);

View file

@ -41,6 +41,12 @@ main {
text-decoration: none;
}
.boosted {
padding: 0 0.75rem 0.75rem;
color: var(--fg-reduced);
font-weight: bold;
}
.status-header > address {
/*
Avoid stretching so wide that user
@ -59,17 +65,27 @@ main {
"avatar author-strap author-strap";
gap: 0 0.5rem;
font-style: normal;
.avatar {
grid-area: avatar;
height: 3.5rem;
width: 3.5rem;
object-fit: cover;
position: relative;
border: 0.15rem solid $avatar-border;
border-radius: $br;
overflow: hidden; /* hides corners from img overflowing */
.boosted-avatar {
height: 50%;
width: 50%;
z-index: 10;
position: absolute;
bottom: 0;
inset-inline-end: 0;
}
img {
height: 100%;
width: 100%;
@ -77,7 +93,7 @@ main {
background: $bg;
}
}
.author-strap {
grid-area: author-strap;
display: grid;
@ -87,7 +103,7 @@ main {
"display display"
"user user";
gap: 0 0.5rem;
.displayname, .username {
justify-self: start;
align-self: start;
@ -95,12 +111,12 @@ main {
font-size: 1rem;
line-height: 1.3rem;
}
.displayname {
grid-area: display;
font-weight: bold;
}
.username {
grid-area: user;
color: $link-fg;
@ -200,34 +216,34 @@ main {
.poll {
background-color: $gray2;
z-index: 2;
display: flex;
flex-direction: column;
border-radius: $br;
padding: 0.5rem;
margin: 0;
gap: 1rem;
.poll-options {
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
gap: 1rem;
.poll-option {
display: flex;
flex-direction: column;
gap: 0.1rem;
label {
cursor: default;
}
meter {
width: 100%;
}
.poll-vote-summary {
display: flex;
flex-wrap: wrap;
@ -236,7 +252,7 @@ main {
}
}
}
.poll-info {
background-color: $gray4;
display: flex;
@ -245,7 +261,7 @@ main {
border-radius: $br-inner;
padding: 0.25rem;
gap: 0.25rem;
span {
justify-self: center;
white-space: nowrap;
@ -301,12 +317,12 @@ main {
width: 100%;
z-index: 3;
overflow: hidden;
display: grid;
padding: 1rem;
grid-template-columns: 1fr auto 1fr;
grid-template-rows: 1fr 1fr;
grid-template-areas:
grid-template-areas:
"eye sensitive ."
". sensitive .";
@ -369,7 +385,7 @@ main {
height: 100%;
padding: 0.8rem;
border: 0.2rem dashed $white2;
display: flex;
flex-direction: column;
align-items: center;
@ -518,4 +534,4 @@ main {
.plyr {
max-height: 100%;
}
}
}

View file

@ -77,7 +77,7 @@ function UserProfileForm({ data: profile }) {
maxPinnedFields: instance?.configuration?.accounts?.max_profile_fields ?? 6
};
}, [instance]);
// Parse out available theme options into nice format.
const { data: themes } = useAccountThemesQuery();
const themeOptions = useMemo(() => {
@ -114,6 +114,7 @@ function UserProfileForm({ data: profile }) {
locked: useBoolInput("locked", { source: profile }),
discoverable: useBoolInput("discoverable", { source: profile}),
enableRSS: useBoolInput("enable_rss", { source: profile }),
hideBoosts: useBoolInput("hide_boosts", { source: profile }),
hideCollections: useBoolInput("hide_collections", { source: profile }),
webVisibility: useTextInput("web_visibility", { source: profile, valueSelector: (p) => p.source?.web_visibility }),
fields: useFieldArrayInput("fields_attributes", {
@ -158,7 +159,7 @@ function UserProfileForm({ data: profile }) {
autoCapitalize="sentences"
/>
</div>
<div className="file-input-with-image-description">
<FileInput
label="Avatar (1:1 images look best)"
@ -257,6 +258,10 @@ function UserProfileForm({ data: profile }) {
field={form.enableRSS}
label="Enable RSS feed of posts."
/>
<Checkbox
field={form.hideBoosts}
label="Hide boosts from your public page"
/>
<Checkbox
field={form.hideCollections}
label="Hide who you follow / are followed by."

View file

@ -247,6 +247,16 @@
class="status expanded"
{{- includeAttr "status_attributes.tmpl" . | indentAttr 6 }}
>
{{- if .ReblogAccount }}
<div class="boosted text-cutoff">
<i class="fa fa-retweet" aria-hidden="true"></i>&nbsp
{{- if $.account.DisplayName }}
{{- emojify $.account.Emojis (escape $.account.DisplayName) }} boosted
{{- else }}
{{- $.account.Username }} boosted
{{- end }}
</div>
{{- end }}
{{- include "status.tmpl" . | indent 6 }}
</article>
{{- end }}
@ -264,4 +274,4 @@
</div>
</div>
</main>
{{- end }}
{{- end }}

View file

@ -48,6 +48,16 @@
alt="Avatar for {{ .Username -}}"
title="Avatar for {{ .Username -}}"
>
{{ if $.ReblogAccount }}
<img
class="boosted-avatar"
src="{{ $.ReblogAccount.Avatar }}"
alt="Avatar for {{ $.ReblogAccount.Username -}}"
title="Avatar for {{ $.ReblogAccount.Username -}}"
>
{{ end }}
</picture>
<div class="author-strap">
<span class="displayname text-cutoff">
@ -63,4 +73,4 @@
<span class="sr-only">(open profile)</span>
</a>
</address>
{{- end }}
{{- end }}