@@ -32,216 +32,216 @@ |
||
32 | 32 | |
33 | 33 | class Notifier implements INotifier { |
34 | 34 | |
35 | - /** @var IFactory */ |
|
36 | - protected $l10nFactory; |
|
37 | - |
|
38 | - /** @var IURLGenerator */ |
|
39 | - protected $urlGenerator; |
|
40 | - |
|
41 | - /** |
|
42 | - * @param IFactory $l10nFactory |
|
43 | - * @param IURLGenerator $urlGenerator |
|
44 | - */ |
|
45 | - public function __construct(IFactory $l10nFactory, IURLGenerator $urlGenerator) { |
|
46 | - $this->l10nFactory = $l10nFactory; |
|
47 | - $this->urlGenerator = $urlGenerator; |
|
48 | - } |
|
49 | - |
|
50 | - public function getID(): string { |
|
51 | - return 'files'; |
|
52 | - } |
|
53 | - |
|
54 | - public function getName(): string { |
|
55 | - return $this->l10nFactory->get('files')->t('Files'); |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * @param INotification $notification |
|
60 | - * @param string $languageCode The code of the language that should be used to prepare the notification |
|
61 | - * @return INotification |
|
62 | - * @throws \InvalidArgumentException When the notification was not prepared by a notifier |
|
63 | - */ |
|
64 | - public function prepare(INotification $notification, string $languageCode): INotification { |
|
65 | - if ($notification->getApp() !== 'files') { |
|
66 | - throw new \InvalidArgumentException('Unhandled app'); |
|
67 | - } |
|
68 | - |
|
69 | - if ($notification->getSubject() === 'transferownershipRequest') { |
|
70 | - return $this->handleTransferownershipRequest($notification, $languageCode); |
|
71 | - } |
|
72 | - if ($notification->getSubject() === 'transferOwnershipFailedSource') { |
|
73 | - return $this->handleTransferOwnershipFailedSource($notification, $languageCode); |
|
74 | - } |
|
75 | - if ($notification->getSubject() === 'transferOwnershipFailedTarget') { |
|
76 | - return $this->handleTransferOwnershipFailedTarget($notification, $languageCode); |
|
77 | - } |
|
78 | - if ($notification->getSubject() === 'transferOwnershipDoneSource') { |
|
79 | - return $this->handleTransferOwnershipDoneSource($notification, $languageCode); |
|
80 | - } |
|
81 | - if ($notification->getSubject() === 'transferOwnershipDoneTarget') { |
|
82 | - return $this->handleTransferOwnershipDoneTarget($notification, $languageCode); |
|
83 | - } |
|
84 | - |
|
85 | - throw new \InvalidArgumentException('Unhandled subject'); |
|
86 | - } |
|
87 | - |
|
88 | - public function handleTransferownershipRequest(INotification $notification, string $languageCode): INotification { |
|
89 | - $l = $this->l10nFactory->get('files', $languageCode); |
|
90 | - $id = $notification->getObjectId(); |
|
91 | - $param = $notification->getSubjectParameters(); |
|
92 | - |
|
93 | - $approveAction = $notification->createAction() |
|
94 | - ->setParsedLabel($l->t('Accept')) |
|
95 | - ->setPrimary(true) |
|
96 | - ->setLink( |
|
97 | - $this->urlGenerator->getAbsoluteURL( |
|
98 | - $this->urlGenerator->linkTo( |
|
99 | - '', |
|
100 | - 'ocs/v2.php/apps/files/api/v1/transferownership/' . $id |
|
101 | - ) |
|
102 | - ), |
|
103 | - IAction::TYPE_POST |
|
104 | - ); |
|
105 | - |
|
106 | - $disapproveAction = $notification->createAction() |
|
107 | - ->setParsedLabel($l->t('Decline')) |
|
108 | - ->setPrimary(false) |
|
109 | - ->setLink( |
|
110 | - $this->urlGenerator->getAbsoluteURL( |
|
111 | - $this->urlGenerator->linkTo( |
|
112 | - '', |
|
113 | - 'ocs/v2.php/apps/files/api/v1/transferownership/' . $id |
|
114 | - ) |
|
115 | - ), |
|
116 | - IAction::TYPE_DELETE |
|
117 | - ); |
|
118 | - |
|
119 | - $notification->addParsedAction($approveAction) |
|
120 | - ->addParsedAction($disapproveAction) |
|
121 | - ->setRichSubject( |
|
122 | - $l->t('Incoming file transfer from {user}'), |
|
123 | - [ |
|
124 | - 'user' => [ |
|
125 | - 'type' => 'user', |
|
126 | - 'id' => $param['sourceUser'], |
|
127 | - 'name' => $param['sourceUser'], |
|
128 | - ], |
|
129 | - ]) |
|
130 | - ->setParsedSubject(str_replace('{user}', $param['sourceUser'], $l->t('Incoming file transfer from {user}'))) |
|
131 | - ->setRichMessage( |
|
132 | - $l->t('Do you want to accept {path}?'), |
|
133 | - [ |
|
134 | - 'path' => [ |
|
135 | - 'type' => 'highlight', |
|
136 | - 'id' => $param['targetUser'] . '::' . $param['nodeName'], |
|
137 | - 'name' => $param['nodeName'], |
|
138 | - ] |
|
139 | - ]) |
|
140 | - ->setParsedMessage(str_replace('{path}', $param['nodeName'], $l->t('Do you want to accept {path}?'))); |
|
141 | - |
|
142 | - return $notification; |
|
143 | - } |
|
144 | - |
|
145 | - public function handleTransferOwnershipFailedSource(INotification $notification, string $languageCode): INotification { |
|
146 | - $l = $this->l10nFactory->get('files', $languageCode); |
|
147 | - $param = $notification->getSubjectParameters(); |
|
148 | - |
|
149 | - $notification->setRichSubject($l->t('File transfer failed')) |
|
150 | - ->setParsedSubject($l->t('File transfer failed')) |
|
151 | - |
|
152 | - ->setRichMessage( |
|
153 | - $l->t('Your transfer of {path} to {user} failed.'), |
|
154 | - [ |
|
155 | - 'path' => [ |
|
156 | - 'type' => 'highlight', |
|
157 | - 'id' => $param['targetUser'] . '::' . $param['nodeName'], |
|
158 | - 'name' => $param['nodeName'], |
|
159 | - ], |
|
160 | - 'user' => [ |
|
161 | - 'type' => 'user', |
|
162 | - 'id' => $param['targetUser'], |
|
163 | - 'name' => $param['targetUser'], |
|
164 | - ], |
|
165 | - ]) |
|
166 | - ->setParsedMessage(str_replace(['{path}', '{user}'], [$param['nodeName'], $param['targetUser']], $l->t('Your transfer of {path} to {user} failed.'))); |
|
167 | - return $notification; |
|
168 | - } |
|
169 | - |
|
170 | - public function handleTransferOwnershipFailedTarget(INotification $notification, string $languageCode): INotification { |
|
171 | - $l = $this->l10nFactory->get('files', $languageCode); |
|
172 | - $param = $notification->getSubjectParameters(); |
|
173 | - |
|
174 | - $notification->setRichSubject($l->t('File transfer failed')) |
|
175 | - ->setParsedSubject($l->t('File transfer failed')) |
|
176 | - |
|
177 | - ->setRichMessage( |
|
178 | - $l->t('The transfer of {path} from {user} failed.'), |
|
179 | - [ |
|
180 | - 'path' => [ |
|
181 | - 'type' => 'highlight', |
|
182 | - 'id' => $param['sourceUser'] . '::' . $param['nodeName'], |
|
183 | - 'name' => $param['nodeName'], |
|
184 | - ], |
|
185 | - 'user' => [ |
|
186 | - 'type' => 'user', |
|
187 | - 'id' => $param['sourceUser'], |
|
188 | - 'name' => $param['sourceUser'], |
|
189 | - ], |
|
190 | - ]) |
|
191 | - ->setParsedMessage(str_replace(['{path}', '{user}'], [$param['nodeName'], $param['sourceUser']], $l->t('The transfer of {path} from {user} failed.'))); |
|
192 | - |
|
193 | - return $notification; |
|
194 | - } |
|
195 | - |
|
196 | - public function handleTransferOwnershipDoneSource(INotification $notification, string $languageCode): INotification { |
|
197 | - $l = $this->l10nFactory->get('files', $languageCode); |
|
198 | - $param = $notification->getSubjectParameters(); |
|
199 | - |
|
200 | - $notification->setRichSubject($l->t('File transfer done')) |
|
201 | - ->setParsedSubject($l->t('File transfer done')) |
|
202 | - |
|
203 | - ->setRichMessage( |
|
204 | - $l->t('Your transfer of {path} to {user} has completed.'), |
|
205 | - [ |
|
206 | - 'path' => [ |
|
207 | - 'type' => 'highlight', |
|
208 | - 'id' => $param['targetUser'] . '::' . $param['nodeName'], |
|
209 | - 'name' => $param['nodeName'], |
|
210 | - ], |
|
211 | - 'user' => [ |
|
212 | - 'type' => 'user', |
|
213 | - 'id' => $param['targetUser'], |
|
214 | - 'name' => $param['targetUser'], |
|
215 | - ], |
|
216 | - ]) |
|
217 | - ->setParsedMessage(str_replace(['{path}', '{user}'], [$param['nodeName'], $param['targetUser']], $l->t('Your transfer of {path} to {user} has completed.'))); |
|
218 | - |
|
219 | - return $notification; |
|
220 | - } |
|
221 | - |
|
222 | - public function handleTransferOwnershipDoneTarget(INotification $notification, string $languageCode): INotification { |
|
223 | - $l = $this->l10nFactory->get('files', $languageCode); |
|
224 | - $param = $notification->getSubjectParameters(); |
|
225 | - |
|
226 | - $notification->setRichSubject($l->t('File transfer done')) |
|
227 | - ->setParsedSubject($l->t('File transfer done')) |
|
228 | - |
|
229 | - ->setRichMessage( |
|
230 | - $l->t('The transfer of {path} from {user} has completed.'), |
|
231 | - [ |
|
232 | - 'path' => [ |
|
233 | - 'type' => 'highlight', |
|
234 | - 'id' => $param['sourceUser'] . '::' . $param['nodeName'], |
|
235 | - 'name' => $param['nodeName'], |
|
236 | - ], |
|
237 | - 'user' => [ |
|
238 | - 'type' => 'user', |
|
239 | - 'id' => $param['sourceUser'], |
|
240 | - 'name' => $param['sourceUser'], |
|
241 | - ], |
|
242 | - ]) |
|
243 | - ->setParsedMessage(str_replace(['{path}', '{user}'], [$param['nodeName'], $param['sourceUser']], $l->t('The transfer of {path} from {user} has completed.'))); |
|
244 | - |
|
245 | - return $notification; |
|
246 | - } |
|
35 | + /** @var IFactory */ |
|
36 | + protected $l10nFactory; |
|
37 | + |
|
38 | + /** @var IURLGenerator */ |
|
39 | + protected $urlGenerator; |
|
40 | + |
|
41 | + /** |
|
42 | + * @param IFactory $l10nFactory |
|
43 | + * @param IURLGenerator $urlGenerator |
|
44 | + */ |
|
45 | + public function __construct(IFactory $l10nFactory, IURLGenerator $urlGenerator) { |
|
46 | + $this->l10nFactory = $l10nFactory; |
|
47 | + $this->urlGenerator = $urlGenerator; |
|
48 | + } |
|
49 | + |
|
50 | + public function getID(): string { |
|
51 | + return 'files'; |
|
52 | + } |
|
53 | + |
|
54 | + public function getName(): string { |
|
55 | + return $this->l10nFactory->get('files')->t('Files'); |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * @param INotification $notification |
|
60 | + * @param string $languageCode The code of the language that should be used to prepare the notification |
|
61 | + * @return INotification |
|
62 | + * @throws \InvalidArgumentException When the notification was not prepared by a notifier |
|
63 | + */ |
|
64 | + public function prepare(INotification $notification, string $languageCode): INotification { |
|
65 | + if ($notification->getApp() !== 'files') { |
|
66 | + throw new \InvalidArgumentException('Unhandled app'); |
|
67 | + } |
|
68 | + |
|
69 | + if ($notification->getSubject() === 'transferownershipRequest') { |
|
70 | + return $this->handleTransferownershipRequest($notification, $languageCode); |
|
71 | + } |
|
72 | + if ($notification->getSubject() === 'transferOwnershipFailedSource') { |
|
73 | + return $this->handleTransferOwnershipFailedSource($notification, $languageCode); |
|
74 | + } |
|
75 | + if ($notification->getSubject() === 'transferOwnershipFailedTarget') { |
|
76 | + return $this->handleTransferOwnershipFailedTarget($notification, $languageCode); |
|
77 | + } |
|
78 | + if ($notification->getSubject() === 'transferOwnershipDoneSource') { |
|
79 | + return $this->handleTransferOwnershipDoneSource($notification, $languageCode); |
|
80 | + } |
|
81 | + if ($notification->getSubject() === 'transferOwnershipDoneTarget') { |
|
82 | + return $this->handleTransferOwnershipDoneTarget($notification, $languageCode); |
|
83 | + } |
|
84 | + |
|
85 | + throw new \InvalidArgumentException('Unhandled subject'); |
|
86 | + } |
|
87 | + |
|
88 | + public function handleTransferownershipRequest(INotification $notification, string $languageCode): INotification { |
|
89 | + $l = $this->l10nFactory->get('files', $languageCode); |
|
90 | + $id = $notification->getObjectId(); |
|
91 | + $param = $notification->getSubjectParameters(); |
|
92 | + |
|
93 | + $approveAction = $notification->createAction() |
|
94 | + ->setParsedLabel($l->t('Accept')) |
|
95 | + ->setPrimary(true) |
|
96 | + ->setLink( |
|
97 | + $this->urlGenerator->getAbsoluteURL( |
|
98 | + $this->urlGenerator->linkTo( |
|
99 | + '', |
|
100 | + 'ocs/v2.php/apps/files/api/v1/transferownership/' . $id |
|
101 | + ) |
|
102 | + ), |
|
103 | + IAction::TYPE_POST |
|
104 | + ); |
|
105 | + |
|
106 | + $disapproveAction = $notification->createAction() |
|
107 | + ->setParsedLabel($l->t('Decline')) |
|
108 | + ->setPrimary(false) |
|
109 | + ->setLink( |
|
110 | + $this->urlGenerator->getAbsoluteURL( |
|
111 | + $this->urlGenerator->linkTo( |
|
112 | + '', |
|
113 | + 'ocs/v2.php/apps/files/api/v1/transferownership/' . $id |
|
114 | + ) |
|
115 | + ), |
|
116 | + IAction::TYPE_DELETE |
|
117 | + ); |
|
118 | + |
|
119 | + $notification->addParsedAction($approveAction) |
|
120 | + ->addParsedAction($disapproveAction) |
|
121 | + ->setRichSubject( |
|
122 | + $l->t('Incoming file transfer from {user}'), |
|
123 | + [ |
|
124 | + 'user' => [ |
|
125 | + 'type' => 'user', |
|
126 | + 'id' => $param['sourceUser'], |
|
127 | + 'name' => $param['sourceUser'], |
|
128 | + ], |
|
129 | + ]) |
|
130 | + ->setParsedSubject(str_replace('{user}', $param['sourceUser'], $l->t('Incoming file transfer from {user}'))) |
|
131 | + ->setRichMessage( |
|
132 | + $l->t('Do you want to accept {path}?'), |
|
133 | + [ |
|
134 | + 'path' => [ |
|
135 | + 'type' => 'highlight', |
|
136 | + 'id' => $param['targetUser'] . '::' . $param['nodeName'], |
|
137 | + 'name' => $param['nodeName'], |
|
138 | + ] |
|
139 | + ]) |
|
140 | + ->setParsedMessage(str_replace('{path}', $param['nodeName'], $l->t('Do you want to accept {path}?'))); |
|
141 | + |
|
142 | + return $notification; |
|
143 | + } |
|
144 | + |
|
145 | + public function handleTransferOwnershipFailedSource(INotification $notification, string $languageCode): INotification { |
|
146 | + $l = $this->l10nFactory->get('files', $languageCode); |
|
147 | + $param = $notification->getSubjectParameters(); |
|
148 | + |
|
149 | + $notification->setRichSubject($l->t('File transfer failed')) |
|
150 | + ->setParsedSubject($l->t('File transfer failed')) |
|
151 | + |
|
152 | + ->setRichMessage( |
|
153 | + $l->t('Your transfer of {path} to {user} failed.'), |
|
154 | + [ |
|
155 | + 'path' => [ |
|
156 | + 'type' => 'highlight', |
|
157 | + 'id' => $param['targetUser'] . '::' . $param['nodeName'], |
|
158 | + 'name' => $param['nodeName'], |
|
159 | + ], |
|
160 | + 'user' => [ |
|
161 | + 'type' => 'user', |
|
162 | + 'id' => $param['targetUser'], |
|
163 | + 'name' => $param['targetUser'], |
|
164 | + ], |
|
165 | + ]) |
|
166 | + ->setParsedMessage(str_replace(['{path}', '{user}'], [$param['nodeName'], $param['targetUser']], $l->t('Your transfer of {path} to {user} failed.'))); |
|
167 | + return $notification; |
|
168 | + } |
|
169 | + |
|
170 | + public function handleTransferOwnershipFailedTarget(INotification $notification, string $languageCode): INotification { |
|
171 | + $l = $this->l10nFactory->get('files', $languageCode); |
|
172 | + $param = $notification->getSubjectParameters(); |
|
173 | + |
|
174 | + $notification->setRichSubject($l->t('File transfer failed')) |
|
175 | + ->setParsedSubject($l->t('File transfer failed')) |
|
176 | + |
|
177 | + ->setRichMessage( |
|
178 | + $l->t('The transfer of {path} from {user} failed.'), |
|
179 | + [ |
|
180 | + 'path' => [ |
|
181 | + 'type' => 'highlight', |
|
182 | + 'id' => $param['sourceUser'] . '::' . $param['nodeName'], |
|
183 | + 'name' => $param['nodeName'], |
|
184 | + ], |
|
185 | + 'user' => [ |
|
186 | + 'type' => 'user', |
|
187 | + 'id' => $param['sourceUser'], |
|
188 | + 'name' => $param['sourceUser'], |
|
189 | + ], |
|
190 | + ]) |
|
191 | + ->setParsedMessage(str_replace(['{path}', '{user}'], [$param['nodeName'], $param['sourceUser']], $l->t('The transfer of {path} from {user} failed.'))); |
|
192 | + |
|
193 | + return $notification; |
|
194 | + } |
|
195 | + |
|
196 | + public function handleTransferOwnershipDoneSource(INotification $notification, string $languageCode): INotification { |
|
197 | + $l = $this->l10nFactory->get('files', $languageCode); |
|
198 | + $param = $notification->getSubjectParameters(); |
|
199 | + |
|
200 | + $notification->setRichSubject($l->t('File transfer done')) |
|
201 | + ->setParsedSubject($l->t('File transfer done')) |
|
202 | + |
|
203 | + ->setRichMessage( |
|
204 | + $l->t('Your transfer of {path} to {user} has completed.'), |
|
205 | + [ |
|
206 | + 'path' => [ |
|
207 | + 'type' => 'highlight', |
|
208 | + 'id' => $param['targetUser'] . '::' . $param['nodeName'], |
|
209 | + 'name' => $param['nodeName'], |
|
210 | + ], |
|
211 | + 'user' => [ |
|
212 | + 'type' => 'user', |
|
213 | + 'id' => $param['targetUser'], |
|
214 | + 'name' => $param['targetUser'], |
|
215 | + ], |
|
216 | + ]) |
|
217 | + ->setParsedMessage(str_replace(['{path}', '{user}'], [$param['nodeName'], $param['targetUser']], $l->t('Your transfer of {path} to {user} has completed.'))); |
|
218 | + |
|
219 | + return $notification; |
|
220 | + } |
|
221 | + |
|
222 | + public function handleTransferOwnershipDoneTarget(INotification $notification, string $languageCode): INotification { |
|
223 | + $l = $this->l10nFactory->get('files', $languageCode); |
|
224 | + $param = $notification->getSubjectParameters(); |
|
225 | + |
|
226 | + $notification->setRichSubject($l->t('File transfer done')) |
|
227 | + ->setParsedSubject($l->t('File transfer done')) |
|
228 | + |
|
229 | + ->setRichMessage( |
|
230 | + $l->t('The transfer of {path} from {user} has completed.'), |
|
231 | + [ |
|
232 | + 'path' => [ |
|
233 | + 'type' => 'highlight', |
|
234 | + 'id' => $param['sourceUser'] . '::' . $param['nodeName'], |
|
235 | + 'name' => $param['nodeName'], |
|
236 | + ], |
|
237 | + 'user' => [ |
|
238 | + 'type' => 'user', |
|
239 | + 'id' => $param['sourceUser'], |
|
240 | + 'name' => $param['sourceUser'], |
|
241 | + ], |
|
242 | + ]) |
|
243 | + ->setParsedMessage(str_replace(['{path}', '{user}'], [$param['nodeName'], $param['sourceUser']], $l->t('The transfer of {path} from {user} has completed.'))); |
|
244 | + |
|
245 | + return $notification; |
|
246 | + } |
|
247 | 247 | } |