Commit 6f81975f authored by Anthony Léonard's avatar Anthony Léonard

deduplicate code retrieving conversation from uid

This code had multiple occurences throughout the client. It is now an
inlinable helper function in utils.h header.

Change-Id: Ic9ba45e4622338d1c40399e58eb969d9f99faa6a
Reviewed-by: default avatarOlivier Soldano <olivier.soldano@savoirfairelinux.com>
parent a9d7c8e1
......@@ -95,7 +95,7 @@
auto& convQueue = convModel_->allFilteredConversations();
auto it = std::find_if(convQueue.begin(), convQueue.end(), [self](const lrc::api::conversation::Info& conv) {return conv.uid == convUid_;});
auto it = getConversationFromUid(convUid_, *convModel_);
if (it != convQueue.end())
cachedConv_ = &(*it);
......
......@@ -45,6 +45,7 @@
#import "BrokerVC.h"
#import "views/IconButton.h"
#import "views/CallLayer.h"
#import "utils.h"
@interface RendererConnectionsHolder : NSObject
......@@ -292,10 +293,7 @@
[ringingPanel setHidden:NO];
[controlsPanel setHidden:YES];
[headerContainer setHidden:YES];
auto it = std::find_if(convModel->allFilteredConversations().begin(), convModel->allFilteredConversations().end(),
[self] (const lrc::api::conversation::Info& conv) {
return convUid_ == conv.uid;
});
auto it = getConversationFromUid(convUid_, *convModel);
if (it != convModel->allFilteredConversations().end()) {
auto& imgManip = reinterpret_cast<Interfaces::ImageManipulationDelegate&>(GlobalInstances::pixmapManipulator());
QVariant photo = imgManip.conversationPhoto(*it, *accountInfo_);
......
......@@ -31,6 +31,7 @@
#import "views/MessageBubbleView.h"
#import "INDSequentialTextSelectionManager.h"
#import "delegates/ImageManipulationDelegate.h"
#import "utils.h"
@interface MessagesVC () <NSTableViewDelegate, NSTableViewDataSource> {
......@@ -64,7 +65,7 @@
auto& convQueue = convModel_->allFilteredConversations();
auto it = std::find_if(convQueue.begin(), convQueue.end(), [self](const lrc::api::conversation::Info& conv) {return conv.uid == convUid_;});
auto it = getConversationFromUid(convUid_, *convModel_);
if (it != convQueue.end())
cachedConv_ = &(*it);
......
......@@ -118,10 +118,7 @@ NSInteger const PRESENCE_TAG = 800;
[smartView reloadData];
if (!selectedUid_.empty() && model_ != nil) {
auto it = std::find_if(model_->allFilteredConversations().begin(), model_->allFilteredConversations().end(),
[self] (const lrc::api::conversation::Info& conv) {
return selectedUid_ == conv.uid;
});
auto it = getConversationFromUid(selectedUid_, *model_);
if (it != model_->allFilteredConversations().end()) {
NSIndexSet* indexSet = [NSIndexSet indexSetWithIndex:(it - model_->allFilteredConversations().begin())];
[smartView selectRowIndexes:indexSet byExtendingSelection:NO];
......@@ -177,10 +174,7 @@ NSInteger const PRESENCE_TAG = 800;
[self setConversationModel:model];
if (model_ != nil) {
auto it = std::find_if(model_->allFilteredConversations().begin(), model_->allFilteredConversations().end(),
[self] (const lrc::api::conversation::Info& conv) {
return selectedUid_ == conv.uid;
});
auto it = getConversationFromUid(selectedUid_, *model_);
if (it != model_->allFilteredConversations().end()) {
NSIndexSet* indexSet = [NSIndexSet indexSetWithIndex:(it - model_->allFilteredConversations().begin())];
[smartView selectRowIndexes:indexSet byExtendingSelection:NO];
......
......@@ -23,6 +23,7 @@
#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)
{
......@@ -41,3 +42,17 @@ static inline NSString* bestNameForConversation(const lrc::api::conversation::In
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;
});
}
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