Implement commenting on issues from Mastodon
parent
f5a50ce457
commit
c64d3fa195
|
@ -26,6 +26,7 @@ import (
|
||||||
"code.gitea.io/gitea/modules/markup"
|
"code.gitea.io/gitea/modules/markup"
|
||||||
"code.gitea.io/gitea/modules/markup/markdown"
|
"code.gitea.io/gitea/modules/markup/markdown"
|
||||||
"code.gitea.io/gitea/modules/references"
|
"code.gitea.io/gitea/modules/references"
|
||||||
|
"code.gitea.io/gitea/modules/setting"
|
||||||
"code.gitea.io/gitea/modules/structs"
|
"code.gitea.io/gitea/modules/structs"
|
||||||
"code.gitea.io/gitea/modules/timeutil"
|
"code.gitea.io/gitea/modules/timeutil"
|
||||||
"code.gitea.io/gitea/modules/util"
|
"code.gitea.io/gitea/modules/util"
|
||||||
|
@ -1549,3 +1550,18 @@ func FixCommentTypeLabelWithOutsideLabels() (int64, error) {
|
||||||
|
|
||||||
return res.RowsAffected()
|
return res.RowsAffected()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Comment) GetIRI() string {
|
||||||
|
err := c.LoadIssue()
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
err = c.Issue.LoadRepo(db.DefaultContext)
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
if strings.Contains(c.Issue.Repo.OwnerName, "@") {
|
||||||
|
return c.OldTitle
|
||||||
|
}
|
||||||
|
return setting.AppURL + "api/v1/activitypub/note/" + c.Issue.Repo.OwnerName + "/" + c.Issue.Repo.Name + "/" + strconv.FormatInt(c.Issue.Index, 10) + "/" + strconv.FormatInt(c.ID, 10)
|
||||||
|
}
|
||||||
|
|
|
@ -308,10 +308,11 @@ func createComment(ctx context.Context, note *ap.Note) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = issues_model.CreateCommentCtx(ctx, &issues_model.CreateCommentOptions{
|
_, err = issues_model.CreateCommentCtx(ctx, &issues_model.CreateCommentOptions{
|
||||||
Doer: user,
|
Doer: user,
|
||||||
Repo: repo,
|
Repo: repo,
|
||||||
Issue: issue,
|
Issue: issue,
|
||||||
Content: note.Content.String(),
|
OldTitle: note.GetLink().String(),
|
||||||
|
Content: note.Content.String(),
|
||||||
})
|
})
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -134,6 +134,14 @@ func PersonInbox(ctx *context.APIContext) {
|
||||||
err = follow(ctx, activity)
|
err = follow(ctx, activity)
|
||||||
case ap.UndoType:
|
case ap.UndoType:
|
||||||
err = unfollow(ctx, activity)
|
err = unfollow(ctx, activity)
|
||||||
|
case ap.CreateType:
|
||||||
|
// TODO: this is kinda a hack
|
||||||
|
err = ap.OnObject(activity.Object, func(n *ap.Note) error {
|
||||||
|
noteIRI := n.InReplyTo.GetLink().String()
|
||||||
|
noteIRISplit := strings.Split(noteIRI, "/")
|
||||||
|
n.Context = ap.IRI(strings.TrimSuffix(noteIRI, "/"+noteIRISplit[len(noteIRISplit)-1]))
|
||||||
|
return createComment(ctx, n)
|
||||||
|
})
|
||||||
default:
|
default:
|
||||||
log.Info("Incoming unsupported ActivityStreams type: %s", activity.GetType())
|
log.Info("Incoming unsupported ActivityStreams type: %s", activity.GetType())
|
||||||
ctx.PlainText(http.StatusNotImplemented, "ActivityStreams type not supported")
|
ctx.PlainText(http.StatusNotImplemented, "ActivityStreams type not supported")
|
||||||
|
|
|
@ -140,7 +140,7 @@ func RepoInbox(ctx *context.APIContext) {
|
||||||
return createComment(ctx, n)
|
return createComment(ctx, n)
|
||||||
})
|
})
|
||||||
default:
|
default:
|
||||||
log.Info("Incoming unsupported ActivityStreams object type: %s", activity.Object.GetType())
|
log.Info("Incoming unsupported ActivityStreams object type: %s", activity.Object.GetType())
|
||||||
ctx.PlainText(http.StatusNotImplemented, "ActivityStreams object type not supported")
|
ctx.PlainText(http.StatusNotImplemented, "ActivityStreams object type not supported")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,8 +26,10 @@ func Note(comment *issues_model.Comment) (*ap.Note, error) {
|
||||||
}
|
}
|
||||||
note := ap.Note{
|
note := ap.Note{
|
||||||
Type: ap.NoteType,
|
Type: ap.NoteType,
|
||||||
|
ID: ap.IRI(comment.GetIRI()),
|
||||||
AttributedTo: ap.IRI(comment.Poster.GetIRI()),
|
AttributedTo: ap.IRI(comment.Poster.GetIRI()),
|
||||||
Context: ap.IRI(comment.Issue.GetIRI()),
|
Context: ap.IRI(comment.Issue.GetIRI()),
|
||||||
|
To: ap.ItemCollection{ap.IRI("https://www.w3.org/ns/activitystreams#Public")},
|
||||||
}
|
}
|
||||||
note.Content = ap.NaturalLanguageValuesNew()
|
note.Content = ap.NaturalLanguageValuesNew()
|
||||||
err = note.Content.Set("en", ap.Content(comment.Content))
|
err = note.Content.Set("en", ap.Content(comment.Content))
|
||||||
|
|
|
@ -36,7 +36,7 @@ func CreateIssueComment(doer *user_model.User, repo *repo_model.Repository, issu
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
create := activitypub.Create(repo.OriginalURL + "/inbox", note)
|
create := activitypub.Create(repo.OriginalURL+"/inbox", note)
|
||||||
err = activitypub.Send(doer, create)
|
err = activitypub.Send(doer, create)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -35,7 +35,7 @@ func NewIssue(repo *repo_model.Repository, issue *issues_model.Issue, labelIDs [
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
create := activitypub.Create(repo.OriginalURL + "/inbox", ticket)
|
create := activitypub.Create(repo.OriginalURL+"/inbox", ticket)
|
||||||
err = activitypub.Send(issue.Poster, create)
|
err = activitypub.Send(issue.Poster, create)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in New Issue