blob: e6ba40f59df659bd373b22776f75b6956f788287 [file] [log] [blame]
/*
* Copyright (C) 2017 Savoir-faire Linux Inc.
* Author: Anthony LĂ©onard <anthony.leonard@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#import <Foundation/Foundation.h>
#import <api/conversation.h>
#import <api/conversationmodel.h>
#import <api/account.h>
#import <api/contactmodel.h>
#import <api/contact.h>
#import <map>
static inline NSString* bestIDForConversation(const lrc::api::conversation::Info& conv, const lrc::api::ConversationModel& model)
{
auto contact = model.owner.contactModel->getContact(conv.participants[0]);
if (!contact.registeredName.empty())
return @(contact.registeredName.c_str());
else
return @(contact.profileInfo.uri.c_str());
}
static inline NSString* bestNameForConversation(const lrc::api::conversation::Info& conv, const lrc::api::ConversationModel& model)
{
auto contact = model.owner.contactModel->getContact(conv.participants[0]);
if (!contact.profileInfo.alias.empty())
return @(contact.profileInfo.alias.c_str());
else
return bestIDForConversation(conv, model);
}
/**
* This function return an iterator pointing to a Conversation::Info in ConversationModel given its uid. If not found
* the iterator is invalid thus it needs to be checked by caller.
* @param uid UID of conversation being searched
* @param model ConversationModel in which to do the lookup
* @return iterator pointing to corresponding Conversation if any. Points to past-the-end element otherwise.
*/
static inline lrc::api::ConversationModel::ConversationQueue::const_iterator getConversationFromUid(const std::string& uid, const lrc::api::ConversationModel& model) {
return std::find_if(model.allFilteredConversations().begin(), model.allFilteredConversations().end(),
[&] (const lrc::api::conversation::Info& conv) {
return uid == conv.uid;
});
}