addDeprecatedInfoSpaceFeeds function

List<SpaceFeeds> addDeprecatedInfoSpaceFeeds(
  1. List<SpaceFeeds> chats
)

Implementation

List<SpaceFeeds> addDeprecatedInfoSpaceFeeds(List<SpaceFeeds> chats) {
  Map<String, String> latestDIDs = {};

  for (var chat in chats) {
    if (isValidCAIP10NFTAddress(chat.did)) {
      List<String> didParts = chat.did!.split(':');
      String didWithoutTimestamp = didParts.sublist(0, 5).join(':');
      String timestamp = didParts[5];

      if (!latestDIDs.containsKey(didWithoutTimestamp) ||
          timestamp.compareTo(
                  latestDIDs[didWithoutTimestamp].toString().split(':')[5]) >
              0) {
        latestDIDs[didWithoutTimestamp] = chat.did!;
      }
    }
  }

  for (var chat in chats) {
    if (isValidCAIP10NFTAddress(chat.did)) {
      List<String> didParts = chat.did!.split(':');
      String didWithoutTimestamp = didParts.sublist(0, 5).join(':');

      if (latestDIDs[didWithoutTimestamp] != chat.did!) {
        chat.deprecated = true;
        chat.deprecatedCode = 'NFT Owner Changed';
      }
    }
  }

  return chats;
}