Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'skashin/meeting_cancellation' into 'master'
[nemo-qml-plugin-calendar] Call sendUpdate in invitation plugin if event with attendees was deleted. Fixes JB#43462

See merge request mer-core/nemo-qml-plugin-calendar!33
  • Loading branch information
pvuorela committed Dec 19, 2018
2 parents 975e582 + 8d2dd56 commit 34f9d2f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/calendarworker.cpp
Expand Up @@ -112,6 +112,7 @@ void NemoCalendarWorker::deleteEvent(const QString &uid, const KDateTime &recurr
} else {
mCalendar->deleteEvent(event);
}
mExceptionEvents.append(QPair<QString, QDateTime>(uid, dateTime));
}

void NemoCalendarWorker::deleteAll(const QString &uid)
Expand All @@ -124,6 +125,7 @@ void NemoCalendarWorker::deleteAll(const QString &uid)

mCalendar->deleteEventInstances(event);
mCalendar->deleteEvent(event);
mDeletedEvents.append(uid);
}

bool NemoCalendarWorker::sendResponse(const NemoCalendarData::Event &eventData, const NemoCalendarEvent::Response response)
Expand Down Expand Up @@ -183,6 +185,29 @@ QString NemoCalendarWorker::convertEventToVCalendar(const QString &uid, const QS
void NemoCalendarWorker::save()
{
mStorage->save();
if (!mDeletedEvents.isEmpty()) {
for (const QString &uid: mDeletedEvents) {
KCalCore::Event::Ptr event = mCalendar->deletedEvent(uid);
if (!needSendCancellation(event)) {
continue;
}
event->setStatus(KCalCore::Incidence::StatusCanceled);
mKCal::ServiceHandler::instance().sendUpdate(event, QString(), mCalendar, mStorage);
}
mDeletedEvents.clear();
}
if (!mExceptionEvents.isEmpty()) {
for (const QPair<QString, QDateTime> &exceptionEvent: mExceptionEvents) {
KCalCore::Event::Ptr event = mCalendar->deletedEvent(exceptionEvent.first,
KDateTime(exceptionEvent.second, KDateTime::Spec(KDateTime::LocalZone)));
if (!needSendCancellation(event)) {
continue;
}
event->setStatus(KCalCore::Incidence::StatusCanceled);
mKCal::ServiceHandler::instance().sendUpdate(event, QString(), mCalendar, mStorage);
}
mExceptionEvents.clear();
}
}

void NemoCalendarWorker::saveEvent(const NemoCalendarData::Event &eventData)
Expand Down Expand Up @@ -411,6 +436,27 @@ bool NemoCalendarWorker::setReminder(KCalCore::Event::Ptr &event, NemoCalendarEv
return true;
}

bool NemoCalendarWorker::needSendCancellation(KCalCore::Event::Ptr &event) const
{
if (!event) {
qWarning() << Q_FUNC_INFO << "event is NULL";
return false;
}
KCalCore::Attendee::List attendees = event->attendees();
if (attendees.size() == 0) {
return false;
}
KCalCore::Person::Ptr calOrganizer = event->organizer();
if (calOrganizer.isNull() || calOrganizer->isEmpty()) {
return false;
}
// we shouldn't send a response if we are not an organizer
if (calOrganizer->email() != mKCal::ServiceHandler::instance().emailAddress(mStorage->notebook(mCalendar->notebook(event)), mStorage)) {
return false;
}
return true;
}

QList<NemoCalendarData::Notebook> NemoCalendarWorker::notebooks() const
{
return mNotebooks.values();
Expand Down
7 changes: 7 additions & 0 deletions src/calendarworker.h
Expand Up @@ -115,6 +115,7 @@ public slots:

bool setRecurrence(KCalCore::Event::Ptr &event, NemoCalendarEvent::Recur recur);
bool setReminder(KCalCore::Event::Ptr &event, NemoCalendarEvent::Reminder reminder);
bool needSendCancellation(KCalCore::Event::Ptr &event) const;

KCalCore::Duration reminderToDuration(NemoCalendarEvent::Reminder reminder) const;
NemoCalendarData::Event createEventStruct(const KCalCore::Event::Ptr &event) const;
Expand All @@ -128,6 +129,12 @@ public slots:
mKCal::ExtendedCalendar::Ptr mCalendar;
mKCal::ExtendedStorage::Ptr mStorage;

// mDeletedEvents and mExceptionEvents are used to make sure
// that we are sending a cancellation email for events only
// when user actually saved (so truly deleted) changes by calling of save()
QStringList mDeletedEvents;
QList<QPair<QString, QDateTime>> mExceptionEvents;

QHash<QString, NemoCalendarData::Notebook> mNotebooks;

// Tracks which events have been already passed to manager. Maps Uid -> RecurrenceId
Expand Down

0 comments on commit 34f9d2f

Please sign in to comment.