Commit e486b3c6 authored by Kateryna Kostiuk's avatar Kateryna Kostiuk Committed by Kateryna Kostiuk

swarm: use peersForConversation

Change-Id: I3ad4575ddf9aacca1618e37af211947a5d5f55be
parent 98827a19
......@@ -216,7 +216,7 @@ NSInteger const MAXIMUM_TABLE_SIZE = 240;
[self.delegate joinCall: callID];
}
} else if (table == contactsView) {
auto uid = conv.participants.front();
auto uid = convModel->peersForConversation(conv.uid)[0];
if ([self.delegate respondsToSelector: @selector(joinCall:)]) {
[self.delegate callToContact:uid convUID: convID];
}
......@@ -373,7 +373,7 @@ NSInteger const MAXIMUM_TABLE_SIZE = 240;
[photoView setHidden: NO];
[photoView setImage: image];
try {
auto contact = convModel->owner.contactModel->getContact(conversationInfo.participants[0]);
auto contact = convModel->owner.contactModel->getContact(convModel->peersForConversation(conversationInfo.uid)[0]);
if (contact.isPresent) {
[presenceView setHidden:NO];
}
......
......@@ -270,7 +270,7 @@ NSInteger const SEND_PANEL_MAX_HEIGHT = 120;
[titleTopConstraint setActive:!hideBestId];
auto accountType = convModel_->owner.profileInfo.type;
try {
[addContactButton setHidden:((convModel_->owner.contactModel->getContact(conv->participants[0]).profileInfo.type != lrc::api::profile::Type::TEMPORARY) || accountType == lrc::api::profile::Type::SIP)];
[addContactButton setHidden:((convModel_->owner.contactModel->getContact(convModel_->peersForConversation(conv->uid)[0]).profileInfo.type != lrc::api::profile::Type::TEMPORARY) || accountType == lrc::api::profile::Type::SIP)];
} catch (std::out_of_range& e) {
[addContactButton setHidden: true];
NSLog(@"contact out of range");
......
......@@ -316,7 +316,6 @@ CVPixelBufferRef pixelBufferPreview;
return;
}
lrc::api::conversation::Info& conv = *convOpt;
auto& contact = accountInfo_->contactModel->getContact(conv.participants[0]);
[contactPhoto setImage: [self getContactImageOfSize:120.0 withDefaultAvatar:YES]];
[self.delegate conversationInfoUpdatedFor:convUid_];
[self setBackground];
......@@ -703,7 +702,7 @@ CVPixelBufferRef pixelBufferPreview;
QVariant photo = imgManip.conversationPhoto(conv, *accountInfo_, QSize(size, size), NO);
return QtMac::toNSImage(qvariant_cast<QPixmap>(photo));
}
auto contact = accountInfo_->contactModel->getContact(conv.participants[0]);
auto contact = accountInfo_->contactModel->getContact(accountInfo_->conversationModel->peersForConversation(conv.uid)[0]);
NSData *imageData = [[NSData alloc] initWithBase64EncodedString:contact.profileInfo.avatar.toNSString() options:NSDataBase64DecodingIgnoreUnknownCharacters];
return [[NSImage alloc] initWithData:imageData];
}
......@@ -1075,7 +1074,7 @@ CVPixelBufferRef pixelBufferPreview;
if (conv.uid.isEmpty() || conv.participants.empty()) {
return;
}
auto& contact = accountInfo_->contactModel->getContact(conv.participants[0]);
auto& contact = accountInfo_->contactModel->getContact(accountInfo_->conversationModel->peersForConversation(conv.uid)[0]);
if (contact.profileInfo.type == lrc::api::profile::Type::PENDING) {
accountInfo_->conversationModel->makePermanent(convUid_);
}
......
......@@ -54,7 +54,7 @@
@synthesize avModel;
@synthesize accountModel;
-(id) initWithWindowNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil accountModel:( lrc::api::NewAccountModel*) accountModel avModel: (lrc::api::AVModel*)avModel {
-(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil accountModel:( lrc::api::NewAccountModel*) accountModel avModel: (lrc::api::AVModel*)avModel {
if (self = [self initWithNibName:nibNameOrNil bundle:nibBundleOrNil])
{
self.accountModel = accountModel;
......
......@@ -413,7 +413,7 @@ typedef NS_ENUM(NSInteger, MessageSequencing) {
[conversationView.layer addAnimation:fadeIn forKey:fadeIn.keyPath];
conversationView.alphaValue = 1;
try {
[sendFileButton setEnabled:(convModel_->owner.contactModel->getContact(conv->participants[0]).profileInfo.type != lrc::api::profile::Type::SIP)];
[sendFileButton setEnabled:(convModel_->owner.contactModel->getContact(convModel_->peersForConversation(conv->uid)[0]).profileInfo.type != lrc::api::profile::Type::SIP)];
} catch (std::out_of_range& e) {
NSLog(@"contact out of range");
}
......@@ -866,7 +866,7 @@ typedef NS_ENUM(NSInteger, MessageSequencing) {
bool shouldDisplayAvatar = (sequence != MIDDLE_IN_SEQUENCE && sequence != FIRST_WITHOUT_TIME
&& sequence != FIRST_WITH_TIME) ? YES : NO;
[result.photoView setHidden:!shouldDisplayAvatar];
BOOL showIndicator = convModel_->isLastDisplayed(convUid_, it->first, conv->participants.front());
BOOL showIndicator = convModel_->isLastDisplayed(convUid_, it->first, convModel_->peersForConversation(conv->uid)[0]);
[result.readIndicator setHidden: !showIndicator];
@autoreleasepool {
auto& imageManip = reinterpret_cast<Interfaces::ImageManipulationDelegate&>(GlobalInstances::pixmapManipulator());
......
......@@ -256,7 +256,7 @@ typedef NS_ENUM(NSInteger, ViewState) {
if (!convOpt.has_value()) { return; }
lrc::api::conversation::Info& convInfo = *convOpt;
try {
if (accInfo->contactModel->getContact(convInfo.participants[0]).profileInfo.type == lrc::api::profile::Type::PENDING)
if (accInfo->contactModel->getContact(convModel->peersForConversation(convInfo.uid)[0]).profileInfo.type == lrc::api::profile::Type::PENDING)
[smartViewVC selectPendingList];
else
[smartViewVC selectConversationList];
......@@ -295,7 +295,7 @@ typedef NS_ENUM(NSInteger, ViewState) {
return;
}
try {
if (accInfo->contactModel->getContact(convInfo.participants[0]).profileInfo.type == lrc::api::profile::Type::PENDING)
if (accInfo->contactModel->getContact(convModel->peersForConversation(convInfo.uid)[0]).profileInfo.type == lrc::api::profile::Type::PENDING)
[smartViewVC selectPendingList];
else
[smartViewVC selectConversationList];
......@@ -692,7 +692,7 @@ typedef NS_ENUM(NSInteger, ViewState) {
return;
}
lrc::api::conversation::Info& convInfo = *convOpt;
if (accInfo.contactModel->getContact(convInfo.participants[0]).profileInfo.type == lrc::api::profile::Type::PENDING) {
if (accInfo.contactModel->getContact(accInfo.conversationModel->peersForConversation(convInfo.uid)[0]).profileInfo.type == lrc::api::profile::Type::PENDING) {
[smartViewVC selectPendingList];
}
else {
......
......@@ -301,7 +301,7 @@ NSInteger const REQUEST_SEG = 1;
});
newConversationConnection_ = QObject::connect(convModel_, &lrc::api::ConversationModel::newConversation,
[self] (const QString& convUid) {
[self reloadData];
[smartView noteNumberOfRowsChanged];
[self updateConversationForNewContact:convUid.toNSString()];
});
conversationRemovedConnection_ = QObject::connect(convModel_, &lrc::api::ConversationModel::conversationRemoved,
......@@ -540,7 +540,7 @@ NSInteger const REQUEST_SEG = 1;
NSView* presenceView = [result viewWithTag:PRESENCE_TAG];
[presenceView setHidden:YES];
try {
auto contact = convModel_->owner.contactModel->getContact(conversation.participants.front());
auto contact = convModel_->owner.contactModel->getContact(convModel_->peersForConversation(conversation.uid)[0]);
if (contact.isPresent) {
[presenceView setHidden:NO];
}
......@@ -680,8 +680,9 @@ NSInteger const REQUEST_SEG = 1;
if (!convOpt.has_value())
return;
lrc::api::conversation::Info& conversation = *convOpt;
if (conversation.participants.size() > 0) {
if (conversation.participants[0] == selectedUid_) {
auto& peers = convModel_->peersForConversation(conversation.uid);
if (peers.size() == 1) {
if (peers[0] == selectedUid_) {
selectedUid_ = uid;
convModel_->selectConversation(uid);
}
......@@ -724,8 +725,12 @@ NSInteger const REQUEST_SEG = 1;
if (selectedUid_ == uid) {
return YES;
}
auto& peers = convModel_->peersForConversation(conversation.uid);
if (peers.size() != 1) {
return NO;
}
try {
auto contact = convModel_->owner.contactModel->getContact(conversation.participants[0]);
auto contact = convModel_->owner.contactModel->getContact(peers[0]);
if ((contact.profileInfo.uri.isEmpty() && contact.profileInfo.type != lrc::api::profile::Type::SIP) || contact.profileInfo.type == lrc::api::profile::Type::INVALID) {
return YES;
}
......@@ -788,9 +793,12 @@ NSInteger const REQUEST_SEG = 1;
if (!convOpt.has_value())
return nil;
lrc::api::conversation::Info& conversation = *convOpt;
auto& peers = convModel_->peersForConversation(conversation.uid);
if (peers.size() != 1) {
return nil;
}
try {
auto contact = convModel_->owner.contactModel->getContact(conversation.participants[0]);
auto contact = convModel_->owner.contactModel->getContact(peers[0]);
if (contact.profileInfo.type == lrc::api::profile::Type::INVALID) {
return nil;
}
......
......@@ -37,6 +37,7 @@
#import <api/conversation.h>
#import <api/account.h>
#import <api/contactmodel.h>
#import <api/conversationmodel.h>
#import <api/contact.h>
#import <api/profile.h>
......@@ -129,7 +130,8 @@ namespace Interfaces {
Q_UNUSED(displayPresence)
try {
auto contact = accountInfo.contactModel->getContact(conversation.participants[0]);
auto contact = accountInfo.contactModel->getContact(accountInfo.conversationModel->peersForConversation(conversation.uid)[0]);
// auto contact = accountInfo.contactModel->getContact(accountInfo.conversationModel.peersForConversation(conversation.uid)[0]);
auto& avatar = contact.profileInfo.avatar;
if (!avatar.isEmpty()) {
QPixmap pxm;
......
......@@ -35,10 +35,10 @@
#import <QtCore/QDir>
#import <qapplication.h>
static inline NSString* bestIDForConversation(const lrc::api::conversation::Info& conv, const lrc::api::ConversationModel& model)
static inline NSString* bestIDForConversation(const lrc::api::conversation::Info& conv, lrc::api::ConversationModel& model)
{
try {
auto contact = model.owner.contactModel->getContact(conv.participants[0]);
auto contact = model.owner.contactModel->getContact(model.peersForConversation(conv.uid)[0]);
auto name = contact.registeredName.trimmed().replace("\r","").replace("\n","");
if (!name.isEmpty()) {
return [name.toNSString() removeEmptyLinesAtBorders];
......@@ -86,10 +86,10 @@ static inline NSString* bestNameForContact(const lrc::api::contact::Info& contac
return contact.profileInfo.alias.toNSString();
}
static inline NSString* bestNameForConversation(const lrc::api::conversation::Info& conv, const lrc::api::ConversationModel& model)
static inline NSString* bestNameForConversation(const lrc::api::conversation::Info& conv, lrc::api::ConversationModel& model)
{
try {
auto contact = model.owner.contactModel->getContact(conv.participants[0]);
auto contact = model.owner.contactModel->getContact(model.peersForConversation(conv.uid)[0]);
if (contact.profileInfo.alias.isEmpty()) {
return bestIDForConversation(conv, model);
}
......@@ -111,13 +111,13 @@ static inline NSString* defaultRingtonePath() {
return [ringtonesDir.path().toNSString() stringByAppendingString:@"/default.opus"];
}
static inline lrc::api::profile::Type profileType(const lrc::api::conversation::Info& conv, const lrc::api::ConversationModel& model)
static inline lrc::api::profile::Type profileType(const lrc::api::conversation::Info& conv, lrc::api::ConversationModel& model)
{
@try {
auto contact = model.owner.contactModel->getContact(conv.participants[0]);
try {
auto& peers = model.peersForConversation(conv.uid);
const auto contact = model.owner.contactModel->getContact(peers[0]);
return contact.profileInfo.type;
}
@catch (NSException *exception) {
} catch (std::out_of_range& e) {
lrc::api::profile::Type::INVALID;
}
}
......
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