mirror of
https://gitea.phreedom.club/localhost_frssoft/bloat.git
synced 2024-11-22 12:49:21 +02:00
Add conversation muting
This commit is contained in:
parent
c702a2b501
commit
4d9e0af373
|
@ -343,3 +343,25 @@ func (c *Client) GetTimelineDirect(ctx context.Context, pg *Pagination) ([]*Stat
|
||||||
}
|
}
|
||||||
return statuses, nil
|
return statuses, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MuteConversation mutes status specified by id.
|
||||||
|
func (c *Client) MuteConversation(ctx context.Context, id string) (*Status, error) {
|
||||||
|
var status Status
|
||||||
|
|
||||||
|
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/statuses/%s/mute", id), nil, &status, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &status, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnmuteConversation unmutes status specified by id.
|
||||||
|
func (c *Client) UnmuteConversation(ctx context.Context, id string) (*Status, error) {
|
||||||
|
var status Status
|
||||||
|
|
||||||
|
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/statuses/%s/unmute", id), nil, &status, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &status, nil
|
||||||
|
}
|
||||||
|
|
|
@ -284,3 +284,27 @@ func (s *as) SaveSettings(ctx context.Context, c *model.Client, settings *model.
|
||||||
}
|
}
|
||||||
return s.Service.SaveSettings(ctx, c, settings)
|
return s.Service.SaveSettings(ctx, c, settings)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *as) MuteConversation(ctx context.Context, c *model.Client, id string) (err error) {
|
||||||
|
err = s.authenticateClient(ctx, c)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = checkCSRF(ctx, c)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return s.Service.MuteConversation(ctx, c, id)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *as) UnMuteConversation(ctx context.Context, c *model.Client, id string) (err error) {
|
||||||
|
err = s.authenticateClient(ctx, c)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = checkCSRF(ctx, c)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return s.Service.UnMuteConversation(ctx, c, id)
|
||||||
|
}
|
||||||
|
|
|
@ -212,3 +212,19 @@ func (s *ls) SaveSettings(ctx context.Context, c *model.Client, settings *model.
|
||||||
}(time.Now())
|
}(time.Now())
|
||||||
return s.Service.SaveSettings(ctx, c, settings)
|
return s.Service.SaveSettings(ctx, c, settings)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *ls) MuteConversation(ctx context.Context, c *model.Client, id string) (err error) {
|
||||||
|
defer func(begin time.Time) {
|
||||||
|
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
|
||||||
|
"MuteConversation", id, time.Since(begin), err)
|
||||||
|
}(time.Now())
|
||||||
|
return s.Service.MuteConversation(ctx, c, id)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ls) UnMuteConversation(ctx context.Context, c *model.Client, id string) (err error) {
|
||||||
|
defer func(begin time.Time) {
|
||||||
|
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
|
||||||
|
"UnMuteConversation", id, time.Since(begin), err)
|
||||||
|
}(time.Now())
|
||||||
|
return s.Service.UnMuteConversation(ctx, c, id)
|
||||||
|
}
|
||||||
|
|
|
@ -44,6 +44,8 @@ type Service interface {
|
||||||
Follow(ctx context.Context, c *model.Client, id string) (err error)
|
Follow(ctx context.Context, c *model.Client, id string) (err error)
|
||||||
UnFollow(ctx context.Context, c *model.Client, id string) (err error)
|
UnFollow(ctx context.Context, c *model.Client, id string) (err error)
|
||||||
SaveSettings(ctx context.Context, c *model.Client, settings *model.Settings) (err error)
|
SaveSettings(ctx context.Context, c *model.Client, settings *model.Settings) (err error)
|
||||||
|
MuteConversation(ctx context.Context, c *model.Client, id string) (err error)
|
||||||
|
UnMuteConversation(ctx context.Context, c *model.Client, id string) (err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type service struct {
|
type service struct {
|
||||||
|
@ -848,3 +850,15 @@ func (svc *service) SaveSettings(ctx context.Context, c *model.Client,
|
||||||
session.Settings = *settings
|
session.Settings = *settings
|
||||||
return svc.sessionRepo.Add(session)
|
return svc.sessionRepo.Add(session)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (svc *service) MuteConversation(ctx context.Context, c *model.Client,
|
||||||
|
id string) (err error) {
|
||||||
|
_, err = c.MuteConversation(ctx, id)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (svc *service) UnMuteConversation(ctx context.Context, c *model.Client,
|
||||||
|
id string) (err error) {
|
||||||
|
_, err = c.UnmuteConversation(ctx, id)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
|
@ -481,6 +481,38 @@ func NewHandler(s Service, staticDir string) http.Handler {
|
||||||
w.WriteHeader(http.StatusFound)
|
w.WriteHeader(http.StatusFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
muteConversation := func(w http.ResponseWriter, req *http.Request) {
|
||||||
|
c := newClient(w)
|
||||||
|
ctx := newCtxWithSesionCSRF(req, req.FormValue("csrf_token"))
|
||||||
|
id, _ := mux.Vars(req)["id"]
|
||||||
|
|
||||||
|
err := s.MuteConversation(ctx, c, id)
|
||||||
|
if err != nil {
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
s.ServeErrorPage(ctx, c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Header().Add("Location", req.Header.Get("Referer"))
|
||||||
|
w.WriteHeader(http.StatusFound)
|
||||||
|
}
|
||||||
|
|
||||||
|
unMuteConversation := func(w http.ResponseWriter, req *http.Request) {
|
||||||
|
c := newClient(w)
|
||||||
|
ctx := newCtxWithSesionCSRF(req, req.FormValue("csrf_token"))
|
||||||
|
id, _ := mux.Vars(req)["id"]
|
||||||
|
|
||||||
|
err := s.UnMuteConversation(ctx, c, id)
|
||||||
|
if err != nil {
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
s.ServeErrorPage(ctx, c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Header().Add("Location", req.Header.Get("Referer"))
|
||||||
|
w.WriteHeader(http.StatusFound)
|
||||||
|
}
|
||||||
|
|
||||||
signout := func(w http.ResponseWriter, req *http.Request) {
|
signout := func(w http.ResponseWriter, req *http.Request) {
|
||||||
// TODO remove session from database
|
// TODO remove session from database
|
||||||
http.SetCookie(w, &http.Cookie{
|
http.SetCookie(w, &http.Cookie{
|
||||||
|
@ -588,6 +620,8 @@ func NewHandler(s Service, staticDir string) http.Handler {
|
||||||
r.HandleFunc("/follow/{id}", follow).Methods(http.MethodPost)
|
r.HandleFunc("/follow/{id}", follow).Methods(http.MethodPost)
|
||||||
r.HandleFunc("/unfollow/{id}", unfollow).Methods(http.MethodPost)
|
r.HandleFunc("/unfollow/{id}", unfollow).Methods(http.MethodPost)
|
||||||
r.HandleFunc("/settings", settings).Methods(http.MethodPost)
|
r.HandleFunc("/settings", settings).Methods(http.MethodPost)
|
||||||
|
r.HandleFunc("/muteconv/{id}", muteConversation).Methods(http.MethodPost)
|
||||||
|
r.HandleFunc("/unmuteconv/{id}", unMuteConversation).Methods(http.MethodPost)
|
||||||
r.HandleFunc("/signout", signout).Methods(http.MethodGet)
|
r.HandleFunc("/signout", signout).Methods(http.MethodGet)
|
||||||
r.HandleFunc("/fluoride/like/{id}", fLike).Methods(http.MethodPost)
|
r.HandleFunc("/fluoride/like/{id}", fLike).Methods(http.MethodPost)
|
||||||
r.HandleFunc("/fluoride/unlike/{id}", fUnlike).Methods(http.MethodPost)
|
r.HandleFunc("/fluoride/unlike/{id}", fUnlike).Methods(http.MethodPost)
|
||||||
|
|
|
@ -280,7 +280,6 @@ a:hover,
|
||||||
|
|
||||||
.remote-link {
|
.remote-link {
|
||||||
margin-left: 4px;
|
margin-left: 4px;
|
||||||
display: inline-block;
|
|
||||||
font-size: 8pt;
|
font-size: 8pt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -430,6 +429,29 @@ a:hover,
|
||||||
margin: 16px 0 0 0;
|
margin: 16px 0 0 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.more-container {
|
||||||
|
position: relative;
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.more-content {
|
||||||
|
display: none;
|
||||||
|
position: absolute;
|
||||||
|
background-color: #ffffff;
|
||||||
|
padding: 2px 4px;
|
||||||
|
border: 1px solid #aaaaaa;
|
||||||
|
}
|
||||||
|
|
||||||
|
.more-container:hover .more-content {
|
||||||
|
display: initial;
|
||||||
|
}
|
||||||
|
|
||||||
|
.more-link {
|
||||||
|
font-size: 8pt;
|
||||||
|
display: block;
|
||||||
|
margin: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
.dark {
|
.dark {
|
||||||
background-color: #222222;
|
background-color: #222222;
|
||||||
background-image: none;
|
background-image: none;
|
||||||
|
@ -463,3 +485,8 @@ a:hover,
|
||||||
.dark .status-visibility {
|
.dark .status-visibility {
|
||||||
color: #eaeaea;
|
color: #eaeaea;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.dark .more-content {
|
||||||
|
background-color: #222222;
|
||||||
|
border-color: #444444;
|
||||||
|
}
|
||||||
|
|
|
@ -24,12 +24,27 @@
|
||||||
<a href="/user/{{.Account.ID}}" >
|
<a href="/user/{{.Account.ID}}" >
|
||||||
<span class="status-uname"> {{.Account.Acct}} </span>
|
<span class="status-uname"> {{.Account.Acct}} </span>
|
||||||
</a>
|
</a>
|
||||||
<span class="status-visibility">
|
<div class="more-container" title="more">
|
||||||
{{.Visibility}}
|
<div class="remote-link" title="mute">
|
||||||
</span>
|
{{.Visibility}}
|
||||||
<a class="remote-link" href="{{.URL}}" target="_blank" title="source">
|
</div>
|
||||||
source
|
<div class="more-content">
|
||||||
</a>
|
<a class="more-link" href="{{.URL}}" target="_blank" title="mute">
|
||||||
|
source
|
||||||
|
</a>
|
||||||
|
{{if .Muted}}
|
||||||
|
<form action="/unmuteconv/{{.ID}}" method="post">
|
||||||
|
<input type="hidden" name="csrf_token" value="{{$.Ctx.CSRFToken}}">
|
||||||
|
<input type="submit" value="unmute" class="btn-link more-link" title="unmute">
|
||||||
|
</form>
|
||||||
|
{{else}}
|
||||||
|
<form action="/muteconv/{{.ID}}" method="post">
|
||||||
|
<input type="hidden" name="csrf_token" value="{{$.Ctx.CSRFToken}}">
|
||||||
|
<input type="submit" value="mute" class="btn-link more-link" title="mute">
|
||||||
|
</form>
|
||||||
|
{{end}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="status-reply-container">
|
<div class="status-reply-container">
|
||||||
{{if .InReplyToID}}
|
{{if .InReplyToID}}
|
||||||
|
|
Loading…
Reference in New Issue