Browse Source

Update CalendarHandler.swift

pull/101/head
Abhishek 3 years ago
parent
commit
8a3e7ed92f
  1. 52
      Clocker/Events and Reminders/CalendarHandler.swift

52
Clocker/Events and Reminders/CalendarHandler.swift

@ -157,12 +157,32 @@ extension EventCenter {
let relevantEvents = filteredEvents[autoupdatingCalendar.startOfDay(for: Date())] ?? []
let filteredEvent = relevantEvents.filter {
let filteredEvents = relevantEvents.filter {
$0.event.isAllDay == false && $0.event.startDate.timeIntervalSinceNow > -300
}.first
if let firstEvent = filteredEvent {
return firstEvent
}
if filteredEvents.count == 1 { return filteredEvents.first }
// If there are multipl events coming up, prefer the ones the currentUser has accepted
let acceptedEvents = filteredEvents.filter {
$0.attendeStatus == .accepted
}
let optionalEvents = filteredEvents.filter {
$0.attendeStatus == .tentative
}
if let firstAcceptedEvent = acceptedEvents.first {
return firstAcceptedEvent
}
// If there are no accepted events, prefer the first optional event
if acceptedEvents.isEmpty && !optionalEvents.isEmpty {
return optionalEvents.first
}
// Otherwise check if there's a filtered event at all and return it
if let first = filteredEvents.first {
return first
}
let filteredAllDayEvent = relevantEvents.filter {
@ -333,13 +353,15 @@ extension EventCenter {
let isEndDate = autoupdatingCalendar.isDate(date, inSameDayAs: event.endDate) && (event.startDate.compare(date) == .orderedAscending)
let isAllDay = event.isAllDay || (event.startDate.compare(date) == .orderedAscending && event.endDate.compare(nextDate) == .orderedSame)
let isSingleDay = event.isAllDay && (event.startDate.compare(date) == .orderedSame && event.endDate.compare(nextDate) == .orderedSame)
let eventParticipationStatus = attendingStatusForUser(event)
let meetingURL = retrieveMeetingURL(event)
let eventInfo = EventInfo(event: event,
isStartDate: isStartDate,
isEndDate: isEndDate,
isAllDay: isAllDay,
isSingleDay: isSingleDay,
meetingURL: meetingURL)
meetingURL: meetingURL,
attendeStatus: eventParticipationStatus)
return eventInfo
}
@ -416,6 +438,23 @@ extension EventCenter {
return nil
}
private func attendingStatusForUser(_ event: EKEvent) -> EKParticipantStatus {
// First check if the current user is the organizer
if event.organizer?.isCurrentUser == true {
return event.organizer?.participantStatus ?? .unknown
}
guard let attendes = event.attendees else {
return .unknown
}
for attende in attendes where attende.isCurrentUser {
return attende.participantStatus
}
return .unknown
}
}
struct CalendarInfo {
@ -430,6 +469,7 @@ struct EventInfo {
let isAllDay: Bool
let isSingleDay: Bool
let meetingURL: URL?
let attendeStatus: EKParticipantStatus
func metadataForMeeting() -> String {
let timeIntervalSinceNowForMeeting = event.startDate.timeIntervalSinceNow

Loading…
Cancel
Save