-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathquestions.go
More file actions
43 lines (38 loc) · 1.44 KB
/
questions.go
File metadata and controls
43 lines (38 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package processing
import (
vocab "github.com/go-ap/activitypub"
)
// QuestionActivity processes matching activities
//
// https://www.w3.org/TR/activitystreams-vocabulary/#h-motivations-questions
//
// The Questions use case primarily deals with representing inquiries of any type.
// See 5.4 Representing Questions for more information: https://www.w3.org/TR/activitystreams-vocabulary/#questions
func (p *P) QuestionActivity(q *vocab.Question) (*vocab.Question, error) {
// NOTE(marius): this behaviour is not in accordance to the spec.
// Saving the question items as individual objects makes sense to me,
// but it's not mention in either of the documents we're basing this implementation on.
// I can't think of any reason why saving them might be a _bad_ idea, so for the moment I'll leave it like this.
if q.AnyOf != nil {
return q, vocab.OnItemCollection(q.AnyOf, p.saveQuestionAnswers(q))
}
if q.OneOf != nil {
return q, vocab.OnItemCollection(q.OneOf, p.saveQuestionAnswers(q))
}
return q, nil
}
func (p *P) saveQuestionAnswers(q *vocab.Question) func(col *vocab.ItemCollection) error {
return func(col *vocab.ItemCollection) error {
var err error
for _, ans := range col.Collection() {
if iri := ans.GetLink(); len(iri) == 0 {
err = p.SetIDIfMissing(ans, nil, q)
}
_ = vocab.OnActivity(q, func(act *vocab.Activity) error {
return p.updateCreateActivityObject(ans, act)
})
ans, err = p.s.Save(ans)
}
return err
}
}