Skip to content

Commit 26de49d

Browse files
feat: send import finished notification to View receipients
Signed-off-by: Luka Trovic <luka@nextcloud.com>
1 parent 7a354c6 commit 26de49d

4 files changed

Lines changed: 60 additions & 17 deletions

File tree

lib/Activity/ActivityManager.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,8 @@ public function getActivityMessage($language, $subjectIdentifier) {
787787
}
788788

789789
public function findRecipientsByElement(Table|View $element): array {
790-
$cacheKey = 'element_recipients_' . $element->getId();
790+
$elementType = $element instanceof Table ? 'table' : 'view';
791+
$cacheKey = 'element_recipients_' . $elementType . '_' . $element->getId();
791792
$cached = $this->cache->get($cacheKey);
792793
if ($cached !== null) {
793794
return $cached;
@@ -800,13 +801,7 @@ public function findRecipientsByElement(Table|View $element): array {
800801
$recipients[] = $owner;
801802
}
802803

803-
if ($element instanceof View) {
804-
$recipients = array_merge($recipients, $this->shareService->findSharedWithUserIds($element->getId(), 'view'));
805-
}
806-
if ($element instanceof Table) {
807-
$recipients = array_merge($recipients, $this->shareService->findSharedWithUserIds($element->getId(), 'table'));
808-
}
809-
804+
$recipients = array_merge($recipients, $this->shareService->findSharedWithUserIds($element->getId(), $elementType));
810805
$recipients = array_unique($recipients);
811806
$this->cache->set($cacheKey, $recipients);
812807
return $recipients;

lib/BackgroundJob/ImportTableJob.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,20 @@ public function run($argument): void {
8181
],
8282
author: $userId
8383
);
84-
$this->notificationHelper->sendNotification(
85-
objectType: ActivityManager::TABLES_OBJECT_TABLE,
86-
object: $this->tableMapper->find($tableId),
87-
subject: ActivityManager::SUBJECT_IMPORT_FINISHED,
88-
author: $userId
89-
);
84+
if ($viewId) {
85+
$this->notificationHelper->sendNotification(
86+
objectType: ActivityManager::TABLES_OBJECT_VIEW,
87+
object: $this->viewMapper->find($viewId),
88+
subject: ActivityManager::SUBJECT_IMPORT_FINISHED,
89+
author: $userId
90+
);
91+
} else {
92+
$this->notificationHelper->sendNotification(
93+
objectType: ActivityManager::TABLES_OBJECT_TABLE,
94+
object: $this->tableMapper->find($tableId),
95+
subject: ActivityManager::SUBJECT_IMPORT_FINISHED,
96+
author: $userId
97+
);
98+
}
9099
}
91100
}

lib/Notification/NotificationHelper.php

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,24 @@ public function __construct(
4343
}
4444

4545
/**
46-
* @param Table|Row2|Column $object
46+
* @param Table|View|Row2|Column $object
4747
* @param string $subject
4848
* @param array<string, mixed> $additionalParams
4949
* @param string|null $author
5050
*/
51-
public function sendNotification(string $objectType, Table|Row2|Column $object, string $subject, array $additionalParams = [], ?string $author = null): void {
51+
public function sendNotification(string $objectType, Table|View|Row2|Column $object, string $subject, array $additionalParams = [], ?string $author = null): void {
5252
try {
5353
switch ($objectType) {
5454
case ActivityManager::TABLES_OBJECT_TABLE:
5555
if ($object instanceof Table) {
5656
$this->sendTableNotification($object, $subject, $author);
5757
}
5858
break;
59+
case ActivityManager::TABLES_OBJECT_VIEW:
60+
if ($object instanceof View) {
61+
$this->sendViewNotification($object, $subject, $author);
62+
}
63+
break;
5964
case ActivityManager::TABLES_OBJECT_ROW:
6065
if ($object instanceof Row2) {
6166
$this->sendRowNotification($object, $subject, $additionalParams, $author);
@@ -97,6 +102,26 @@ private function sendTableNotification(Table $object, string $subject, ?string $
97102
);
98103
}
99104

105+
private function sendViewNotification(View $object, string $subject, ?string $author): void {
106+
$subjectParams = [
107+
'author' => $author,
108+
'objectType' => ActivityManager::TABLES_OBJECT_VIEW,
109+
'view' => [
110+
'id' => $object->getId(),
111+
'title' => $object->getTitle(),
112+
],
113+
];
114+
$this->sendNotifiesByElement(
115+
element: $object,
116+
subject: $subject,
117+
subjectParams: $subjectParams,
118+
objectType: ActivityManager::TABLES_OBJECT_VIEW,
119+
objectId: (string)$object->getId(),
120+
authorId: null,
121+
configKey: null,
122+
);
123+
}
124+
100125
/**
101126
* @param string|null $author
102127
*/

lib/Notification/Notifier.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,23 @@ public function prepare(INotification $notification, string $languageCode): INot
294294
break;
295295

296296
case ActivityManager::SUBJECT_IMPORT_FINISHED:
297-
$link = $richParams['table']['link'];
297+
$link = $hasViewContext ? $richParams['view']['link'] : $richParams['table']['link'];
298298
$recipient = $notification->getUser();
299299
$isActivityOwner = $params['author'] === $recipient;
300+
if ($hasViewContext) {
301+
$parsedSubject = $isActivityOwner
302+
? $l->t('You have imported file to view {view}', [
303+
$richParams['view']['name'] ?? '',
304+
])
305+
: $l->t('{user} has imported file to view {view}', [
306+
$richParams['user']['name'] ?? '',
307+
$richParams['view']['name'] ?? '',
308+
]);
309+
$subject = $isActivityOwner
310+
? $l->t('You have imported file to view {view}')
311+
: $l->t('{user} has imported file to view {view}');
312+
break;
313+
}
300314
$parsedSubject = $isActivityOwner
301315
? $l->t('You have imported file to table {table}', [
302316
$richParams['table']['name'] ?? '',

0 commit comments

Comments
 (0)