Feature: Bare bones Editing implimented

This commit is contained in:
localhost_frssoft 2022-10-31 18:26:16 +03:00
parent 4df1f096be
commit 53353c0e64
5 changed files with 16 additions and 6 deletions

View File

@ -260,6 +260,7 @@ func (c *Client) GetAccessToken(ctx context.Context) string {
// Toot is struct to post status. // Toot is struct to post status.
type Toot struct { type Toot struct {
Edit string `json:"id"`
Status string `json:"status"` Status string `json:"status"`
InReplyToID string `json:"in_reply_to_id"` InReplyToID string `json:"in_reply_to_id"`
MediaIDs []string `json:"media_ids"` MediaIDs []string `json:"media_ids"`

View File

@ -333,10 +333,16 @@ func (c *Client) PostStatus(ctx context.Context, toot *Toot) (*Status, error) {
params.Set("content_type", toot.ContentType) params.Set("content_type", toot.ContentType)
} }
var status Status var status Status
err := c.doAPI(ctx, http.MethodPost, "/api/v1/statuses", params, &status, nil) if toot.Edit != "" {
err := c.doAPI(ctx, http.MethodPut, fmt.Sprintf("/api/v1/statuses/%s", toot.Edit), params, &status, nil)
if err != nil { if err != nil {
return nil, err return nil, err
}
} else {
err := c.doAPI(ctx, http.MethodPost, "/api/v1/statuses", params, &status, nil)
if err != nil {
return nil, err
}
} }
return &status, nil return &status, nil
} }

View File

@ -986,7 +986,7 @@ func (s *service) Signout(c *client) (err error) {
func (s *service) Post(c *client, content string, replyToID string, func (s *service) Post(c *client, content string, replyToID string,
format string, visibility string, isNSFW bool, spoilerText string, format string, visibility string, isNSFW bool, spoilerText string,
files []*multipart.FileHeader) (id string, err error) { files []*multipart.FileHeader, edit string) (id string, err error) {
var mediaIDs []string var mediaIDs []string
for _, f := range files { for _, f := range files {
@ -1005,6 +1005,7 @@ func (s *service) Post(c *client, content string, replyToID string,
ContentType: format, ContentType: format,
Visibility: visibility, Visibility: visibility,
Sensitive: isNSFW, Sensitive: isNSFW,
Edit: edit,
} }
st, err := c.PostStatus(c.ctx, tweet) st, err := c.PostStatus(c.ctx, tweet)
if err != nil { if err != nil {

View File

@ -282,8 +282,9 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler {
isNSFW := c.r.FormValue("is_nsfw") == "true" isNSFW := c.r.FormValue("is_nsfw") == "true"
quickReply := c.r.FormValue("quickreply") == "true" quickReply := c.r.FormValue("quickreply") == "true"
files := c.r.MultipartForm.File["attachments"] files := c.r.MultipartForm.File["attachments"]
edit := c.r.FormValue("edit-status-id")
id, err := s.Post(c, content, replyToID, format, visibility, isNSFW, spoilerText, files) id, err := s.Post(c, content, replyToID, format, visibility, isNSFW, spoilerText, files, edit)
if err != nil { if err != nil {
return err return err
} }

View File

@ -47,6 +47,7 @@
</div> </div>
<button type="submit" accesskey="P" title="Post (P)"> Post </button> <button type="submit" accesskey="P" title="Post (P)"> Post </button>
<button type="reset" title="Reset"> Reset </button> <button type="reset" title="Reset"> Reset </button>
<input id="edit-status-id" name="edit-status-id" placeholder="Input Status ID for edit" title="Edit ID">
</form> </form>
{{end}} {{end}}