Skip to content

Commit cc7c56c

Browse files
committed
fix(files_reminder): passed reminder handling
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
1 parent 0cf140e commit cc7c56c

5 files changed

Lines changed: 42 additions & 9 deletions

File tree

apps/files_reminders/lib/Service/ReminderService.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,19 @@ public function getDueForUser(IUser $user, int $fileId, bool $checkNode = true):
7474
return null;
7575
}
7676
if ($cachedReminder instanceof Reminder) {
77+
if ($cachedReminder->getDueDate() < new DateTime()) {
78+
return null;
79+
}
7780
return new RichReminder($cachedReminder, $this->root);
7881
}
7982

8083
try {
8184
$reminder = $this->reminderMapper->findDueForUser($user, $fileId);
85+
// If reminder is in the past, do not return it and do not cache it.
86+
if ($reminder->getDueDate() < new DateTime()) {
87+
return null;
88+
}
89+
8290
$this->cache->set("{$user->getUID()}-$fileId", $reminder);
8391
return new RichReminder($reminder, $this->root);
8492
} catch (DoesNotExistException $e) {

apps/files_reminders/src/components/SetCustomReminderModal.vue

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ import type { INode } from '@nextcloud/files'
88
99
import { showError, showSuccess } from '@nextcloud/dialogs'
1010
import { emit as emitEventBus } from '@nextcloud/event-bus'
11-
import { t } from '@nextcloud/l10n'
12-
import { onBeforeMount, onMounted, ref } from 'vue'
11+
import { formatRelativeTime, t } from '@nextcloud/l10n'
12+
import { computed, onBeforeMount, onMounted, ref } from 'vue'
1313
import NcButton from '@nextcloud/vue/components/NcButton'
14-
import NcDateTime from '@nextcloud/vue/components/NcDateTime'
1514
import NcDateTimePickerNative from '@nextcloud/vue/components/NcDateTimePickerNative'
1615
import NcDialog from '@nextcloud/vue/components/NcDialog'
1716
import NcNoteCard from '@nextcloud/vue/components/NcNoteCard'
@@ -33,6 +32,15 @@ const isValid = ref(true)
3332
const customDueDate = ref<Date>()
3433
const nowDate = ref(new Date())
3534
35+
const informationText = computed(() => {
36+
const relativeDueDate = formatRelativeTime(customDueDate.value ?? 0)
37+
return (nowDate.value.getTime() >= (customDueDate.value?.getTime() ?? 0))
38+
// TRANSLATORS: {relativeDueDate} will be replaced with a relative time, e.g. "2 hours ago" or "in 3 days".
39+
? t('files_reminders', 'We reminded you of this file {relativeDueDate}', { relativeDueDate })
40+
// TRANSLATORS: {relativeDueDate} will be replaced with a relative time, e.g. "2 hours ago" or "in 3 days".
41+
: t('files_reminders', 'We will remind you of this file {relativeDueDate}', { relativeDueDate })
42+
})
43+
3644
onBeforeMount(() => {
3745
const dueDate = props.node.attributes['reminder-due-date']
3846
? new Date(props.node.attributes['reminder-due-date'])
@@ -132,8 +140,7 @@ function onInput(): void {
132140
@input="onInput" />
133141

134142
<NcNoteCard v-if="isValid && customDueDate" type="info">
135-
{{ t('files_reminders', 'We will remind you of this file') }}
136-
<NcDateTime :timestamp="customDueDate" />
143+
{{ informationText }}
137144
</NcNoteCard>
138145

139146
<NcNoteCard v-else type="error">

apps/files_reminders/src/files_actions/reminderStatusAction.spec.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe('reminderStatusAction', () => {
2222
owner: 'user',
2323
source: 'https://example.com/remote.php/dav/files/user/folder',
2424
attributes: {
25-
'reminder-due-date': '2024-12-25T10:00:00Z',
25+
'reminder-due-date': '2099-12-25T10:00:00Z',
2626
},
2727
root: '/files/user',
2828
})
@@ -38,6 +38,17 @@ describe('reminderStatusAction', () => {
3838
})).toBe(true)
3939
})
4040

41+
it('should be disabled for one node with past due date', () => {
42+
const node = folder.clone()
43+
node.attributes['reminder-due-date'] = '2000-01-01T00:00:00Z'
44+
expect(action.enabled!({
45+
nodes: [node],
46+
view,
47+
folder: root,
48+
contents: [],
49+
})).toBe(false)
50+
})
51+
4152
it('should be disabled with more than one node', () => {
4253
expect(action.enabled!({
4354
nodes: [folder, folder],
@@ -64,6 +75,6 @@ describe('reminderStatusAction', () => {
6475
view,
6576
folder: root,
6677
contents: [],
67-
})).toMatchInlineSnapshot('"Reminder set – Wednesday, December 25, 2024 at 10:00 AM"')
78+
})).toMatchInlineSnapshot('"Reminder set – Friday, December 25, 2099 at 10:00 AM"')
6879
})
6980
})

apps/files_reminders/src/files_actions/reminderStatusAction.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ export const action: IFileAction = {
3333

3434
const node = nodes.at(0)!
3535
const dueDate = node.attributes['reminder-due-date']
36-
return Boolean(dueDate)
36+
const now = new Date()
37+
38+
// Do not show if the reminder is in the past
39+
return Boolean(dueDate) && new Date(dueDate) > now
3740
},
3841

3942
async exec({ nodes }) {

apps/files_reminders/src/services/reminderService.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ export async function setReminder(fileId: number, dueDate: Date): Promise<[]> {
4848
*/
4949
export async function clearReminder(fileId: number): Promise<[]> {
5050
const url = generateOcsUrl('/apps/files_reminders/api/v1/{fileId}', { fileId })
51-
const response = await axios.delete(url)
51+
const response = await axios.delete(url, {
52+
// We allow 404 as it means there is no reminder to delete,
53+
// which is the desired state after this function is called anyway
54+
validateStatus: (status) => status === 200 || status === 404,
55+
})
5256

5357
return response.data.ocs.data
5458
}

0 commit comments

Comments
 (0)