Skip to content
Snippets Groups Projects
Commit 94fdd646 authored by Kateryna Kostiuk's avatar Kateryna Kostiuk Committed by Kateryna Kostiuk
Browse files

account settings: set default moderators

Gitlab: #265

Change-Id: I3a02650b4e0e3a4f13991d168cf49342ec8021ff
parent 870acd4a
No related branches found
No related tags found
No related merge requests found
......@@ -20,7 +20,8 @@
#import <Cocoa/Cocoa.h>
#import "AccAdvancedVC.h"
#import "ChooseContactVC.h"
@interface AccAdvancedRingVC : AccAdvancedVC <NSTextFieldDelegate>
@interface AccAdvancedRingVC : AccAdvancedVC <NSTextFieldDelegate, ChooseContactVCDelegate, NSPopoverDelegate>
@end
......@@ -18,20 +18,34 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#import "AccAdvancedRingVC.h"
#import "utils.h"
//LRC
#import <api/lrc.h>
#import <api/newaccountmodel.h>
#import <api/newdevicemodel.h>
#import <api/contactmodel.h>
#import <api/contact.h>
#import <globalinstances.h>
#import <api/conversationmodel.h>
#import "delegates/ImageManipulationDelegate.h"
//Qt
#import <QtMacExtras/qmacfunctions.h>
#import <QPixmap>
@interface AccAdvancedRingVC () {
__unsafe_unretained IBOutlet NSButton *allowIncoming;
__unsafe_unretained IBOutlet NSTextField *nameServerField;
__unsafe_unretained IBOutlet NSTextField *proxyServerField;
__unsafe_unretained IBOutlet NSTextField *bootstrapServerField;
__unsafe_unretained IBOutlet NSTextField *noDefaultModeratorsLabel;
__unsafe_unretained IBOutlet NSButton *enableProxyButton;
__unsafe_unretained IBOutlet NSButton *enableLocalModeratorButton;
__unsafe_unretained IBOutlet NSButton *togleRendezVous;
IBOutlet NSTableView* defaultModeratorsView;
IBOutlet NSPopover* contactPickerPopoverVC;
}
@end
......@@ -52,10 +66,13 @@ const NSInteger BOOTSTRAP_SERVER_TAG = 300;
[proxyServerField setEditable:accountProperties.proxyEnabled];
[togleRendezVous setState: accountProperties.isRendezVous];
[enableLocalModeratorButton setState: self.accountModel->isLocalModeratorsEnabled(self.selectedAccountID)];
noDefaultModeratorsLabel.hidden = self.accountModel->getDefaultModerators(self.selectedAccountID).size() > 0;
}
-(void) viewDidLoad {
[super viewDidLoad];
defaultModeratorsView.delegate = self;
defaultModeratorsView.dataSource = self;
[[self view] setAutoresizingMask: NSViewMinXMargin | NSViewMaxXMargin | NSViewWidthSizable];
[self updateView];
}
......@@ -126,6 +143,44 @@ const NSInteger BOOTSTRAP_SERVER_TAG = 300;
[super valueDidChange:sender];
}
- (IBAction)removeModerator:(id)sender
{
NSInteger row = [defaultModeratorsView rowForView:sender];
if(row < 0) {
return;
}
auto moderators = self.accountModel->getDefaultModerators(self.selectedAccountID);
if ((moderators.size()-1) < row) {
return;
}
auto moderator = moderators[row];
self.accountModel->setDefaultModerator(self.selectedAccountID, moderator, false);
NSIndexSet *indexes = [[NSIndexSet alloc] initWithIndex:row];
[defaultModeratorsView removeRowsAtIndexes:indexes withAnimation: NSTableViewAnimationSlideUp];
[defaultModeratorsView noteNumberOfRowsChanged];
noDefaultModeratorsLabel.hidden = self.accountModel->getDefaultModerators(self.selectedAccountID).size() > 0;
}
- (IBAction)selectContact:(id)sender
{
if (contactPickerPopoverVC != nullptr) {
[contactPickerPopoverVC performClose:self];
contactPickerPopoverVC = NULL;
} else {
auto* contactSelectorVC = [[ChooseContactVC alloc] initWithNibName:@"ChooseContactVC" bundle:nil];
auto* contModel = self.accountModel->getAccountInfo(self.selectedAccountID).contactModel.get();
[contactSelectorVC setUpCpntactPickerwithModel:self.accountModel andAccountId:self.selectedAccountID];
contactSelectorVC.delegate = self;
contactPickerPopoverVC = [[NSPopover alloc] init];
[contactPickerPopoverVC setContentSize:contactSelectorVC.view.frame.size];
[contactPickerPopoverVC setContentViewController:contactSelectorVC];
[contactPickerPopoverVC setAnimates:YES];
[contactPickerPopoverVC setBehavior:NSPopoverBehaviorTransient];
[contactPickerPopoverVC setDelegate:self];
[contactPickerPopoverVC showRelativeToRect:[sender bounds] ofView:sender preferredEdge:NSMinYEdge];
}
}
#pragma mark - NSTextFieldDelegate methods
-(void)controlTextDidEndEditing:(NSNotification *)notif
......@@ -134,4 +189,75 @@ const NSInteger BOOTSTRAP_SERVER_TAG = 300;
[self valueDidChange:textField];
}
#pragma mark - NSTableViewDelegate methods
- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
if(tableView == defaultModeratorsView) {
NSTableCellView* moderatorCell = [tableView makeViewWithIdentifier:@"TableCellDefaultModerator" owner:self];
NSImageView* avatar = [moderatorCell viewWithTag: 100];
NSTextField* nameLabel = [moderatorCell viewWithTag: 200];
NSTextField* profileNameLabel = [moderatorCell viewWithTag: 300];
NSButton* removeModerator = [moderatorCell viewWithTag: 400];
auto moderators = self.accountModel->getDefaultModerators(self.selectedAccountID);
if ((moderators.size() - 1) < row) {
return nil;
}
auto moderator = moderators[row];
auto& moderatorInfo = self.accountModel->getAccountInfo(self.selectedAccountID).contactModel->getContact(moderator);
auto convOpt = getConversationFromURI(moderatorInfo.profileInfo.uri, *self.accountModel->getAccountInfo(self.selectedAccountID).conversationModel);
if (convOpt.has_value()) {
lrc::api::conversation::Info& conversation = *convOpt;
auto& imageManip = reinterpret_cast<Interfaces::ImageManipulationDelegate&>(GlobalInstances::pixmapManipulator());
NSImage* image = QtMac::toNSImage(qvariant_cast<QPixmap>(imageManip.conversationPhoto(conversation, self.accountModel->getAccountInfo(self.selectedAccountID))));
if(image) {
avatar.wantsLayer = YES;
avatar.layer.cornerRadius = avatar.frame.size.width * 0.5;
[avatar setImage:image];
}
}
[nameLabel setStringValue: bestIDForContact(moderatorInfo)];
[profileNameLabel setStringValue: bestNameForContact(moderatorInfo)];
[removeModerator setAction:@selector(removeModerator:)];
[removeModerator setTarget:self];
return moderatorCell;
}
return [super tableView:tableView viewForTableColumn:tableColumn row:row];
}
- (NSTableRowView *)tableView:(NSTableView *)tableView rowViewForRow:(NSInteger)row
{
if(![tableView isEnabled]) {
return nil;
}
return [tableView makeViewWithIdentifier:@"HoverRowView" owner:nil];
}
#pragma mark - NSTableViewDataSource methods
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView {
if(tableView == defaultModeratorsView) {
return self.accountModel->getDefaultModerators(self.selectedAccountID).size();
}
return [super numberOfRowsInTableView:tableView];
}
#pragma mark Popover delegate
- (void)popoverWillClose:(NSNotification *)notification
{
if (contactPickerPopoverVC != nullptr) {
[contactPickerPopoverVC performClose:self];
contactPickerPopoverVC = NULL;
}
}
# pragma mark -ChooseContactVCDelegate
-(void)contactChosen:(const QString&)contactUri {
self.accountModel->setDefaultModerator(self.selectedAccountID, contactUri, true);
[defaultModeratorsView reloadData];
noDefaultModeratorsLabel.hidden = self.accountModel->getDefaultModerators(self.selectedAccountID).size() > 0;
}
@end
......@@ -20,9 +20,15 @@
#import <Cocoa/Cocoa.h>
#include <qstring.h>
typedef enum {
FROM_CONTACT = 1,
FROM_CONFERENCABLE_ITEM
} ContactPickerType;
@protocol ChooseContactVCDelegate <NSObject>
-(void)callToContact:(const QString&)contactUri convUID:(const QString&)convID;
-(void)joinCall:(const QString&)callId;
-(void)contactChosen:(const QString&)contactUri;
@end
namespace lrc {
......@@ -31,13 +37,16 @@ namespace lrc {
namespace conversation {
struct Info;
}
class ContactModel;
class NewAccountModel;
}
}
@interface ChooseContactVC: NSViewController
@property (retain, nonatomic) id <ChooseContactVCDelegate> delegate;
- (void)setConversationModel:(lrc::api::ConversationModel *)conversationModel
- (void)setUpForConference:(lrc::api::ConversationModel *)conversationModel
andCurrentConversation:(const QString&)conversation;
- (void)setUpCpntactPickerwithModel:(lrc::api::NewAccountModel *) newaccountModel andAccountId:(const QString&)account;
@end
......@@ -28,6 +28,8 @@
#import <api/conversationmodel.h>
#import <api/account.h>
#import <api/newaccountmodel.h>
#import <api/contactmodel.h>
#import <api/contact.h>
//Qt
#import <QtMacExtras/qmacfunctions.h>
......@@ -49,9 +51,13 @@
@implementation ChooseContactVC
lrc::api::ConversationModel* convModel;
lrc::api::NewAccountModel* accountModel;
QString currentConversation;
QString accountId;
ContactPickerType type;
QMap<lrc::api::ConferenceableItem, lrc::api::ConferenceableValue> values;
QList<lrc::api::contact::Info> contacts;
// Tags for views
NSInteger const IMAGE_TAG = 100;
......@@ -64,8 +70,42 @@ NSInteger const MINIMUM_TABLE_SIZE = 0;
NSInteger const NORMAL_TABLE_SIZE = 120;
NSInteger const MAXIMUM_TABLE_SIZE = 240;
- (void)setUpCpntactPickerwithModel:(lrc::api::NewAccountModel *) newaccountModel andAccountId:(const QString&)account{
accountId = account;
accountModel = newaccountModel;
type = FROM_CONTACT;
[self updateModerators];
[self reloadView];
}
- (void)setUpForConference:(lrc::api::ConversationModel *)conversationModel
andCurrentConversation:(const QString&)conversation
{
type = FROM_CONFERENCABLE_ITEM;
convModel = conversationModel;
if (convModel == nil) {
return;
}
currentConversation = conversation;
values = convModel->getConferenceableConversations(currentConversation, "");
[self reloadView];
}
- (void)controlTextDidChange:(NSNotification *) notification
{
if (type == FROM_CONTACT) {
auto allContacts = accountModel->getAccountInfo(accountId).contactModel->getAllContacts();
auto moderators = accountModel->getDefaultModerators(accountId);
contacts.clear();
auto filter = QString::fromNSString(searchField.stringValue);
for (auto contact : allContacts.values()) {
if ((contact.registeredName.contains(filter) || contact.profileInfo.alias.contains(filter)) && !moderators.contains(contact.profileInfo.uri)) {
contacts.append(contact);
}
}
[self reloadView];
return;
}
values = convModel->getConferenceableConversations(currentConversation, QString::fromNSString(searchField.stringValue));
[self reloadView];
}
......@@ -74,6 +114,13 @@ NSInteger const MAXIMUM_TABLE_SIZE = 240;
{
[callsView reloadData];
[contactsView reloadData];
if (type == FROM_CONTACT) {
[callsContainer setHidden: YES];
contactsViewHeightConstraint.constant = MAXIMUM_TABLE_SIZE + 35;
calsViewHeightConstraint.constant = 0;
[contactsLabel setHidden: YES];
return;
}
auto callsSize = [callsView numberOfRows] * ROW_HEIGHT;
auto contactsSize = [contactsView numberOfRows] * ROW_HEIGHT;
if (callsSize >= NORMAL_TABLE_SIZE) {
......@@ -103,16 +150,15 @@ NSInteger const MAXIMUM_TABLE_SIZE = 240;
[self reloadView];
}
- (void)setConversationModel:(lrc::api::ConversationModel *)conversationModel
andCurrentConversation:(const QString&)conversation
{
convModel = conversationModel;
if (convModel == nil) {
return;
-(void) updateModerators {
auto allContacts = accountModel->getAccountInfo(accountId).contactModel->getAllContacts();
auto moderators = accountModel->getDefaultModerators(accountId);
for (auto moderator : moderators) {
if (allContacts.find(moderator) != allContacts.end()) {
allContacts.remove(moderator);
}
}
currentConversation = conversation;
values = convModel->getConferenceableConversations(currentConversation, "");
[self reloadView];
contacts = allContacts.values();
}
#pragma mark - NSTableViewDelegate methods
......@@ -137,6 +183,10 @@ NSInteger const MAXIMUM_TABLE_SIZE = 240;
HoverTableRowView* cellRowView = [table rowViewAtRow:i makeIfNecessary: NO];
[cellRowView drawSelection: (i == row)];
}
if (type == FROM_CONTACT) {
[self chooseContactForRow:row];
return;
}
if (row == -1 || convModel == nil)
return;
QVector<QVector<lrc::api::AccountConversation>> conversations = table == callsView ? values.value(lrc::api::ConferenceableItem::CALL) : values.value(lrc::api::ConferenceableItem::CONTACT);
......@@ -158,10 +208,27 @@ NSInteger const MAXIMUM_TABLE_SIZE = 240;
lrc::api::conversation::Info& conv = *conversationInfo;
if (table == callsView) {
auto callID = conv.confId.isEmpty() ? conv.callId : conv.confId;
[self.delegate joinCall: callID];
if ([self.delegate respondsToSelector: @selector(joinCall:)]) {
[self.delegate joinCall: callID];
}
} else if (table == contactsView) {
auto uid = conv.participants.front();
[self.delegate callToContact:uid convUID: convID];
if ([self.delegate respondsToSelector: @selector(joinCall:)]) {
[self.delegate callToContact:uid convUID: convID];
}
}
}
-(void)chooseContactForRow:(NSInteger) row {
if (row < 0 || row >= contacts.size()) {
return;
}
auto contact = contacts[row];
if ([self.delegate respondsToSelector: @selector(contactChosen:)]) {
[self.delegate contactChosen: contact.profileInfo.uri];
[self updateModerators];
NSIndexSet *indexes = [[NSIndexSet alloc] initWithIndex:row];
[contactsView removeRowsAtIndexes:indexes withAnimation: NSTableViewAnimationSlideUp];
}
}
......@@ -172,8 +239,40 @@ NSInteger const MAXIMUM_TABLE_SIZE = 240;
return howerRow;
}
-(NSView *)configureContactRowForRow:(NSInteger)row tableView:(NSTableView*)tableView {
if (tableView != contactsView || row < 0 || row >= contacts.size()) {
return nil;
}
NSTableCellView* result = [tableView makeViewWithIdentifier:@"MainCell" owner:tableView];
NSTextField* displayName = [result viewWithTag:DISPLAYNAME_TAG];
NSTextField* displayRingID = [result viewWithTag:RING_ID_LABEL];
NSImageView* photoView = [result viewWithTag:IMAGE_TAG];
NSView* presenceView = [result viewWithTag:PRESENCE_TAG];
[presenceView setHidden:YES];
auto contact = contacts[row];
auto convOpt = getConversationFromURI(contact.profileInfo.uri, *accountModel->getAccountInfo(accountId).conversationModel);
if (convOpt.has_value()) {
lrc::api::conversation::Info& conversation = *convOpt;
auto& imageManip = reinterpret_cast<Interfaces::ImageManipulationDelegate&>(GlobalInstances::pixmapManipulator());
NSImage* image = QtMac::toNSImage(qvariant_cast<QPixmap>(imageManip.conversationPhoto(conversation, accountModel->getAccountInfo(accountId))));
if(image) {
photoView.wantsLayer = YES;
photoView.layer.cornerRadius = photoView.frame.size.width * 0.5;
[photoView setImage:image];
}
}
[displayRingID setStringValue: bestIDForContact(contact)];
[displayName setStringValue: bestNameForContact(contact)];
return result;
}
- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
if (type == FROM_CONTACT) {
return [self configureContactRowForRow:row tableView: tableView];
}
if (convModel == nil)
return nil;
......@@ -289,6 +388,9 @@ NSInteger const MAXIMUM_TABLE_SIZE = 240;
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView
{
if (type == FROM_CONTACT) {
return contacts.size();
}
if(!convModel) {
return 0;
}
......
......@@ -1071,7 +1071,7 @@ CVPixelBufferRef pixelBufferPreview;
} else {
auto* contactSelectorVC = [[ChooseContactVC alloc] initWithNibName:@"ChooseContactVC" bundle:nil];
auto* convModel = accountInfo_->conversationModel.get();
[contactSelectorVC setConversationModel:convModel andCurrentConversation: convUid_];
[contactSelectorVC setUpForConference:convModel andCurrentConversation:convUid_];
contactSelectorVC.delegate = self;
brokerPopoverVC = [[NSPopover alloc] init];
[brokerPopoverVC setContentSize:contactSelectorVC.view.frame.size];
......
......@@ -118,3 +118,9 @@
/* Class = "NSButtonCell"; title = "Enable rendezvous point: turn your account into a conference room"; ObjectID = "2cZ-SI-nbz"; */
"2cZ-SI-nbz.title" = "Enable rendezvous point: turn your account into a conference room";
/* Class = "NSButtonCell"; title = "Add default moderator"; ObjectID = "RKw-pg-2N8"; */
"RKw-pg-2N8.title" = "Add default moderator";
/* Class = "NSTextFieldCell"; title = "You do not have default moderators"; ObjectID = "g2o-3r-Dx7"; */
"g2o-3r-Dx7.title" = "You do not have default moderators";
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="17156" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="17701" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="17156"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="17701"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
......@@ -21,7 +21,7 @@
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customView misplaced="YES" id="Hz6-mo-xeY">
<rect key="frame" x="0.0" y="0.0" width="250" height="358"/>
<rect key="frame" x="0.0" y="0.0" width="250" height="356"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<stackView distribution="fill" orientation="vertical" alignment="centerX" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="y8b-Oz-KzK">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment