@@ -48,6 +48,7 @@ def __init__(self, cx, debug=False, default_timeout=None, auto_reconnect=False,
4848 self ._self_info = {}
4949 self ._time = 0
5050 self ._lastmod = 0
51+ self ._auto_update_contacts = False
5152
5253 # Set up event subscriptions to track data
5354 self ._setup_data_tracking ()
@@ -180,7 +181,12 @@ async def wait_for_event(self, event_type: EventType, attribute_filters: Optiona
180181 def _setup_data_tracking (self ):
181182 """Set up event subscriptions to track data internally"""
182183 async def _update_contacts (event ):
183- self ._contacts .update (event .payload )
184+ #self._contacts.update(event.payload)
185+ for c in event .payload .values ():
186+ if c ["public_key" ] in self ._contacts :
187+ self ._contacts [c ["public_key" ]].update (c )
188+ else :
189+ self ._contacts [c ["public_key" ]]= c
184190 if "lastmod" in event .attributes :
185191 self ._lastmod = event .attributes ['lastmod' ]
186192 self ._contacts_dirty = False
@@ -191,6 +197,8 @@ async def _add_pending_contact(event):
191197
192198 async def _contact_change (event ):
193199 self ._contacts_dirty = True
200+ if self ._auto_update_contacts :
201+ await self .ensure_contacts (follow = True )
194202
195203 async def _update_self_info (event ):
196204 self ._self_info = event .payload
@@ -217,6 +225,15 @@ def contacts_dirty(self):
217225 """Get wether contact list is in sync"""
218226 return self ._contacts_dirty
219227
228+ @property
229+ def auto_update_contacts (self ):
230+ """Get wether contact list is in sync"""
231+ return self ._auto_update_contacts
232+
233+ @auto_update_contacts .setter
234+ def auto_update_contacts (self , value ):
235+ self ._auto_update_contacts = value
236+
220237 @property
221238 def self_info (self ):
222239 """Get device self info"""
0 commit comments