Skip to content

Commit bb962d6

Browse files
committed
fix(files_reminder): passed reminder handling
Signed-off-by: John Molakvoæ (skjnldsv) <[email protected]>
1 parent 0cf140e commit bb962d6

File tree

5 files changed

+43
-9
lines changed

5 files changed

+43
-9
lines changed

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: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55

66
<script setup lang="ts">
77
import type { INode } from '@nextcloud/files'
8+
import type { OCSResponse } from '@nextcloud/typings/ocs'
89
910
import { showError, showSuccess } from '@nextcloud/dialogs'
1011
import { emit as emitEventBus } from '@nextcloud/event-bus'
11-
import { t } from '@nextcloud/l10n'
12-
import { onBeforeMount, onMounted, ref } from 'vue'
12+
import { formatRelativeTime, t } from '@nextcloud/l10n'
13+
import { computed, onBeforeMount, onMounted, ref } from 'vue'
1314
import NcButton from '@nextcloud/vue/components/NcButton'
14-
import NcDateTime from '@nextcloud/vue/components/NcDateTime'
1515
import NcDateTimePickerNative from '@nextcloud/vue/components/NcDateTimePickerNative'
1616
import NcDialog from '@nextcloud/vue/components/NcDialog'
1717
import NcNoteCard from '@nextcloud/vue/components/NcNoteCard'
@@ -33,6 +33,15 @@ const isValid = ref(true)
3333
const customDueDate = ref<Date>()
3434
const nowDate = ref(new Date())
3535
36+
const informationText = computed(() => {
37+
const relativeDueDate = formatRelativeTime(customDueDate.value ?? 0)
38+
return (nowDate.value.getTime() >= (customDueDate.value?.getTime() ?? 0))
39+
// TRANSLATORS: {relativeDueDate} will be replaced with a relative time, e.g. "2 hours ago" or "in 3 days".
40+
? t('files_reminders', 'We reminded you of this file {relativeDueDate}', { relativeDueDate })
41+
// TRANSLATORS: {relativeDueDate} will be replaced with a relative time, e.g. "2 hours ago" or "in 3 days".
42+
: t('files_reminders', 'We will remind you of this file {relativeDueDate}', { relativeDueDate })
43+
})
44+
3645
onBeforeMount(() => {
3746
const dueDate = props.node.attributes['reminder-due-date']
3847
? new Date(props.node.attributes['reminder-due-date'])
@@ -132,8 +141,7 @@ function onInput(): void {
132141
@input="onInput" />
133142

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

139147
<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)