Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 1 | /* |
Anthony Léonard | e7d62ed | 2018-01-25 10:51:47 -0500 | [diff] [blame] | 2 | * Copyright (C) 2016-2018 Savoir-faire Linux Inc. |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 3 | * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com> |
Anthony Léonard | 2382b56 | 2017-12-13 15:51:28 -0500 | [diff] [blame] | 4 | * Author: Anthony Léonard <anthony.leonard@savoirfairelinux.com> |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | */ |
| 20 | |
| 21 | #import "ConversationVC.h" |
| 22 | |
| 23 | #import <QItemSelectionModel> |
| 24 | #import <qstring.h> |
| 25 | #import <QPixmap> |
| 26 | #import <QtMacExtras/qmacfunctions.h> |
| 27 | |
Anthony Léonard | 2382b56 | 2017-12-13 15:51:28 -0500 | [diff] [blame] | 28 | // LRC |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 29 | #import <globalinstances.h> |
| 30 | |
| 31 | #import "views/IconButton.h" |
Kateryna Kostiuk | db95b47 | 2018-04-17 16:35:57 -0400 | [diff] [blame] | 32 | #import "views/HoverButton.h" |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 33 | #import "views/IMTableCellView.h" |
| 34 | #import "views/NSColor+RingTheme.h" |
| 35 | #import "QNSTreeController.h" |
Alexandre Lision | 83180df | 2016-01-18 11:32:20 -0500 | [diff] [blame] | 36 | #import "INDSequentialTextSelectionManager.h" |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 37 | #import "delegates/ImageManipulationDelegate.h" |
Kateryna Kostiuk | 0ba1baf | 2017-05-12 16:51:27 -0400 | [diff] [blame] | 38 | #import "PhoneDirectoryModel.h" |
| 39 | #import "account.h" |
| 40 | #import "AvailableAccountModel.h" |
Kateryna Kostiuk | 58276bc | 2017-06-07 08:50:48 -0400 | [diff] [blame] | 41 | #import "MessagesVC.h" |
Anthony Léonard | 2382b56 | 2017-12-13 15:51:28 -0500 | [diff] [blame] | 42 | #import "utils.h" |
Anthony Léonard | 8585cc0 | 2017-12-28 14:03:45 -0500 | [diff] [blame] | 43 | #import "RingWindowController.h" |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 44 | |
| 45 | #import <QuartzCore/QuartzCore.h> |
| 46 | |
Anthony Léonard | 2382b56 | 2017-12-13 15:51:28 -0500 | [diff] [blame] | 47 | @interface ConversationVC () { |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 48 | |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 49 | __unsafe_unretained IBOutlet NSTextField* messageField; |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 50 | NSMutableString* textSelection; |
| 51 | |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 52 | __unsafe_unretained IBOutlet NSView* sendPanel; |
| 53 | __unsafe_unretained IBOutlet NSTextField* conversationTitle; |
Olivier Soldano | 13c69e3 | 2018-01-05 12:01:36 -0500 | [diff] [blame] | 54 | __unsafe_unretained IBOutlet NSTextField *conversationID; |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 55 | __unsafe_unretained IBOutlet IconButton* sendButton; |
Anthony Léonard | e7d62ed | 2018-01-25 10:51:47 -0500 | [diff] [blame] | 56 | __unsafe_unretained IBOutlet IconButton *sendFileButton; |
Kateryna Kostiuk | db95b47 | 2018-04-17 16:35:57 -0400 | [diff] [blame] | 57 | __unsafe_unretained IBOutlet HoverButton *addContactButton; |
Kateryna Kostiuk | 78e1f12 | 2017-06-14 14:52:34 -0400 | [diff] [blame] | 58 | __unsafe_unretained IBOutlet NSLayoutConstraint* sentContactRequestWidth; |
| 59 | __unsafe_unretained IBOutlet NSButton* sentContactRequestButton; |
Kateryna Kostiuk | 58276bc | 2017-06-07 08:50:48 -0400 | [diff] [blame] | 60 | IBOutlet MessagesVC* messagesViewVC; |
Anthony Léonard | ade9f9b | 2017-07-26 15:51:12 -0400 | [diff] [blame] | 61 | |
Olivier Soldano | f563e15 | 2018-01-09 16:08:32 -0500 | [diff] [blame] | 62 | IBOutlet NSLayoutConstraint *titleCenteredConstraint; |
Anthony Léonard | ade9f9b | 2017-07-26 15:51:12 -0400 | [diff] [blame] | 63 | IBOutlet NSLayoutConstraint* titleTopConstraint; |
Anthony Léonard | 2382b56 | 2017-12-13 15:51:28 -0500 | [diff] [blame] | 64 | |
| 65 | std::string convUid_; |
| 66 | const lrc::api::conversation::Info* cachedConv_; |
| 67 | lrc::api::ConversationModel* convModel_; |
| 68 | |
Anthony Léonard | 8585cc0 | 2017-12-28 14:03:45 -0500 | [diff] [blame] | 69 | RingWindowController* delegate; |
| 70 | |
Anthony Léonard | 0163410 | 2017-12-27 16:37:16 -0500 | [diff] [blame] | 71 | // All those connections are needed to invalidate cached conversation as pointer |
Anthony Léonard | 2382b56 | 2017-12-13 15:51:28 -0500 | [diff] [blame] | 72 | // may not be referencing the same conversation anymore |
Anthony Léonard | 0163410 | 2017-12-27 16:37:16 -0500 | [diff] [blame] | 73 | QMetaObject::Connection modelSortedConnection_, filterChangedConnection_, newConversationConnection_, conversationRemovedConnection_; |
| 74 | |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 75 | } |
| 76 | |
Alexandre Lision | 83180df | 2016-01-18 11:32:20 -0500 | [diff] [blame] | 77 | |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 78 | @end |
| 79 | |
| 80 | @implementation ConversationVC |
| 81 | |
Anthony Léonard | 8585cc0 | 2017-12-28 14:03:45 -0500 | [diff] [blame] | 82 | - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil delegate:(RingWindowController*) mainWindow |
| 83 | { |
| 84 | if (self = [self initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) |
| 85 | { |
| 86 | delegate = mainWindow; |
| 87 | } |
| 88 | return self; |
| 89 | } |
| 90 | |
Anthony Léonard | 2382b56 | 2017-12-13 15:51:28 -0500 | [diff] [blame] | 91 | -(const lrc::api::conversation::Info*) getCurrentConversation |
| 92 | { |
| 93 | if (convModel_ == nil || convUid_.empty()) |
| 94 | return nil; |
| 95 | |
| 96 | if (cachedConv_ != nil) |
| 97 | return cachedConv_; |
| 98 | |
| 99 | auto& convQueue = convModel_->allFilteredConversations(); |
| 100 | |
Anthony Léonard | 6f81975 | 2018-01-05 09:53:40 -0500 | [diff] [blame] | 101 | auto it = getConversationFromUid(convUid_, *convModel_); |
Anthony Léonard | 2382b56 | 2017-12-13 15:51:28 -0500 | [diff] [blame] | 102 | |
| 103 | if (it != convQueue.end()) |
| 104 | cachedConv_ = &(*it); |
| 105 | |
| 106 | return cachedConv_; |
| 107 | } |
| 108 | |
| 109 | -(void) setConversationUid:(const std::string)convUid model:(lrc::api::ConversationModel *)model { |
| 110 | if (convUid_ == convUid && convModel_ == model) |
| 111 | return; |
| 112 | |
| 113 | cachedConv_ = nil; |
| 114 | convUid_ = convUid; |
| 115 | convModel_ = model; |
| 116 | |
| 117 | [messagesViewVC setConversationUid:convUid_ model:convModel_]; |
| 118 | |
| 119 | if (convUid_.empty() || convModel_ == nil) |
| 120 | return; |
| 121 | |
| 122 | // Signals tracking changes in conversation list, we need them as cached conversation can be invalid |
| 123 | // after a reordering. |
Anthony Léonard | 0163410 | 2017-12-27 16:37:16 -0500 | [diff] [blame] | 124 | QObject::disconnect(modelSortedConnection_); |
| 125 | QObject::disconnect(filterChangedConnection_); |
| 126 | QObject::disconnect(newConversationConnection_); |
| 127 | QObject::disconnect(conversationRemovedConnection_); |
| 128 | modelSortedConnection_ = QObject::connect(convModel_, &lrc::api::ConversationModel::modelSorted, |
Anthony Léonard | 2382b56 | 2017-12-13 15:51:28 -0500 | [diff] [blame] | 129 | [self](){ |
| 130 | cachedConv_ = nil; |
| 131 | }); |
Anthony Léonard | 0163410 | 2017-12-27 16:37:16 -0500 | [diff] [blame] | 132 | filterChangedConnection_ = QObject::connect(convModel_, &lrc::api::ConversationModel::filterChanged, |
Anthony Léonard | 2382b56 | 2017-12-13 15:51:28 -0500 | [diff] [blame] | 133 | [self](){ |
| 134 | cachedConv_ = nil; |
| 135 | }); |
Kateryna Kostiuk | 557f5ea | 2018-03-29 13:41:53 -0400 | [diff] [blame] | 136 | newConversationConnection_ = QObject::connect(convModel_, &lrc::api::ConversationModel::newConversation, |
Anthony Léonard | 0163410 | 2017-12-27 16:37:16 -0500 | [diff] [blame] | 137 | [self](){ |
| 138 | cachedConv_ = nil; |
| 139 | }); |
Kateryna Kostiuk | 557f5ea | 2018-03-29 13:41:53 -0400 | [diff] [blame] | 140 | conversationRemovedConnection_ = QObject::connect(convModel_, &lrc::api::ConversationModel::conversationRemoved, |
Anthony Léonard | 0163410 | 2017-12-27 16:37:16 -0500 | [diff] [blame] | 141 | [self](){ |
| 142 | cachedConv_ = nil; |
| 143 | }); |
Anthony Léonard | 2382b56 | 2017-12-13 15:51:28 -0500 | [diff] [blame] | 144 | |
| 145 | auto* conv = [self getCurrentConversation]; |
| 146 | |
| 147 | if (conv == nil) |
| 148 | return; |
| 149 | |
| 150 | // Setup UI elements according to new conversation |
| 151 | NSString* bestName = bestNameForConversation(*conv, *convModel_); |
Olivier Soldano | 13c69e3 | 2018-01-05 12:01:36 -0500 | [diff] [blame] | 152 | NSString* bestId = bestIDForConversation(*conv, *convModel_); |
Anthony Léonard | 2382b56 | 2017-12-13 15:51:28 -0500 | [diff] [blame] | 153 | [conversationTitle setStringValue: bestName]; |
Olivier Soldano | 13c69e3 | 2018-01-05 12:01:36 -0500 | [diff] [blame] | 154 | [conversationID setStringValue: bestId]; |
Anthony Léonard | e7d62ed | 2018-01-25 10:51:47 -0500 | [diff] [blame] | 155 | [sendFileButton setEnabled:(convModel_->owner.contactModel->getContact(conv->participants[0]).profileInfo.type != lrc::api::profile::Type::SIP)]; |
Anthony Léonard | 2382b56 | 2017-12-13 15:51:28 -0500 | [diff] [blame] | 156 | |
Olivier Soldano | f563e15 | 2018-01-09 16:08:32 -0500 | [diff] [blame] | 157 | BOOL hideBestId = [bestNameForConversation(*conv, *convModel_) isEqualTo:bestIDForConversation(*conv, *convModel_)]; |
Anthony Léonard | 2382b56 | 2017-12-13 15:51:28 -0500 | [diff] [blame] | 158 | |
Olivier Soldano | f563e15 | 2018-01-09 16:08:32 -0500 | [diff] [blame] | 159 | [conversationID setHidden:hideBestId]; |
| 160 | [titleCenteredConstraint setActive:hideBestId]; |
| 161 | [titleTopConstraint setActive:!hideBestId]; |
Kateryna Kostiuk | db95b47 | 2018-04-17 16:35:57 -0400 | [diff] [blame] | 162 | auto accountType = convModel_->owner.profileInfo.type; |
| 163 | [addContactButton setHidden:((convModel_->owner.contactModel->getContact(conv->participants[0]).profileInfo.type != lrc::api::profile::Type::TEMPORARY) || accountType == lrc::api::profile::Type::SIP)]; |
Anthony Léonard | 2382b56 | 2017-12-13 15:51:28 -0500 | [diff] [blame] | 164 | } |
| 165 | |
Alexandre Lision | 4baba4c | 2016-02-11 13:00:57 -0500 | [diff] [blame] | 166 | - (void)loadView { |
| 167 | [super loadView]; |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 168 | // Do view setup here. |
| 169 | [self.view setWantsLayer:YES]; |
| 170 | [self.view setLayer:[CALayer layer]]; |
| 171 | [self.view.layer setBackgroundColor:[NSColor ringGreyHighlight].CGColor]; |
| 172 | [self.view.layer setCornerRadius:5.0f]; |
| 173 | |
Kateryna Kostiuk | 64d025a | 2017-07-14 11:30:44 -0400 | [diff] [blame] | 174 | [messageField setFocusRingType:NSFocusRingTypeNone]; |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 175 | } |
| 176 | |
Kateryna Kostiuk | 78e1f12 | 2017-06-14 14:52:34 -0400 | [diff] [blame] | 177 | -(Account* ) chosenAccount |
| 178 | { |
| 179 | QModelIndex index = AvailableAccountModel::instance().selectionModel()->currentIndex(); |
| 180 | if(!index.isValid()) { |
| 181 | return nullptr; |
| 182 | } |
| 183 | Account* account = index.data(static_cast<int>(Account::Role::Object)).value<Account*>(); |
| 184 | return account; |
| 185 | } |
| 186 | |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 187 | - (void) initFrame |
| 188 | { |
| 189 | [self.view setFrame:self.view.superview.bounds]; |
| 190 | [self.view setHidden:YES]; |
| 191 | self.view.layer.position = self.view.frame.origin; |
| 192 | } |
| 193 | |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 194 | - (IBAction)sendMessage:(id)sender |
| 195 | { |
| 196 | /* make sure there is text to send */ |
| 197 | NSString* text = self.message; |
| 198 | if (text && text.length > 0) { |
Anthony Léonard | 0a9904c | 2018-01-11 16:43:47 -0500 | [diff] [blame] | 199 | auto* conv = [self getCurrentConversation]; |
| 200 | bool isPending = convModel_->owner.contactModel->getContact(conv->participants[0]).profileInfo.type == lrc::api::profile::Type::PENDING; |
Anthony Léonard | 4b0935f | 2017-12-26 12:05:22 -0500 | [diff] [blame] | 201 | convModel_->sendMessage(convUid_, std::string([text UTF8String])); |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 202 | self.message = @""; |
Anthony Léonard | 0a9904c | 2018-01-11 16:43:47 -0500 | [diff] [blame] | 203 | if (isPending) |
| 204 | [delegate currentConversationTrusted]; |
Anthony Léonard | 2382b56 | 2017-12-13 15:51:28 -0500 | [diff] [blame] | 205 | [messagesViewVC newMessageSent]; |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 206 | } |
| 207 | } |
| 208 | |
Anthony Léonard | e7d62ed | 2018-01-25 10:51:47 -0500 | [diff] [blame] | 209 | - (IBAction)sendFile:(id)sender |
| 210 | { |
| 211 | NSOpenPanel* filePicker = [NSOpenPanel openPanel]; |
| 212 | [filePicker setCanChooseFiles:YES]; |
| 213 | [filePicker setCanChooseDirectories:NO]; |
| 214 | [filePicker setAllowsMultipleSelection:NO]; |
| 215 | |
| 216 | if ([filePicker runModal] == NSFileHandlingPanelOKButton) { |
| 217 | if ([[filePicker URLs] count] == 1) { |
| 218 | NSURL* url = [[filePicker URLs] objectAtIndex:0]; |
| 219 | const char* fullPath = [url fileSystemRepresentation]; |
| 220 | NSString* fileName = [url lastPathComponent]; |
| 221 | if (convModel_) { |
Anthony Léonard | 0c65bd1 | 2018-02-08 16:47:19 -0500 | [diff] [blame] | 222 | auto* conv = [self getCurrentConversation]; |
| 223 | bool isPending = convModel_->owner.contactModel->getContact(conv->participants[0]).profileInfo.type == lrc::api::profile::Type::PENDING; |
| 224 | |
Anthony Léonard | e7d62ed | 2018-01-25 10:51:47 -0500 | [diff] [blame] | 225 | convModel_->sendFile(convUid_, std::string(fullPath), std::string([fileName UTF8String])); |
Anthony Léonard | 0c65bd1 | 2018-02-08 16:47:19 -0500 | [diff] [blame] | 226 | |
| 227 | if (isPending) |
| 228 | [delegate currentConversationTrusted]; |
Anthony Léonard | e7d62ed | 2018-01-25 10:51:47 -0500 | [diff] [blame] | 229 | } |
| 230 | } |
| 231 | } |
| 232 | } |
| 233 | |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 234 | - (IBAction)placeCall:(id)sender |
| 235 | { |
Anthony Léonard | 2382b56 | 2017-12-13 15:51:28 -0500 | [diff] [blame] | 236 | auto* conv = [self getCurrentConversation]; |
| 237 | convModel_->placeCall(conv->uid); |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 238 | } |
| 239 | |
Kateryna Kostiuk | db95b47 | 2018-04-17 16:35:57 -0400 | [diff] [blame] | 240 | - (IBAction)placeAudioCall:(id)sender |
| 241 | { |
| 242 | auto* conv = [self getCurrentConversation]; |
| 243 | convModel_->placeAudioOnlyCall(conv->uid); |
| 244 | } |
| 245 | |
| 246 | - (IBAction)addContact:(id)sender |
| 247 | { |
| 248 | auto* conv = [self getCurrentConversation]; |
| 249 | convModel_->makePermanent(conv->uid); |
| 250 | } |
| 251 | |
Alexandre Lision | 01cf5e3 | 2016-01-21 15:54:30 -0500 | [diff] [blame] | 252 | - (IBAction)backPressed:(id)sender { |
Anthony Léonard | 8585cc0 | 2017-12-28 14:03:45 -0500 | [diff] [blame] | 253 | [delegate rightPanelClosed]; |
Andreas Traczyk | ecdc4fa | 2018-03-22 16:11:47 -0400 | [diff] [blame] | 254 | [self hideWithAnimation:false]; |
Kateryna Kostiuk | 0ba1baf | 2017-05-12 16:51:27 -0400 | [diff] [blame] | 255 | } |
| 256 | |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 257 | # pragma mark private IN/OUT animations |
| 258 | |
Andreas Traczyk | ecdc4fa | 2018-03-22 16:11:47 -0400 | [diff] [blame] | 259 | -(void) showWithAnimation:(BOOL)animate |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 260 | { |
Andreas Traczyk | ecdc4fa | 2018-03-22 16:11:47 -0400 | [diff] [blame] | 261 | if (!animate) { |
| 262 | [self.view setHidden:NO]; |
| 263 | return; |
| 264 | } |
| 265 | |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 266 | CGRect frame = CGRectOffset(self.view.superview.bounds, -self.view.superview.bounds.size.width, 0); |
| 267 | [self.view setHidden:NO]; |
| 268 | |
| 269 | [CATransaction begin]; |
| 270 | CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"]; |
| 271 | [animation setFromValue:[NSValue valueWithPoint:frame.origin]]; |
| 272 | [animation setToValue:[NSValue valueWithPoint:self.view.superview.bounds.origin]]; |
| 273 | [animation setDuration:0.2f]; |
| 274 | [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]]; |
| 275 | [self.view.layer addAnimation:animation forKey:animation.keyPath]; |
| 276 | |
| 277 | [CATransaction commit]; |
| 278 | } |
| 279 | |
Andreas Traczyk | ecdc4fa | 2018-03-22 16:11:47 -0400 | [diff] [blame] | 280 | -(void) hideWithAnimation:(BOOL)animate |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 281 | { |
| 282 | if(self.view.frame.origin.x < 0) { |
| 283 | return; |
| 284 | } |
| 285 | |
Andreas Traczyk | ecdc4fa | 2018-03-22 16:11:47 -0400 | [diff] [blame] | 286 | if (!animate) { |
| 287 | [self.view setHidden:YES]; |
| 288 | return; |
| 289 | } |
| 290 | |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 291 | CGRect frame = CGRectOffset(self.view.frame, -self.view.frame.size.width, 0); |
| 292 | [CATransaction begin]; |
| 293 | CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"]; |
| 294 | [animation setFromValue:[NSValue valueWithPoint:self.view.frame.origin]]; |
| 295 | [animation setToValue:[NSValue valueWithPoint:frame.origin]]; |
| 296 | [animation setDuration:0.2f]; |
| 297 | [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]]; |
| 298 | |
| 299 | [CATransaction setCompletionBlock:^{ |
| 300 | [self.view setHidden:YES]; |
| 301 | }]; |
| 302 | [self.view.layer addAnimation:animation forKey:animation.keyPath]; |
| 303 | |
| 304 | [self.view.layer setPosition:frame.origin]; |
| 305 | [CATransaction commit]; |
| 306 | } |
| 307 | |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 308 | #pragma mark - NSTextFieldDelegate |
| 309 | |
| 310 | - (BOOL)control:(NSControl *)control textView:(NSTextView *)fieldEditor doCommandBySelector:(SEL)commandSelector |
| 311 | { |
| 312 | if (commandSelector == @selector(insertNewline:) && self.message.length > 0) { |
| 313 | [self sendMessage:nil]; |
| 314 | return YES; |
| 315 | } |
| 316 | return NO; |
| 317 | } |
| 318 | |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 319 | |
| 320 | @end |