mirror of
https://gitea.phreedom.club/localhost_frssoft/bloat.git
synced 2024-12-23 22:19:49 +00:00
Add support for expiring mutes
This commit is contained in:
parent
9816045c21
commit
5147897c6c
@ -246,11 +246,10 @@ func (c *Client) AccountUnblock(ctx context.Context, id string) (*Relationship,
|
||||
}
|
||||
|
||||
// AccountMute mute the account.
|
||||
func (c *Client) AccountMute(ctx context.Context, id string, notifications *bool) (*Relationship, error) {
|
||||
func (c *Client) AccountMute(ctx context.Context, id string, notifications bool, duration int) (*Relationship, error) {
|
||||
params := url.Values{}
|
||||
if notifications != nil {
|
||||
params.Set("notifications", strconv.FormatBool(*notifications))
|
||||
}
|
||||
params.Set("notifications", strconv.FormatBool(notifications))
|
||||
params.Set("duration", strconv.Itoa(duration))
|
||||
var relationship Relationship
|
||||
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/accounts/%s/mute", url.PathEscape(string(id))), params, &relationship, nil)
|
||||
if err != nil {
|
||||
|
@ -155,3 +155,8 @@ type FiltersData struct {
|
||||
*CommonData
|
||||
Filters []*mastodon.Filter
|
||||
}
|
||||
|
||||
type MuteData struct {
|
||||
*CommonData
|
||||
User *mastodon.Account
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ const (
|
||||
SearchPage = "search.tmpl"
|
||||
SettingsPage = "settings.tmpl"
|
||||
FiltersPage = "filters.tmpl"
|
||||
MutePage = "mute.tmpl"
|
||||
)
|
||||
|
||||
type TemplateData struct {
|
||||
|
@ -678,6 +678,19 @@ func (s *service) UserSearchPage(c *client,
|
||||
return s.renderer.Render(c.rctx, c.w, renderer.UserSearchPage, data)
|
||||
}
|
||||
|
||||
func (s *service) MutePage(c *client, id string) (err error) {
|
||||
user, err := c.GetAccount(c.ctx, id)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
cdata := s.cdata(c, "Mute"+user.DisplayName+" @"+user.Acct, 0, 0, "")
|
||||
data := &renderer.UserData{
|
||||
User: user,
|
||||
CommonData: cdata,
|
||||
}
|
||||
return s.renderer.Render(c.rctx, c.w, renderer.MutePage, data)
|
||||
}
|
||||
|
||||
func (s *service) AboutPage(c *client) (err error) {
|
||||
cdata := s.cdata(c, "about", 0, 0, "")
|
||||
data := &renderer.AboutData{
|
||||
@ -930,8 +943,8 @@ func (s *service) Reject(c *client, id string) (err error) {
|
||||
return c.FollowRequestReject(c.ctx, id)
|
||||
}
|
||||
|
||||
func (s *service) Mute(c *client, id string, notifications *bool) (err error) {
|
||||
_, err = c.AccountMute(c.ctx, id, notifications)
|
||||
func (s *service) Mute(c *client, id string, notifications bool, duration int) (err error) {
|
||||
_, err = c.AccountMute(c.ctx, id, notifications, duration)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -171,6 +171,11 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler {
|
||||
return s.UserSearchPage(c, id, sq, offset)
|
||||
}, SESSION, HTML)
|
||||
|
||||
mutePage := handle(func(c *client) error {
|
||||
id, _ := mux.Vars(c.r)["id"]
|
||||
return s.MutePage(c, id)
|
||||
}, SESSION, HTML)
|
||||
|
||||
aboutPage := handle(func(c *client) error {
|
||||
return s.AboutPage(c)
|
||||
}, SESSION, HTML)
|
||||
@ -361,17 +366,13 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler {
|
||||
|
||||
mute := handle(func(c *client) error {
|
||||
id, _ := mux.Vars(c.r)["id"]
|
||||
q := c.r.URL.Query()
|
||||
var notifications *bool
|
||||
if r, ok := q["notifications"]; ok && len(r) > 0 {
|
||||
notifications = new(bool)
|
||||
*notifications = r[0] == "true"
|
||||
}
|
||||
err := s.Mute(c, id, notifications)
|
||||
notifications, _ := strconv.ParseBool(c.r.FormValue("notifications"))
|
||||
duration, _ := strconv.Atoi(c.r.FormValue("duration"))
|
||||
err := s.Mute(c, id, notifications, duration)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c.redirect(c.r.FormValue("referrer"))
|
||||
c.redirect("/user/" + id)
|
||||
return nil
|
||||
}, CSRF, HTML)
|
||||
|
||||
@ -673,6 +674,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler {
|
||||
r.HandleFunc("/user/{id}", userPage).Methods(http.MethodGet)
|
||||
r.HandleFunc("/user/{id}/{type}", userPage).Methods(http.MethodGet)
|
||||
r.HandleFunc("/usersearch/{id}", userSearchPage).Methods(http.MethodGet)
|
||||
r.HandleFunc("/mute/{id}", mutePage).Methods(http.MethodGet)
|
||||
r.HandleFunc("/about", aboutPage).Methods(http.MethodGet)
|
||||
r.HandleFunc("/emojis", emojisPage).Methods(http.MethodGet)
|
||||
r.HandleFunc("/search", searchPage).Methods(http.MethodGet)
|
||||
|
29
templates/mute.tmpl
Normal file
29
templates/mute.tmpl
Normal file
@ -0,0 +1,29 @@
|
||||
{{with .Data}}
|
||||
{{template "header.tmpl" (WithContext .CommonData $.Ctx)}}
|
||||
<div class="page-title"> Mute {{.User.Acct}} </div>
|
||||
|
||||
<form action="/mute/{{.User.ID}}" method="POST">
|
||||
<input type="hidden" name="csrf_token" value="{{$.Ctx.CSRFToken}}">
|
||||
<input type="hidden" name="referrer" value="{{$.Ctx.Referrer}}">
|
||||
<div class="settings-form-field">
|
||||
<input id="notifications" name="notifications" type="checkbox" value="true" checked>
|
||||
<label for="notifications"> Mute notifications </label>
|
||||
</div>
|
||||
<div class="settings-form-field">
|
||||
<label for="duration"> Auto unmute </label>
|
||||
<select id="duration" name="duration">
|
||||
<option value="0" selected>Disabled</option>
|
||||
<option value="300">After 5m</option>
|
||||
<option value="1800">After 30m</option>
|
||||
<option value="3600">After 1h</option>
|
||||
<option value="21600">After 6h</option>
|
||||
<option value="86400">After 1d</option>
|
||||
<option value="259200">After 3d</option>
|
||||
<option value="604800">After 7d</option>
|
||||
</select>
|
||||
</div>
|
||||
<button type="submit"> Mute </button>
|
||||
</form>
|
||||
|
||||
{{template "footer.tmpl"}}
|
||||
{{end}}
|
@ -79,17 +79,7 @@
|
||||
<input type="submit" value="unmute" class="btn-link">
|
||||
</form>
|
||||
{{else}}
|
||||
<form class="d-inline" action="/mute/{{.User.ID}}" method="post">
|
||||
<input type="hidden" name="csrf_token" value="{{$.Ctx.CSRFToken}}">
|
||||
<input type="hidden" name="referrer" value="{{$.Ctx.Referrer}}">
|
||||
<input type="submit" value="mute" class="btn-link">
|
||||
</form>
|
||||
-
|
||||
<form class="d-inline" action="/mute/{{.User.ID}}?notifications=false" method="post">
|
||||
<input type="hidden" name="csrf_token" value="{{$.Ctx.CSRFToken}}">
|
||||
<input type="hidden" name="referrer" value="{{$.Ctx.Referrer}}">
|
||||
<input type="submit" value="mute (keep notifications)" class="btn-link">
|
||||
</form>
|
||||
<a href="/mute/{{.User.ID}}"> mute </a>
|
||||
{{end}}
|
||||
{{if .User.Pleroma.Relationship.Following}}
|
||||
-
|
||||
|
Loading…
Reference in New Issue
Block a user