/
MainViewController.m
5445 lines (5039 loc) · 317 KB
/
MainViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// MainViewController.m
//
// Copyright (C) 2013 IRCCloud, Ltd.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#import <AssetsLibrary/AssetsLibrary.h>
#import <MobileCoreServices/UTCoreTypes.h>
#import <MobileCoreServices/UTType.h>
#import <UserNotifications/UserNotifications.h>
#import <Intents/Intents.h>
#import "MainViewController.h"
#import "NetworkConnection.h"
#import "ColorFormatter.h"
#import "ChannelModeListTableViewController.h"
#import "AppDelegate.h"
#import "IgnoresTableViewController.h"
#import "EditConnectionViewController.h"
#import "UIColor+IRCCloud.h"
#import "ECSlidingViewController.h"
#import "ChannelInfoViewController.h"
#import "ChannelListTableViewController.h"
#import "SettingsViewController.h"
#import "CallerIDTableViewController.h"
#import "WhoisViewController.h"
#import "DisplayOptionsViewController.h"
#import "WhoListTableViewController.h"
#import "NamesListTableViewController.h"
#import "ImgurLoginViewController.h"
#import <objc/message.h>
#import "config.h"
#import "UIDevice+UIDevice_iPhone6Hax.h"
#import "FileMetadataViewController.h"
#import "FilesTableViewController.h"
#import "PastebinEditorViewController.h"
#import "PastebinsTableViewController.h"
#import "ARChromeActivity.h"
#import "TUSafariActivity.h"
#import "OpenInChromeController.h"
#import "ServerReorderViewController.h"
#import "FontAwesome.h"
#import "YouTubeViewController.h"
#import "AvatarsDataSource.h"
#import "TextTableViewController.h"
#import "SpamViewController.h"
#import "LinksListTableViewController.h"
#import "WhoWasTableViewController.h"
#import "LogExportsTableViewController.h"
#import "ImageCache.h"
#import "AvatarsTableViewController.h"
extern NSDictionary *emojiMap;
NSArray *_sortedUsers;
NSArray *_sortedChannels;
@implementation UpdateSuggestionsTask
-(UIExpandingTextView *)message {
return _message;
}
-(void)setMessage:(UIExpandingTextView *)message {
self->_message = message;
self->_text = message.text;
}
-(void)cancel {
self->_cancelled = YES;
}
-(void)run {
self.isEmoji = NO;
NSMutableSet *suggestions_set = [[NSMutableSet alloc] init];
NSMutableArray *suggestions = [[NSMutableArray alloc] init];
if(self->_text.length > 0) {
NSString *text = self->_text.lowercaseString;
NSUInteger lastSpace = [text rangeOfString:@" " options:NSBackwardsSearch].location;
if(lastSpace != NSNotFound && lastSpace != text.length) {
text = [text substringFromIndex:lastSpace + 1];
}
if([text hasSuffix:@":"])
text = [text substringToIndex:text.length - 1];
if([text hasPrefix:@"@"]) {
self->_atMention = YES;
text = [text substringFromIndex:1];
} else {
self->_atMention = NO;
}
if(!_sortedChannels)
_sortedChannels = [[[ChannelsDataSource sharedInstance] channels] sortedArrayUsingSelector:@selector(compare:)];
if([[[[NSUserDefaults standardUserDefaults] objectForKey:@"disable-nick-suggestions"] objectForKey:[NSString stringWithFormat:@"%i",_buffer.bid]] intValue]) {
if(self->_atMention || _force) {
if(_sortedUsers.count == 0)
_sortedUsers = nil;
} else {
_sortedUsers = @[];
}
}
if(!_sortedUsers)
_sortedUsers = [[[UsersDataSource sharedInstance] usersForBuffer:self->_buffer.bid] sortedArrayUsingSelector:@selector(compareByMentionTime:)];
if(self->_cancelled)
return;
if(text.length > 1 || _force) {
if([self->_buffer.type isEqualToString:@"channel"] && [[self->_buffer.name lowercaseString] hasPrefix:text]) {
[suggestions_set addObject:self->_buffer.name.lowercaseString];
[suggestions addObject:self->_buffer.name];
}
for(Channel *channel in _sortedChannels) {
if(self->_cancelled)
return;
if(text.length > 0 && channel.name.length > 0 && [channel.name characterAtIndex:0] == [text characterAtIndex:0] && channel.bid != self->_buffer.bid && [[channel.name lowercaseString] hasPrefix:text] && ![suggestions_set containsObject:channel.name.lowercaseString] && ![[BuffersDataSource sharedInstance] getBuffer:channel.bid].isMPDM) {
[suggestions_set addObject:channel.name.lowercaseString];
[suggestions addObject:channel.name];
self.isEmoji = YES;
}
}
for(User *user in _sortedUsers) {
if(self->_cancelled)
return;
NSString *nick = user.nick.lowercaseString;
NSString *displayName = user.display_name.lowercaseString;
NSUInteger location = [nick rangeOfCharacterFromSet:[NSCharacterSet alphanumericCharacterSet]].location;
if([text rangeOfCharacterFromSet:[NSCharacterSet alphanumericCharacterSet]].location == 0 && location != NSNotFound && location > 0) {
nick = [nick substringFromIndex:location];
}
if((text.length == 0 || [nick hasPrefix:text] || [displayName hasPrefix:text]) && ![suggestions_set containsObject:user.nick.lowercaseString]) {
[suggestions_set addObject:user.nick.lowercaseString];
if(![user.nick isEqualToString:user.display_name])
[suggestions addObject:[NSString stringWithFormat:@"%@\u00a0(%@)",user.display_name,user.nick]];
else
[suggestions addObject:user.nick];
}
}
}
if(text.length > 2 && [text hasPrefix:@":"]) {
NSString *q = [text substringFromIndex:1];
for(NSString *emocode in emojiMap.keyEnumerator) {
if(self->_cancelled)
return;
if([emocode hasPrefix:q]) {
NSString *emoji = [emojiMap objectForKey:emocode];
if(![suggestions_set containsObject:emoji]) {
self.isEmoji = YES;
[suggestions_set addObject:emoji];
[suggestions addObject:emoji];
}
}
}
}
}
if(self->_cancelled)
return;
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
if(self->_nickCompletionView.selection == -1 || suggestions.count == 0)
[self->_nickCompletionView setSuggestions:suggestions];
if(self->_cancelled)
return;
if(suggestions.count == 0) {
if(self->_nickCompletionView.alpha > 0) {
[UIView animateWithDuration:0.25 animations:^{ self->_nickCompletionView.alpha = 0; } completion:nil];
if([[[[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."] objectAtIndex:0] intValue] < 9) {
self->_message.internalTextView.autocorrectionType = UITextAutocorrectionTypeYes;
[self->_message.internalTextView reloadInputViews];
id k = objc_msgSend(NSClassFromString(@"UIKeyboard"), NSSelectorFromString(@"activeKeyboard"));
if([k respondsToSelector:NSSelectorFromString(@"_setAutocorrects:")]) {
objc_msgSend(k, NSSelectorFromString(@"_setAutocorrects:"), YES);
}
}
_sortedChannels = nil;
_sortedUsers = nil;
}
self->_atMention = NO;
} else {
if(self->_nickCompletionView.alpha == 0) {
[UIView animateWithDuration:0.25 animations:^{ self->_nickCompletionView.alpha = 1; } completion:nil];
NSString *text = self->_message.text;
id delegate = self->_message.delegate;
self->_message.delegate = nil;
self->_message.text = text;
self->_message.selectedRange = NSMakeRange(text.length, 0);
if([[[[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."] objectAtIndex:0] intValue] < 9) {
self->_message.internalTextView.autocorrectionType = UITextAutocorrectionTypeNo;
[self->_message.internalTextView reloadInputViews];
id k = objc_msgSend(NSClassFromString(@"UIKeyboard"), NSSelectorFromString(@"activeKeyboard"));
if([k respondsToSelector:NSSelectorFromString(@"_setAutocorrects:")]) {
objc_msgSend(k, NSSelectorFromString(@"_setAutocorrects:"), NO);
objc_msgSend(k, NSSelectorFromString(@"removeAutocorrectPrompt"));
}
}
if(self->_force && self->_nickCompletionView.selection == -1) {
[self->_nickCompletionView setSelection:0];
NSString *text = self->_message.text;
if(text.length == 0) {
if(self->_buffer.serverIsSlack)
self->_message.text = [NSString stringWithFormat:@"@%@",[self->_nickCompletionView suggestion]];
else
self->_message.text = [self->_nickCompletionView suggestion];
} else {
while(text.length > 0 && [text characterAtIndex:text.length - 1] != ' ') {
text = [text substringToIndex:text.length - 1];
}
if(self->_buffer.serverIsSlack)
text = [text stringByAppendingString:@"@"];
text = [text stringByAppendingString:[self->_nickCompletionView suggestion]];
self->_message.text = text;
}
if([text rangeOfString:@" "].location == NSNotFound && !self->_buffer.serverIsSlack)
self->_message.text = [self->_message.text stringByAppendingString:@":"];
}
self->_message.delegate = delegate;
}
}
}];
}
@end
@implementation MainViewController
-(instancetype)initWithCoder:(NSCoder *)aDecoder {
if(self = [super initWithCoder:aDecoder]) {
self->_cidToOpen = -1;
self->_bidToOpen = -1;
self->_pendingEvents = [[NSMutableArray alloc] init];
}
return self;
}
-(void)dealloc {
AudioServicesDisposeSystemSoundID(alertSound);
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)_themeChanged {
if(![self->_currentTheme isEqualToString:[UIColor currentTheme]]) {
self->_currentTheme = [UIColor currentTheme];
UIView *v = self.navigationController.view.superview;
if(v) {
[self.navigationController.view removeFromSuperview];
[v addSubview: self.navigationController.view];
}
[self applyTheme];
}
}
- (void)applyTheme {
self->_currentTheme = [UIColor currentTheme];
if (@available(iOS 13, *))
self.view.window.overrideUserInterfaceStyle = [self->_currentTheme isEqualToString:@"dawn"]?UIUserInterfaceStyleLight:UIUserInterfaceStyleDark;
self.view.window.backgroundColor = [UIColor textareaBackgroundColor];
self.view.backgroundColor = [UIColor contentBackgroundColor];
self.slidingViewController.view.backgroundColor = self.navigationController.view.backgroundColor = [UIColor navBarColor];
self->_bottomBar.backgroundColor = [UIColor contentBackgroundColor];
[self.navigationController.navigationBar setBackgroundImage:[UIColor navBarBackgroundImage] forBarMetrics:UIBarMetricsDefault];
[self->_uploadsBtn setTintColor:[UIColor textareaBackgroundColor]];
UIColor *c = ([NetworkConnection sharedInstance].state == kIRCCloudStateConnected)?([UIColor isDarkTheme]?[UIColor whiteColor]:[UIColor unreadBlueColor]):[UIColor textareaBackgroundColor];
[self->_sendBtn setTitleColor:c forState:UIControlStateNormal];
[self->_sendBtn setTitleColor:c forState:UIControlStateDisabled];
[self->_sendBtn setTitleColor:c forState:UIControlStateHighlighted];
[self->_settingsBtn setTintColor:[UIColor textareaBackgroundColor]];
[self->_message setBackgroundImage:[UIColor textareaBackgroundImage]];
self->_message.textColor = [UIColor textareaTextColor];
self->_message.keyboardAppearance = [UITextField appearance].keyboardAppearance;
self->_defaultTextareaFont = [UIFont systemFontOfSize:FONT_SIZE weight:UIFontWeightRegular];
if(!_message.text.length)
self->_message.font = self->_defaultTextareaFont;
self->_message.minimumHeight = FONT_SIZE + 22;
if(self->_message.minimumHeight < 35)
self->_message.minimumHeight = 35;
UIButton *users = [UIButton buttonWithType:UIButtonTypeCustom];
[users setImage:[[UIImage imageNamed:@"users"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
[users addTarget:self action:@selector(usersButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
users.frame = CGRectMake(0,0,24,22);
[users setTintColor:[UIColor navBarSubheadingColor]];
users.accessibilityLabel = @"Channel members list";
self->_usersButtonItem = [[UIBarButtonItem alloc] initWithCustomView:users];
self->_menuBtn.tintColor = [UIColor navBarSubheadingColor];
self->_eventsView.topUnreadView.backgroundColor = [UIColor chatterBarColor];
self->_eventsView.bottomUnreadView.backgroundColor = [UIColor chatterBarColor];
self->_eventsView.topUnreadLabel.textColor = [UIColor chatterBarTextColor];
self->_eventsView.bottomUnreadLabel.textColor = [UIColor chatterBarTextColor];
self->_eventsView.topUnreadArrow.textColor = self->_eventsView.bottomUnreadArrow.textColor = [UIColor chatterBarTextColor];
self->_borders.backgroundColor = [UIColor iPadBordersColor];
[[self->_borders.subviews objectAtIndex:0] setBackgroundColor:[UIColor contentBackgroundColor]];
self->_eventActivity.activityIndicatorViewStyle = self->_headerActivity.activityIndicatorViewStyle = [UIColor activityIndicatorViewStyle];
[[UIApplication sharedApplication] setStatusBarStyle:[UIColor isDarkTheme]?UIStatusBarStyleLightContent:UIStatusBarStyleDefault];
self->_globalMsg.linkAttributes = [UIColor lightLinkAttributes];
}
- (void)viewDidLoad {
[super viewDidLoad];
self.slidingViewController.view.frame = self.view.window.bounds;
[self->_eventsView viewDidLoad];
[[NSNotificationCenter defaultCenter] removeObserver:self];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleEvent:) name:kIRCCloudEventNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(backlogStarted:)
name:kIRCCloudBacklogStartedNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(backlogProgress:)
name:kIRCCloudBacklogProgressNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(backlogCompleted:)
name:kIRCCloudBacklogCompletedNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(connectivityChanged:)
name:kIRCCloudConnectivityNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillBeHidden:)
name:UIKeyboardWillHideNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didSwipe:)
name:ECSlidingViewUnderLeftWillAppear object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didSwipe:)
name:ECSlidingViewUnderRightWillAppear object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didSwipe:)
name:ECSlidingViewUnderLeftWillDisappear object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didSwipe:)
name:ECSlidingViewUnderRightWillDisappear object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(statusBarFrameWillChange:)
name:UIApplicationWillChangeStatusBarFrameNotification object:nil];
[super viewDidLoad];
[self addChildViewController:self->_eventsView];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"a" ofType:@"caf"]], &alertSound);
self->_globalMsg.linkDelegate = self;
[self->_globalMsg addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(globalMsgPressed:)]];
if(!_buffersView) {
self->_buffersView = [[BuffersTableView alloc] initWithStyle:UITableViewStylePlain];
self->_buffersView.view.autoresizingMask = UIViewAutoresizingNone;
self->_buffersView.view.translatesAutoresizingMaskIntoConstraints = NO;
self->_buffersView.delegate = self;
}
if(!_usersView) {
self->_usersView = [[UsersTableView alloc] initWithStyle:UITableViewStylePlain];
self->_usersView.view.autoresizingMask = UIViewAutoresizingNone;
self->_usersView.view.translatesAutoresizingMaskIntoConstraints = NO;
self->_usersView.delegate = self;
}
if(self->_swipeTip)
self->_swipeTip.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"tip_bg"]];
if(_2swipeTip)
_2swipeTip.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"tip_bg"]];
if(self->_mentionTip)
self->_mentionTip.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"tip_bg"]];
self->_lock.font = [UIFont fontWithName:@"FontAwesome" size:18];
self->_uploadsBtn = [UIButton buttonWithType:UIButtonTypeCustom];
self->_uploadsBtn.contentMode = UIViewContentModeCenter;
self->_uploadsBtn.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;
[self->_uploadsBtn setImage:[[UIImage imageNamed:@"upload_arrow"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
[self->_uploadsBtn addTarget:self action:@selector(uploadsButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[self->_uploadsBtn sizeToFit];
self->_uploadsBtn.frame = CGRectMake(9,2,_uploadsBtn.frame.size.width + 16, _uploadsBtn.frame.size.height + 16);
self->_uploadsBtn.accessibilityLabel = @"Uploads";
[self->_bottomBar addSubview:self->_uploadsBtn];
self->_sendBtn = [UIButton buttonWithType:UIButtonTypeCustom];
self->_sendBtn.contentMode = UIViewContentModeCenter;
self->_sendBtn.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin;
[self->_sendBtn setTitle:@"Send" forState:UIControlStateNormal];
[self->_sendBtn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateDisabled];
[self->_sendBtn sizeToFit];
self->_sendBtn.frame = CGRectMake(self->_bottomBar.frame.size.width - _sendBtn.frame.size.width - 8,4,_sendBtn.frame.size.width,_sendBtn.frame.size.height);
[self->_sendBtn addTarget:self action:@selector(sendButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[self->_sendBtn sizeToFit];
self->_sendBtn.enabled = NO;
self->_sendBtn.adjustsImageWhenHighlighted = NO;
[self->_bottomBar addSubview:self->_sendBtn];
self->_settingsBtn = [UIButton buttonWithType:UIButtonTypeCustom];
self->_settingsBtn.contentMode = UIViewContentModeCenter;
self->_settingsBtn.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin;
[self->_settingsBtn setImage:[[UIImage imageNamed:@"settings"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
[self->_settingsBtn addTarget:self action:@selector(settingsButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[self->_settingsBtn sizeToFit];
self->_settingsBtn.accessibilityLabel = @"Menu";
self->_settingsBtn.enabled = NO;
self->_settingsBtn.alpha = 0;
self->_settingsBtn.frame = CGRectMake(self->_bottomBar.frame.size.width - _settingsBtn.frame.size.width - 24,2,_settingsBtn.frame.size.width + 16,_settingsBtn.frame.size.height + 16);
[self->_bottomBar addSubview:self->_settingsBtn];
self.slidingViewController.shouldAllowPanningPastAnchor = NO;
if(self.slidingViewController.underLeftViewController == nil)
self.slidingViewController.underLeftViewController = self->_buffersView;
if(self.slidingViewController.underRightViewController == nil)
self.slidingViewController.underRightViewController = self->_usersView;
self.slidingViewController.anchorLeftRevealAmount = 240;
self.slidingViewController.anchorRightRevealAmount = 240;
self.slidingViewController.underLeftWidthLayout = ECFixedRevealWidth;
self.slidingViewController.underRightWidthLayout = ECFixedRevealWidth;
self.navigationController.view.layer.shadowOpacity = 0.75f;
self.navigationController.view.layer.shadowRadius = 2.0f;
self.navigationController.view.layer.shadowColor = [UIColor blackColor].CGColor;
self->_menuBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[self->_menuBtn setImage:[[UIImage imageNamed:@"menu"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
[self->_menuBtn addTarget:self action:@selector(listButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
self->_menuBtn.frame = CGRectMake(0,0,20,18);
self->_menuBtn.accessibilityLabel = @"Channels list";
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:self->_menuBtn];
self->_message = [[UIExpandingTextView alloc] initWithFrame:CGRectZero];
self->_message.delegate = self;
self->_message.returnKeyType = UIReturnKeySend;
self->_message.autoresizesSubviews = NO;
self->_message.translatesAutoresizingMaskIntoConstraints = NO;
// _message.internalTextView.font = self->_defaultTextareaFont = [UIFont fontWithDescriptor:[UIFontDescriptor preferredFontDescriptorWithTextStyle:UIFontTextStyleBody] size:FONT_SIZE];
self->_message.internalTextView.font = self->_defaultTextareaFont = [UIFont systemFontOfSize:FONT_SIZE weight:UIFontWeightRegular];
self->_messageWidthConstraint = [NSLayoutConstraint constraintWithItem:self->_message attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:0 multiplier:1.0f constant:0.0f];
self->_messageHeightConstraint = [NSLayoutConstraint constraintWithItem:self->_message attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:0 multiplier:1.0f constant:36.0f];
[self->_message addConstraints:@[self->_messageWidthConstraint, _messageHeightConstraint]];
[self->_bottomBar addSubview:self->_message];
[self->_bottomBar addConstraints:@[
[NSLayoutConstraint constraintWithItem:self->_message attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self->_bottomBar attribute:NSLayoutAttributeLeading multiplier:1.0f constant:50.0f],
[NSLayoutConstraint constraintWithItem:self->_message attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self->_bottomBar attribute:NSLayoutAttributeBottom multiplier:1.0f constant:-2.0f]
]];
self->_nickCompletionView = [[NickCompletionView alloc] initWithFrame:CGRectZero];
self->_nickCompletionView.translatesAutoresizingMaskIntoConstraints = NO;
self->_nickCompletionView.completionDelegate = self;
self->_nickCompletionView.alpha = 0;
[self.view addSubview:self->_nickCompletionView];
[self.view addConstraints:@[
[NSLayoutConstraint constraintWithItem:self->_nickCompletionView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self->_eventsView.tableView attribute:NSLayoutAttributeCenterX multiplier:1.0f constant:0.0f],
[NSLayoutConstraint constraintWithItem:self->_nickCompletionView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self->_eventsView.tableView attribute:NSLayoutAttributeWidth multiplier:1.0f constant:-20.0f],
[NSLayoutConstraint constraintWithItem:self->_nickCompletionView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self->_eventsView.bottomUnreadView attribute:NSLayoutAttributeTop multiplier:1.0f constant:-6.0f]
]];
self->_colorPickerView = [[IRCColorPickerView alloc] initWithFrame:CGRectZero];
self->_colorPickerView.translatesAutoresizingMaskIntoConstraints = NO;
self->_colorPickerView.delegate = self;
self->_colorPickerView.alpha = 0;
[self.view addSubview:self->_colorPickerView];
[self.view addConstraints:@[
[NSLayoutConstraint constraintWithItem:self->_colorPickerView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self->_eventsView.tableView attribute:NSLayoutAttributeCenterX multiplier:1.0f constant:0.0f],
[NSLayoutConstraint constraintWithItem:self->_colorPickerView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self->_bottomBar attribute:NSLayoutAttributeTop multiplier:1.0f constant:-2.0f]
]];
self->_connectingProgress = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
[self->_connectingProgress sizeToFit];
self->_connectingProgress.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
self->_connectingProgress.frame = CGRectMake(0,self.navigationController.navigationBar.bounds.size.height - _connectingProgress.bounds.size.height,self.navigationController.navigationBar.bounds.size.width,_connectingProgress.bounds.size.height);
[self.navigationController.navigationBar addSubview:self->_connectingProgress];
self->_connectingStatus.font = [UIFont boldSystemFontOfSize:20];
self.navigationItem.titleView = self->_titleView;
self->_connectingProgress.hidden = YES;
self->_connectingProgress.progress = 0;
[UIColor setTheme:[[NSUserDefaults standardUserDefaults] objectForKey:@"theme"]];
[self _themeChanged];
[self connectivityChanged:nil];
[self updateLayout];
[self _updateEventsInsets];
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeBack:)];
swipe.numberOfTouchesRequired = 2;
swipe.direction = UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:swipe];
swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeForward:)];
swipe.numberOfTouchesRequired = 2;
swipe.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipe];
if([self respondsToSelector:@selector(registerForPreviewingWithDelegate:sourceView:)]) {
__previewer = [self registerForPreviewingWithDelegate:self sourceView:self.navigationController.view];
}
if (@available(iOS 11, *)) {
[self.view addInteraction:[[UIDropInteraction alloc] initWithDelegate:self]];
}
}
-(BOOL)dropInteraction:(UIDropInteraction *)interaction canHandleSession:(id<UIDropSession>)session __attribute__((availability(ios,introduced=11))) {
return session.items.count == 1 && [session hasItemsConformingToTypeIdentifiers:@[@"com.apple.DocumentManager.uti.FPItem.File", @"public.image", @"public.movie"]];
}
-(UIDropProposal *)dropInteraction:(UIDropInteraction *)interaction sessionDidUpdate:(id<UIDropSession>)session __attribute__((availability(ios,introduced=11))) {
if (@available(iOS 11, *)) {
return [[UIDropProposal alloc] initWithDropOperation:UIDropOperationCopy];
} else {
return nil;
}
}
-(void)dropInteraction:(UIDropInteraction *)interaction performDrop:(id<UIDropSession>)session __attribute__((availability(ios,introduced=11))) {
if (@available(iOS 11, *)) {
NSItemProvider *i = session.items.firstObject.itemProvider;
FileUploader *u = [[FileUploader alloc] init];
u.delegate = self;
u.bid = self->_buffer.bid;
NSString *UTI = i.registeredTypeIdentifiers.lastObject;
u.originalFilename = i.suggestedName;
if(![u.originalFilename containsString:@"."] && ![UTI hasPrefix:@"dyn."]) {
u.originalFilename = [u.originalFilename stringByAppendingPathExtension:[UTI componentsSeparatedByString:@"."].lastObject];
}
u.mimeType = (__bridge_transfer NSString *)UTTypeCopyPreferredTagWithClass((__bridge CFStringRef _Nonnull)(UTI), kUTTagClassMIMEType);
FileMetadataViewController *fvc = [[FileMetadataViewController alloc] initWithUploader:u];
u.metadatadelegate = fvc;
[i loadPreviewImageWithOptions:nil completionHandler:^(UIImage *preview, NSError *error) {
if(preview) {
[fvc setImage:preview];
} else if([i canLoadObjectOfClass:UIImage.class]) {
[i loadObjectOfClass:UIImage.class completionHandler:^(UIImage *item, NSError *error) {
if(item) {
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[fvc setImage:item];
}];
}
}];
}
}];
id imageHandler = ^(UIImage *item, NSError *error) {
if(item) {
if([[[NSUserDefaults standardUserDefaults] objectForKey:@"imageService"] isEqualToString:@"IRCCloud"]) {
CLS_LOG(@"Uploading dropped image to IRCCloud");
[u uploadImage:item];
} else {
CLS_LOG(@"Uploading dropped image to imgur");
ImageUploader *img = [[ImageUploader alloc] init];
img.delegate = self;
img.bid = self->_buffer.bid;
[img upload:item];
}
} else {
CLS_LOG(@"Unable to handle dropped image: %@", error);
}
};
if([i hasItemConformingToTypeIdentifier:@"com.apple.DocumentManager.uti.FPItem.File"]) {
if(![[[NSUserDefaults standardUserDefaults] objectForKey:@"imageService"] isEqualToString:@"IRCCloud"] && [i hasItemConformingToTypeIdentifier:@"public.image"]) {
[i loadObjectOfClass:UIImage.class completionHandler:imageHandler];
} else {
[i loadInPlaceFileRepresentationForTypeIdentifier:@"com.apple.DocumentManager.uti.FPItem.File" completionHandler:^(NSURL *url, BOOL isInPlace, NSError *error) {
if(url) {
CLS_LOG(@"Uploading dropped file to IRCCloud");
[i hasItemConformingToTypeIdentifier:@"public.movie"]?[u uploadVideo:url]:[u uploadFile:url];
} else {
CLS_LOG(@"Unable to handle dropped file: %@", error);
}
}];
}
} else if([i hasItemConformingToTypeIdentifier:@"public.movie"]) {
[i loadInPlaceFileRepresentationForTypeIdentifier:@"public.movie" completionHandler:^(NSURL *url, BOOL isInPlace, NSError *error) {
if(url) {
CLS_LOG(@"Uploading dropped movie to IRCCloud");
[u uploadVideo:url];
} else {
CLS_LOG(@"Unable to handle dropped movie: %@", error);
}
}];
} else if([i hasItemConformingToTypeIdentifier:@"public.image"]) {
[i loadObjectOfClass:UIImage.class completionHandler:imageHandler];
}
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
if([[[NSUserDefaults standardUserDefaults] objectForKey:@"imageService"] isEqualToString:@"IRCCloud"] || ![i hasItemConformingToTypeIdentifier:@"public.image"]) {
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:fvc];
[nc.navigationBar setBackgroundImage:[UIColor navBarBackgroundImage] forBarMetrics:UIBarMetricsDefault];
if([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad && ![[UIDevice currentDevice] isBigPhone])
nc.modalPresentationStyle = UIModalPresentationFormSheet;
else
nc.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:nc animated:YES completion:nil];
[self _resetStatusBar];
}
}];
}
}
- (UIViewController *)previewingContext:(id<UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location {
if(CGRectContainsPoint(self->_titleView.frame, [self->_titleView convertPoint:location fromView:self.navigationController.view])) {
if(self->_buffer && [self->_buffer.type isEqualToString:@"channel"] && [[ChannelsDataSource sharedInstance] channelForBuffer:self->_buffer.bid]) {
previewingContext.sourceRect = [self.navigationController.view convertRect:self->_titleView.frame fromView:self.navigationController.navigationBar];
ChannelInfoViewController *c = [[ChannelInfoViewController alloc] initWithChannel:[[ChannelsDataSource sharedInstance] channelForBuffer:self->_buffer.bid]];
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:c];
[nc.navigationBar setBackgroundImage:[UIColor navBarBackgroundImage] forBarMetrics:UIBarMetricsDefault];
nc.navigationBarHidden = YES;
if([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad && ![[UIDevice currentDevice] isBigPhone])
nc.modalPresentationStyle = UIModalPresentationFormSheet;
else
nc.modalPresentationStyle = UIModalPresentationCurrentContext;
return nc;
}
}
return nil;
}
- (void)previewingContext:(id<UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit {
if([viewControllerToCommit isKindOfClass:[UINavigationController class]]) {
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:((UINavigationController *)viewControllerToCommit).topViewController];
[nc.navigationBar setBackgroundImage:[UIColor navBarBackgroundImage] forBarMetrics:UIBarMetricsDefault];
if([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad && ![[UIDevice currentDevice] isBigPhone])
nc.modalPresentationStyle = UIModalPresentationFormSheet;
else
nc.modalPresentationStyle = UIModalPresentationCurrentContext;
viewControllerToCommit = nc;
}
[self presentViewController:viewControllerToCommit animated:YES completion:nil];
}
- (void) observeValueForKeyPath:(NSString*)keyPath ofObject:(id)object change:(NSDictionary*)change context:(void*)context {
if (object == self->_eventsView.topUnreadView) {
if(![[change objectForKey:NSKeyValueChangeOldKey] isEqualToNumber:[change objectForKey:NSKeyValueChangeNewKey]])
[self _updateEventsInsets];
} else if(object == self->_eventsView.tableView.layer) {
CGRect old = [[change objectForKey:NSKeyValueChangeOldKey] CGRectValue];
CGRect new = [[change objectForKey:NSKeyValueChangeNewKey] CGRectValue];
if(new.size.height > 0 && old.size.width != new.size.width) {
[self->_eventsView clearCachedHeights];
}
} else {
NSLog(@"Change: %@", change);
}
}
- (void)swipeBack:(UISwipeGestureRecognizer *)sender {
if(self->_buffer.lastBuffer) {
Buffer *b = self->_buffer;
Buffer *last = self->_buffer.lastBuffer.lastBuffer;
[self bufferSelected:b.lastBuffer.bid];
self->_buffer.lastBuffer = last;
self->_buffer.nextBuffer = b;
}
}
- (void)swipeForward:(UISwipeGestureRecognizer *)sender {
if(self->_buffer.nextBuffer) {
Buffer *b = self->_buffer;
Buffer *last = self->_buffer.lastBuffer;
Buffer *next = self->_buffer.nextBuffer;
Buffer *nextnext = self->_buffer.nextBuffer.nextBuffer;
[self bufferSelected:next.bid];
self->_buffer.nextBuffer = nextnext;
b.nextBuffer = next;
b.lastBuffer = last;
}
}
- (void)_updateUnreadIndicator {
@synchronized(self->_buffer) {
int unreadCount = 0;
int highlightCount = 0;
NSDictionary *prefs = [[NetworkConnection sharedInstance] prefs];
NSArray *buffers = [[BuffersDataSource sharedInstance] getBuffers];
for(Buffer *buffer in buffers) {
int type = -1;
int joined = 1;
if([buffer.type isEqualToString:@"channel"]) {
type = 1;
Channel *channel = [[ChannelsDataSource sharedInstance] channelForBuffer:buffer.bid];
if(!channel) {
joined = 0;
}
} else if([buffer.type isEqualToString:@"conversation"]) {
type = 2;
}
if(joined > 0 && buffer.archived == 0) {
int unread = 0;
int highlights = 0;
if(unreadCount == 0)
unread = [[EventsDataSource sharedInstance] unreadStateForBuffer:buffer.bid lastSeenEid:buffer.last_seen_eid type:buffer.type];
highlights = [[EventsDataSource sharedInstance] highlightStateForBuffer:buffer.bid lastSeenEid:buffer.last_seen_eid type:buffer.type];
if(type == 1) {
if([[prefs objectForKey:@"channel-disableTrackUnread"] isKindOfClass:[NSDictionary class]] && [[[prefs objectForKey:@"channel-disableTrackUnread"] objectForKey:[NSString stringWithFormat:@"%i",buffer.bid]] intValue] == 1)
unread = 0;
} else {
if([[prefs objectForKey:@"buffer-disableTrackUnread"] isKindOfClass:[NSDictionary class]] && [[[prefs objectForKey:@"buffer-disableTrackUnread"] objectForKey:[NSString stringWithFormat:@"%i",buffer.bid]] intValue] == 1)
unread = 0;
if(type == 2 && [[prefs objectForKey:@"buffer-disableTrackUnread"] isKindOfClass:[NSDictionary class]] && [[[prefs objectForKey:@"buffer-disableTrackUnread"] objectForKey:[NSString stringWithFormat:@"%i",buffer.bid]] intValue] == 1)
highlights = 0;
}
if([[prefs objectForKey:@"disableTrackUnread"] intValue] == 1) {
if(type == 1) {
if(![[prefs objectForKey:@"channel-enableTrackUnread"] isKindOfClass:[NSDictionary class]] || [[[prefs objectForKey:@"channel-enableTrackUnread"] objectForKey:[NSString stringWithFormat:@"%i",buffer.bid]] intValue] != 1)
unread = 0;
} else {
if(![[prefs objectForKey:@"buffer-enableTrackUnread"] isKindOfClass:[NSDictionary class]] || [[[prefs objectForKey:@"buffer-enableTrackUnread"] objectForKey:[NSString stringWithFormat:@"%i",buffer.bid]] intValue] != 1)
unread = 0;
if(type == 2 && (![[prefs objectForKey:@"buffer-enableTrackUnread"] isKindOfClass:[NSDictionary class]] || [[[prefs objectForKey:@"buffer-enableTrackUnread"] objectForKey:[NSString stringWithFormat:@"%i",buffer.bid]] intValue] != 1))
highlights = 0;
}
}
if(buffer.bid != self->_buffer.bid) {
unreadCount += unread;
highlightCount += highlights;
}
if(highlightCount > 0)
break;
}
}
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
if(highlightCount) {
self->_menuBtn.tintColor = [UIColor redColor];
self->_menuBtn.accessibilityValue = @"Unread highlights";
} else if(unreadCount) {
if(![self->_menuBtn.tintColor isEqual:[UIColor unreadBlueColor]])
UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, @"New unread messages");
self->_menuBtn.tintColor = [UIColor unreadBlueColor];
self->_menuBtn.accessibilityValue = @"Unread messages";
} else {
self->_menuBtn.tintColor = [UIColor navBarSubheadingColor];
self->_menuBtn.accessibilityValue = nil;
}
}];
}
}
- (void)handleEvent:(NSNotification *)notification {
kIRCEvent event = [[notification.userInfo objectForKey:kIRCCloudEventKey] intValue];
Channel *c;
Buffer *b = nil;
IRCCloudJSONObject *o = nil;
ChannelModeListTableViewController *cmltv = nil;
ChannelListTableViewController *ctv = nil;
CallerIDTableViewController *citv = nil;
WhoListTableViewController *wtv = nil;
NamesListTableViewController *ntv = nil;
Event *e = nil;
Server *s = nil;
NSString *msg = nil;
NSString *type = nil;
UIAlertController *ac = nil;
switch(event) {
case kIRCEventSessionDeleted:
[self bufferSelected:-1];
[(AppDelegate *)([UIApplication sharedApplication].delegate) showLoginView];
break;
case kIRCEventGlobalMsg:
[self _updateGlobalMsg];
break;
case kIRCEventWhois:
{
if([self.presentedViewController isKindOfClass:UINavigationController.class] && [((UINavigationController *)self.presentedViewController).topViewController isKindOfClass:WhoisViewController.class]) {
WhoisViewController *wvc = (WhoisViewController *)(((UINavigationController *)self.presentedViewController).topViewController);
[wvc setData:notification.object];
} else {
WhoisViewController *wvc = [[WhoisViewController alloc] init];
[wvc setData:notification.object];
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:wvc];
[nc.navigationBar setBackgroundImage:[UIColor navBarBackgroundImage] forBarMetrics:UIBarMetricsDefault];
if([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad && ![[UIDevice currentDevice] isBigPhone])
nc.modalPresentationStyle = UIModalPresentationFormSheet;
else
nc.modalPresentationStyle = UIModalPresentationCurrentContext;
if(self.presentedViewController)
[self dismissViewControllerAnimated:NO completion:nil];
[self presentViewController:nc animated:YES completion:nil];
}
}
break;
case kIRCEventChannelTopicIs:
o = notification.object;
b = [[BuffersDataSource sharedInstance] getBufferWithName:[o objectForKey:@"chan"] server:o.cid];
if(b) {
c = [[ChannelsDataSource sharedInstance] channelForBuffer:b.bid];
} else {
c = [[Channel alloc] init];
c.cid = o.cid;
c.bid = -1;
c.name = [o objectForKey:@"chan"];
c.topic_author = [o objectForKey:@"author"]?[o objectForKey:@"author"]:[o objectForKey:@"server"];
c.topic_time = [[o objectForKey:@"time"] doubleValue];
c.topic_text = [o objectForKey:@"text"];
}
if(c) {
ChannelInfoViewController *cvc = [[ChannelInfoViewController alloc] initWithChannel:c];
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:cvc];
[nc.navigationBar setBackgroundImage:[UIColor navBarBackgroundImage] forBarMetrics:UIBarMetricsDefault];
if([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad && ![[UIDevice currentDevice] isBigPhone])
nc.modalPresentationStyle = UIModalPresentationFormSheet;
else
nc.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:nc animated:YES completion:nil];
}
break;
case kIRCEventChannelInit:
case kIRCEventChannelTopic:
case kIRCEventChannelMode:
[self _updateTitleArea];
[self _updateUserListVisibility];
break;
case kIRCEventBadChannelKey: {
self->_alertObject = notification.object;
s = [[ServersDataSource sharedInstance] getServer:self->_alertObject.cid];
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[self dismissKeyboard];
[self.view.window endEditing:YES];
UIAlertController *alert = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"%@ (%@:%i)", s.name, s.hostname, s.port] message:[NSString stringWithFormat:@"Password for %@",[self->_alertObject objectForKey:@"chan"]] preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]];
[alert addAction:[UIAlertAction actionWithTitle:@"Join" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
if(((UITextField *)[alert.textFields objectAtIndex:0]).text.length)
[[NetworkConnection sharedInstance] join:[self->_alertObject objectForKey:@"chan"] key:((UITextField *)[alert.textFields objectAtIndex:0]).text cid:self->_alertObject.cid handler:^(IRCCloudJSONObject *result) {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Error" message:[NSString stringWithFormat:@"Unable to join channel: %@. Please try again shortly.", [result objectForKey:@"message"]] preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"Close" style:UIAlertActionStyleCancel handler:nil]];
[self presentViewController:alert animated:YES completion:nil];
}];
}]];
if([[[[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."] objectAtIndex:0] intValue] < 9) {
[self presentViewController:alert animated:YES completion:nil];
}
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.delegate = self;
[textField becomeFirstResponder];
}];
if([[[[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."] objectAtIndex:0] intValue] >= 9)
[self presentViewController:alert animated:YES completion:nil];
}];}
break;
case kIRCEventAlert:
o = notification.object;
type = o.type;
if([type isEqualToString:@"help"] || [type isEqualToString:@"stats"]) {
TextTableViewController *tv;
if([self.presentedViewController isKindOfClass:UINavigationController.class] && [((UINavigationController *)self.presentedViewController).viewControllers.firstObject isKindOfClass:TextTableViewController.class]) {
tv = ((UINavigationController *)self.presentedViewController).viewControllers.firstObject;
if(![tv.type isEqualToString:type])
tv = nil;
}
NSString *msg = [o objectForKey:@"parts"];
if([[o objectForKey:@"msg"] length]) {
if(msg.length)
msg = [msg stringByAppendingFormat:@": %@", [o objectForKey:@"msg"]];
else
msg = [o objectForKey:@"msg"];
}
msg = [msg stringByAppendingString:@"\n"];
if(!msg)
msg = @"\n";
if(tv) {
[tv appendText:msg];
} else {
tv = [[TextTableViewController alloc] initWithText:msg];
if([[o objectForKey:@"command"] length])
tv.navigationItem.title = [NSString stringWithFormat:@"HELP For %@", [o objectForKey:@"command"]];
else
tv.navigationItem.title = type.uppercaseString;
tv.server = [[ServersDataSource sharedInstance] getServer:self->_buffer.cid];
tv.type = type;
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:tv];
[nc.navigationBar setBackgroundImage:[UIColor navBarBackgroundImage] forBarMetrics:UIBarMetricsDefault];
if([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad && ![[UIDevice currentDevice] isBigPhone])
nc.modalPresentationStyle = UIModalPresentationFormSheet;
else
nc.modalPresentationStyle = UIModalPresentationCurrentContext;
if(self.presentedViewController)
[self dismissViewControllerAnimated:NO completion:nil];
[self presentViewController:nc animated:YES completion:nil];
}
} else {
if([type isEqualToString:@"invite_only_chan"])
msg = [NSString stringWithFormat:@"You need an invitation to join %@", [o objectForKey:@"chan"]];
else if([type isEqualToString:@"channel_full"])
msg = [NSString stringWithFormat:@"%@ isn't allowing any more members to join.", [o objectForKey:@"chan"]];
else if([type isEqualToString:@"banned_from_channel"])
msg = [NSString stringWithFormat:@"You've been banned from %@", [o objectForKey:@"chan"]];
else if([type isEqualToString:@"invalid_nickchange"])
msg = [NSString stringWithFormat:@"%@: %@", [o objectForKey:@"ban_channel"], [o objectForKey:@"msg"]];
else if([type isEqualToString:@"bad_channel_name"])
msg = [NSString stringWithFormat:@"Bad channel name: %@", [o objectForKey:@"chan"]];
else if([type isEqualToString:@"no_messages_from_non_registered"]) {
if([[o objectForKey:@"nick"] length])
msg = [NSString stringWithFormat:@"%@: %@", [o objectForKey:@"nick"], [o objectForKey:@"msg"]];
else
msg = [o objectForKey:@"msg"];
} else if([type isEqualToString:@"not_registered"]) {
NSString *first = [o objectForKey:@"first"];
if([[o objectForKey:@"rest"] length])
first = [first stringByAppendingString:[o objectForKey:@"rest"]];
msg = [NSString stringWithFormat:@"%@: %@", first, [o objectForKey:@"msg"]];
} else if([type isEqualToString:@"too_many_channels"])
msg = [NSString stringWithFormat:@"Couldn't join %@: %@", [o objectForKey:@"chan"], [o objectForKey:@"msg"]];
else if([type isEqualToString:@"too_many_targets"])
msg = [NSString stringWithFormat:@"%@: %@", [o objectForKey:@"description"], [o objectForKey:@"msg"]];
else if([type isEqualToString:@"no_such_server"])
msg = [NSString stringWithFormat:@"%@: %@", [o objectForKey:@"server"], [o objectForKey:@"msg"]];
else if([type isEqualToString:@"unknown_command"]) {
NSString *m = [o objectForKey:@"msg"];
if(!m.length)
m = @"Unknown command";
msg = [NSString stringWithFormat:@"%@: %@", m, [o objectForKey:@"command"]];
} else if([type isEqualToString:@"help_not_found"])
msg = [NSString stringWithFormat:@"%@: %@", [o objectForKey:@"topic"], [o objectForKey:@"msg"]];
else if([type isEqualToString:@"accept_exists"])
msg = [NSString stringWithFormat:@"%@ %@", [o objectForKey:@"nick"], [o objectForKey:@"msg"]];
else if([type isEqualToString:@"accept_not"])
msg = [NSString stringWithFormat:@"%@ %@", [o objectForKey:@"nick"], [o objectForKey:@"msg"]];
else if([type isEqualToString:@"nick_collision"])
msg = [NSString stringWithFormat:@"%@: %@", [o objectForKey:@"collision"], [o objectForKey:@"msg"]];
else if([type isEqualToString:@"nick_too_fast"])
msg = [NSString stringWithFormat:@"%@: %@", [o objectForKey:@"nick"], [o objectForKey:@"msg"]];
else if([type isEqualToString:@"save_nick"])
msg = [NSString stringWithFormat:@"%@: %@: %@", [o objectForKey:@"nick"], [o objectForKey:@"msg"], [o objectForKey:@"new_nick"]];
else if([type isEqualToString:@"unknown_mode"])
msg = [NSString stringWithFormat:@"Missing mode: %@", [o objectForKey:@"param"]];
else if([type isEqualToString:@"user_not_in_channel"])
msg = [NSString stringWithFormat:@"%@ is not in %@", [o objectForKey:@"nick"], [o objectForKey:@"channel"]];
else if([type isEqualToString:@"need_more_params"])
msg = [NSString stringWithFormat:@"Missing parameters for command: %@", [o objectForKey:@"command"]];
else if([type isEqualToString:@"chan_privs_needed"])
msg = [NSString stringWithFormat:@"%@: %@", [o objectForKey:@"chan"], [o objectForKey:@"msg"]];
else if([type isEqualToString:@"not_on_channel"])
msg = [NSString stringWithFormat:@"%@: %@", [o objectForKey:@"channel"], [o objectForKey:@"msg"]];
else if([type isEqualToString:@"ban_on_chan"])
msg = [NSString stringWithFormat:@"You cannot change your nick to %@ while banned on %@", [o objectForKey:@"proposed_nick"], [o objectForKey:@"channel"]];
else if([type isEqualToString:@"cannot_send_to_chan"])
msg = [NSString stringWithFormat:@"%@: %@", [o objectForKey:@"channel"], [o objectForKey:@"msg"]];
else if([type isEqualToString:@"user_on_channel"])
msg = [NSString stringWithFormat:@"%@ is already a member of %@", [o objectForKey:@"nick"], [o objectForKey:@"channel"]];
else if([type isEqualToString:@"nickname_in_use"])
msg = [NSString stringWithFormat:@"%@ is already in use", [o objectForKey:@"nick"]];
else if([type isEqualToString:@"no_nick_given"])
msg = [NSString stringWithFormat:@"No nickname given"];
else if([type isEqualToString:@"silence"]) {
NSString *mask = [o objectForKey:@"usermask"];
if([mask hasPrefix:@"-"])
msg = [NSString stringWithFormat:@"%@ removed from silence list", [mask substringFromIndex:1]];
else if([mask hasPrefix:@"+"])
msg = [NSString stringWithFormat:@"%@ added to silence list", [mask substringFromIndex:1]];
else
msg = [NSString stringWithFormat:@"Silence list change: %@", mask];
} else if([type isEqualToString:@"no_channel_topic"])
msg = [NSString stringWithFormat:@"%@: %@", [o objectForKey:@"channel"], [o objectForKey:@"msg"]];
else if([type isEqualToString:@"time"]) {
msg = [o objectForKey:@"time_string"];
if([[o objectForKey:@"time_stamp"] length]) {