Add nsfw checkbox for posts
authorr <r@freesoftwareextremist.com>
Sun, 22 Dec 2019 16:27:49 +0000 (16:27 +0000)
committerr <r@freesoftwareextremist.com>
Sun, 22 Dec 2019 16:27:49 +0000 (16:27 +0000)
service/auth.go
service/logging.go
service/service.go
service/transport.go
static/main.css
templates/postform.tmpl
templates/status.tmpl

index 13e9c5059f31187d5416cbbeb87992b6eea5f7c0..1b2700ce5a3cc62f07c12abeb69af3f0951a0a5c 100644 (file)
@@ -157,12 +157,12 @@ func (s *authService) UnRetweet(ctx context.Context, client io.Writer, c *model.
        return s.Service.UnRetweet(ctx, client, c, id)
 }
 
-func (s *authService) PostTweet(ctx context.Context, client io.Writer, c *model.Client, content string, replyToID string, visibility string, files []*multipart.FileHeader) (id string, err error) {
+func (s *authService) PostTweet(ctx context.Context, client io.Writer, c *model.Client, content string, replyToID string, visibility string, isNSFW bool, files []*multipart.FileHeader) (id string, err error) {
        c, err = s.getClient(ctx)
        if err != nil {
                return
        }
-       return s.Service.PostTweet(ctx, client, c, content, replyToID, visibility, files)
+       return s.Service.PostTweet(ctx, client, c, content, replyToID, visibility, isNSFW, files)
 }
 
 func (s *authService) Follow(ctx context.Context, client io.Writer, c *model.Client, id string) (err error) {
index ceba716871adaac0fb01f80fda592d75b02f7395..444584e877b50d864c68e095692b40e0dc3b66cf 100644 (file)
@@ -133,12 +133,12 @@ func (s *loggingService) UnRetweet(ctx context.Context, client io.Writer, c *mod
        return s.Service.UnRetweet(ctx, client, c, id)
 }
 
-func (s *loggingService) PostTweet(ctx context.Context, client io.Writer, c *model.Client, content string, replyToID string, visibility string, files []*multipart.FileHeader) (id string, err error) {
+func (s *loggingService) PostTweet(ctx context.Context, client io.Writer, c *model.Client, content string, replyToID string, visibility string, isNSFW bool, files []*multipart.FileHeader) (id string, err error) {
        defer func(begin time.Time) {
-               s.logger.Printf("method=%v, content=%v, reply_to_id=%v, visibility=%v, took=%v, err=%v\n",
-                       "PostTweet", content, replyToID, visibility, time.Since(begin), err)
+               s.logger.Printf("method=%v, content=%v, reply_to_id=%v, visibility=%v, is_nsfw=%v, took=%v, err=%v\n",
+                       "PostTweet", content, replyToID, visibility, isNSFW, time.Since(begin), err)
        }(time.Now())
-       return s.Service.PostTweet(ctx, client, c, content, replyToID, visibility, files)
+       return s.Service.PostTweet(ctx, client, c, content, replyToID, visibility, isNSFW, files)
 }
 
 func (s *loggingService) Follow(ctx context.Context, client io.Writer, c *model.Client, id string) (err error) {
index 07a026aadc070bda52c497ee8f57a2d39c1a05c9..ad47408f88ef9f22fd1f3300633fd981b0c7b242 100644 (file)
@@ -38,7 +38,7 @@ type Service interface {
        UnLike(ctx context.Context, client io.Writer, c *model.Client, id string) (err error)
        Retweet(ctx context.Context, client io.Writer, c *model.Client, id string) (err error)
        UnRetweet(ctx context.Context, client io.Writer, c *model.Client, id string) (err error)
-       PostTweet(ctx context.Context, client io.Writer, c *model.Client, content string, replyToID string, visibility string, files []*multipart.FileHeader) (id string, err error)
+       PostTweet(ctx context.Context, client io.Writer, c *model.Client, content string, replyToID string, visibility string, isNSFW bool, files []*multipart.FileHeader) (id string, err error)
        Follow(ctx context.Context, client io.Writer, c *model.Client, id string) (err error)
        UnFollow(ctx context.Context, client io.Writer, c *model.Client, id string) (err error)
 }
@@ -482,7 +482,7 @@ func (svc *service) UnRetweet(ctx context.Context, client io.Writer, c *model.Cl
        return
 }
 
-func (svc *service) PostTweet(ctx context.Context, client io.Writer, c *model.Client, content string, replyToID string, visibility string, files []*multipart.FileHeader) (id string, err error) {
+func (svc *service) PostTweet(ctx context.Context, client io.Writer, c *model.Client, content string, replyToID string, visibility string, isNSFW bool, files []*multipart.FileHeader) (id string, err error) {
        var mediaIds []string
        for _, f := range files {
                a, err := c.UploadMediaFromMultipartFileHeader(ctx, f)
@@ -503,6 +503,7 @@ func (svc *service) PostTweet(ctx context.Context, client io.Writer, c *model.Cl
                InReplyToID: replyToID,
                MediaIDs:    mediaIds,
                Visibility:  visibility,
+               Sensitive:   isNSFW,
        }
 
        s, err := c.PostStatus(ctx, tweet)
index 4e852f240033f4449fdabf17639655b91ac0cc7f..e3ec113cc75a657c071a3bdb99be1ac90f3a0be9 100644 (file)
@@ -156,9 +156,11 @@ func NewHandler(s Service, staticDir string) http.Handler {
                content := getMultipartFormValue(req.MultipartForm, "content")
                replyToID := getMultipartFormValue(req.MultipartForm, "reply_to_id")
                visibility := getMultipartFormValue(req.MultipartForm, "visibility")
+               isNSFW := "on" == getMultipartFormValue(req.MultipartForm, "is_nsfw")
+
                files := req.MultipartForm.File["attachments"]
 
-               id, err := s.PostTweet(ctx, w, nil, content, replyToID, visibility, files)
+               id, err := s.PostTweet(ctx, w, nil, content, replyToID, visibility, isNSFW, files)
                if err != nil {
                        s.ServeErrorPage(ctx, w, err)
                        return
index 2dcb4a6effed2b048b1eb657c8737bbfd685389f..b4b616b196220e0fe7c5f074807fae931faeca86 100644 (file)
 .user-profile-img {
        max-height: 100px;
        max-width: 100px;
+       object-fit: contain;
+       vertical-align: top;
 }
 
 .user-profile-decription {
        position: relative;
 }
 
+.status-profile-img-container .img-link {
+       width: 48px;
+       overflow: hidden;
+}
+
 .status-nsfw-overlay {
        height: 100%;
        width: 100%;
 .status-video-container:hover .status-nsfw-overlay {
        display: none;
 }
+
+.post-form-field>* {
+  vertical-align: middle;
+}
index 309e139984a11275ffca6180689a6d13768e45fc..ea93efad9cce655e44d1ef56ede80e23e9a130ed 100644 (file)
@@ -9,17 +9,25 @@
                <textarea id="post-content" name="content" class="post-content" cols="50" rows="5">{{if .ReplyContext}}{{.ReplyContext.ReplyContent}}{{end}}</textarea>
        </div>
        <div>
-               <label for ="post-visilibity"> Visibility </label>
-               <select id="post-visilibity" name="visibility">
-                       <option value="public" {{if eq .DefaultVisibility "public"}}selected{{end}}>Public</option>
-                       <option value="unlisted" {{if eq .DefaultVisibility "unlisted"}}selected{{end}}>Unlisted</option>
-                       <option value="private" {{if eq .DefaultVisibility "private"}}selected{{end}}>Private</option>
-                       <option value="direct" {{if eq .DefaultVisibility "direct"}}selected{{end}}>Direct</option>
-               </select>
+               <span class="post-form-field">
+                       <label for="post-visilibity"> Visibility </label>
+                       <select id="post-visilibity" name="visibility">
+                               <option value="public" {{if eq .DefaultVisibility "public"}}selected{{end}}>Public</option>
+                               <option value="unlisted" {{if eq .DefaultVisibility "unlisted"}}selected{{end}}>Unlisted</option>
+                               <option value="private" {{if eq .DefaultVisibility "private"}}selected{{end}}>Private</option>
+                               <option value="direct" {{if eq .DefaultVisibility "direct"}}selected{{end}}>Direct</option>
+                       </select>
+               </span>
+               <span class="post-form-field">
+                       <input type="checkbox" id="nsfw-checkbox" name="is_nsfw" value="on">
+                       <label for="nsfw-checkbox"> Is NSFW </label>
+               </span>
        </div>
        <div>
-               <label for ="post-file-picker"> Attachments </label>
-               <input id="post-file-picker" type="file" name="attachments" multiple>
+               <span class="post-form-field">
+                       <label for ="post-file-picker"> Attachments </label>
+                       <input id="post-file-picker" type="file" name="attachments" multiple>
+               </span>
        </div>
        <button type="submit"> Post </button>
 </form>
index e62296d255bf0cda578074d3972f748927f26a7d..c27a67434eaefef276b2d9aaa8077c20d3c5b614 100644 (file)
@@ -2,7 +2,7 @@
        {{if .Reblog}}
        <div class="retweet-info">
                <a class="img-link" href="/user/{{.Account.ID}}">
-                       <img class="status-profile-img" src="{{.Account.AvatarStatic}}" alt="profile-avatar" />
+                       <img class="status-profile-img" src="{{.Account.AvatarStatic}}" alt="avatar" />
                </a>
                <span class="status-dname"> {{EmojiFilter .Account.DisplayName .Account.Emojis}} </span>  
                <span class="icon dripicons-retweet retweeted"></span> 
@@ -15,7 +15,7 @@
                {{if not .HideAccountInfo}}
                <div class="status-profile-img-container">
                        <a class="img-link" href="/user/{{.Account.ID}}">
-                               <img class="status-profile-img" src="{{.Account.AvatarStatic}}" alt="profile-avatar" />
+                               <img class="status-profile-img" src="{{.Account.AvatarStatic}}" alt="avatar" />
                        </a>
                </div>
                {{end}}