appview: add personal pronouns to profile #688

merged
opened by serendipty01.dev targeting master from serendipty01.dev/tangled-core: pronouns
Changed files
+52 -6
api
tangled
appview
db
models
pages
templates
state
lexicons
actor
+1
api/tangled/actorprofile.go
···
// pinnedRepositories: Any ATURI, it is up to appviews to validate these fields.
PinnedRepositories []string `json:"pinnedRepositories,omitempty" cborgen:"pinnedRepositories,omitempty"`
Stats []string `json:"stats,omitempty" cborgen:"stats,omitempty"`
+
Pronouns *string `json:"pronouns,omitempty" cborgen:"pronouns,omitempty"`
}
+7
appview/db/db.go
···
return err
})
+
runMigration(conn, logger, "add-pronouns-profile", func(tx *sql.Tx) error {
+
_, err := tx.Exec(`
+
alter table profile add column pronouns text;
+
`)
+
return err
+
})
+
return &DB{
db,
logger,
+14 -6
appview/db/profile.go
···
did,
description,
include_bluesky,
-
location
+
location,
+
pronouns
)
-
values (?, ?, ?, ?)`,
+
values (?, ?, ?, ?, ?)`,
profile.Did,
profile.Description,
includeBskyValue,
profile.Location,
+
profile.Pronouns,
)
if err != nil {
···
did,
description,
include_bluesky,
-
location
+
location,
+
pronouns
from
profile
%s`,
···
var profile models.Profile
var includeBluesky int
-
err = rows.Scan(&profile.ID, &profile.Did, &profile.Description, &includeBluesky, &profile.Location)
+
err = rows.Scan(&profile.ID, &profile.Did, &profile.Description, &includeBluesky, &profile.Location, &profile.Pronouns)
if err != nil {
return nil, err
}
···
includeBluesky := 0
err := e.QueryRow(
-
`select description, include_bluesky, location from profile where did = ?`,
+
`select description, include_bluesky, location, pronouns from profile where did = ?`,
did,
-
).Scan(&profile.Description, &includeBluesky, &profile.Location)
+
).Scan(&profile.Description, &includeBluesky, &profile.Location, &profile.Pronouns)
if err == sql.ErrNoRows {
profile := models.Profile{}
profile.Did = did
···
return fmt.Errorf("Entered location is too long.")
}
+
// ensure pronouns are not too long
+
if len(profile.Pronouns) > 40 {
+
return fmt.Errorf("Entered pronouns are too long.")
+
}
+
// ensure links are in order
err := validateLinks(profile)
if err != nil {
+6
appview/ingester.go
···
includeBluesky := record.Bluesky
+
pronouns := ""
+
if record.Pronouns != nil {
+
pronouns = *record.Pronouns
+
}
+
location := ""
if record.Location != nil {
location = *record.Location
···
Links: links,
Stats: stats,
PinnedRepos: pinned,
+
Pronouns: pronouns,
}
ddb, ok := i.Db.Execer.(*db.DB)
+1
appview/models/profile.go
···
Links [5]string
Stats [2]VanityStat
PinnedRepos [6]syntax.ATURI
+
Pronouns string
}
func (p Profile) IsLinksEmpty() bool {
+11
appview/pages/templates/user/fragments/editBio.html
···
placeholder="write a bio">{{ $description }}</textarea>
</div>
+
<div class="flex flex-col gap-1">
+
<label class="m-0 p-0" for="pronouns">pronouns</label>
+
<div class="flex items-center gap-2 w-full">
+
{{ $pronouns := "" }}
+
{{ if and .Profile .Profile.Pronouns }}
+
{{ $pronouns = .Profile.Pronouns }}
+
{{ end }}
+
<input type="text" class="py-1 px-1 w-full" name="pronouns" value="{{ $pronouns }}">
+
</div>
+
</div>
+
<div class="flex flex-col gap-1">
<label class="m-0 p-0" for="location">location</label>
<div class="flex items-center gap-2 w-full">
+5
appview/pages/templates/user/fragments/profileCard.html
···
class="text-lg font-bold dark:text-white overflow-hidden text-ellipsis whitespace-nowrap">
{{ $userIdent }}
</p>
+
{{ with .Profile }}
+
{{ if .Pronouns }}
+
<span>{{ .Pronouns }}</span>
+
{{ end }}
+
{{ end }}
<a href="/{{ $userIdent }}/feed.atom">{{ i "rss" "size-4" }}</a>
</div>
+2
appview/state/profile.go
···
profile.Description = r.FormValue("description")
profile.IncludeBluesky = r.FormValue("includeBluesky") == "on"
profile.Location = r.FormValue("location")
+
profile.Pronouns = r.FormValue("pronouns")
var links [5]string
for i := range 5 {
···
Location: &profile.Location,
PinnedRepositories: pinnedRepoStrings,
Stats: vanityStats[:],
+
Pronouns: &profile.Pronouns,
}},
SwapRecord: cid,
})
+5
lexicons/actor/profile.json
···
"type": "string",
"format": "at-uri"
}
+
},
+
"pronouns": {
+
"type": "string",
+
"description": "Preferred gender pronouns.",
+
"maxLength": 40
}
}
}