@ebarooni/capacitor-calendar 8.10.0 → 8.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/README.md +94 -54
  2. package/android/src/main/java/dev/barooni/capacitor/calendar/CapacitorCalendarPlugin.kt +18 -0
  3. package/android/src/main/java/dev/barooni/capacitor/calendar/PluginError.kt +4 -0
  4. package/android/src/main/java/dev/barooni/capacitor/calendar/implementation/CapacitorCalendar.kt +128 -2
  5. package/android/src/main/java/dev/barooni/capacitor/calendar/models/data/EventRecurrenceRule.kt +4 -3
  6. package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/GetEventByIdInput.kt +13 -0
  7. package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/ListEventsInRangeInput.kt +5 -0
  8. package/android/src/main/java/dev/barooni/capacitor/calendar/models/results/GetEventByIdResult.kt +15 -0
  9. package/android/src/main/java/dev/barooni/capacitor/calendar/models/results/ListEventsInRangeResult.kt +47 -43
  10. package/android/src/main/java/dev/barooni/capacitor/calendar/utils/ImplementationHelper.kt +35 -2
  11. package/dist/docs.json +204 -6
  12. package/dist/esm/index.d.ts +4 -1
  13. package/dist/esm/index.js.map +1 -1
  14. package/dist/esm/schemas/interfaces/delete-event-options.d.ts +2 -1
  15. package/dist/esm/schemas/interfaces/delete-event-options.js.map +1 -1
  16. package/dist/esm/schemas/interfaces/delete-event-with-prompt-options.d.ts +2 -1
  17. package/dist/esm/schemas/interfaces/delete-event-with-prompt-options.js.map +1 -1
  18. package/dist/esm/schemas/interfaces/get-event-by-id-options.d.ts +11 -0
  19. package/dist/esm/schemas/interfaces/get-event-by-id-options.js +2 -0
  20. package/dist/esm/schemas/interfaces/get-event-by-id-options.js.map +1 -0
  21. package/dist/esm/schemas/interfaces/get-event-by-id-result.d.ts +13 -0
  22. package/dist/esm/schemas/interfaces/get-event-by-id-result.js +2 -0
  23. package/dist/esm/schemas/interfaces/get-event-by-id-result.js.map +1 -0
  24. package/dist/esm/schemas/interfaces/list-events-in-range-options.d.ts +8 -0
  25. package/dist/esm/schemas/interfaces/list-events-in-range-options.js.map +1 -1
  26. package/dist/esm/schemas/interfaces/modify-event-options.d.ts +11 -0
  27. package/dist/esm/schemas/interfaces/modify-event-options.js.map +1 -1
  28. package/dist/esm/schemas/interfaces/modify-event-with-prompt-options.d.ts +10 -0
  29. package/dist/esm/schemas/interfaces/modify-event-with-prompt-options.js.map +1 -1
  30. package/dist/esm/sub-definitions/event-operations.d.ts +33 -0
  31. package/dist/esm/sub-definitions/event-operations.js.map +1 -1
  32. package/dist/esm/web.d.ts +3 -0
  33. package/dist/esm/web.js +3 -0
  34. package/dist/esm/web.js.map +1 -1
  35. package/dist/plugin.cjs.js +3 -0
  36. package/dist/plugin.cjs.js.map +1 -1
  37. package/dist/plugin.js +3 -0
  38. package/dist/plugin.js.map +1 -1
  39. package/ios/Plugin/CapacitorCalendarPlugin.swift +17 -1
  40. package/ios/Plugin/Implementation/CapacitorCalendar.swift +41 -7
  41. package/ios/Plugin/Models/Inputs/CreateEventInput.swift +1 -1
  42. package/ios/Plugin/Models/Inputs/CreateEventWithPromptInput.swift +61 -70
  43. package/ios/Plugin/Models/Inputs/DeleteEventInput.swift +7 -0
  44. package/ios/Plugin/Models/Inputs/DeleteEventWithPromptInput.swift +7 -0
  45. package/ios/Plugin/Models/Inputs/GetEventByIdInput.swift +16 -0
  46. package/ios/Plugin/Models/Inputs/ListEventsInRangeInput.swift +20 -0
  47. package/ios/Plugin/Models/Inputs/ModifyEventInput.swift +13 -23
  48. package/ios/Plugin/Models/Inputs/ModifyEventWithPromptInput.swift +10 -5
  49. package/ios/Plugin/Models/Results/GetEventByIdResult.swift +27 -0
  50. package/ios/Plugin/Models/Structs/RecurrenceInput.swift +14 -0
  51. package/ios/Plugin/PluginConfig.swift +1 -0
  52. package/ios/Plugin/PluginError.swift +7 -0
  53. package/ios/Plugin/Utils/ImplementationHelper.swift +33 -2
  54. package/package.json +1 -1
