summaryrefslogtreecommitdiffstats
path: root/examples/caldavresource/caldavresource.cpp
diff options
context:
space:
mode:
authorMinijackson <minijackson@riseup.net>2018-04-30 13:48:50 +0200
committerMinijackson <minijackson@riseup.net>2018-04-30 14:31:46 +0200
commitde9e304c724b5de421a231bcc449a6f3dd0eb48b (patch)
tree295843d23a8533aa99b1634b3a4c14b26a21f9b4 /examples/caldavresource/caldavresource.cpp
parent7a166895a54c4037749229b9ec9d0c90d60987b5 (diff)
downloadsink-de9e304c724b5de421a231bcc449a6f3dd0eb48b.tar.gz
sink-de9e304c724b5de421a231bcc449a6f3dd0eb48b.zip
Add replay of events
Diffstat (limited to 'examples/caldavresource/caldavresource.cpp')
-rw-r--r--examples/caldavresource/caldavresource.cpp71
1 files changed, 71 insertions, 0 deletions
diff --git a/examples/caldavresource/caldavresource.cpp b/examples/caldavresource/caldavresource.cpp
index 6bf1a27..3fbd624 100644
--- a/examples/caldavresource/caldavresource.cpp
+++ b/examples/caldavresource/caldavresource.cpp
@@ -107,6 +107,77 @@ protected:
107 { 107 {
108 return syncStore().resolveRemoteId(ENTITY_TYPE_CALENDAR, resourceID(calendar)); 108 return syncStore().resolveRemoteId(ENTITY_TYPE_CALENDAR, resourceID(calendar));
109 } 109 }
110
111 KAsync::Job<QByteArray> replay(const Event &event, Sink::Operation operation,
112 const QByteArray &oldRemoteId, const QList<QByteArray> &changedProperties) Q_DECL_OVERRIDE
113 {
114 SinkLog() << "Replaying event";
115
116 //auto incidence = KCalCore::ICalFormat().readIncidence(rawIcal);
117
118 KDAV2::DavItem item;
119
120 switch (operation) {
121 case Sink::Operation_Creation: {
122 SinkLog() << "Replaying creation";
123
124 auto rawIcal = event.getIcal();
125 if(rawIcal == "") {
126 return KAsync::error<QByteArray>("No ICal in event for creation replay");
127 }
128
129 auto collectionId = syncStore().resolveLocalId(ENTITY_TYPE_CALENDAR, event.getCalendar());
130
131 item.setData(rawIcal);
132 item.setContentType("text/calendar");
133 item.setUrl(urlOf(collectionId, event.getUid()));
134
135 return createItem(item).then([item] { return resourceID(item); });
136 }
137 case Sink::Operation_Removal: {
138 // We only need the URL in the DAV item for removal
139 item.setUrl(urlOf(oldRemoteId));
140
141 return removeItem(item).then([oldRemoteId] { return oldRemoteId; });
142 }
143 case Sink::Operation_Modification:
144 SinkLog() << "Replaying modification";
145
146 auto rawIcal = event.getIcal();
147 if(rawIcal == "") {
148 return KAsync::error<QByteArray>("No ICal in event for modification replay");
149 }
150
151 item.setData(rawIcal);
152 item.setContentType("text/calendar");
153 item.setUrl(urlOf(oldRemoteId));
154
155 // It would be nice to check that the URL of the item hasn't
156 // changed and move he item if it did, but since the URL is
157 // pretty much arbitrary, whoe does that anyway?
158 return modifyItem(item).then([oldRemoteId] { return oldRemoteId; });
159 }
160 }
161
162 KAsync::Job<QByteArray> replay(const Calendar &calendar, Sink::Operation operation,
163 const QByteArray &oldRemoteId, const QList<QByteArray> &changedProperties) Q_DECL_OVERRIDE
164 {
165
166 // TODO: add the URL to list of attributes, can't do nothing otherwise
167 switch (operation) {
168 case Sink::Operation_Creation:
169 SinkLog() << "Replaying calendar creation";
170 break;
171 case Sink::Operation_Removal:
172 SinkLog() << "Replaying calendar removal";
173 break;
174 case Sink::Operation_Modification:
175 SinkLog() << "Replaying calendar modification";
176 break;
177 }
178
179 return KAsync::null<QByteArray>();
180 }
110}; 181};
111 182
112CalDavResource::CalDavResource(const Sink::ResourceContext &context) 183CalDavResource::CalDavResource(const Sink::ResourceContext &context)