Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[nemo-qml-plugin-calendar] Use ResponseType if available to show cale…
…ndar attendance. Contributes to JB#46554

The ResponseType returned by an EAS server indicates how the user
responded to a event invitation request (Accepted, Declined, Tentative).
The ownerStatus is set to this value if available, which is used by the
UI to display the user's attendance status.

The previous behaviour used the list of invited users and attendance
status assigned to each to determine the user's response. The EAS server
won't always provide these values. Moreover, if the user has multiple
email addresses for an account the address used for the invitation may
not match the account username, preventing the value from being picked
up. In case the value is available and set, it's still used in
preference to the ResponseType.
  • Loading branch information
llewelld committed Jan 13, 2020
1 parent 69d36da commit d44e8e9
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
23 changes: 22 additions & 1 deletion src/calendarutils.cpp
@@ -1,5 +1,7 @@
/*
* Copyright (C) 2015 Jolla Ltd.
* Copyright (c) 2015-2019 Jolla Ltd.
* Copyright (c) 2019 Open Mobile Platform LLC.
*
* Contact: Petri M. Gerdt <petri.gerdt@jollamobile.com>
*
* You may use this file under the terms of the BSD license as follows:
Expand Down Expand Up @@ -301,3 +303,22 @@ KCalCore::Attendee::PartStat CalendarUtils::convertResponse(CalendarEvent::Respo
return KCalCore::Attendee::NeedsAction;
}
}

CalendarEvent::Response CalendarUtils::convertResponseType(const QString &responseType)
{
// QString::toInt() conversion defaults to 0 on failure
switch (responseType.toInt()) {
case 1: // OrganizerResponseType (Organizer's acceptance is implicit)
case 3: // AcceptedResponseType
return CalendarEvent::ResponseAccept;
case 2: // TentativeResponseType
return CalendarEvent::ResponseTentative;
case 4: // DeclinedResponseType
return CalendarEvent::ResponseDecline;
case -1: // ResponseTypeUnset
case 0: // NoneResponseType
case 5: // NotRespondedResponseType
default:
return CalendarEvent::ResponseUnspecified;
}
}
5 changes: 4 additions & 1 deletion src/calendarutils.h
@@ -1,5 +1,7 @@
/*
* Copyright (C) 2015 Jolla Ltd.
* Copyright (c) 2015-2019 Jolla Ltd.
* Copyright (c) 2019 Open Mobile Platform LLC.
*
* Contact: Petri M. Gerdt <petri.gerdt@jollamobile.com>
*
* You may use this file under the terms of the BSD license as follows:
Expand Down Expand Up @@ -53,6 +55,7 @@ bool importFromFile(const QString &fileName, KCalCore::Calendar::Ptr calendar);
bool importFromIcsRawData(const QByteArray &icsData, KCalCore::Calendar::Ptr calendar);
CalendarEvent::Response convertPartStat(KCalCore::Attendee::PartStat status);
KCalCore::Attendee::PartStat convertResponse(CalendarEvent::Response response);
CalendarEvent::Response convertResponseType(const QString &responseType);

} // namespace CalendarUtils

Expand Down
16 changes: 14 additions & 2 deletions src/calendarworker.cpp
@@ -1,5 +1,7 @@
/*
* Copyright (C) 2014 Jolla Ltd.
* Copyright (c) 2014-2019 Jolla Ltd.
* Copyright (c) 2019 Open Mobile Platform LLC.
*
* Contact: Petri M. Gerdt <petri.gerdt@jollamobile.com>
*
* You may use this file under the terms of the BSD license as follows:
Expand Down Expand Up @@ -806,11 +808,21 @@ CalendarData::Event CalendarWorker::createEventStruct(const KCalCore::Event::Ptr
}
event.externalInvitation = externalInvitation;

// It would be good to set the attendance status directly in the event within the plugin,
// however in some cases the account email and owner attendee email won't necessarily match
// (e.g. in the case where server-side aliases are defined but unknown to the plugin).
// So we handle this here to avoid "missing" some status changes due to owner email mismatch.
// This defaults to QString() -> ResponseUnspecified in case the property is undefined
event.ownerStatus = CalendarUtils::convertResponseType(e->nonKDECustomProperty("X-EAS-RESPONSE-TYPE"));

KCalCore::Attendee::List attendees = e->attendees();

foreach (KCalCore::Attendee::Ptr calAttendee, attendees) {
if (calAttendee->email() == calendarOwnerEmail) {
event.ownerStatus = CalendarUtils::convertPartStat(calAttendee->status());
if (CalendarUtils::convertPartStat(calAttendee->status()) != CalendarEvent::ResponseUnspecified) {
// Override the ResponseType
event.ownerStatus = CalendarUtils::convertPartStat(calAttendee->status());
}
//TODO: KCalCore::Attendee::RSVP() returns false even if response was requested for some accounts like Google.
// We can use attendee role until the problem is not fixed (probably in Google plugin).
// To be updated later when google account support for responses is added.
Expand Down
1 change: 1 addition & 0 deletions src/src.pro
Expand Up @@ -6,6 +6,7 @@ CONFIG += qt plugin hide_symbols

QT += qml concurrent
QT -= gui
QMAKE_CXXFLAGS += -Werror

target.path = $$[QT_INSTALL_QML]/$$PLUGIN_IMPORT_PATH
PKGCONFIG += libkcalcoren-qt5 libmkcal-qt5 libical accounts-qt5
Expand Down

0 comments on commit d44e8e9

Please sign in to comment.