Implemented readOnly for OpenArticle

This commit is contained in:
マリウス 2021-12-28 11:52:00 -05:00
parent 0568fa3ec7
commit 62642f21f8
No known key found for this signature in database
GPG Key ID: 272ED814BF63261F
2 changed files with 8 additions and 4 deletions

View File

@ -17,7 +17,7 @@ func MillisecondsToDate(ms int64) (string) {
return time.Unix(0, ms * int64(time.Millisecond)).Format("Mon Jan _2 15:04:05 2006")
}
func (t *TUI) OpenArticle(article *models.Article) (models.Article, error) {
func (t *TUI) OpenArticle(article *models.Article, readOnly bool) (models.Article, error) {
if editor, exist := os.LookupEnv("EDITOR"); exist == false || editor == "" {
return *article, errors.New("EDITOR environment variable not available, please export!")
}
@ -40,6 +40,10 @@ func (t *TUI) OpenArticle(article *models.Article) (models.Article, error) {
return *article, err
}
if readOnly == true {
os.Chmod(tmpFile.Name(), 0400)
}
wasSuspended := t.App.Suspend(func() {
cmd := exec.Command(os.Getenv("EDITOR"), tmpFile.Name())
cmd.Stdin = os.Stdin

View File

@ -267,7 +267,7 @@ func(mainscreen *Mainscreen) selectHandler(item string)(func(int, string, string
case "group":
mainscreen.Refresh()
case "article":
mainscreen.T.OpenArticle(mainscreen.ArticlesList[index])
mainscreen.T.OpenArticle(mainscreen.ArticlesList[index], true)
}
}
}
@ -281,7 +281,7 @@ func(mainscreen *Mainscreen) submitNewArticle(group string) {
newArticle.Organization = mainscreen.T.Config.Profile.Organization
newArticle.Body = ""
updatedNewArticle, err := mainscreen.T.OpenArticle(newArticle)
updatedNewArticle, err := mainscreen.T.OpenArticle(newArticle, false)
if err != nil {
mainscreen.T.ShowErrorModal(err.Error())
return
@ -319,7 +319,7 @@ func(mainscreen *Mainscreen) replyToArticle(article *models.Article) {
newArticle.Organization = mainscreen.T.Config.Profile.Organization
newArticle.Body = fmt.Sprintf("\nOn %s %s wrote:\n> %s", MillisecondsToDate(article.Date), article.From, strings.Replace(article.Body, "\n", "\n> ", -1))
updatedNewArticle, err := mainscreen.T.OpenArticle(newArticle)
updatedNewArticle, err := mainscreen.T.OpenArticle(newArticle, false)
if err != nil {
mainscreen.T.ShowErrorModal(err.Error())
return