Skip to content

Commit

Permalink
Save contacts cache
Browse files Browse the repository at this point in the history
  • Loading branch information
exquo committed Oct 27, 2022
1 parent 8ccae9f commit 3f60ded
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion scli
Original file line number Diff line number Diff line change
Expand Up @@ -1153,6 +1153,9 @@ class Contact:
def name_or_id(self):
return self.name or self.id

def serialize(self):
return self._record


class Contacts:
def __init__(self, sigdata, contacts_cache=None):
Expand Down Expand Up @@ -1199,6 +1202,8 @@ class Contacts:
def get_by_id(self, contact_id):
return self.map.get(contact_id)

def serialize(self):
return {c.id: c.serialize() for c in self.map.values()}

# #############################################################################
# chats data
Expand Down Expand Up @@ -1854,6 +1859,7 @@ class ChatsData:
self.typing_indicators = TypingIndicators(self.chats)
self._history = history_file
self.current_contact = None
self.contacts_cache = None

if self._history:
self._load_history()
Expand All @@ -1870,9 +1876,11 @@ class ChatsData:
unread_counts = self.unread_counts.serialize()
delivery_status = self.delivery_status.dump()
items = {
'version': 5,
'envelopes': envelopes,
'unread_counts': unread_counts,
'delivery_status': delivery_status,
'contacts_cache': self.contacts_cache,
}

class JSONSetEncoder(json.JSONEncoder):
Expand Down Expand Up @@ -1917,6 +1925,7 @@ class ChatsData:
self.chats.add_envelope(envelope)

self.unread_counts = UnreadCounts(history.get('unread_counts', {}))
self.contacts_cache = history.get('contacts_cache', {})


# #############################################################################
Expand Down Expand Up @@ -4319,6 +4328,7 @@ class Actions:
def update_contacts_async(self):
def on_contacts_updated():
self._update_contacts_ui()
self._chats_data.contacts_cache = self._contacts.serialize()
self._update_indiv_contacts_async(
self._update_groups_async,
on_contacts_updated,
Expand Down Expand Up @@ -4474,7 +4484,7 @@ class Coordinate:
def __init__(self):
self._chats_data = ChatsData(cfg.save_history)
sigdata = SignalData(cfg.username)
self._contacts = Contacts(sigdata)
self._contacts = Contacts(sigdata, self._chats_data.contacts_cache)
self._ui = UrwidUI(self._contacts, self._chats_data)
self.daemon = Daemon(self._ui.loop, cfg.username)
self._actions = Actions(self.daemon, self._contacts, self._chats_data, self._ui)
Expand Down

0 comments on commit 3f60ded

Please sign in to comment.