Commit ab499f4b authored by Kateryna Kostiuk's avatar Kateryna Kostiuk Committed by Andreas Traczyk

fix: update conversation when account deleted

Update main ring window when an account is removed.

Change-Id: I7ae06098aec450c1497aff4e6bca8ea2b638402d
Reviewed-by: Andreas Traczyk's avatarAndreas Traczyk <andreas.traczyk@savoirfairelinux.com>
parent 46d53af3
......@@ -35,6 +35,7 @@ namespace lrc {
@property const lrc::api::account::Info& savedAccount;
-(void) clearSelectedAccount;
- (id) initWithAccountModel:(const lrc::api::NewAccountModel*) accMdl;
@end
......@@ -48,15 +48,32 @@ NSString* const savedUserAccountKey = @"savedUserSelectedAccountKey";
return [[NSUserDefaults standardUserDefaults] stringForKey:savedUserAccountKey];
}
- (void) clearSelectedAccount
{
[[NSUserDefaults standardUserDefaults] setObject:nil forKey:savedUserAccountKey];
}
- (const lrc::api::account::Info&) savedAccount
{
NSString* savedAccountId = [self getSavedAccountId];
if (savedAccountId == nil) {
auto accId = accMdl_->getAccountList().front();
[self saveAccountWithId:@(accId.c_str())];
return accMdl_->getAccountInfo(accId);
} else
return accMdl_->getAccountInfo(std::string([savedAccountId UTF8String]));
NSException* noAccEx = [NSException
exceptionWithName:@"NoAccountSavedException"
reason:@"No saved account"
userInfo:nil];
@throw noAccEx;
} else {
try {
return accMdl_->getAccountInfo(std::string([savedAccountId UTF8String]));
} catch (std::out_of_range& e) {
NSException* outOfRangeEx = [NSException
exceptionWithName:@"outofrange"
reason:@"out of range"
userInfo:nil];
@throw outOfRangeEx;
}
}
}
- (void) setSavedAccount:(const lrc::api::account::Info&) acc
......
......@@ -93,6 +93,8 @@ NSInteger const TAG_NAME = 200;
NSInteger const TAG_STATUS = 300;
NSInteger const TAG_TYPE = 400;
QMetaObject::Connection accountChangedConnection, selectedAccountChangedConnection, accountTypeChangedConnection;
- (void)awakeFromNib
{
......@@ -105,7 +107,10 @@ NSInteger const TAG_TYPE = 400;
[accountsListView bind:@"sortDescriptors" toObject:treeController withKeyPath:@"sortDescriptors" options:nil];
[accountsListView bind:@"selectionIndexPaths" toObject:treeController withKeyPath:@"selectionIndexPaths" options:nil];
QObject::connect(&AccountModel::instance(),
QObject::disconnect(accountChangedConnection);
QObject::disconnect(selectedAccountChangedConnection);
accountChangedConnection = QObject::connect(&AccountModel::instance(),
&QAbstractItemModel::dataChanged,
[=](const QModelIndex &topLeft, const QModelIndex &bottomRight) {
[accountsListView reloadDataForRowIndexes:
......@@ -113,7 +118,7 @@ NSInteger const TAG_TYPE = 400;
columnIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, accountsListView.tableColumns.count)]];
});
QObject::connect(AccountModel::instance().selectionModel(),
selectedAccountChangedConnection = QObject::connect(AccountModel::instance().selectionModel(),
&QItemSelectionModel::currentChanged,
[=](const QModelIndex &current, const QModelIndex &previous) {
[accountDetailsView setHidden:!current.isValid()];
......@@ -124,14 +129,14 @@ NSInteger const TAG_TYPE = 400;
[treeController setSelectionQModelIndex:current];
});
AccountModel::instance().selectionModel()->clearCurrentIndex();
QModelIndex qProtocolIdx = AccountModel::instance().protocolModel()->selectionModel()->currentIndex();
[self.protocolList addItemWithTitle:
AccountModel::instance().protocolModel()->data(qProtocolIdx, Qt::DisplayRole).toString().toNSString()];
QObject::connect(AccountModel::instance().protocolModel()->selectionModel(),
QObject::disconnect(accountTypeChangedConnection);
accountTypeChangedConnection = QObject::connect(AccountModel::instance().protocolModel()->selectionModel(),
&QItemSelectionModel::currentChanged,
[=](const QModelIndex &current, const QModelIndex &previous) {
if (!current.isValid()) {
......
......@@ -77,17 +77,34 @@ NSMenuItem* selectedMenuItem;
QObject::connect(accMdl_,
&lrc::api::NewAccountModel::accountAdded,
[self]{
[self] (const std::string& accountID) {
[self update];
@try {
auto& account = [self selectedAccount];
[delegate selectAccount:account];
}
@catch (NSException * e) {
NSLog(@"account selection failed");
}
});
QObject::connect(accMdl_,
&lrc::api::NewAccountModel::accountRemoved,
[self]{
[self] (const std::string& accountID) {
if ([self selectedAccount].id.compare(accountID) == 0) {
[accountSelectionManager_ clearSelectedAccount];
}
@try {
auto& account = [self selectedAccount];
[delegate selectAccount:account];
}
@catch (NSException * e) {
[delegate allAccountsDeleted];
}
[self update];
});
QObject::connect(accMdl_,
&lrc::api::NewAccountModel::profileUpdated,
[self]{
[self] (const std::string& accountID) {
[self update];
});
}
......@@ -96,10 +113,13 @@ NSMenuItem* selectedMenuItem;
{
try {
return [accountSelectionManager_ savedAccount];
} catch (std::out_of_range& e) { // Is thrown when no account are saved yet
} catch (NSException *ex) {
auto accountList = accMdl_->getAccountList();
if (!accountList.empty()) {
const auto& fallbackAccount = accMdl_->getAccountInfo(accountList.at(0));
if (accountList.size() == 1) {
[accountSelectionManager_ setSavedAccount:fallbackAccount];
}
return fallbackAccount;
} else {
NSException* noAccEx = [NSException
......@@ -213,7 +233,6 @@ NSMenuItem* selectedMenuItem;
return;
}
[self updateMenu];
[self updatePhoto];
[self setPopUpButtonSelection];
}
......
......@@ -34,10 +34,14 @@ namespace lrc {
* KVO to show or hide some UI elements in RingWindow:
* - Share button
* - QRCode
* - RingID field
* - Explanatory label
*/
@property (nonatomic) BOOL hideRingID;
@property (nonatomic) BOOL notRingAccount;
/**
* KVO to show or hide ringIDLabel
*/
@property (nonatomic) BOOL isSIPAccount;
- (IBAction)openPreferences:(id)sender;
......@@ -69,4 +73,9 @@ namespace lrc {
*/
-(void) listTypeChanged;
/**
* Triggered by Choosen account VC when all accounts deleted
*/
-(void)allAccountsDeleted;
@end
......@@ -63,6 +63,7 @@
__unsafe_unretained IBOutlet NSLayoutConstraint* centerYQRCodeConstraint;
__unsafe_unretained IBOutlet NSLayoutConstraint* centerYWelcomeContainerConstraint;
IBOutlet NSLayoutConstraint* ringLabelTrailingConstraint;
__unsafe_unretained IBOutlet NSView* welcomeContainer;
__unsafe_unretained IBOutlet NSView* callView;
__unsafe_unretained IBOutlet NSTextField* ringIDLabel;
......@@ -186,10 +187,13 @@ NSString* const kChangeAccountToolBarItemIdentifier = @"ChangeAccountToolBarIte
[ringIDLabel setStringValue:@""];
if(account.profileInfo.type != lrc::api::profile::Type::RING) {
self.hideRingID = YES;
self.notRingAccount = YES;
self.isSIPAccount = YES;
return;
}
self.hideRingID = NO;
self.isSIPAccount = NO;
self.notRingAccount = NO;
[ringLabelTrailingConstraint setActive:YES];
auto& registeredName = account.registeredName;
auto& ringID = account.profileInfo.uri;
NSString* uriToDisplay = nullptr;
......@@ -203,7 +207,9 @@ NSString* const kChangeAccountToolBarItemIdentifier = @"ChangeAccountToolBarIte
}
@catch (NSException *ex) {
NSLog(@"Caught exception %@: %@", [ex name], [ex reason]);
self.hideRingID = NO;
self.notRingAccount = YES;
self.isSIPAccount = NO;
[ringLabelTrailingConstraint setActive:NO];
[ringIDLabel setStringValue:NSLocalizedString(@"No account available", @"Displayed as RingID when no accounts are available for selection")];
}
}
......@@ -380,6 +386,14 @@ NSString* const kChangeAccountToolBarItemIdentifier = @"ChangeAccountToolBarIte
[self updateRingID];
}
-(void)allAccountsDeleted
{
[smartViewVC clearConversationModel];
[currentCallVC hideWithAnimation:false];
[conversationVC hideWithAnimation:false];
[self updateRingID];
}
-(void)rightPanelClosed
{
[smartViewVC deselect];
......
......@@ -60,5 +60,9 @@ namespace lrc {
* Change list selection to Pending
*/
-(void)selectPendingList;
/**
* clear conversation when account list is empty
*/
-(void) clearConversationModel;
@end
......@@ -120,6 +120,8 @@ NSInteger const REQUEST_SEG = 1;
row = [smartView selectedRow];
else
return;
if (model_ == nil)
return;
auto conv = model_->filteredConversation(row);
model_->placeCall(conv.uid);
......@@ -129,6 +131,8 @@ NSInteger const REQUEST_SEG = 1;
{
NSLog(@"reload");
[smartView deselectAll:nil];
if (model_ == nil)
return;
if (!model_->owner.contactModel->hasPendingRequests()) {
if (currentFilterType == lrc::api::profile::Type::PENDING) {
......@@ -266,6 +270,12 @@ NSInteger const REQUEST_SEG = 1;
[smartView deselectAll:nil];
}
-(void) clearConversationModel {
model_ = nil;
[self deselect];
[smartView reloadData];
}
- (IBAction) listTypeChanged:(id)sender
{
NSInteger selectedItem = [sender selectedSegment];
......@@ -331,6 +341,8 @@ NSInteger const REQUEST_SEG = 1;
if (row == -1)
return;
if (model_ == nil)
return;
auto uid = model_->filteredConversation(row).uid;
if (selectedUid_ != uid) {
......@@ -427,6 +439,8 @@ NSInteger const REQUEST_SEG = 1;
if (row == -1)
return;
if (model_ == nil)
return;
auto conv = model_->filteredConversation(row);
auto& callId = conv.callId;
......@@ -451,6 +465,8 @@ NSInteger const REQUEST_SEG = 1;
- (void) processSearchFieldInput
{
if (model_ == nil)
return;
model_->setFilter(std::string([[searchField stringValue] UTF8String]));
}
......@@ -484,6 +500,10 @@ NSInteger const REQUEST_SEG = 1;
if (commandSelector != @selector(insertNewline:) || [[searchField stringValue] isEqual:@""]) {
return NO;
}
if (model_ == nil) {
[self displayErrorModalWithTitle:NSLocalizedString(@"No account available", @"Displayed as RingID when no accounts are available for selection") WithMessage:NSLocalizedString(@"Navigate to preferences to create a new account", @"Allert message when no accounts are available")];
return NO;
}
if (model_->allFilteredConversations().size() <= 0) {
return YES;
}
......@@ -539,6 +559,8 @@ NSInteger const REQUEST_SEG = 1;
{
if ([smartView selectedRow] == -1)
return;
if (model_ == nil)
return ;
auto uid = model_->filteredConversation([smartView selectedRow]).uid;
model_->makePermanent(uid);
......
......@@ -91,6 +91,9 @@
/* Displayed as RingID when no accounts are available for selection */
"No account available" = "No account available";
/* Allert message when no accounts are available */
"Navigate to preferences to create a new account" = "Navigate to preferences to create a new account";
/* Text show to the user when password didn't match */
"Password and confirmation mismatch." = "Password and confirmation mismatch.";
......
......@@ -13,6 +13,7 @@
<outlet property="currentView" destination="se5-gp-TjO" id="Sae-7F-MB3"/>
<outlet property="qrcodeView" destination="dZR-JL-MY4" id="6Jf-42-qwY"/>
<outlet property="ringIDLabel" destination="JN3-vO-zcd" id="WHd-L7-6od"/>
<outlet property="ringLabelTrailingConstraint" destination="4u6-30-3Ac" id="SnB-9E-wuO"/>
<outlet property="shareButton" destination="Oac-o7-2Ge" id="b0D-xr-PCx"/>
<outlet property="smartViewVC" destination="jrf-42-1l2" id="lM5-3U-244"/>
<outlet property="welcomeContainer" destination="D6e-KX-8gC" id="zV3-38-ClK"/>
......@@ -373,7 +374,7 @@
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
<connections>
<binding destination="-2" name="hidden" keyPath="self.hideRingID" id="EPK-C2-VsC"/>
<binding destination="-2" name="hidden" keyPath="self.notRingAccount" id="r7A-Pi-WHz"/>
</connections>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" allowsCharacterPickerTouchBarItem="YES" translatesAutoresizingMaskIntoConstraints="NO" id="JN3-vO-zcd" userLabel="Ring ID" customClass="RingIDField">
......@@ -388,7 +389,7 @@
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
<connections>
<binding destination="-2" name="hidden" keyPath="self.hideRingID" id="nmu-Lf-o2m"/>
<binding destination="-2" name="hidden" keyPath="self.isSIPAccount" id="llK-P7-CiI"/>
</connections>
</textField>
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="f62-JV-dgr">
......@@ -411,11 +412,14 @@
</buttonCell>
<connections>
<action selector="shareRingID:" target="-2" id="8bY-RW-cQS"/>
<binding destination="-2" name="hidden" keyPath="self.hideRingID" id="WnF-cs-9yr"/>
<binding destination="-2" name="hidden" keyPath="self.notRingAccount" id="CUd-nb-MzH"/>
</connections>
</button>
<button translatesAutoresizingMaskIntoConstraints="NO" id="eXV-BT-B6J" customClass="IconButton">
<rect key="frame" x="431" y="62" width="30" height="30"/>
<constraints>
<constraint firstAttribute="width" constant="30" id="FrZ-2C-m7y"/>
</constraints>
<buttonCell key="cell" type="square" bezelStyle="shadowlessSquare" image="qrcode" imagePosition="only" alignment="center" transparent="YES" imageScaling="proportionallyUpOrDown" inset="2" id="vvm-Gy-Tbh">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
......@@ -427,7 +431,7 @@
</userDefinedRuntimeAttributes>
<connections>
<action selector="toggleQRCode:" target="-2" id="jZa-65-o5C"/>
<binding destination="-2" name="hidden" keyPath="self.hideRingID" id="4zb-wx-Nna"/>
<binding destination="-2" name="hidden" keyPath="self.notRingAccount" id="aWO-1T-QfL"/>
</connections>
</button>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" setsMaxLayoutWidthAtFirstLayout="YES" allowsCharacterPickerTouchBarItem="YES" translatesAutoresizingMaskIntoConstraints="NO" id="VJ1-xk-v5e">
......@@ -441,9 +445,8 @@
</subviews>
<constraints>
<constraint firstItem="f62-JV-dgr" firstAttribute="top" secondItem="D6e-KX-8gC" secondAttribute="top" constant="20" id="0b6-u8-yQg"/>
<constraint firstItem="eXV-BT-B6J" firstAttribute="leading" secondItem="JN3-vO-zcd" secondAttribute="trailing" constant="11" id="4u6-30-3Ac"/>
<constraint firstItem="eXV-BT-B6J" firstAttribute="leading" secondItem="JN3-vO-zcd" secondAttribute="trailing" priority="999" constant="11" id="4u6-30-3Ac"/>
<constraint firstItem="Oac-o7-2Ge" firstAttribute="centerY" secondItem="JN3-vO-zcd" secondAttribute="centerY" id="9sL-W9-dDT"/>
<constraint firstItem="JN3-vO-zcd" firstAttribute="leading" secondItem="D6e-KX-8gC" secondAttribute="leading" constant="20" id="AMV-Tt-nEu"/>
<constraint firstItem="VJ1-xk-v5e" firstAttribute="centerX" secondItem="D6e-KX-8gC" secondAttribute="centerX" id="ID9-YU-lFv"/>
<constraint firstAttribute="trailing" secondItem="Oac-o7-2Ge" secondAttribute="trailing" constant="20" id="J2a-v7-JnP"/>
<constraint firstItem="eXV-BT-B6J" firstAttribute="centerY" secondItem="JN3-vO-zcd" secondAttribute="centerY" id="KqQ-sn-ZT0"/>
......@@ -454,6 +457,7 @@
<constraint firstItem="kFj-Sh-o5u" firstAttribute="centerX" secondItem="D6e-KX-8gC" secondAttribute="centerX" id="X8P-ae-ug3"/>
<constraint firstItem="eXV-BT-B6J" firstAttribute="top" secondItem="kFj-Sh-o5u" secondAttribute="bottom" constant="6" id="jfB-b4-Gyc"/>
<constraint firstAttribute="width" constant="520" id="nXn-Wh-VAi"/>
<constraint firstItem="JN3-vO-zcd" firstAttribute="centerX" secondItem="D6e-KX-8gC" secondAttribute="centerX" priority="750" id="uWT-kG-rQw"/>
<constraint firstItem="kFj-Sh-o5u" firstAttribute="top" secondItem="VJ1-xk-v5e" secondAttribute="bottom" constant="8" id="wQ0-UB-Yo2"/>
<constraint firstItem="VJ1-xk-v5e" firstAttribute="top" secondItem="f62-JV-dgr" secondAttribute="bottom" constant="8" id="zNb-f8-m6q"/>
</constraints>
......
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