Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TF-3298 Fix blink when refresh email list #3299

Merged
merged 2 commits into from
Nov 25, 2024

Conversation

dab246
Copy link
Member

@dab246 dab246 commented Nov 23, 2024

Issue

#3298

Root cause

According to the response returned from the server, the number of elements in Email/get and Email/query are different. Because some elements are not found in the notFound list. This leads to the sortingByOrderOfIdList function returning the list from Email/get.

{
    "sessionState": "2c9f1b12-b35a-43e6-9af2-0106fb53a943",
    "methodResponses": [
        [
            "Email/query",
            {
                "accountId": "cce2ec1540fa8f369c1f75f2151e8c7a2364a158881c0fed63c068aae0015901",
                "queryState": "b09ff786",
                "canCalculateChanges": false,
                "ids": [
                    "2c503360-a8e7-11ef-8f35-2b6b7de002f9",
                    "14d6a350-a8e6-11ef-8f35-2b6b7de002f9",
                    "3f42c470-a8d7-11ef-9ab4-c903a7f1e8a3",
                    "f8f0aa80-a8ba-11ef-9340-0d8f5a8bd4f9",
                    "2c21f0e0-a8ba-11ef-9340-0d8f5a8bd4f9",
                    "2492b9c0-a88f-11ef-9340-0d8f5a8bd4f9",
                    "1f069710-a88f-11ef-9ab4-c903a7f1e8a3",
                    "1a14b890-a88f-11ef-9340-0d8f5a8bd4f9",
                    "441861f0-da0e-11ee-9863-a368905d3405",
                    "f5890ba0-d81b-11ee-a7f2-0302da82fa0d",
                    "a48f37b0-d81b-11ee-9863-a368905d3405",
                    "858b4ae0-c9eb-11ee-b31c-939afe0b6132",
                    "6603a830-c9ea-11ee-bfc8-8baa82bb865e",
                    "365c4150-c9ea-11ee-bfc8-8baa82bb865e",
                    "642a3370-c9cd-11ee-8e22-3b54566f9f90",
                    "541d5ad0-c9a9-11ee-9073-63121fc97643",
                    "a4dbc8b0-c983-11ee-a89a-a70d425dc805",
                    "86ded7f0-c972-11ee-a89a-a70d425dc805",
                    "c93de160-c970-11ee-9073-63121fc97643",
                    "0d4d3d70-c970-11ee-9073-63121fc97643"
                ],
                "position": 0
            },
            "c0"
        ],
        [
            "Email/get",
            {
                "accountId": "cce2ec1540fa8f369c1f75f2151e8c7a2364a158881c0fed63c068aae0015901",
                "state": "bbe31d30-a8e7-11ef-9ab4-c903a7f1e8a3",
                "list": [
                    {
                        "id": "1a14b890-a88f-11ef-9340-0d8f5a8bd4f9",
                        "blobId": "1a14b890-a88f-11ef-9340-0d8f5a8bd4f9",
                        "keywords": {},
                        "mailboxIds": {
                            "4b028e10-c5c2-11ee-82c9-61411f1e5bf8": true
                        },
                        "size": 1407,
                        "receivedAt": "2024-11-22T05:03:24Z",
                        "to": [
                            {
                                "name": "[email protected]",
                                "email": "[email protected]"
                            }
                        ],
                        "from": [
                            {
                                "name": "signature 2",
                                "email": "[email protected]"
                            }
                        ],
                        "replyTo": [
                            {
                                "email": "[email protected]"
                            }
                        ],
                        "subject": "26",
                        "sentAt": "2024-11-22T05:03:15Z",
                        "hasAttachment": false,
                        "preview": "--  Hello Signature 2",
                        "header:X-MEETING-UID:asText": null
                    },
                    {
                        "id": "1f069710-a88f-11ef-9ab4-c903a7f1e8a3",
                        "blobId": "1f069710-a88f-11ef-9ab4-c903a7f1e8a3",
                        "keywords": {},
                        "mailboxIds": {
                            "4b028e10-c5c2-11ee-82c9-61411f1e5bf8": true
                        },
                        "size": 1407,
                        "receivedAt": "2024-11-22T05:03:32Z",
                        "to": [
                            {
                                "name": "[email protected]",
                                "email": "[email protected]"
                            }
                        ],
                        "from": [
                            {
                                "name": "signature 2",
                                "email": "[email protected]"
                            }
                        ],
                        "replyTo": [
                            {
                                "email": "[email protected]"
                            }
                        ],
                        "subject": "27",
                        "sentAt": "2024-11-22T05:03:24Z",
                        "hasAttachment": false,
                        "preview": "--  Hello Signature 2",
                        "header:X-MEETING-UID:asText": null
                    },
                    {
                        "id": "2c21f0e0-a8ba-11ef-9340-0d8f5a8bd4f9",
                        "blobId": "2c21f0e0-a8ba-11ef-9340-0d8f5a8bd4f9",
                        "keywords": {
                            "$seen": true
                        },
                        "mailboxIds": {
                            "4b028e10-c5c2-11ee-82c9-61411f1e5bf8": true
                        },
                        "size": 4516,
                        "receivedAt": "2024-11-22T10:11:42Z",
                        "to": [
                            {
                                "name": "Test preprod avocat.fr",
                                "email": "[email protected]"
                            }
                        ],
                        "from": [
                            {
                                "name": "Patrick PEREIRA",
                                "email": "[email protected]"
                            }
                        ],
                        "replyTo": [
                            {
                                "email": "[email protected]"
                            }
                        ],
                        "subject": "Hello",
                        "sentAt": "2024-11-22T10:11:24Z",
                        "hasAttachment": false,
                        "preview": "Coucou",
                        "header:X-MEETING-UID:asText": null
                    },
                    {
                        "id": "14d6a350-a8e6-11ef-8f35-2b6b7de002f9",
                        "blobId": "14d6a350-a8e6-11ef-8f35-2b6b7de002f9",
                        "keywords": {
                            "$seen": true
                        },
                        "mailboxIds": {
                            "4b028e10-c5c2-11ee-82c9-61411f1e5bf8": true
                        },
                        "size": 4891,
                        "receivedAt": "2024-11-22T15:26:01Z",
                        "to": [
                            {
                                "name": "[email protected]",
                                "email": "[email protected]"
                            }
                        ],
                        "from": [
                            {
                                "name": "Benoit TELLIER",
                                "email": "[email protected]"
                            }
                        ],
                        "replyTo": [
                            {
                                "email": "[email protected]"
                            }
                        ],
                        "subject": "erewrfwe",
                        "sentAt": "2024-11-22T15:25:41Z",
                        "hasAttachment": false,
                        "preview": "qwefqwef--  Best regards, Benoit TELLIER General manager of Linagora VIETNAM. Product owner for Team-Mail product. Chairman of the Apache James project. Mail: [email protected] Tel: (0033) 6 77 26 04 58 (WhatsApp, Signal)",
                        "header:X-MEETING-UID:asText": null
                    },
                    {
                        "id": "2c503360-a8e7-11ef-8f35-2b6b7de002f9",
                        "blobId": "2c503360-a8e7-11ef-8f35-2b6b7de002f9",
                        "keywords": {
                            "$seen": true
                        },
                        "mailboxIds": {
                            "4b028e10-c5c2-11ee-82c9-61411f1e5bf8": true
                        },
                        "size": 6461,
                        "receivedAt": "2024-11-22T15:33:50Z",
                        "to": [
                            {
                                "name": "[email protected]",
                                "email": "[email protected]"
                            }
                        ],
                        "from": [
                            {
                                "name": "Benoit TELLIER",
                                "email": "[email protected]"
                            }
                        ],
                        "replyTo": [
                            {
                                "email": "[email protected]"
                            }
                        ],
                        "subject": "Re: erewrfwe",
                        "sentAt": "2024-11-22T15:33:31Z",
                        "hasAttachment": false,
                        "preview": "--  Best regards, Benoit TELLIER General manager of Linagora VIETNAM. Product owner for Team-Mail product. Chairman of the Apache James project. Mail: [email protected] Tel: (0033) 6 77 26 04 58 (WhatsApp, Signal) On Nov 22, 2024 4:25 PM, from Benoit T",
                        "header:X-MEETING-UID:asText": null
                    },
                    {
                        "id": "f8f0aa80-a8ba-11ef-9340-0d8f5a8bd4f9",
                        "blobId": "f8f0aa80-a8ba-11ef-9340-0d8f5a8bd4f9",
                        "keywords": {
                            "$seen": true
                        },
                        "mailboxIds": {
                            "4b028e10-c5c2-11ee-82c9-61411f1e5bf8": true
                        },
                        "size": 400078,
                        "receivedAt": "2024-11-22T10:17:26Z",
                        "to": [
                            {
                                "email": "[email protected]"
                            }
                        ],
                        "from": [
                            {
                                "name": "Patrick PEREIRA",
                                "email": "[email protected]"
                            }
                        ],
                        "replyTo": [
                            {
                                "email": "[email protected]"
                            }
                        ],
                        "subject": "Re : test S3 -> ppereira",
                        "sentAt": "2024-11-22T10:17:08Z",
                        "hasAttachment": true,
                        "preview": "Le nov. 22, 2024 11:16 AM, de Signature 2 --  Hello Signature 2",
                        "header:X-MEETING-UID:asText": null
                    },
                    {
                        "id": "3f42c470-a8d7-11ef-9ab4-c903a7f1e8a3",
                        "blobId": "3f42c470-a8d7-11ef-9ab4-c903a7f1e8a3",
                        "keywords": {
                            "$seen": true
                        },
                        "mailboxIds": {
                            "4b028e10-c5c2-11ee-82c9-61411f1e5bf8": true
                        },
                        "size": 132052,
                        "receivedAt": "2024-11-22T13:39:50Z",
                        "to": [
                            {
                                "email": "[email protected]"
                            }
                        ],
                        "from": [
                            {
                                "name": "Twake Drive",
                                "email": "[email protected]"
                            }
                        ],
                        "subject": "Alerte Antivirus dans votre Twake Drive",
                        "sentAt": "2024-11-22T13:39:41Z",
                        "hasAttachment": false,
                        "preview": "Important: Alerte Antivirus dans votre Twake Drive L'analyse antivirus d'un fichier dans votre Twake Drive a signalé un problème. Fichier: eicar_com.zip Problème: Contenu malveillant détecté ⚠️ Voir sur Twake Drive Retrouvez nous sur les réseaux [instagram",
                        "header:X-MEETING-UID:asText": null
                    },
                    {
                        "id": "2492b9c0-a88f-11ef-9340-0d8f5a8bd4f9",
                        "blobId": "2492b9c0-a88f-11ef-9340-0d8f5a8bd4f9",
                        "keywords": {
                            "$seen": true
                        },
                        "mailboxIds": {
                            "4b028e10-c5c2-11ee-82c9-61411f1e5bf8": true
                        },
                        "size": 1407,
                        "receivedAt": "2024-11-22T05:03:41Z",
                        "to": [
                            {
                                "name": "[email protected]",
                                "email": "[email protected]"
                            }
                        ],
                        "from": [
                            {
                                "name": "signature 2",
                                "email": "[email protected]"
                            }
                        ],
                        "replyTo": [
                            {
                                "email": "[email protected]"
                            }
                        ],
                        "subject": "28",
                        "sentAt": "2024-11-22T05:03:33Z",
                        "hasAttachment": false,
                        "preview": "--  Hello Signature 2",
                        "header:X-MEETING-UID:asText": null
                    }
                ],
                "notFound": [
                    "0d4d3d70-c970-11ee-9073-63121fc97643",
                    "6603a830-c9ea-11ee-bfc8-8baa82bb865e",
                    "642a3370-c9cd-11ee-8e22-3b54566f9f90",
                    "a48f37b0-d81b-11ee-9863-a368905d3405",
                    "365c4150-c9ea-11ee-bfc8-8baa82bb865e",
                    "c93de160-c970-11ee-9073-63121fc97643",
                    "541d5ad0-c9a9-11ee-9073-63121fc97643",
                    "441861f0-da0e-11ee-9863-a368905d3405",
                    "86ded7f0-c972-11ee-a89a-a70d425dc805",
                    "858b4ae0-c9eb-11ee-b31c-939afe0b6132",
                    "f5890ba0-d81b-11ee-a7f2-0302da82fa0d",
                    "a4dbc8b0-c983-11ee-a89a-a70d425dc805"
                ]
            },
            "c1"
        ]
    ]
}
cause-sort

