2
2
3
3
from h .models import Annotation , User
4
4
from h .presenters import DocumentJSONPresenter
5
+ from h .presenters .mention_json import MentionJSONPresenter
5
6
from h .security import Identity , identity_permits
6
7
from h .security .permissions import Permission
8
+ from h .services import MentionService
7
9
from h .services .annotation_read import AnnotationReadService
10
+ from h .services .feature import FeatureService
8
11
from h .services .flag import FlagService
9
12
from h .services .links import LinksService
10
13
from h .services .user import UserService
@@ -22,6 +25,8 @@ def __init__(
22
25
links_service : LinksService ,
23
26
flag_service : FlagService ,
24
27
user_service : UserService ,
28
+ mention_service : MentionService ,
29
+ feature_service : FeatureService ,
25
30
):
26
31
"""
27
32
Instantiate the service.
@@ -30,11 +35,14 @@ def __init__(
30
35
:param links_service: LinksService instance
31
36
:param flag_service: FlagService instance
32
37
:param user_service: UserService instance
38
+ :param mention_service: MentionService instance
33
39
"""
34
40
self ._annotation_read_service = annotation_read_service
35
41
self ._links_service = links_service
36
42
self ._flag_service = flag_service
37
43
self ._user_service = user_service
44
+ self ._mention_service = mention_service
45
+ self ._feature_service = feature_service
38
46
39
47
def present (self , annotation : Annotation ):
40
48
"""
@@ -73,6 +81,11 @@ def present(self, annotation: Annotation):
73
81
"links" : self ._links_service .get_all (annotation ),
74
82
}
75
83
)
84
+ if self ._feature_service .enabled ("at_mentions" ): # pragma: no cover
85
+ model ["mentions" ] = [
86
+ MentionJSONPresenter (mention ).asdict ()
87
+ for mention in annotation .mentions
88
+ ]
76
89
77
90
model .update (user_info (self ._user_service .fetch (annotation .userid )))
78
91
@@ -151,6 +164,8 @@ def present_all_for_user(self, annotation_ids, user: User):
151
164
# which ultimately depends on group permissions, causing a
152
165
# group lookup for every annotation without this
153
166
Annotation .group ,
167
+ # Optimise access to the mentions
168
+ Annotation .mentions ,
154
169
],
155
170
)
156
171
@@ -184,4 +199,6 @@ def factory(_context, request):
184
199
links_service = request .find_service (name = "links" ),
185
200
flag_service = request .find_service (name = "flag" ),
186
201
user_service = request .find_service (name = "user" ),
202
+ mention_service = request .find_service (MentionService ),
203
+ feature_service = request .find_service (name = "feature" ),
187
204
)
0 commit comments