imip-agent

Change of imiptools/content.py

100:3d5387851b23
imiptools/content.py
     1.1 --- a/imiptools/content.py	Thu Oct 30 23:44:37 2014 +0100
     1.2 +++ b/imiptools/content.py	Thu Oct 30 23:52:27 2014 +0100
     1.3 @@ -385,7 +385,7 @@
     1.4          else:
     1.5              return addresses
     1.6  
     1.7 -    def require_organiser_and_attendees(self):
     1.8 +    def require_organiser_and_attendees(self, from_organiser=True):
     1.9  
    1.10          """
    1.11          Return the organiser and attendees for the current object, filtered by
    1.12 @@ -397,8 +397,10 @@
    1.13  
    1.14          # Only provide details for recipients who are also attendees.
    1.15  
    1.16 +        filter_fn = from_organiser and self.filter_by_recipients or self.filter_by_senders
    1.17 +
    1.18          attendees = {}
    1.19 -        for attendee in map(get_uri, self.filter_by_recipients(attendee_map)):
    1.20 +        for attendee in map(get_uri, filter_fn(attendee_map)):
    1.21              attendees[attendee] = attendee_map[attendee]
    1.22  
    1.23          if not attendees or not organiser:
    1.24 @@ -425,23 +427,33 @@
    1.25  
    1.26          return self.filter_by_senders(identities)
    1.27  
    1.28 -    def have_new_object(self, attendee, objtype):
    1.29 +    def get_object(self, user, objtype):
    1.30 +
    1.31 +        """
    1.32 +        Return the stored object to which the current object refers for the
    1.33 +        given 'user' and for the given 'objtype'.
    1.34 +        """
    1.35 +
    1.36 +        f = self.store.get_event(user, self.uid)
    1.37 +        obj = f and parse_object(f, "utf-8", objtype)
    1.38 +        return obj
    1.39 +
    1.40 +    def have_new_object(self, attendee, objtype, obj=None):
    1.41  
    1.42          """
    1.43          Return whether the current object is new to the 'attendee' for the
    1.44          given 'objtype'.
    1.45          """
    1.46  
    1.47 -        f = self.store.get_event(attendee, self.uid)
    1.48 -        event = f and parse_object(f, "utf-8", objtype)
    1.49 +        obj = obj or self.get_object(attendee, objtype)
    1.50  
    1.51          # If found, compare SEQUENCE and potentially DTSTAMP.
    1.52  
    1.53 -        if event:
    1.54 -            sequence = get_value(event, "SEQUENCE")
    1.55 -            dtstamp = get_value(event, "DTSTAMP")
    1.56 +        if obj:
    1.57 +            sequence = get_value(obj, "SEQUENCE")
    1.58 +            dtstamp = get_value(obj, "DTSTAMP")
    1.59  
    1.60 -            # If the request refers to an older version of the event, ignore
    1.61 +            # If the request refers to an older version of the object, ignore
    1.62              # it.
    1.63  
    1.64              old_dtstamp = self.dtstamp < dtstamp