Solution

  • Fix the sortEmailsById function to always return a list of emails from Email/get sorted by Email/query regardless of the number of elements in Email/query.
  List<Email> sortEmailsById(List<Id> referenceIds) {
    final indexMap = {
      for (var i = 0; i < referenceIds.length; i++)
        referenceIds[i]: i
    };

    sort((email1, email2) {
      final indexEmail1 = indexMap[email1.id!.id] ?? double.maxFinite;
      final indexEmail2 = indexMap[email2.id!.id] ?? double.maxFinite;

      return indexEmail1.compareTo(indexEmail2);
    });

    return this;
  }

Resolved

  • Passed unit test for sortEmailsById function

Copy link

This PR has been deployed to https://linagora.github.io/tmail-flutter/3299.

@chibenwa
Copy link
Member

Ok, we encountered that because the probe see a very high volume of traffic.

Thus the email index is way more subject to being screwed up.

Regular users should not be affected.

Thanks for the quick reaction and for having a look @hoangdat @dab246 !

hoangdat
hoangdat previously approved these changes Nov 24, 2024
Copy link
Member

@hoangdat hoangdat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rebase

@dab246
Copy link
Member Author

dab246 commented Nov 25, 2024

Please rebase

Please use Squash and merge. Thanks @hoangdat

@dab246 dab246 requested a review from hoangdat November 25, 2024 07:21
@hoangdat hoangdat merged commit d339dd8 into master Nov 25, 2024
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants