~aleteoryx/muditaos

2e8d3dd720f22763b947ce088b0caf284ec78ef3 — Lucjan Bryndza 3 years ago 4ee8672
[MOS-85] Fix contact that has no Last name

If a contact contains only first name I would expect it to appear on the
list sorted alphabetically according to the letters.

Signed-off-by: Lucjan Bryndza <lucjan.bryndza@mudita.com>
M module-apps/application-phonebook/widgets/PhonebookItem.cpp => module-apps/application-phonebook/widgets/PhonebookItem.cpp +6 -2
@@ 52,10 52,14 @@ namespace gui
            // If contact is favorite return proper UTF string
            return utils::translate("app_phonebook_favourite_contacts_title");
        }
        else {
            // else return first surname contact letter
        else if (!contact->alternativeName.empty()) {
            // else if return first surname contact letter
            return contact->alternativeName.substr(0, 1);
        }
        else {
            // else return first firstname contact letter
            return contact->primaryName.substr(0, 1);
        }
    }

    void PhonebookItem::markFavourite(bool val)

M module-db/Tables/ContactsTable.cpp => module-db/Tables/ContactsTable.cpp +8 -4
@@ 1,4 1,4 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "ContactsTable.hpp"


@@ 170,7 170,11 @@ std::string ContactsTable::GetSortedByNameQueryString(ContactQuerySection sectio
                " , UPPER(contact_name.name_alternative) ; ";
    }
    else if (section == ContactQuerySection::Mixed) {
        query = " SELECT contacts._id, contact_name.name_alternative  FROM contacts "
        query = " SELECT contacts._id, "
                " CASE WHEN contact_name.name_alternative != ''"
                " THEN contact_name.name_alternative ELSE contact_name.name_primary"
                " END AS name_all"
                " FROM contacts "
                " INNER JOIN contact_name ON contact_name.contact_id == contacts._id "
                " LEFT JOIN contact_match_groups ON contact_match_groups.contact_id == contacts._id AND "
                " contact_match_groups.group_id = 1 "


@@ 179,8 183,8 @@ std::string ContactsTable::GetSortedByNameQueryString(ContactQuerySection sectio
                "    FROM contact_match_groups cmg, contact_groups cg "
                "    WHERE cmg.group_id = cg._id "
                "       AND cg.name = 'Temporary' ) "
                " ORDER BY  (contact_name.name_alternative ='') ASC "
                " , UPPER(contact_name.name_alternative) ; ";
                " ORDER BY  (name_all ='') ASC "
                " , UPPER(name_all) ; ";
    }
    return query;
}