-
Notifications
You must be signed in to change notification settings - Fork 0
/
document_special.go
94 lines (78 loc) · 2.45 KB
/
document_special.go
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package streams
import "github.com/benpate/hannibal/vocab"
// IsActivity returns TRUE if this document represents an Activity
func (document Document) IsActivity() bool {
switch document.Type() {
case vocab.ActivityTypeAccept,
vocab.ActivityTypeAdd,
vocab.ActivityTypeAnnounce,
vocab.ActivityTypeArrive,
vocab.ActivityTypeBlock,
vocab.ActivityTypeCreate,
vocab.ActivityTypeDelete,
vocab.ActivityTypeDislike,
vocab.ActivityTypeFlag,
vocab.ActivityTypeFollow,
vocab.ActivityTypeIgnore,
vocab.ActivityTypeInvite,
vocab.ActivityTypeJoin,
vocab.ActivityTypeLeave,
vocab.ActivityTypeLike,
vocab.ActivityTypeListen,
vocab.ActivityTypeMove,
vocab.ActivityTypeOffer,
vocab.ActivityTypeQuestion,
vocab.ActivityTypeReject,
vocab.ActivityTypeRead,
vocab.ActivityTypeRemove,
vocab.ActivityTypeTentativeReject,
vocab.ActivityTypeTentativeAccept,
vocab.ActivityTypeTravel,
vocab.ActivityTypeUndo,
vocab.ActivityTypeUpdate,
vocab.ActivityTypeView:
return true
}
return false
}
// IsActor returns TRUE if this document represents an Actor
func (document Document) IsActor() bool {
switch document.Type() {
case vocab.ActorTypeApplication,
vocab.ActorTypeGroup,
vocab.ActorTypeOrganization,
vocab.ActorTypePerson,
vocab.ActorTypeService:
return true
}
return false
}
// Statistics returns counts for various interactions: Announces, Replies, Likes, and Dislikes
func (document Document) Statistics() Statistics {
return document.statistics
}
// HasImage returns TRUE if this document has a valid Image property
func (document Document) HasImage() bool {
return document.Image().NotNil()
}
// HasContent returns TRUE if this document has a valid Content property
func (document Document) HasContent() bool {
return document.Content() != ""
}
// HasSummary returns TRUE if this document has a valid Summary property
func (document Document) HasSummary() bool {
return document.Summary() != ""
}
// If this document is an activity (create, update, delete, etc), then
// this method returns the activity's Object. Otherwise, it returns
// the document itself.
func (document Document) UnwrapActivity() Document {
// If this is an "Activity" type, the dig deeper into the object
// to find the actual document. This is recursive because it's
// possible to have a deep tree such as Announce > Create > Document
// Looking at you, Lemmy...
if document.IsActivity() {
return document.Object().UnwrapActivity()
}
return document
}