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/markdown"
|
||||
"code.gitea.io/gitea/modules/references"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
|
@ -1549,3 +1550,18 @@ func FixCommentTypeLabelWithOutsideLabels() (int64, error) {
|
|||
|
||||
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)
|
||||
}
|
||||
|
|
|
@ -311,6 +311,7 @@ func createComment(ctx context.Context, note *ap.Note) error {
|
|||
Doer: user,
|
||||
Repo: repo,
|
||||
Issue: issue,
|
||||
OldTitle: note.GetLink().String(),
|
||||
Content: note.Content.String(),
|
||||
})
|
||||
return err
|
||||
|
|
|
@ -134,6 +134,14 @@ func PersonInbox(ctx *context.APIContext) {
|
|||
err = follow(ctx, activity)
|
||||
case ap.UndoType:
|
||||
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:
|
||||
log.Info("Incoming unsupported ActivityStreams type: %s", activity.GetType())
|
||||
ctx.PlainText(http.StatusNotImplemented, "ActivityStreams type not supported")
|
||||
|
|
|
@ -26,8 +26,10 @@ func Note(comment *issues_model.Comment) (*ap.Note, error) {
|
|||
}
|
||||
note := ap.Note{
|
||||
Type: ap.NoteType,
|
||||
ID: ap.IRI(comment.GetIRI()),
|
||||
AttributedTo: ap.IRI(comment.Poster.GetIRI()),
|
||||
Context: ap.IRI(comment.Issue.GetIRI()),
|
||||
To: ap.ItemCollection{ap.IRI("https://www.w3.org/ns/activitystreams#Public")},
|
||||
}
|
||||
note.Content = ap.NaturalLanguageValuesNew()
|
||||
err = note.Content.Set("en", ap.Content(comment.Content))
|
||||
|
|
Loading…
Reference in New Issue