Commit 4e39aa5c authored by Andreas Traczyk's avatar Andreas Traczyk Committed by Adrien Béraud

fix: check out_of_range exceptions from ContactModel::getContact

Change-Id: Ibc82dc1fe85bb9b331e39639dd874afb89b616c9
Reviewed-by: Kateryna Kostiuk's avatarKateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com>
parent c8035c6f
......@@ -464,12 +464,18 @@ NSInteger const REQUEST_SEG = 1;
[photoView setImage: image];
NSView* presenceView = [result viewWithTag:PRESENCE_TAG];
auto contact = convModel_->owner.contactModel->getContact(conversation.participants[0]);
if (contact.isPresent) {
[presenceView setHidden:NO];
} else {
[presenceView setHidden:YES];
[presenceView setHidden:YES];
if (!conversation.participants.empty()){
try {
auto contact = convModel_->owner.contactModel->getContact(conversation.participants[0]);
if (contact.isPresent) {
[presenceView setHidden:NO];
}
} catch (std::out_of_range& e) {
NSLog(@"viewForTableColumn: getContact - out of range");
}
}
NSButton* addContactButton = [result viewWithTag:ADD_BUTTON_TAG];
NSButton* refuseContactButton = [result viewWithTag:REFUSE_BUTTON_TAG];
NSButton* blockContactButton = [result viewWithTag:BLOCK_BUTTON_TAG];
......
......@@ -36,14 +36,19 @@
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()) {
contact.registeredName.erase(std::remove(contact.registeredName.begin(), contact.registeredName.end(), '\n'), contact.registeredName.end());
contact.registeredName.erase(std::remove(contact.registeredName.begin(), contact.registeredName.end(), '\r'), contact.registeredName.end());
return [@(contact.registeredName.c_str()) removeEmptyLinesAtBorders];
try {
auto contact = model.owner.contactModel->getContact(conv.participants[0]);
if (!contact.registeredName.empty()) {
contact.registeredName.erase(std::remove(contact.registeredName.begin(), contact.registeredName.end(), '\n'), contact.registeredName.end());
contact.registeredName.erase(std::remove(contact.registeredName.begin(), contact.registeredName.end(), '\r'), contact.registeredName.end());
return [@(contact.registeredName.c_str()) removeEmptyLinesAtBorders];
}
else {
return [@(contact.profileInfo.uri.c_str()) removeEmptyLinesAtBorders];
}
} catch (std::out_of_range& e) {
NSLog(@"bestIDForConversation: getContact - out of range");
}
else
return [@(contact.profileInfo.uri.c_str()) removeEmptyLinesAtBorders];
}
static inline NSString* bestIDForAccount(const lrc::api::account::Info& account)
......@@ -80,17 +85,21 @@ static inline NSString* bestNameForContact(const lrc::api::contact::Info& contac
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 bestIDForConversation(conv, model);
}
auto alias = contact.profileInfo.alias;
alias.erase(std::remove(alias.begin(), alias.end(), '\n'), alias.end());
alias.erase(std::remove(alias.begin(), alias.end(), '\r'), alias.end());
if(alias.length() == 0) {
return bestIDForConversation(conv, model);
try {
auto contact = model.owner.contactModel->getContact(conv.participants[0]);
if (contact.profileInfo.alias.empty()) {
return bestIDForConversation(conv, model);
}
auto alias = contact.profileInfo.alias;
alias.erase(std::remove(alias.begin(), alias.end(), '\n'), alias.end());
alias.erase(std::remove(alias.begin(), alias.end(), '\r'), alias.end());
if(alias.length() == 0) {
return bestIDForConversation(conv, model);
}
return @(alias.c_str());
} catch (std::out_of_range& e) {
NSLog(@"bestNameForConversation: getContact - out of range");
}
return @(alias.c_str());
}
static inline lrc::api::profile::Type profileType(const lrc::api::conversation::Info& conv, const lrc::api::ConversationModel& model)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment