blob: d496e562f8daa576294be91ddbe5a5711841e757 [file] [log] [blame]
Olivier Soldanod4311552017-11-20 15:09:53 -05001/*
2 * Copyright (C) 2017 Savoir-faire Linux Inc.
3 * Author: Anthony LĂ©onard <anthony.leonard@savoirfairelinux.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20#import <Foundation/Foundation.h>
21#import <api/conversation.h>
22#import <api/conversationmodel.h>
23#import <api/account.h>
24#import <api/contactmodel.h>
25#import <api/contact.h>
26
27static inline NSString* bestIDForConversation(const lrc::api::conversation::Info& conv, const lrc::api::ConversationModel& model)
28{
29 auto contact = model.owner.contactModel->getContact(conv.participants[0]);
30 if (!contact.registeredName.empty())
31 return @(contact.registeredName.c_str());
32 else
33 return @(contact.profileInfo.uri.c_str());
34}
35
36static inline NSString* bestNameForConversation(const lrc::api::conversation::Info& conv, const lrc::api::ConversationModel& model)
37{
38 auto contact = model.owner.contactModel->getContact(conv.participants[0]);
39 if (!contact.profileInfo.alias.empty())
40 return @(contact.profileInfo.alias.c_str());
41 else
42 return bestIDForConversation(conv, model);
43}