getOlmSessions method

Future<List<OlmSession>> getOlmSessions(
  1. String senderKey, {
  2. bool getFromDb = true,
})

Implementation

Future<List<OlmSession>> getOlmSessions(String senderKey,
    {bool getFromDb = true}) async {
  var sess = olmSessions[senderKey];
  if ((getFromDb) && (sess == null || sess.isEmpty)) {
    final sessions = await getOlmSessionsFromDatabase(senderKey);
    if (sessions.isEmpty) {
      return [];
    }
    sess = _olmSessions[senderKey] = sessions;
  }
  if (sess == null) {
    return [];
  }
  sess.sort((a, b) => a.lastReceived == b.lastReceived
      ? (a.sessionId ?? '').compareTo(b.sessionId ?? '')
      : (b.lastReceived ?? DateTime(0))
          .compareTo(a.lastReceived ?? DateTime(0)));
  return sess;
}