Commit 78e1f126 authored by Kateryna Kostiuk's avatar Kateryna Kostiuk

Contact Request: hide for SIP account

This patch checks when SIP account is used and disables functions
related to contact request:
 - allows sending contact request only to ContactMethod that conform
RING protocol and from RING account.
 - shows pending contact requests list only for RING accounts.

Change-Id: If1b3056207f21ca346ac18b656aa9ccba73eac0f
Reviewed-by: default avatarAnthony Léonard <anthony.leonard@savoirfairelinux.com>
parent 14e7bf33
......@@ -45,27 +45,22 @@ QMetaObject::Connection requestRemoved;
QObject::connect(&AvailableAccountModel::instance(),
&QAbstractItemModel::rowsRemoved,
[self]{
[self.view setHidden:AvailableAccountModel::instance().rowCount() == 0];
[self hideIfNeeded];
});
QObject::connect(&AvailableAccountModel::instance(),
&QAbstractItemModel::dataChanged,
[self]{
[self.view setHidden:AvailableAccountModel::instance().rowCount() == 0];
[self hideIfNeeded];
});
QObject::connect(AvailableAccountModel::instance().selectionModel(),
&QItemSelectionModel::currentChanged,
[self](const QModelIndex& idx){
Account* chosenAccount = [self chosenAccount];
if(chosenAccount) {
[self connectAccountContactRequests];
}
[self setupWithSelectedAccount];
});
Account* chosenAccount = [self chosenAccount];
self.hideRequestNumberLabel = YES;
if(chosenAccount) {
[self connectAccountContactRequests];
}
[self setupWithSelectedAccount];
}
- (IBAction)displayTrustRequests:(NSView*)sender
......@@ -82,7 +77,7 @@ QMetaObject::Connection requestRemoved;
}
- (void)popoverDidClose:(NSNotification *)notification {
// when popover is closed remove ContactRequestsListVC to let it be allocated
// when popover is closed remove ContactRequestsListVC to let it be deallocated
[pendingContactRequestPopover setContentViewController:nil];
}
......@@ -95,22 +90,33 @@ QMetaObject::Connection requestRemoved;
-(Account* ) chosenAccount
{
QModelIndex index = AvailableAccountModel::instance().selectionModel()->currentIndex();
if(!index.isValid()) {
return nullptr;
}
Account* account = index.data(static_cast<int>(Account::Role::Object)).value<Account*>();
return account;
}
-(void) connectAccountContactRequests
-(void) setupWithSelectedAccount
{
Account* chosenAccount = [self chosenAccount];
if(!chosenAccount) {
return;
}
[self.view setHidden:chosenAccount->protocol() != Account::Protocol::RING];
if(chosenAccount->protocol() != Account::Protocol::RING) {
return;
}
self.numberOfRequests = chosenAccount->pendingContactRequestModel()->rowCount();
QObject::disconnect(requestAdded);
requestAdded = QObject::connect(chosenAccount->pendingContactRequestModel(),
&QAbstractItemModel::rowsInserted,
[=]() {
self.numberOfRequests = chosenAccount->pendingContactRequestModel()->rowCount();
}
);
&QAbstractItemModel::rowsInserted,
[=]() {
self.numberOfRequests = chosenAccount->pendingContactRequestModel()->rowCount();
}
);
QObject::disconnect(requestRemoved);
requestRemoved = QObject::connect(chosenAccount->pendingContactRequestModel(),
&QAbstractItemModel::rowsRemoved,
......@@ -121,4 +127,17 @@ QMetaObject::Connection requestRemoved;
);
}
-(void)hideIfNeeded
{
if(AvailableAccountModel::instance().rowCount() == 0) {
[self.view setHidden:YES];
return;
}
Account* chosenAccount = [self chosenAccount];
if(!chosenAccount) {
return;
}
[self.view setHidden:chosenAccount->protocol() != Account::Protocol::RING];
}
@end
......@@ -63,6 +63,8 @@
__unsafe_unretained IBOutlet NSTextField* emptyConversationPlaceHolder;
__unsafe_unretained IBOutlet IconButton* sendButton;
__unsafe_unretained IBOutlet NSPopUpButton* contactMethodsPopupButton;
__unsafe_unretained IBOutlet NSLayoutConstraint* sentContactRequestWidth;
__unsafe_unretained IBOutlet NSButton* sentContactRequestButton;
IBOutlet MessagesVC* messagesViewVC;
}
......@@ -86,6 +88,16 @@
}
-(Account* ) chosenAccount
{
QModelIndex index = AvailableAccountModel::instance().selectionModel()->currentIndex();
if(!index.isValid()) {
return nullptr;
}
Account* account = index.data(static_cast<int>(Account::Role::Object)).value<Account*>();
return account;
}
- (void) initFrame
{
[self.view setFrame:self.view.superview.bounds];
......@@ -195,7 +207,6 @@
[CATransaction commit];
}
#pragma mark - NSTextFieldDelegate
- (BOOL)control:(NSControl *)control textView:(NSTextView *)fieldEditor doCommandBySelector:(SEL)commandSelector
......@@ -213,6 +224,25 @@
NSInteger index = [(NSPopUpButton *)sender indexOfSelectedItem];
selectedContactMethod = contactMethods.at(index);
/*to send contact request we need to meet two condition:
1)contact method has RING protocol
2)accound is used to send request is also RING*/
Boolean hideSendTrustRequestButton = NO;
if(selectedContactMethod->protocolHint() != URI::ProtocolHint::RING) {
hideSendTrustRequestButton = YES;
}
else if(selectedContactMethod->account()) {
hideSendTrustRequestButton = selectedContactMethod->account()->protocol() != Account::Protocol::RING;
}
else if([self chosenAccount]) {
Boolean hideSendTrustRequestButton = [self chosenAccount]->protocol() != Account::Protocol::RING;
}
[sentContactRequestButton setHidden:hideSendTrustRequestButton];
sentContactRequestWidth.priority = hideSendTrustRequestButton ? 999: 250;
[conversationTitle setStringValue:selectedContactMethod->primaryName().toNSString()];
QObject::disconnect(contactMethodChanged);
contactMethodChanged = QObject::connect(selectedContactMethod,
......
......@@ -15,6 +15,8 @@
<outlet property="messagesViewVC" destination="iH6-17-JsM" id="uxH-Ra-lSr"/>
<outlet property="sendButton" destination="UJf-cF-RAo" id="8PF-7G-w1d"/>
<outlet property="sendPanel" destination="Rth-di-Tls" id="vCd-kM-DLc"/>
<outlet property="sentContactRequestButton" destination="isI-We-3h9" id="Kal-Wn-gWo"/>
<outlet property="sentContactRequestWidth" destination="J5j-bs-Mgk" id="EQx-Gj-4vx"/>
<outlet property="view" destination="Hz6-mo-xeY" id="0bl-1N-x8E"/>
</connections>
</customObject>
......@@ -291,6 +293,9 @@
</textField>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="isI-We-3h9">
<rect key="frame" x="711" y="537" width="73" height="32"/>
<constraints>
<constraint firstAttribute="width" priority="250" id="J5j-bs-Mgk"/>
</constraints>
<buttonCell key="cell" type="push" title="Invite" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="9su-fU-MPG">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
......
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