LCOV - code coverage report
Current view: top level - lib/cwtch - cwtchNotifier.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 0 279 0.0 %
Date: 2024-04-16 06:18:13 Functions: 0 0 -

          Line data    Source code
       1             : import 'dart:convert';
       2             : import 'package:cwtch/cwtch/cwtch.dart';
       3             : import 'package:cwtch/main.dart';
       4             : import 'package:cwtch/models/appstate.dart';
       5             : import 'package:cwtch/models/contact.dart';
       6             : import 'package:cwtch/models/profilelist.dart';
       7             : import 'package:cwtch/models/remoteserver.dart';
       8             : import 'package:cwtch/models/servers.dart';
       9             : import 'package:cwtch/notification_manager.dart';
      10             : 
      11             : import 'package:cwtch/torstatus.dart';
      12             : 
      13             : import '../config.dart';
      14             : import '../errorHandler.dart';
      15             : import '../settings.dart';
      16             : 
      17             : typedef SeenMessageCallback = Function(String, int, DateTime);
      18             : 
      19             : // Class that handles libcwtch-go events (received either via ffi with an isolate or gomobile over a method channel from kotlin)
      20             : //   Takes Notifiers and triggers them on appropriate events
      21             : class CwtchNotifier {
      22             :   late ProfileListState profileCN;
      23             :   late Settings settings;
      24             :   late ErrorHandler error;
      25             :   late TorStatus torStatus;
      26             :   late NotificationsManager notificationManager;
      27             :   late AppState appState;
      28             :   late ServerListState serverListState;
      29             :   late FlwtchState flwtchState;
      30             : 
      31             :   String? notificationSimple;
      32             :   String? notificationConversationInfo;
      33             : 
      34             :   SeenMessageCallback? seenMessageCallback;
      35             : 
      36           0 :   CwtchNotifier(ProfileListState pcn, Settings settingsCN, ErrorHandler errorCN, TorStatus torStatusCN, NotificationsManager notificationManagerP, AppState appStateCN,
      37             :       ServerListState serverListStateCN, FlwtchState flwtchStateCN) {
      38           0 :     profileCN = pcn;
      39           0 :     settings = settingsCN;
      40           0 :     error = errorCN;
      41           0 :     torStatus = torStatusCN;
      42           0 :     notificationManager = notificationManagerP;
      43           0 :     appState = appStateCN;
      44           0 :     serverListState = serverListStateCN;
      45           0 :     flwtchState = flwtchStateCN;
      46             :   }
      47             : 
      48           0 :   void l10nInit(String notificationSimple, String notificationConversationInfo) {
      49           0 :     this.notificationSimple = notificationSimple;
      50           0 :     this.notificationConversationInfo = notificationConversationInfo;
      51             :   }
      52             : 
      53           0 :   void setMessageSeenCallback(SeenMessageCallback callback) {
      54           0 :     seenMessageCallback = callback;
      55             :   }
      56             : 
      57           0 :   void handleMessage(String type, dynamic data) {
      58             :     // EnvironmentConfig.debugLog("NewEvent $type $data");
      59             :     switch (type) {
      60           0 :       case "CwtchStarted":
      61             : 
      62             : 
      63             : 
      64           0 :         if (data["Reload"] == "true" && profileCN.num > 0) {
      65             :           // don't reload...
      66             :           // unless we have loaded no profiles...then there isnt a risk and this
      67             :           // might be a first time (e.g. new apk, existing service)
      68             :         } else {
      69           0 :           flwtchState.cwtch.LoadProfiles(DefaultPassword);
      70             :         }
      71             : 
      72           0 :         appState.SetCwtchInit();
      73             :         break;
      74           0 :       case "CwtchStartError":
      75           0 :         appState.SetAppError(data["Error"]);
      76             :         break;
      77           0 :       case "NewPeer":
      78             :         // EnvironmentConfig.debugLog("NewPeer $data");
      79             :         // if tag != v1-defaultPassword then it is either encrypted OR it is an unencrypted account created during pre-beta...
      80           0 :         profileCN.add(
      81           0 :           data["Identity"],
      82           0 :           data["name"],
      83           0 :           data["picture"],
      84           0 :           data["defaultPicture"],
      85           0 :           data["ContactsJson"],
      86           0 :           data["ServerList"],
      87           0 :           data["Online"] == "true",
      88           0 :           data["autostart"] == "true",
      89           0 :           data["tag"] != "v1-defaultPassword",
      90           0 :           data["appearOffline"] == "true",
      91             :         );
      92             : 
      93             :         // Update Profile Attributes
      94           0 :         EnvironmentConfig.debugLog("Looking up Profile Attributes ${data["Identity"]} ${profileCN.getProfile(data["Identity"])}");
      95           0 :         flwtchState.cwtch.GetProfileAttribute(data["Identity"], "profile.profile-attribute-1").then((value) => profileCN.getProfile(data["Identity"])?.setAttribute(0, value));
      96           0 :         flwtchState.cwtch.GetProfileAttribute(data["Identity"], "profile.profile-attribute-2").then((value) => profileCN.getProfile(data["Identity"])?.setAttribute(1, value));
      97           0 :         flwtchState.cwtch.GetProfileAttribute(data["Identity"], "profile.profile-attribute-3").then((value) => profileCN.getProfile(data["Identity"])?.setAttribute(2, value));
      98           0 :         flwtchState.cwtch.GetProfileAttribute(data["Identity"], "profile.profile-status").then((value) => profileCN.getProfile(data["Identity"])?.setAvailabilityStatus(value ?? ""));
      99             : 
     100           0 :         EnvironmentConfig.debugLog("Looking up Profile Information for Contact...");
     101           0 :         profileCN.getProfile(data["Identity"])?.contactList.contacts.forEach((contact) {
     102           0 :           flwtchState.cwtch.GetConversationAttribute(data["Identity"], contact.identifier, "public.profile.profile-attribute-1").then((value) => contact.setAttribute(0, value));
     103           0 :           flwtchState.cwtch.GetConversationAttribute(data["Identity"], contact.identifier, "public.profile.profile-attribute-2").then((value) => contact.setAttribute(1, value));
     104           0 :           flwtchState.cwtch.GetConversationAttribute(data["Identity"], contact.identifier, "public.profile.profile-attribute-3").then((value) => contact.setAttribute(2, value));
     105           0 :           flwtchState.cwtch.GetConversationAttribute(data["Identity"], contact.identifier, "public.profile.profile-status").then((value) => contact.setAvailabilityStatus(value ?? ""));
     106             :         });
     107             : 
     108             :         break;
     109           0 :       case "ContactCreated":
     110           0 :         EnvironmentConfig.debugLog("ContactCreated $data");
     111             : 
     112           0 :         profileCN.getProfile(data["ProfileOnion"])?.contactList.add(ContactInfoState(data["ProfileOnion"], int.parse(data["ConversationID"]), data["RemotePeer"],
     113           0 :             nickname: data["nick"],
     114           0 :             status: data["status"],
     115           0 :             imagePath: data["picture"],
     116           0 :             defaultImagePath: data["defaultPicture"],
     117           0 :             blocked: data["blocked"] == "true",
     118           0 :             accepted: data["accepted"] == "true",
     119           0 :             savePeerHistory: data["saveConversationHistory"] == null ? "DeleteHistoryConfirmed" : data["saveConversationHistory"],
     120           0 :             numMessages: int.parse(data["numMessages"]),
     121           0 :             numUnread: int.parse(data["unread"]),
     122             :             isGroup: false, // by definition
     123             :             server: null,
     124             :             archived: false,
     125           0 :             lastMessageTime: DateTime.now(), //show at the top of the contact list even if no messages yet
     126           0 :             notificationPolicy: data["notificationPolicy"] ?? "ConversationNotificationPolicy.Default"));
     127             : 
     128             :         break;
     129           0 :       case "NewServer":
     130           0 :         EnvironmentConfig.debugLog("NewServer $data");
     131           0 :         serverListState.add(data["Onion"], data["ServerBundle"], data["Running"] == "true", data["Description"], data["Autostart"] == "true", data["StorageType"] == "storage-password");
     132             :         break;
     133           0 :       case "ServerIntentUpdate":
     134           0 :         EnvironmentConfig.debugLog("ServerIntentUpdate $data");
     135           0 :         var server = serverListState.getServer(data["Identity"]);
     136             :         if (server != null) {
     137           0 :           server.setRunning(data["Intent"] == "running");
     138             :         }
     139             :         break;
     140           0 :       case "ServerStatsUpdate":
     141           0 :         EnvironmentConfig.debugLog("ServerStatsUpdate $data");
     142           0 :         var totalMessages = int.parse(data["TotalMessages"]);
     143           0 :         var connections = int.parse(data["Connections"]);
     144           0 :         serverListState.updateServerStats(data["Identity"], totalMessages, connections);
     145             :         break;
     146           0 :       case "GroupCreated":
     147             :         // Retrieve Server Status from Cache...
     148             :         String status = "";
     149           0 :         RemoteServerInfoState? serverInfoState = profileCN.getProfile(data["ProfileOnion"])?.serverList.getServer(data["GroupServer"]);
     150             :         if (serverInfoState != null) {
     151           0 :           status = serverInfoState.status;
     152             :         }
     153           0 :         if (profileCN.getProfile(data["ProfileOnion"])?.contactList.getContact(int.parse(data["ConversationID"])) == null) {
     154           0 :           profileCN.getProfile(data["ProfileOnion"])?.contactList.add(ContactInfoState(data["ProfileOnion"], int.parse(data["ConversationID"]), data["GroupID"],
     155             :               blocked: false, // we created
     156             :               accepted: true, // we created
     157           0 :               imagePath: data["picture"],
     158           0 :               defaultImagePath: data["picture"],
     159           0 :               nickname: data["GroupName"],
     160             :               status: status,
     161           0 :               server: data["GroupServer"],
     162             :               isGroup: true,
     163           0 :               lastMessageTime: DateTime.now(),
     164           0 :               notificationPolicy: data["notificationPolicy"] ?? "ConversationNotificationPolicy.Default"));
     165             : 
     166           0 :           profileCN.getProfile(data["ProfileOnion"])?.contactList.updateLastMessageReceivedTime(int.parse(data["ConversationID"]), DateTime.now());
     167             :         }
     168             :         break;
     169           0 :       case "PeerDeleted":
     170           0 :         profileCN.delete(data["Identity"]);
     171             :         // todo standarize
     172           0 :         error.handleUpdate("deleteprofile.success");
     173             :         break;
     174           0 :       case "ServerDeleted":
     175           0 :         error.handleUpdate("deletedserver." + data["Status"]);
     176           0 :         if (data["Status"] == "success") {
     177           0 :           serverListState.delete(data["Identity"]);
     178             :         }
     179             :         break;
     180           0 :       case "DeleteContact":
     181           0 :         var identifier = int.parse(data["ConversationID"]);
     182           0 :         profileCN.getProfile(data["ProfileOnion"])?.contactList.removeContact(identifier);
     183             :         break;
     184           0 :       case "PeerStateChange":
     185           0 :         ContactInfoState? contact = profileCN.getProfile(data["ProfileOnion"])?.contactList.findContact(data["RemotePeer"]);
     186             :         if (contact != null) {
     187           0 :           if (data["ConnectionState"] != null) {
     188           0 :             contact.status = data["ConnectionState"];
     189             :           }
     190           0 :           profileCN.getProfile(data["ProfileOnion"])?.contactList.resort();
     191             :         }
     192             :         break;
     193           0 :       case "NewMessageFromPeer":
     194           0 :         var identifier = int.parse(data["ConversationID"]);
     195           0 :         var messageID = int.parse(data["Index"]);
     196           0 :         var timestamp = DateTime.tryParse(data['TimestampReceived'])!;
     197           0 :         var senderHandle = data['RemotePeer'];
     198           0 :         var senderImage = data['picture'];
     199           0 :         var isAuto = data['Auto'] == "true";
     200           0 :         String contenthash = data['ContentHash'];
     201             : 
     202           0 :         var selectedProfile = appState.selectedProfile == data["ProfileOnion"];
     203           0 :         var selectedConversation = selectedProfile && appState.selectedConversation == identifier;
     204           0 :         profileCN.getProfile(data["ProfileOnion"])?.newMessage(
     205             :               identifier,
     206             :               messageID,
     207             :               timestamp,
     208             :               senderHandle,
     209             :               senderImage,
     210             :               isAuto,
     211           0 :               data["Data"],
     212             :               contenthash,
     213             :               selectedProfile,
     214             :               selectedConversation,
     215             :             );
     216             : 
     217             :         // Now perform the notification logic...
     218           0 :         var notification = data["notification"];
     219           0 :         if (selectedConversation && seenMessageCallback != null) {
     220           0 :           seenMessageCallback!(data["ProfileOnion"]!, identifier, DateTime.now().toUtc());
     221             :         }
     222             : 
     223           0 :         if (notification == "SimpleEvent") {
     224           0 :           notificationManager.notify(notificationSimple ?? "New Message", "", 0);
     225           0 :         } else if (notification == "ContactInfo") {
     226           0 :           var contact = profileCN.getProfile(data["ProfileOnion"])?.contactList.getContact(identifier);
     227           0 :           notificationManager.notify((notificationConversationInfo ?? "New Message from %1").replaceFirst("%1", (contact?.nickname ?? senderHandle.toString())), data["ProfileOnion"], identifier);
     228             :         }
     229           0 :         appState.notifyProfileUnread();
     230             :         break;
     231           0 :       case "PeerAcknowledgement":
     232             :         // We don't use these anymore, IndexedAcknowledgement is more suited to the UI front end...
     233             :         break;
     234           0 :       case "IndexedAcknowledgement":
     235           0 :         var conversation = int.parse(data["ConversationID"]);
     236           0 :         var messageID = int.parse(data["Index"]);
     237             : 
     238             :         // We only ever see acks from authenticated peers.
     239             :         // If the contact is marked as offline then override this - can happen when the contact is removed from the front
     240             :         // end during syncing.
     241           0 :         if (profileCN.getProfile(data["ProfileOnion"])?.contactList.getContact(conversation)!.isOnline() == false) {
     242           0 :           profileCN.getProfile(data["ProfileOnion"])?.contactList.getContact(conversation)!.status = "Authenticated";
     243             :         }
     244           0 :         profileCN.getProfile(data["ProfileOnion"])?.contactList.getContact(conversation)!.ackCache(messageID);
     245             : 
     246             :         break;
     247           0 :       case "NewMessageFromGroup":
     248           0 :         var identifier = int.parse(data["ConversationID"]);
     249           0 :         if (data["ProfileOnion"] != data["RemotePeer"]) {
     250           0 :           var idx = int.parse(data["Index"]);
     251           0 :           var senderHandle = data['RemotePeer'];
     252           0 :           var senderImage = data['picture'];
     253           0 :           var timestampSent = DateTime.tryParse(data['TimestampSent'])!;
     254           0 :           var contact = profileCN.getProfile(data["ProfileOnion"])?.contactList.getContact(identifier);
     255           0 :           var currentTotal = contact!.totalMessages;
     256           0 :           var isAuto = data['Auto'] == "true";
     257           0 :           String contenthash = data['ContentHash'];
     258           0 :           var selectedProfile = appState.selectedProfile == data["ProfileOnion"];
     259           0 :           var selectedConversation = selectedProfile && appState.selectedConversation == identifier;
     260           0 :           var notification = data["notification"];
     261             : 
     262             :           // Only bother to do anything if we know about the group and the provided index is greater than our current total...
     263           0 :           if (idx >= currentTotal) {
     264             :             // TODO: There are 2 timestamps associated with a new group message - time sent and time received.
     265             :             // Sent refers to the time a profile alleges they sent a message
     266             :             // Received refers to the time we actually saw the message from the server
     267             :             // These can obviously be very different for legitimate reasons.
     268             :             // We also maintain a relative hash-link through PreviousMessageSignature which is the ground truth for
     269             :             // order.
     270             :             // In the future we will want to combine these 3 ordering mechanisms into a cohesive view of the timeline
     271             :             // For now we perform some minimal checks on the sent timestamp to use to provide a useful ordering for honest contacts
     272             :             // and ensure that malicious contacts in groups can only set this timestamp to a value within the range of `last seen message time`
     273             :             // and `local now`.
     274           0 :             profileCN.getProfile(data["ProfileOnion"])?.newMessage(identifier, idx, timestampSent, senderHandle, senderImage, isAuto, data["Data"], contenthash, selectedProfile, selectedConversation);
     275           0 :             if (selectedConversation && seenMessageCallback != null) {
     276           0 :               seenMessageCallback!(data["ProfileOnion"]!, identifier, DateTime.now().toUtc());
     277             :             }
     278             : 
     279           0 :             if (notification == "SimpleEvent") {
     280           0 :               notificationManager.notify(notificationSimple ?? "New Message", "", 0);
     281           0 :             } else if (notification == "ContactInfo") {
     282           0 :               var contact = profileCN.getProfile(data["ProfileOnion"])?.contactList.getContact(identifier);
     283           0 :               notificationManager.notify((notificationConversationInfo ?? "New Message from %1").replaceFirst("%1", (contact?.nickname ?? senderHandle.toString())), data["ProfileOnion"], identifier);
     284             :             }
     285           0 :             appState.notifyProfileUnread();
     286             :           }
     287           0 :           RemoteServerInfoState? server = profileCN.getProfile(data["ProfileOnion"])?.serverList.getServer(contact.server ?? "");
     288           0 :           server?.updateSyncProgressFor(timestampSent);
     289             :         } else {
     290             :           // This is dealt with by IndexedAcknowledgment
     291           0 :           EnvironmentConfig.debugLog("new message from group from yourself - this should not happen");
     292             :         }
     293             :         break;
     294           0 :       case "IndexedFailure":
     295           0 :         var identifier = int.parse(data["ConversationID"]);
     296           0 :         var contact = profileCN.getProfile(data["ProfileOnion"])?.contactList.getContact(identifier);
     297           0 :         var messageID = int.parse(data["Index"]);
     298           0 :         contact!.errCache(messageID);
     299             :         break;
     300           0 :       case "AppError":
     301           0 :         EnvironmentConfig.debugLog("New App Error: $data");
     302             :         // special case for delete error (todo: standardize cwtch errors)
     303           0 :         if (data["Error"] == "Password did not match") {
     304           0 :           error.handleUpdate("deleteprofile.error");
     305           0 :         } else if (data["Data"] != null) {
     306           0 :           error.handleUpdate(data["Data"]);
     307             :         }
     308             :         break;
     309           0 :       case "UpdateGlobalSettings":
     310           0 :         settings.handleUpdate(jsonDecode(data["Data"]));
     311           0 :         appState.settingsLoaded = true;
     312             :         break;
     313           0 :       case "UpdatedProfileAttribute":
     314           0 :         if (data["Key"] == "public.profile.name") {
     315           0 :           profileCN.getProfile(data["ProfileOnion"])?.nickname = data["Data"];
     316           0 :         } else if (data["Key"].toString().startsWith("local.filesharing.")) {
     317           0 :           if (data["Key"].toString().endsWith(".path")) {
     318             :             // local.conversation.filekey.path
     319           0 :             List<String> keyparts = data["Key"].toString().split(".");
     320           0 :             if (keyparts.length == 5) {
     321           0 :               String filekey = keyparts[2] + "." + keyparts[3];
     322           0 :               profileCN.getProfile(data["ProfileOnion"])?.downloadSetPathForSender(filekey, data["Data"]);
     323             :             }
     324             :           }
     325           0 :         } else if (data["Key"].toString().startsWith("public.profile.profile-attribute")) {
     326             :           // ignore these events...
     327           0 :         } else if (data["Key"].toString().startsWith("public.profile.profile-status")) {
     328           0 :           profileCN.getProfile(data["ProfileOnion"])?.setAvailabilityStatus(data["Data"]);
     329             :         } else {
     330           0 :           EnvironmentConfig.debugLog("unhandled set attribute event: ${data['Key']}");
     331             :         }
     332             :         break;
     333           0 :       case "NetworkError":
     334           0 :         var isOnline = data["Status"] == "Success";
     335           0 :         profileCN.getProfile(data["ProfileOnion"])?.isOnline = isOnline;
     336             :         break;
     337           0 :       case "ACNStatus":
     338           0 :         EnvironmentConfig.debugLog("acn status: $data");
     339           0 :         torStatus.handleUpdate(int.parse(data["Progress"]), data["Status"]);
     340             :         break;
     341           0 :       case "ACNVersion":
     342           0 :         EnvironmentConfig.debugLog("acn version: $data");
     343           0 :         torStatus.updateVersion(data["Data"]);
     344             :         break;
     345           0 :       case "UpdateServerInfo":
     346           0 :         EnvironmentConfig.debugLog("NewEvent  UpdateServerInfo $type $data");
     347           0 :         profileCN.getProfile(data["ProfileOnion"])?.replaceServers(data["ServerList"]);
     348             :         break;
     349           0 :       case "TokenManagerInfo":
     350             :         try {
     351           0 :           List<dynamic> associatedGroups = jsonDecode(data["Data"]);
     352           0 :           int count = int.parse(data["ServerTokenCount"]);
     353           0 :           associatedGroups.forEach((identifier) {
     354           0 :             profileCN.getProfile(data["ProfileOnion"])?.contactList.getContact(int.parse(identifier.toString()))!.antispamTickets = count;
     355             :           });
     356           0 :           EnvironmentConfig.debugLog("update server token count for $associatedGroups, $count");
     357             :         } catch (e) {
     358             :           //  No tokens in data...
     359             :         }
     360             :         break;
     361           0 :       case "NewGroup":
     362           0 :         String invite = data["GroupInvite"].toString();
     363           0 :         if (invite.startsWith("torv3")) {
     364           0 :           String inviteJson = new String.fromCharCodes(base64Decode(invite.substring(5)));
     365           0 :           dynamic groupInvite = jsonDecode(inviteJson);
     366             : 
     367             :           // Retrieve Server Status from Cache...
     368             :           String status = "";
     369           0 :           RemoteServerInfoState? serverInfoState = profileCN.getProfile(data["ProfileOnion"])!.serverList.getServer(groupInvite["ServerHost"]);
     370             :           if (serverInfoState != null) {
     371           0 :             status = serverInfoState.status;
     372             :           }
     373             : 
     374           0 :           if (profileCN.getProfile(data["ProfileOnion"])?.contactList.findContact(groupInvite["GroupID"]) == null) {
     375           0 :             var identifier = int.parse(data["ConversationID"]);
     376           0 :             profileCN.getProfile(data["ProfileOnion"])?.contactList.add(ContactInfoState(data["ProfileOnion"], identifier, groupInvite["GroupID"],
     377             :                 blocked: false, // NewGroup only issued on accepting invite
     378             :                 accepted: true, // NewGroup only issued on accepting invite
     379           0 :                 imagePath: data["picture"],
     380           0 :                 nickname: groupInvite["GroupName"],
     381           0 :                 server: groupInvite["ServerHost"],
     382             :                 status: status,
     383             :                 isGroup: true,
     384           0 :                 lastMessageTime: DateTime.now()));
     385             : 
     386           0 :             profileCN.getProfile(data["ProfileOnion"])?.contactList.updateLastMessageReceivedTime(identifier, DateTime.fromMillisecondsSinceEpoch(0));
     387             :           }
     388             :           // request a new server update...
     389             :           // NOTE: In the future this should also update the TokenManagerInfo
     390             :           // This is not currently communicated by ServerUpdateInfo (but it probably should be)git
     391           0 :           flwtchState.cwtch.PublishServerUpdate(data["ProfileOnion"]);
     392             :         }
     393             :         break;
     394           0 :       case "ServerStateChange":
     395             :         // Update the Server Cache
     396           0 :         profileCN.getProfile(data["ProfileOnion"])?.updateServerStatusCache(data["GroupServer"], data["ConnectionState"]);
     397           0 :         profileCN.getProfile(data["ProfileOnion"])?.contactList.contacts.forEach((contact) {
     398           0 :           if (contact.isGroup == true && contact.server == data["GroupServer"]) {
     399           0 :             contact.status = data["ConnectionState"];
     400             :           }
     401             :         });
     402           0 :         profileCN.getProfile(data["ProfileOnion"])?.contactList.resort();
     403             :         break;
     404           0 :       case "UpdatedConversationAttribute":
     405           0 :         if (data["Path"] == "profile.name") {
     406           0 :           if (data["Data"].toString().trim().length > 0) {
     407             :             // Update locally on the UI...
     408           0 :             if (profileCN.getProfile(data["ProfileOnion"])?.contactList.findContact(data["RemotePeer"]) != null) {
     409           0 :               profileCN.getProfile(data["ProfileOnion"])?.contactList.findContact(data["RemotePeer"])!.nickname = data["Data"];
     410             :             }
     411             :           }
     412           0 :         } else if (data['Path'] == "profile.custom-profile-image") {
     413           0 :           EnvironmentConfig.debugLog("received ret val of custom profile image: $data");
     414           0 :           String fileKey = data['Data'];
     415           0 :           var contact = profileCN.getProfile(data["ProfileOnion"])?.contactList.findContact(data["RemotePeer"]);
     416             :           if (contact != null) {
     417           0 :             EnvironmentConfig.debugLog("waiting for download from $contact");
     418           0 :             profileCN.getProfile(data["ProfileOnion"])?.waitForDownloadComplete(contact.identifier, fileKey);
     419             :           }
     420           0 :         } else if (data['Path'] == "profile.profile-attribute-1" || data['Path'] == "profile.profile-attribute-2" || data['Path'] == "profile.profile-attribute-3") {
     421           0 :           var contact = profileCN.getProfile(data["ProfileOnion"])?.contactList.findContact(data["RemotePeer"]);
     422             :           if (contact != null) {
     423           0 :             switch (data['Path']) {
     424           0 :               case "profile.profile-attribute-1":
     425           0 :                 contact.setAttribute(0, data["Data"]);
     426             :                 break;
     427           0 :               case "profile.profile-attribute-2":
     428           0 :                 contact.setAttribute(1, data["Data"]);
     429             :                 break;
     430           0 :               case "profile.profile-attribute-3":
     431           0 :                 contact.setAttribute(2, data["Data"]);
     432             :                 break;
     433             :             }
     434             :           }
     435           0 :         } else if (data['Path'] == "profile.profile-status") {
     436           0 :           var contact = profileCN.getProfile(data["ProfileOnion"])?.contactList.findContact(data["RemotePeer"]);
     437             :           if (contact != null) {
     438           0 :             contact.setAvailabilityStatus(data['Data']);
     439             :           }
     440             :         } else {
     441           0 :           EnvironmentConfig.debugLog("unhandled ret val event: ${data['Path']}");
     442             :         }
     443             :         break;
     444           0 :       case "ManifestSizeReceived":
     445           0 :         if (!profileCN.getProfile(data["ProfileOnion"])!.downloadActive(data["FileKey"])) {
     446           0 :           profileCN.getProfile(data["ProfileOnion"])?.downloadUpdate(data["FileKey"], 0, 1);
     447             :         }
     448             :         break;
     449           0 :       case "ManifestSaved":
     450           0 :         profileCN.getProfile(data["ProfileOnion"])?.downloadMarkManifest(data["FileKey"]);
     451             :         break;
     452           0 :       case "FileDownloadProgressUpdate":
     453           0 :         var progress = int.parse(data["Progress"]);
     454           0 :         profileCN.getProfile(data["ProfileOnion"])?.downloadUpdate(data["FileKey"], progress, int.parse(data["FileSizeInChunks"]));
     455             :         // progress == -1 is a "download was interrupted" message and should contain a path
     456           0 :         if (progress < 0) {
     457           0 :           profileCN.getProfile(data["ProfileOnion"])?.downloadSetPath(data["FileKey"], data["FilePath"]);
     458             :         }
     459             :         break;
     460           0 :       case "FileDownloaded":
     461           0 :         profileCN.getProfile(data["ProfileOnion"])?.downloadMarkFinished(data["FileKey"], data["FilePath"]);
     462             :         break;
     463           0 :       case "ImportingProfileEvent":
     464             :         break;
     465           0 :       case "StartingStorageMigration":
     466           0 :         appState.SetModalState(ModalState.storageMigration);
     467             :         break;
     468           0 :       case "DoneStorageMigration":
     469           0 :         appState.SetModalState(ModalState.none);
     470             :         break;
     471           0 :       case "BlodeuweddSummary":
     472           0 :         var identifier = int.parse(data["ConversationID"]);
     473           0 :         profileCN.getProfile(data["ProfileOnion"])?.contactList.getContact(identifier)?.updateSummaryEvent(data["Summary"]);
     474             :         break;
     475           0 :       case "BlodeuweddTranslation":
     476           0 :         var identifier = int.parse(data["ConversationID"]);
     477           0 :         var mid = int.parse(data["Index"]);
     478           0 :         EnvironmentConfig.debugLog("received translation event: $identifier $mid $data");
     479           0 :         profileCN.getProfile(data["ProfileOnion"])?.contactList.getContact(identifier)?.updateTranslationEvent(mid, data["Translation"]);
     480             :         break;
     481           0 :       case "ACNInfo":
     482           0 :         var key = data["Key"];
     483           0 :         var handle = data["Handle"];
     484           0 :         if (key == "circuit") {
     485           0 :           profileCN.getProfile(data["ProfileOnion"])?.contactList.findContact(handle)?.acnCircuit = data["Data"];
     486             :         }
     487             :         break;
     488           0 :       case "SearchResult":
     489           0 :         String searchID = data["SearchID"];
     490           0 :         var conversationIdentifier = int.parse(data["ConversationID"]);
     491           0 :         var messageIndex = int.parse(data["RowIndex"]);
     492           0 :         profileCN.getProfile(data["ProfileOnion"])?.handleSearchResult(searchID, conversationIdentifier, messageIndex);
     493             :         break;
     494             :       default:
     495           0 :         EnvironmentConfig.debugLog("unhandled event: $type");
     496             :     }
     497             :   }
     498             : }

Generated by: LCOV version 1.14