JLChen
2021-08-02 38f4fb064df09f344fc3237409c76a9fba2a8a9e
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
/*
 * Copyright (c) 2010-2020 Belledonne Communications SARL.
 *
 * This file is part of linphone-iphone
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
 
#import "HistoryDetailsView.h"
#import "PhoneMainView.h"
#import "FastAddressBook.h"
 
@implementation HistoryDetailsView
 
#pragma mark - UICompositeViewDelegate Functions
 
static UICompositeViewDescription *compositeDescription = nil;
 
+ (UICompositeViewDescription *)compositeViewDescription {
    if (compositeDescription == nil) {
        compositeDescription = [[UICompositeViewDescription alloc] init:self.class
                                                              statusBar:StatusBarView.class
                                                                 tabBar:TabBarView.class
                                                               sideMenu:SideMenuView.class
                                                             fullscreen:false
                                                         isLeftFragment:NO
                                                           fragmentWith:HistoryListView.class];
    }
    return compositeDescription;
}
 
- (UICompositeViewDescription *)compositeViewDescription {
    return self.class.compositeViewDescription;
}
 
#pragma mark - Property Functions
 
- (void)setCallLogId:(NSString *)acallLogId {
    _callLogId = [acallLogId copy];
    [self update];
}
 
#pragma mark - ViewController Functions
 
- (void)viewDidLoad {
    [super viewDidLoad];
 
    // if we use fragments, remove back button
    if (IPAD) {
        _backButton.hidden = YES;
        _backButton.alpha = 0;
        
    }
 
    UITapGestureRecognizer *headerTapGesture =
        [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onContactClick:)];
    [_headerView addGestureRecognizer:headerTapGesture];
}
 
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    _waitView.hidden = YES;
    [self update];
 
    [NSNotificationCenter.defaultCenter addObserver:self
                                           selector:@selector(update)
                                               name:kLinphoneAddressBookUpdate
                                             object:nil];
 
    [NSNotificationCenter.defaultCenter addObserver:self
                                           selector:@selector(coreUpdateEvent:)
                                               name:kLinphoneCoreUpdate
                                             object:nil];
    
    [[NSNotificationCenter defaultCenter] addObserver: self
                                             selector: @selector(deviceOrientationDidChange:)
                                                 name: UIDeviceOrientationDidChangeNotification
                                               object: nil];
}
 
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [NSNotificationCenter.defaultCenter removeObserver:self];
}
 
#pragma mark - Event Functions
 
- (void)coreUpdateEvent:(NSNotification *)notif {
    @try {
        [self update];
    }
    @catch (NSException *exception) {
        if ([exception.name isEqualToString:@"LinphoneCoreException"]) {
            LOGE(@"Core already destroyed");
            return;
        }
        LOGE(@"Uncaught exception : %@", exception.description);
        abort();
    }
}
 
- (void) deviceOrientationDidChange:(NSNotification*) notif {
    [self update];
}
 
#pragma mark -
 
- (void)update {
    // Look for the call log
    callLog = NULL;
    if (_callLogId) {
        const MSList *list = linphone_core_get_call_logs(LC);
        while (list != NULL) {
            LinphoneCallLog *log = (LinphoneCallLog *)list->data;
            const char *cid = linphone_call_log_get_call_id(log);
            if (cid != NULL && [_callLogId isEqualToString:[NSString stringWithUTF8String:cid]]) {
                callLog = log;
                break;
            }
            list = list->next;
        }
    }
 
    // Pop if callLog is null
    if (callLog == NULL) {
        _emptyLabel.hidden = NO;
        _addContactButton.hidden = YES;
        return;
    }
    _emptyLabel.hidden = YES;
 
    const LinphoneAddress *addr = linphone_call_log_get_remote_address(callLog);
    _addContactButton.hidden = ([FastAddressBook getContactWithAddress:addr] != nil);
    [ContactDisplay setDisplayNameLabel:_contactLabel forAddress:addr withAddressLabel:_addressLabel];
    [_avatarImage setImage:[FastAddressBook imageForAddress:addr] bordered:NO withRoundedRadius:YES];
    Contact *contact = [FastAddressBook getContactWithAddress:addr];
    const LinphonePresenceModel *model = contact.friend ? linphone_friend_get_presence_model(contact.friend) : NULL;
    _linphoneImage.hidden = [LinphoneManager.instance lpConfigBoolForKey:@"hide_linphone_contacts" inSection:@"app"] ||
    ! ((model && linphone_presence_model_get_basic_status(model) == LinphonePresenceBasicStatusOpen) || [FastAddressBook contactHasValidSipDomain:contact]);
    LinphoneAccount *defaultAccount = linphone_core_get_default_account(LC);
    [self shouldHideEncryptedChatView:defaultAccount && linphone_account_params_get_conference_factory_uri(linphone_account_get_params(defaultAccount)) && model && linphone_presence_model_has_capability(model, LinphoneFriendCapabilityLimeX3dh)];
    char *addrURI = linphone_address_as_string_uri_only(addr);
    ms_free(addrURI);
 
    [_tableView loadDataForAddress:(callLog ? linphone_call_log_get_remote_address(callLog) : NULL)];
}
 
- (void)shouldHideEncryptedChatView:(BOOL)hasLime {
    _encryptedChatView.hidden = !hasLime;
    CGRect newFrame = _optionsView.frame;
    if (!hasLime) {
        newFrame.origin.x = _encryptedChatView.frame.size.width * 2/3;
        
    } else {
        newFrame.origin.x = 0;
    }
    _optionsView.frame = newFrame;
}
 
#pragma mark - Action Functions
 
- (IBAction)onBackClick:(id)event {
    HistoryListView *view = VIEW(HistoryListView);
    [PhoneMainView.instance popToView:view.compositeViewDescription];
}
 
- (IBAction)onContactClick:(id)event {
    const LinphoneAddress *addr = linphone_call_log_get_remote_address(callLog);
    Contact *contact = [FastAddressBook getContactWithAddress:addr];
    if (contact) {
        ContactDetailsView *view = VIEW(ContactDetailsView);
        [PhoneMainView.instance changeCurrentView:view.compositeViewDescription];
        [ContactSelection setSelectionMode:ContactSelectionModeNone];
        [view setContact:contact];
    }
}
 
- (IBAction)onAddContactClick:(id)event {
    const LinphoneAddress *addr = linphone_call_log_get_remote_address(callLog);
    char *lAddress = linphone_address_as_string_uri_only(addr);
    if (lAddress != NULL) {
        NSString *normSip = [NSString stringWithUTF8String:lAddress];
        normSip = [normSip hasPrefix:@"sip:"] ? [normSip substringFromIndex:4] : normSip;
        [ContactSelection setAddAddress:normSip];
        [ContactSelection setSelectionMode:ContactSelectionModeEdit];
 
        [ContactSelection setSipFilter:nil];
        [ContactSelection enableEmailFilter:FALSE];
        [ContactSelection setNameOrEmailFilter:nil];
        [PhoneMainView.instance changeCurrentView:ContactsListView.compositeViewDescription];
        ms_free(lAddress);
    }
}
 
- (IBAction)onCallClick:(id)event {
    const LinphoneAddress *addr = linphone_call_log_get_remote_address(callLog);
    [LinphoneManager.instance call:addr];
}
 
- (IBAction)onChatClick:(id)event {
    const LinphoneAddress *addr = linphone_call_log_get_remote_address(callLog);
    [LinphoneManager.instance lpConfigSetBool:TRUE forKey:@"create_chat"];
    [PhoneMainView.instance getOrCreateOneToOneChatRoom:addr waitView:_waitView isEncrypted:FALSE];
}
 
- (IBAction)onEncryptedChatClick:(id)sender {
    const LinphoneAddress *addr = linphone_call_log_get_remote_address(callLog);
    [LinphoneManager.instance lpConfigSetBool:TRUE forKey:@"create_chat"];
    [PhoneMainView.instance getOrCreateOneToOneChatRoom:addr waitView:_waitView isEncrypted:TRUE];
}
 
@end