feat: Also show invited events

This commit is contained in:
Peter Vacho 2024-12-30 02:40:29 +01:00
parent b3c386a9dc
commit 0b6546c269
Signed by: school
GPG key ID: 8CFC3837052871B4

View file

@ -67,6 +67,8 @@ class CalendarActivity : AppCompatActivity() {
*
* The returned structure is a hashmap with int keys, being the day numbers in the month.
* If an event spans multiple days, it will be added for each of those days.
*
* Note that this also includes the events this user was invited into.
*/
private suspend fun fetchEventsForMonth(yearMonth: YearMonth): Map<Int, List<EventResponse>> {
val startFrom = yearMonth.atDay(1).atStartOfDay().atOffset(ZoneOffset.UTC)
@ -79,16 +81,23 @@ class CalendarActivity : AppCompatActivity() {
return emptyMap()
}
val events = RetrofitClient.eventsService.userEvents(
val userEvents = RetrofitClient.eventsService.userEvents(
userId = userId,
startFrom = startFrom,
endTo = endTo
)
val invitedEvents = RetrofitClient.eventsService.userEventsInvited(
userId = userId,
startFrom = startFrom,
endTo = endTo
)
val allEvents = userEvents + invitedEvents
// Create a mapping of days to events
val eventsByDay = mutableMapOf<Int, MutableList<EventResponse>>()
for (event in events) {
for (event in allEvents) {
val startDay = maxOf(event.start_time.dayOfMonth, 1)
val endDay = minOf(event.end_time.dayOfMonth, yearMonth.lengthOfMonth())