1.1 --- a/imiptools/handlers/common.py Tue May 19 23:40:57 2015 +0200
1.2 +++ b/imiptools/handlers/common.py Wed May 20 13:41:23 2015 +0200
1.3 @@ -19,7 +19,8 @@
1.4 this program. If not, see <http://www.gnu.org/licenses/>.
1.5 """
1.6
1.7 -from imiptools.data import get_address, get_uri, make_freebusy, to_part
1.8 +from imiptools.data import get_address, get_uri, make_freebusy, to_part, \
1.9 + uri_dict
1.10 from imiptools.dates import format_datetime
1.11 from imiptools.period import Period
1.12
1.13 @@ -66,4 +67,57 @@
1.14
1.15 self.add_result("REPLY", [get_address(organiser)], to_part("REPLY", responses))
1.16
1.17 +class Outgoing:
1.18 +
1.19 + "Common outgoing message handling functionality."
1.20 +
1.21 + def update_event_in_freebusy(self, from_organiser=True):
1.22 +
1.23 + "Update free/busy information when handling an object."
1.24 +
1.25 + freebusy = self.store.get_freebusy(self.user)
1.26 +
1.27 + # Use the stored event in case the reply is incomplete, as is seen
1.28 + # when Claws sends a REPLY for an object originally employing
1.29 + # recurrence information.
1.30 +
1.31 + obj = self.get_definitive_object(from_organiser)
1.32 + if not obj:
1.33 + return False # although this should not happen
1.34 +
1.35 + # If newer than any old version, discard old details from the
1.36 + # free/busy record and check for suitability.
1.37 +
1.38 + # Interpretation of periods can depend on the time zone.
1.39 +
1.40 + periods = obj.get_periods(self.get_tzid(), self.get_window_end())
1.41 +
1.42 + # Obtain the attendance attributes for this user, if available.
1.43 +
1.44 + attendees = uri_dict(self.obj.get_value_map("ATTENDEE"))
1.45 + self.update_freebusy_for_participant(freebusy, periods, attendees.get(self.user), from_organiser)
1.46 +
1.47 + # Remove original recurrence details replaced by additional
1.48 + # recurrences, as well as obsolete additional recurrences.
1.49 +
1.50 + self.remove_freebusy_for_recurrences(freebusy, self.store.get_recurrences(self.user, self.uid))
1.51 + self.store.set_freebusy(self.user, freebusy)
1.52 +
1.53 + if self.publisher and self.is_sharing():
1.54 + self.publisher.set_freebusy(self.user, freebusy)
1.55 +
1.56 + return True
1.57 +
1.58 + def remove_event_from_freebusy(self):
1.59 +
1.60 + "Remove free/busy information when handling an object."
1.61 +
1.62 + freebusy = self.store.get_freebusy(self.user)
1.63 + self.remove_from_freebusy(freebusy)
1.64 + self.remove_freebusy_for_recurrences(freebusy)
1.65 + self.store.set_freebusy(self.user, freebusy)
1.66 +
1.67 + if self.publisher and self.is_sharing():
1.68 + self.publisher.set_freebusy(self.user, freebusy)
1.69 +
1.70 # vim: tabstop=4 expandtab shiftwidth=4