Skip to content

Commit 7ae68db

Browse files
fix: sync the correct timestamp in repeating event exceptions (#766)
* Fix: move only the selected occurrence of a repeating event * docs: update changelog entries * Fix: sync the correct timestamp in repeating event exceptions * Fix: fix detekt issues in EventsHelper.kt * docs: update changelog * Fix: sync the correct timestamp in repeating event exceptions (rework) * Fix: EventsHelper, do not add wrong repetition exceptions, use proper repetition exception db update method * docs: fix changelog entry * docs: fix changelog * Fix: CalDAVHelper, sync correct original instance time * Fix: EventsHelper, schedule next event reminder after updating repetition exceptions * Fix: CalDAVHelper, do not sync original event exceptions if the event occurrence is not specified Refs: #641
1 parent 96e9634 commit 7ae68db

File tree

3 files changed

+18
-24
lines changed

3 files changed

+18
-24
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
- Fixed drag and drop copying events instead of moving them ([#706])
1515
- Fixed crash when editing events with attendees ([#34])
1616
- Fixed event edits being silently discarded on back press ([#49])
17+
- Fixed syncing exceptions to repeating events ([#641])
1718

1819
## [1.6.1] - 2025-09-01
1920
### Changed
@@ -144,6 +145,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
144145
[#603]: https://github.com/FossifyOrg/Calendar/issues/603
145146
[#613]: https://github.com/FossifyOrg/Calendar/issues/613
146147
[#682]: https://github.com/FossifyOrg/Calendar/issues/682
148+
[#641]: https://github.com/FossifyOrg/Calendar/issues/641
147149
[#706]: https://github.com/FossifyOrg/Calendar/issues/706
148150
[#729]: https://github.com/FossifyOrg/Calendar/issues/729
149151
[#732]: https://github.com/FossifyOrg/Calendar/issues/732

app/src/main/kotlin/org/fossify/calendar/helpers/CalDAVHelper.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -408,9 +408,9 @@ class CalDAVHelper(val context: Context) {
408408
}
409409

410410
@SuppressLint("MissingPermission")
411-
fun insertCalDAVEvent(event: Event) {
411+
fun insertCalDAVEvent(event: Event, originalInstanceTime: Long? = null) {
412412
val uri = Events.CONTENT_URI
413-
val values = fillEventContentValues(event)
413+
val values = fillEventContentValues(event, originalInstanceTime)
414414
val newUri = context.contentResolver.insert(uri, values)
415415

416416
val calendarId = event.getCalDAVCalendarId()
@@ -485,7 +485,7 @@ class CalDAVHelper(val context: Context) {
485485
)
486486
}
487487

488-
private fun fillEventContentValues(event: Event): ContentValues {
488+
private fun fillEventContentValues(event: Event, originalInstanceTime: Long? = null): ContentValues {
489489
val calendarId = event.getCalDAVCalendarId()
490490
return ContentValues().apply {
491491
put(Events.CALENDAR_ID, calendarId)
@@ -519,14 +519,14 @@ class CalDAVHelper(val context: Context) {
519519
}
520520

521521
val parentEventId = event.parentId
522-
if (parentEventId != 0L) {
522+
if (parentEventId != 0L && originalInstanceTime != null) {
523523
val parentEvent = context.eventsDB.getEventWithId(parentEventId) ?: return@apply
524524
val isParentAllDay = parentEvent.getIsAllDay()
525525
// original instance time must be in UTC when the parent is an all-day event
526-
val originalInstanceTS = if (isParentAllDay && !event.getIsAllDay()) {
527-
Formatter.getShiftedUtcTS(event.startTS)
526+
val originalInstanceTS = if (isParentAllDay) {
527+
Formatter.getShiftedUtcTS(originalInstanceTime)
528528
} else {
529-
event.startTS
529+
originalInstanceTime
530530
}
531531
put(Events.ORIGINAL_ID, parentEvent.getCalDAVEventId())
532532
put(Events.ORIGINAL_INSTANCE_TIME, originalInstanceTS * 1000L)

app/src/main/kotlin/org/fossify/calendar/helpers/EventsHelper.kt

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -111,45 +111,32 @@ class EventsHelper(val context: Context) {
111111
}
112112
}
113113

114-
fun insertEvent(event: Event, addToCalDAV: Boolean, showToasts: Boolean, enableEventType: Boolean = true, callback: ((id: Long) -> Unit)? = null) {
114+
fun insertEvent(event: Event, addToCalDAV: Boolean, showToasts: Boolean, enableEventType: Boolean = true, eventOccurrenceTS: Long? = null, callback: ((id: Long) -> Unit)? = null) {
115115
if (event.startTS > event.endTS) {
116116
callback?.invoke(0)
117117
return
118118
}
119119

120-
maybeUpdateParentExceptions(event)
121120
event.id = eventsDB.insertOrUpdate(event)
122121
ensureEventTypeVisibility(event, enableEventType)
123122
context.updateWidgets()
124123
context.scheduleNextEventReminder(event, showToasts)
125124

126125
if (addToCalDAV && config.caldavSync && event.source != SOURCE_SIMPLE_CALENDAR && event.source != SOURCE_IMPORTED_ICS) {
127-
context.calDAVHelper.insertCalDAVEvent(event)
126+
context.calDAVHelper.insertCalDAVEvent(event, eventOccurrenceTS)
128127
}
129128

130129
callback?.invoke(event.id!!)
131130
}
132131

133132
fun insertTask(task: Event, showToasts: Boolean, enableEventType: Boolean = true, callback: () -> Unit) {
134-
maybeUpdateParentExceptions(task)
135133
task.id = eventsDB.insertOrUpdate(task)
136134
ensureEventTypeVisibility(task, enableEventType)
137135
context.updateWidgets()
138136
context.scheduleNextEventReminder(task, showToasts)
139137
callback()
140138
}
141139

142-
private fun maybeUpdateParentExceptions(event: Event) {
143-
// if the event is an exception from another event, update the parent event's exceptions list
144-
val parentEventId = event.parentId
145-
if (parentEventId != 0L) {
146-
val parentEvent = eventsDB.getEventOrTaskWithId(parentEventId) ?: return
147-
val startDayCode = Formatter.getDayCodeFromTS(event.startTS)
148-
parentEvent.addRepetitionException(startDayCode)
149-
eventsDB.updateEventRepetitionExceptions(parentEvent.repetitionExceptions.toString(), parentEventId)
150-
}
151-
}
152-
153140
fun insertEvents(events: ArrayList<Event>, addToCalDAV: Boolean) {
154141
try {
155142
for (event in events) {
@@ -198,7 +185,8 @@ class EventsHelper(val context: Context) {
198185
ensureBackgroundThread {
199186
val originalEvent = eventsDB.getEventOrTaskWithId(event.id!!) ?: return@ensureBackgroundThread
200187
originalEvent.addRepetitionException(Formatter.getDayCodeFromTS(eventOccurrenceTS))
201-
updateEvent(originalEvent, updateAtCalDAV = !originalEvent.isTask(), showToasts = false)
188+
eventsDB.updateEventRepetitionExceptions(originalEvent.repetitionExceptions.toString(), originalEvent.id!!)
189+
context.scheduleNextEventReminder(originalEvent, false)
202190

203191
event.apply {
204192
parentId = id!!.toLong()
@@ -210,7 +198,11 @@ class EventsHelper(val context: Context) {
210198
if (event.isTask()) {
211199
insertTask(event, showToasts = showToasts, callback = callback)
212200
} else {
213-
insertEvent(event, addToCalDAV = true, showToasts = showToasts) {
201+
insertEvent(
202+
event, addToCalDAV = true,
203+
showToasts = showToasts,
204+
eventOccurrenceTS = eventOccurrenceTS
205+
) {
214206
callback()
215207
}
216208
}

0 commit comments

Comments
 (0)