package/README.md CHANGED
@@ -353,6 +353,7 @@ See [BREAKING.md](BREAKING.md) for breaking changes and migration steps.
353
353
  - [`deleteEvent(...)`](#deleteevent)
354
354
  - [`deleteEventWithPrompt(...)`](#deleteeventwithprompt)
355
355
  - [`listEventsInRange(...)`](#listeventsinrange)
356
+ - [`getEventById(...)`](#geteventbyid)
356
357
  - [`commit()`](#commit)
357
358
  - [`selectCalendarsWithPrompt(...)`](#selectcalendarswithprompt)
358
359
  - [`fetchAllCalendarSources()`](#fetchallcalendarsources)
@@ -600,6 +601,7 @@ modifyEvent(options: ModifyEventOptions) => Promise<void>
600
601
  ```
601
602
 
602
603
  Modifies an event.
604
+ Fields that you omit keep their current values.
603
605
 
604
606
  | Param | Type |
605
607
  | ------------- | ----------------------------------------------------------------- |
@@ -679,6 +681,7 @@ Retrieves events that overlap a date range.
679
681
 
680
682
  An event is included when its time interval intersects `[from, to]`, including
681
683
  multi-day events that span the range without starting or ending inside it.
684
+ Pass `calendarIds` to search only some calendars.
682
685
 
683
686
  | Param | Type |
684
687
  | ------------- | ----------------------------------------------------------------------------- |
@@ -692,6 +695,28 @@ multi-day events that span the range without starting or ending inside it.
692
695
 
693
696
  ---
694
697
 
698
+ ### getEventById(...)
699
+
700
+ ```typescript
701
+ getEventById(options: GetEventByIdOptions) => Promise<GetEventByIdResult>
702
+ ```
703
+
704
+ Retrieves an event by id.
705
+
706
+ For a recurring event, the result is the first occurrence on iOS and the series master on Android.
707
+
708
+ | Param | Type |
709
+ | ------------- | ------------------------------------------------------------------- |
710
+ | **`options`** | <code><a href="#geteventbyidoptions">GetEventByIdOptions</a></code> |
711
+
712
+ **Returns:** <code>Promise&lt;<a href="#geteventbyidresult">GetEventByIdResult</a>&gt;</code>
713
+
714
+ **Since:** 8.11.0
715
+
716
+ **Platform:** Android, iOS
717
+
718
+ ---
719
+
695
720
  ### commit()
696
721
 
697
722
  ```typescript
@@ -1195,21 +1220,22 @@ Options for {@link CalendarAccess#requestPermission}.
1195
1220
 
1196
1221
  #### ModifyEventWithPromptOptions
1197
1222
 
1198
- | Prop | Type | Description | Since | Platform |
1199
- | ------------------ | ------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----- | ------------ |
1200
- | **`alerts`** | <code>number[]</code> | Alert times in minutes relative to the event start. Use negative numbers for reminders before the start, and positive numbers for reminders after the start. On iOS only 2 alerts are supported. | 7.1.0 | iOS |
1201
- | **`availability`** | <code><a href="#eventavailability">EventAvailability</a></code> | | 7.1.0 | Android, iOS |
1202
- | **`calendarId`** | <code>string</code> | | 0.1.0 | iOS |
1203
- | **`description`** | <code>string</code> | | 7.1.0 | Android, iOS |
1204
- | **`endDate`** | <code>number</code> | | 0.1.0 | Android, iOS |
1205
- | **`id`** | <code>string</code> | The ID of the event to be modified. | 7.1.0 | Android, iOS |
1206
- | **`invitees`** | <code>string[]</code> | An array of emails to invite. | 7.1.0 | Android |
1207
- | **`isAllDay`** | <code>boolean</code> | | 0.1.0 | Android, iOS |
1208
- | **`location`** | <code>string</code> | | 0.1.0 | Android, iOS |
1209
- | **`recurrence`** | <code><a href="#eventrecurrencerule">EventRecurrenceRule</a></code> | Rules for creating a recurring event. | 7.3.0 | Android, iOS |
1210
- | **`startDate`** | <code>number</code> | | 0.1.0 | Android, iOS |
1211
- | **`title`** | <code>string</code> | | 0.1.0 | Android, iOS |
1212
- | **`url`** | <code>string</code> | | 0.1.0 | iOS |
1223
+ | Prop | Type | Description | Since | Platform |
1224
+ | ------------------ | ------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------ | ------------ |
1225
+ | **`alerts`** | <code>number[]</code> | Alert times in minutes relative to the event start. Use negative numbers for reminders before the start, and positive numbers for reminders after the start. On iOS only 2 alerts are supported. | 7.1.0 | iOS |
1226
+ | **`availability`** | <code><a href="#eventavailability">EventAvailability</a></code> | | 7.1.0 | Android, iOS |
1227
+ | **`calendarId`** | <code>string</code> | | 0.1.0 | iOS |
1228
+ | **`description`** | <code>string</code> | | 7.1.0 | Android, iOS |
1229
+ | **`endDate`** | <code>number</code> | | 0.1.0 | Android, iOS |
1230
+ | **`id`** | <code>string</code> | The ID of the event to be modified. | 7.1.0 | Android, iOS |
1231
+ | **`instanceDate`** | <code>number</code> | The start time of the occurrence to modify, in milliseconds since the epoch. Use `startDate` from `listEventsInRange`. If omitted, the first occurrence of a recurring series is the target. | 8.11.0 | iOS |
1232
+ | **`invitees`** | <code>string[]</code> | An array of emails to invite. | 7.1.0 | Android |
1233
+ | **`isAllDay`** | <code>boolean</code> | | 0.1.0 | Android, iOS |
1234
+ | **`location`** | <code>string</code> | | 0.1.0 | Android, iOS |
1235
+ | **`recurrence`** | <code><a href="#eventrecurrencerule">EventRecurrenceRule</a></code> | Rules for creating a recurring event. | 7.3.0 | Android, iOS |
1236
+ | **`startDate`** | <code>number</code> | | 0.1.0 | Android, iOS |
1237
+ | **`title`** | <code>string</code> | | 0.1.0 | Android, iOS |
1238
+ | **`url`** | <code>string</code> | | 0.1.0 | iOS |
1213
1239
 
1214
1240
  #### CreateEventResult
1215
1241
 
@@ -1250,25 +1276,26 @@ Options for {@link CalendarAccess#requestPermission}.
1250
1276
 
1251
1277
  #### ModifyEventOptions
1252
1278
 
1253
- | Prop | Type | Description | Default | Since | Platform |
1254
- | ------------------ | ------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------- | ----- | ------------ |
1255
- | **`alerts`** | <code>number[]</code> | Alert times in minutes relative to the event start. Use negative numbers for alerts before the start, and positive numbers for alerts after the start. | | 7.1.0 | Android, iOS |
1256
- | **`attendees`** | <code>EventGuest[]</code> | The event guests. | | 7.1.0 | Android |
1257
- | **`availability`** | <code><a href="#eventavailability">EventAvailability</a></code> | | | 7.1.0 | Android, iOS |
1258
- | **`calendarId`** | <code>string</code> | | | 0.1.0 | Android, iOS |
1259
- | **`color`** | <code>string</code> | | | 7.1.0 | Android |
1260
- | **`description`** | <code>string</code> | | | 7.1.0 | Android, iOS |
1261
- | **`duration`** | <code>string</code> | Duration of the event in RFC2445 format. | | 7.1.0 | Android |
1262
- | **`endDate`** | <code>number</code> | | | 0.1.0 | Android, iOS |
1263
- | **`id`** | <code>string</code> | The ID of the event to be modified. | | 7.1.0 | Android, iOS |
1264
- | **`isAllDay`** | <code>boolean</code> | | | 0.1.0 | Android, iOS |
1265
- | **`location`** | <code>string</code> | | | 0.1.0 | Android, iOS |
1266
- | **`recurrence`** | <code><a href="#eventrecurrencerule">EventRecurrenceRule</a></code> | Rules for creating a recurring event. | | 7.3.0 | Android, iOS |
1267
- | **`organizer`** | <code>string</code> | Email of the event organizer. | | 7.1.0 | Android |
1268
- | **`span`** | <code><a href="#eventspan">EventSpan</a></code> | The span of modifications. | <code>EventSpan.THIS_EVENT</code> | | iOS |
1269
- | **`startDate`** | <code>number</code> | | | 0.1.0 | Android, iOS |
1270
- | **`title`** | <code>string</code> | | | 0.4.0 | Android, iOS |
1271
- | **`url`** | <code>string</code> | | | 0.1.0 | iOS |
1279
+ | Prop | Type | Description | Default | Since | Platform |
1280
+ | ------------------ | ------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------- | ------ | ------------ |
1281
+ | **`alerts`** | <code>number[]</code> | Alert times in minutes relative to the event start. Use negative numbers for alerts before the start, and positive numbers for alerts after the start. | | 7.1.0 | Android, iOS |
1282
+ | **`attendees`** | <code>EventGuest[]</code> | The event guests. | | 7.1.0 | Android |
1283
+ | **`availability`** | <code><a href="#eventavailability">EventAvailability</a></code> | | | 7.1.0 | Android, iOS |
1284
+ | **`calendarId`** | <code>string</code> | | | 0.1.0 | Android, iOS |
1285
+ | **`color`** | <code>string</code> | | | 7.1.0 | Android |
1286
+ | **`description`** | <code>string</code> | | | 7.1.0 | Android, iOS |
1287
+ | **`duration`** | <code>string</code> | Duration of the event in RFC2445 format. | | 7.1.0 | Android |
1288
+ | **`endDate`** | <code>number</code> | | | 0.1.0 | Android, iOS |
1289
+ | **`id`** | <code>string</code> | The ID of the event to be modified. | | 7.1.0 | Android, iOS |
1290
+ | **`instanceDate`** | <code>number</code> | The start time of the occurrence to modify, in milliseconds since the epoch. Use `startDate` from `listEventsInRange`. If omitted, the first occurrence of a recurring series is the target. The call rejects when `recurrence` is also set and `span` is `THIS_EVENT`. Use `THIS_AND_FUTURE_EVENTS` to change the rule from this occurrence. | | 8.11.0 | iOS |
1291
+ | **`isAllDay`** | <code>boolean</code> | | | 0.1.0 | Android, iOS |
1292
+ | **`location`** | <code>string</code> | | | 0.1.0 | Android, iOS |
1293
+ | **`recurrence`** | <code><a href="#eventrecurrencerule">EventRecurrenceRule</a></code> | Rules for creating a recurring event. | | 7.3.0 | Android, iOS |
1294
+ | **`organizer`** | <code>string</code> | Email of the event organizer. | | 7.1.0 | Android |
1295
+ | **`span`** | <code><a href="#eventspan">EventSpan</a></code> | The span of modifications. | <code>EventSpan.THIS_EVENT</code> | | iOS |
1296
+ | **`startDate`** | <code>number</code> | | | 0.1.0 | Android, iOS |
1297
+ | **`title`** | <code>string</code> | | | 0.4.0 | Android, iOS |
1298
+ | **`url`** | <code>string</code> | | | 0.1.0 | iOS |
1272
1299
 
1273
1300
  #### DeleteEventsByIdResult
1274
1301
 
@@ -1287,25 +1314,25 @@ Options for {@link CalendarAccess#requestPermission}.
1287
1314
 
1288
1315
  #### DeleteEventOptions
1289
1316
 
1290
- | Prop | Type | Description | Default | Since | Platform |
1291
- | ------------------ | ----------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------- | ----- | ------------ |
1292
- | **`commit`** | <code>boolean</code> | Whether to save the deletion to the event store immediately. Pass `false` to batch multiple changes and commit them together using `CapacitorCalendar.commit()`, which is more efficient than committing each save individually. | <code>true</code> | 8.3.0 | iOS |
1293
- | **`id`** | <code>string</code> | The ID of the event to delete. | | 7.1.0 | Android, iOS |
1294
- | **`instanceDate`** | <code>number</code> | The start time of the occurrence to delete, in milliseconds since the epoch. Use `startDate` from `listEventsInRange`. On Android, required for `THIS_EVENT` on recurring events. If omitted with `THIS_AND_FUTURE_EVENTS`, the whole series is deleted. | | 8.3.0 | Android |
1295
- | **`span`** | <code><a href="#eventspan">EventSpan</a></code> | How much of a recurring series to delete. | <code>EventSpan.THIS_EVENT</code> | 7.1.0 | Android, iOS |
1317
+ | Prop | Type | Description | Default | Since | Platform |
1318
+ | ------------------ | ----------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------- | ----- | ------------ |
1319
+ | **`commit`** | <code>boolean</code> | Whether to save the deletion to the event store immediately. Pass `false` to batch multiple changes and commit them together using `CapacitorCalendar.commit()`, which is more efficient than committing each save individually. | <code>true</code> | 8.3.0 | iOS |
1320
+ | **`id`** | <code>string</code> | The ID of the event to delete. | | 7.1.0 | Android, iOS |
1321
+ | **`instanceDate`** | <code>number</code> | The start time of the occurrence to delete, in milliseconds since the epoch. Use `startDate` from `listEventsInRange`. On Android, required for `THIS_EVENT` on recurring events. If omitted with `THIS_AND_FUTURE_EVENTS`, the whole series is deleted. On iOS, optional since 8.11.0. If omitted, the first occurrence of the series is the target. | | 8.3.0 | Android, iOS |
1322
+ | **`span`** | <code><a href="#eventspan">EventSpan</a></code> | How much of a recurring series to delete. | <code>EventSpan.THIS_EVENT</code> | 7.1.0 | Android, iOS |
1296
1323
 
1297
1324
  #### DeleteEventWithPromptOptions
1298
1325
 
1299
- | Prop | Type | Description | Default | Since | Platform |
1300
- | ----------------------- | ----------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------- | ----- | ------------ |
1301
- | **`cancelButtonText`** | <code>string</code> | Text to show on the cancel button. | <code>'Cancel'</code> | 7.1.0 | Android, iOS |
1302
- | **`commit`** | <code>boolean</code> | Whether to save the deletion to the event store immediately. Pass `false` to batch multiple changes and commit them together using `CapacitorCalendar.commit()`, which is more efficient than committing each save individually. | <code>true</code> | 8.3.0 | iOS |
1303
- | **`confirmButtonText`** | <code>string</code> | Text to show on the confirm button. | <code>'Delete'</code> | 7.1.0 | Android, iOS |
1304
- | **`id`** | <code>string</code> | The ID of the event to delete. | | 7.1.0 | Android, iOS |
1305
- | **`instanceDate`** | <code>number</code> | The start time of the occurrence to delete, in milliseconds since the epoch. Use `startDate` from `listEventsInRange`. On Android, required for `THIS_EVENT` on recurring events. If omitted with `THIS_AND_FUTURE_EVENTS`, the whole series is deleted. | | 8.3.0 | Android |
1306
- | **`message`** | <code>string</code> | Message of the dialog. | | 7.1.0 | Android, iOS |
1307
- | **`span`** | <code><a href="#eventspan">EventSpan</a></code> | How much of a recurring series to delete. | <code>EventSpan.THIS_EVENT</code> | 7.1.0 | Android, iOS |
1308
- | **`title`** | <code>string</code> | Title of the dialog. | | 7.1.0 | Android, iOS |
1326
+ | Prop | Type | Description | Default | Since | Platform |
1327
+ | ----------------------- | ----------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------- | ----- | ------------ |
1328
+ | **`cancelButtonText`** | <code>string</code> | Text to show on the cancel button. | <code>'Cancel'</code> | 7.1.0 | Android, iOS |
1329
+ | **`commit`** | <code>boolean</code> | Whether to save the deletion to the event store immediately. Pass `false` to batch multiple changes and commit them together using `CapacitorCalendar.commit()`, which is more efficient than committing each save individually. | <code>true</code> | 8.3.0 | iOS |
1330
+ | **`confirmButtonText`** | <code>string</code> | Text to show on the confirm button. | <code>'Delete'</code> | 7.1.0 | Android, iOS |
1331
+ | **`id`** | <code>string</code> | The ID of the event to delete. | | 7.1.0 | Android, iOS |
1332
+ | **`instanceDate`** | <code>number</code> | The start time of the occurrence to delete, in milliseconds since the epoch. Use `startDate` from `listEventsInRange`. On Android, required for `THIS_EVENT` on recurring events. If omitted with `THIS_AND_FUTURE_EVENTS`, the whole series is deleted. On iOS, optional since 8.11.0. If omitted, the first occurrence of the series is the target. | | 8.3.0 | Android, iOS |
1333
+ | **`message`** | <code>string</code> | Message of the dialog. | | 7.1.0 | Android, iOS |
1334
+ | **`span`** | <code><a href="#eventspan">EventSpan</a></code> | How much of a recurring series to delete. | <code>EventSpan.THIS_EVENT</code> | 7.1.0 | Android, iOS |
1335
+ | **`title`** | <code>string</code> | Title of the dialog. | | 7.1.0 | Android, iOS |
1309
1336
 
1310
1337
  #### ListEventsInRangeResult
1311
1338
 
@@ -1345,10 +1372,23 @@ Options for {@link CalendarAccess#requestPermission}.
1345
1372
 
1346
1373
  #### ListEventsInRangeOptions
1347
1374
 
1348
- | Prop | Type | Description | Since |
1349
- | ---------- | ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
1350
- | **`from`** | <code>number</code> | The start of the range, in milliseconds since the epoch. Events still in progress at this time are included. | 7.1.0 |
1351
- | **`to`** | <code>number</code> | The end of the range, in milliseconds since the epoch. Events that begin at or after this time are typically excluded; prefer the next day's start when querying a single calendar day. | 7.1.0 |
1375
+ | Prop | Type | Description | Since |
1376
+ | ----------------- | --------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ |
1377
+ | **`from`** | <code>number</code> | The start of the range, in milliseconds since the epoch. Events still in progress at this time are included. | 7.1.0 |
1378
+ | **`to`** | <code>number</code> | The end of the range, in milliseconds since the epoch. Events that begin at or after this time are typically excluded; prefer the next day's start when querying a single calendar day. | 7.1.0 |
1379
+ | **`calendarIds`** | <code>string[]</code> | Ids of the calendars to search. When omitted or empty, all calendars are searched. Rejects if an id does not match a calendar. | 8.11.0 |
1380
+
1381
+ #### GetEventByIdResult
1382
+
1383
+ | Prop | Type | Description | Since | Platform |
1384
+ | ----------- | --------------------------------------------------------------- | ------------------------------------------------------- | ------ | ------------ |
1385
+ | **`event`** | <code><a href="#calendarevent">CalendarEvent</a> \| null</code> | The event for the given id, or `null` when none exists. | 8.11.0 | Android, iOS |
1386
+
1387
+ #### GetEventByIdOptions
1388
+
1389
+ | Prop | Type | Description | Since |
1390
+ | -------- | ------------------- | ------------- | ------ |
1391
+ | **`id`** | <code>string</code> | The event id. | 8.11.0 |
1352
1392
 
1353
1393
  #### SelectCalendarsWithPromptResult
1354
1394
 
@@ -20,6 +20,7 @@ import dev.barooni.capacitor.calendar.models.inputs.DeleteEventInput
20
20
  import dev.barooni.capacitor.calendar.models.inputs.DeleteEventWithPromptInput
21
21
  import dev.barooni.capacitor.calendar.models.inputs.DeleteEventsByIdInput
22
22
  import dev.barooni.capacitor.calendar.models.inputs.GetDefaultCalendarInput
23
+ import dev.barooni.capacitor.calendar.models.inputs.GetEventByIdInput
23
24
  import dev.barooni.capacitor.calendar.models.inputs.ListEventsInRangeInput
24
25
  import dev.barooni.capacitor.calendar.models.inputs.ModifyCalendarInput
25
26
  import dev.barooni.capacitor.calendar.models.inputs.ModifyEvent
@@ -491,6 +492,23 @@ class CapacitorCalendarPlugin : Plugin() {
491
492
  }
492
493
  }
493
494
 
495
+ @PluginMethod(returnType = PluginMethod.RETURN_PROMISE)
496
+ fun getEventById(call: PluginCall) {
497
+ try {
498
+ declarationCheck.ensureManifestPermissions(Manifest.permission.READ_CALENDAR)
499
+ val input = GetEventByIdInput(call)
500
+ implementation.getEventById(input) { result, error ->
501
+ if (error != null) {
502
+ rejectCall(call, error)
503
+ return@getEventById
504
+ }
505
+ resolveCall(call, result)
506
+ }
507
+ } catch (error: Exception) {
508
+ rejectCall(call, error)
509
+ }
510
+ }
511
+
494
512
  @PluginMethod
495
513
  fun modifyCalendar(call: PluginCall) {
496
514
  try {
@@ -45,6 +45,8 @@ sealed class PluginError(
45
45
 
46
46
  data object InvalidEventId : PluginError("Invalid event ID.", "EB-CLDR-0001")
47
47
 
48
+ data object InvalidFrequency : PluginError("Invalid frequency.", "EB-CLDR-0001")
49
+
48
50
  data object InvalidInvitees : PluginError("Invalid invitees. Array must contain only strings.", "EB-CLDR-0001")
49
51
 
50
52
  data object InvalidScope : PluginError("Invalid scope.", "EB-CLDR-0001")
@@ -58,6 +60,8 @@ sealed class PluginError(
58
60
  "EB-CLDR-0100",
59
61
  )
60
62
 
63
+ data object MissingFrequency : PluginError("Frequency must be provided.", "EB-CLDR-0001")
64
+
61
65
  data object MissingId : PluginError("Event ID must be provided.", "EB-CLDR-0001")
62
66
 
63
67
  data object MissingScope : PluginError("Scope must be provided.", "EB-CLDR-0001")
@@ -21,6 +21,7 @@ import dev.barooni.capacitor.calendar.models.inputs.DeleteEventInput
21
21
  import dev.barooni.capacitor.calendar.models.inputs.DeleteEventWithPromptInput
22
22
  import dev.barooni.capacitor.calendar.models.inputs.DeleteEventsByIdInput
23
23
  import dev.barooni.capacitor.calendar.models.inputs.GetDefaultCalendarInput
24
+ import dev.barooni.capacitor.calendar.models.inputs.GetEventByIdInput
24
25
  import dev.barooni.capacitor.calendar.models.inputs.ListEventsInRangeInput
25
26
  import dev.barooni.capacitor.calendar.models.inputs.ModifyCalendarInput
26
27
  import dev.barooni.capacitor.calendar.models.inputs.ModifyEvent
@@ -35,6 +36,7 @@ import dev.barooni.capacitor.calendar.models.results.CreateEventResult
35
36
  import dev.barooni.capacitor.calendar.models.results.DeleteEventWithPromptResult
36
37
  import dev.barooni.capacitor.calendar.models.results.DeleteEventsByIdResult
37
38
  import dev.barooni.capacitor.calendar.models.results.GetDefaultCalendarResult
39
+ import dev.barooni.capacitor.calendar.models.results.GetEventByIdResult
38
40
  import dev.barooni.capacitor.calendar.models.results.ListCalendarsResult
39
41
  import dev.barooni.capacitor.calendar.models.results.ListEventsInRangeResult
40
42
  import dev.barooni.capacitor.calendar.models.templates.PluginCompletion
@@ -121,6 +123,7 @@ class CapacitorCalendar(
121
123
 
122
124
  fun modifyEvent(input: ModifyEvent) {
123
125
  val cr = plugin.context.contentResolver
126
+ ImplementationHelper.ensureEventExists(cr, input.id)
124
127
  val updatingDates = input.startDate != null || input.endDate != null
125
128
  val settingAllDay = input.isAllDay == 1
126
129
  // Normalize when setting all-day, or when editing dates on an existing all-day event
@@ -413,10 +416,31 @@ class CapacitorCalendar(
413
416
  CalendarContract.Instances.DTSTART,
414
417
  )
415
418
 
419
+ val calendarIds = input.calendarIds
420
+ calendarIds?.forEach { calendarId ->
421
+ val exists =
422
+ cr
423
+ .query(
424
+ ContentUris.withAppendedId(CalendarContract.Calendars.CONTENT_URI, calendarId),
425
+ arrayOf(CalendarContract.Calendars._ID),
426
+ null,
427
+ null,
428
+ null,
429
+ )?.use { it.moveToFirst() } ?: false
430
+ if (!exists) {
431
+ throw PluginError.CalendarNotFound
432
+ }
433
+ }
434
+ val calendarFilter =
435
+ calendarIds
436
+ ?.let { " AND (${CalendarContract.Instances.CALENDAR_ID} IN (${it.joinToString(",") { "?" }}))" }
437
+ ?: ""
416
438
  val selection =
417
439
  "(${CalendarContract.Instances.BEGIN} < ?) AND " +
418
- "(${CalendarContract.Instances.END} > ?)"
419
- val selectionArgs = arrayOf(input.to.toString(), input.from.toString())
440
+ "(${CalendarContract.Instances.END} > ?)" + calendarFilter
441
+ val selectionArgs =
442
+ arrayOf(input.to.toString(), input.from.toString()) +
443
+ (calendarIds?.map { it.toString() } ?: emptyList())
420
444
 
421
445
  val sortOrder = "${CalendarContract.Instances.BEGIN} ASC"
422
446
 
@@ -571,6 +595,108 @@ class CapacitorCalendar(
571
595
  return ListEventsInRangeResult(events)
572
596
  }
573
597
 
598
+ fun getEventById(
599
+ input: GetEventByIdInput,
600
+ completion: PluginCompletion<GetEventByIdResult>,
601
+ ) {
602
+ try {
603
+ completion(getEventByIdResult(input), null)
604
+ } catch (error: Exception) {
605
+ completion(null, error)
606
+ }
607
+ }
608
+
609
+ private fun getEventByIdResult(input: GetEventByIdInput): GetEventByIdResult {
610
+ val cr = plugin.context.contentResolver
611
+ val eventUri = ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, input.id)
612
+ val projection =
613
+ arrayOf(
614
+ CalendarContract.Events.TITLE,
615
+ CalendarContract.Events.CALENDAR_ID,
616
+ CalendarContract.Events.EVENT_LOCATION,
617
+ CalendarContract.Events.DTSTART,
618
+ CalendarContract.Events.DTEND,
619
+ CalendarContract.Events.ALL_DAY,
620
+ CalendarContract.Events.DESCRIPTION,
621
+ CalendarContract.Events.AVAILABILITY,
622
+ CalendarContract.Events.ORGANIZER,
623
+ CalendarContract.Events.EVENT_COLOR,
624
+ CalendarContract.Events.EVENT_TIMEZONE,
625
+ CalendarContract.Events.STATUS,
626
+ CalendarContract.Events.DURATION,
627
+ CalendarContract.Events.RRULE,
628
+ CalendarContract.Events.ORIGINAL_ID,
629
+ CalendarContract.Events.DELETED,
630
+ )
631
+
632
+ val event =
633
+ cr.query(eventUri, projection, null, null, null)?.use { cursor ->
634
+ if (!cursor.moveToFirst()) {
635
+ return@use null
636
+ }
637
+
638
+ fun column(name: String): Int? = cursor.getColumnIndex(name).takeIf { it != -1 && !cursor.isNull(it) }
639
+
640
+ if (column(CalendarContract.Events.DELETED)?.let { cursor.getInt(it) == 1 } == true) {
641
+ return@use null
642
+ }
643
+
644
+ val startDate = column(CalendarContract.Events.DTSTART)?.let { cursor.getLong(it) } ?: 0L
645
+ val isAllDay = column(CalendarContract.Events.ALL_DAY)?.let { cursor.getInt(it) == 1 } ?: false
646
+ val rrule = column(CalendarContract.Events.RRULE)?.let { cursor.getString(it) }
647
+ val originalId = column(CalendarContract.Events.ORIGINAL_ID)?.let { cursor.getLong(it) }?.takeIf { it != 0L }
648
+ val storedDuration = column(CalendarContract.Events.DURATION)?.let { cursor.getString(it) }
649
+ // Recurring masters have DURATION and no DTEND.
650
+ val endDate =
651
+ column(CalendarContract.Events.DTEND)?.let { cursor.getLong(it) }
652
+ ?: (startDate + (storedDuration?.let { ImplementationHelper.durationToMillis(it) } ?: 0L))
653
+ val duration = storedDuration ?: ImplementationHelper.buildDurationFromBeginEnd(startDate, endDate, isAllDay)
654
+ val isPartOfSeries = !rrule.isNullOrEmpty() || originalId != null
655
+ val seriesStartDate =
656
+ originalId?.let { masterId ->
657
+ cr
658
+ .query(
659
+ ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, masterId),
660
+ arrayOf(CalendarContract.Events.DTSTART),
661
+ null,
662
+ null,
663
+ null,
664
+ )?.use { masterCursor ->
665
+ if (masterCursor.moveToFirst() && !masterCursor.isNull(0)) masterCursor.getLong(0) else null
666
+ }
667
+ } ?: startDate
668
+
669
+ CalendarEvent(
670
+ input.id.toString(),
671
+ (originalId ?: input.id).toString(),
672
+ column(CalendarContract.Events.TITLE)?.let { cursor.getString(it) } ?: "",
673
+ column(CalendarContract.Events.CALENDAR_ID)?.let { cursor.getLong(it).toString() },
674
+ null,
675
+ column(CalendarContract.Events.EVENT_LOCATION)?.let { cursor.getString(it) },
676
+ startDate,
677
+ seriesStartDate,
678
+ endDate,
679
+ isAllDay,
680
+ ImplementationHelper.getEventAlerts(cr, input.id),
681
+ null,
682
+ column(CalendarContract.Events.DESCRIPTION)?.let { cursor.getString(it) },
683
+ column(CalendarContract.Events.AVAILABILITY)?.let { cursor.getInt(it) },
684
+ column(CalendarContract.Events.ORGANIZER)?.let { cursor.getString(it) },
685
+ column(CalendarContract.Events.EVENT_COLOR)?.let { ImplementationHelper.intToHexColor(cursor.getInt(it)) },
686
+ duration,
687
+ null,
688
+ isPartOfSeries,
689
+ null,
690
+ column(CalendarContract.Events.STATUS)?.let { ImplementationHelper.mapEventStatus(cursor.getInt(it)) },
691
+ null,
692
+ null,
693
+ ImplementationHelper.getEventAttendees(cr, input.id),
694
+ column(CalendarContract.Events.EVENT_TIMEZONE)?.let { cursor.getString(it) },
695
+ )
696
+ }
697
+ return GetEventByIdResult(event)
698
+ }
699
+
574
700
  fun modifyCalendar(input: ModifyCalendarInput) {
575
701
  val cr = plugin.context.contentResolver
576
702
  val values =
@@ -1,6 +1,7 @@
1
1
  package dev.barooni.capacitor.calendar.models.data
2
2
 
3
3
  import com.getcapacitor.JSObject
4
+ import dev.barooni.capacitor.calendar.PluginError
4
5
  import org.json.JSONArray
5
6
  import org.json.JSONException
6
7
  import java.util.Calendar
@@ -45,8 +46,8 @@ data class EventRecurrenceRule(
45
46
  }
46
47
 
47
48
  companion object {
48
- fun parseRecurrence(obj: JSObject): EventRecurrenceRule? {
49
- val frequencyString = obj.getString("frequency") ?: return null
49
+ fun parseRecurrence(obj: JSObject): EventRecurrenceRule {
50
+ val frequencyString = obj.getString("frequency") ?: throw PluginError.MissingFrequency
50
51
  val frequency =
51
52
  try {
52
53
  Frequency.valueOf(
@@ -55,7 +56,7 @@ data class EventRecurrenceRule(
55
56
  .replaceFirstChar { it.uppercase() },
56
57
  )
57
58
  } catch (_: IllegalArgumentException) {
58
- return null
59
+ throw PluginError.InvalidFrequency
59
60
  }
60
61
 
61
62
  val interval = (obj.getInteger("interval") ?: 1).coerceAtLeast(1)
@@ -0,0 +1,13 @@
1
+ package dev.barooni.capacitor.calendar.models.inputs
2
+
3
+ import com.getcapacitor.PluginCall
4
+ import dev.barooni.capacitor.calendar.PluginError
5
+
6
+ data class GetEventByIdInput(
7
+ private val call: PluginCall,
8
+ ) {
9
+ val id: Long =
10
+ call.getString("id")?.let { idString ->
11
+ idString.toLongOrNull() ?: throw PluginError.InvalidEventId
12
+ } ?: throw PluginError.MissingId
13
+ }
@@ -11,4 +11,9 @@ data class ListEventsInRangeInput(
11
11
  call.getLong("from")?.let { ImplementationHelper.getCalendarFromTimestamp(it).timeInMillis } ?: throw PluginError.FromDateMissing
12
12
  val to: Long =
13
13
  call.getLong("to")?.let { ImplementationHelper.getCalendarFromTimestamp(it).timeInMillis } ?: throw PluginError.ToDateMissing
14
+ val calendarIds: List<Long>? =
15
+ call
16
+ .getArray("calendarIds")
17
+ ?.let { ImplementationHelper.jsArrayToLongArray(it, PluginError.InvalidCalendarId) }
18
+ ?.takeIf { it.isNotEmpty() }
14
19
  }
@@ -0,0 +1,15 @@
1
+ package dev.barooni.capacitor.calendar.models.results
2
+
3
+ import com.getcapacitor.JSObject
4
+ import dev.barooni.capacitor.calendar.models.data.CalendarEvent
5
+ import dev.barooni.capacitor.calendar.models.templates.JSResult
6
+
7
+ data class GetEventByIdResult(
8
+ private val event: CalendarEvent?,
9
+ ) : JSResult {
10
+ override fun toJSON(): JSObject {
11
+ val result = JSObject()
12
+ result.put("event", event?.toJSObject() ?: JSObject.NULL)
13
+ return result
14
+ }
15
+ }