|
1 | 1 | import 'dart:async'; |
2 | 2 |
|
| 3 | +import 'package:logging/logging.dart'; |
| 4 | + |
3 | 5 | import 'package:webtrit_phone/data/data.dart'; |
4 | 6 | import 'package:webtrit_phone/mappers/mappers.dart'; |
5 | 7 | import 'package:webtrit_phone/models/models.dart'; |
6 | 8 |
|
| 9 | +final _logger = Logger('RecentsRepository'); |
| 10 | + |
7 | 11 | class RecentsRepository with PresenceInfoDriftMapper, CallLogsDriftMapper, ContactsDriftMapper, RecentsDriftMapper { |
8 | 12 | RecentsRepository({required AppDatabase appDatabase}) : _appDatabase = appDatabase; |
9 | 13 |
|
10 | 14 | final AppDatabase _appDatabase; |
11 | 15 |
|
12 | 16 | Stream<List<Recent>> watchRecents() { |
13 | | - return _appDatabase.recentsDao.watchLastRecents().map( |
14 | | - (callLogsExt) => callLogsExt.map(recentFromDrift).toList(growable: false), |
15 | | - ); |
| 17 | + return _appDatabase.recentsDao.watchLastRecents().map((callLogsExt) { |
| 18 | + return callLogsExt |
| 19 | + .map((data) { |
| 20 | + final recent = recentFromDrift(data); |
| 21 | + final entry = recent.callLogEntry; |
| 22 | + final contact = recent.contact; |
| 23 | + |
| 24 | + final numberHash = entry.number.hashCode; |
| 25 | + final usernameHash = entry.username?.hashCode; |
| 26 | + final contactNameHash = contact?.maybeName?.hashCode; |
| 27 | + final resolvedNameHash = recent.name.hashCode; |
| 28 | + |
| 29 | + final nameSource = contact?.maybeName != null |
| 30 | + ? 'contact.maybeName' |
| 31 | + : entry.username != null |
| 32 | + ? 'callLog.username' |
| 33 | + : 'callLog.number'; |
| 34 | + |
| 35 | + final mismatch = recent.name != entry.number; |
| 36 | + |
| 37 | + if (mismatch) { |
| 38 | + _logger.warning( |
| 39 | + '[Recents:mismatch] ' |
| 40 | + 'id=${entry.id} ' |
| 41 | + 'direction=${entry.direction.name} ' |
| 42 | + 'number=${entry.number} ' |
| 43 | + 'number.hash=$numberHash ' |
| 44 | + 'username=${entry.username} ' |
| 45 | + 'username.hash=$usernameHash ' |
| 46 | + 'contactName=${contact?.maybeName} ' |
| 47 | + 'contactName.hash=$contactNameHash ' |
| 48 | + 'resolvedName=${recent.name} ' |
| 49 | + 'resolvedName.hash=$resolvedNameHash ' |
| 50 | + 'nameSource=$nameSource ' |
| 51 | + 'hasContact=${contact != null} ' |
| 52 | + 'contactId=${contact?.id} ' |
| 53 | + 'contactSourceType=${contact?.sourceType} ' |
| 54 | + 'contactPhonesCount=${contact?.phones.length ?? 0} ' |
| 55 | + 'numberEqualsUsername=${entry.number == entry.username}', |
| 56 | + ); |
| 57 | + } |
| 58 | + |
| 59 | + return recent; |
| 60 | + }) |
| 61 | + .toList(growable: false); |
| 62 | + }); |
16 | 63 | } |
17 | 64 |
|
18 | 65 | Future<void> deleteByCallId(int id) async { |
|
0 commit comments