fix crash with markAsRead when goToChatRoom and app is closed

This commit is contained in:
David Idmansour 2018-06-20 15:13:32 +02:00
parent b081df9394
commit 58de233295
8 changed files with 60 additions and 35 deletions

View file

@ -40,6 +40,7 @@
@property(nonatomic) LinphoneChatRoom *chatRoom;
@property(nonatomic) LinphoneChatRoomCbs *chatRoomCbs;
@property(nonatomic) Boolean markAsRead;
@property(weak, nonatomic) IBOutlet UIIconButton *backButton;
@property(nonatomic, strong) IBOutlet ChatConversationTableView *tableController;

View file

@ -84,7 +84,7 @@ static UICompositeViewDescription *compositeDescription = nil;
- (void)viewDidLoad {
[super viewDidLoad];
_markAsRead = TRUE;
// if we use fragments, remove back button
if (IPAD) {
_backButton.hidden = YES;
@ -208,8 +208,10 @@ static UICompositeViewDescription *compositeDescription = nil;
}
- (void)applicationWillEnterForeground:(NSNotification *)notif {
if (_chatRoom)
if (_chatRoom && _markAsRead)
[ChatConversationView markAsRead:_chatRoom];
_markAsRead = TRUE;
}
- (void)callUpdateEvent:(NSNotification *)notif {

View file

@ -141,16 +141,19 @@ static int sorted_history_comparison(LinphoneChatRoom *to_insert, LinphoneChatRo
while (sorted) {
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
LinphoneChatRoom *cr = sorted->data;
const LinphoneAddress *address = linphone_chat_room_get_peer_address(cr);
const LinphoneAddress *peer_address = linphone_chat_room_get_peer_address(cr);
const LinphoneAddress *local_address = linphone_chat_room_get_local_address(cr);
NSString *display;
[dict setObject:[[NSString stringWithUTF8String:linphone_address_as_string_uri_only(address)] substringFromIndex:4]
forKey:@"address"];
[dict setObject:[NSString stringWithUTF8String:linphone_address_as_string_uri_only(peer_address)]
forKey:@"peer"];
[dict setObject:[NSString stringWithUTF8String:linphone_address_as_string_uri_only(local_address)]
forKey:@"local"];
if (linphone_chat_room_get_conference_address(cr))
display = [NSString stringWithUTF8String:linphone_chat_room_get_subject(cr)];
else {
display = [NSString stringWithUTF8String:linphone_address_get_display_name(address)?:linphone_address_get_username(address)];
if ([FastAddressBook imageForAddress:address])
[dict setObject:UIImageJPEGRepresentation([UIImage resizeImage:[FastAddressBook imageForAddress:address]
display = [NSString stringWithUTF8String:linphone_address_get_display_name(peer_address)?:linphone_address_get_username(peer_address)];
if ([FastAddressBook imageForAddress:peer_address])
[dict setObject:UIImageJPEGRepresentation([UIImage resizeImage:[FastAddressBook imageForAddress:peer_address]
withMaxWidth:200
andMaxHeight:200],
1)

View file

@ -344,20 +344,35 @@
NSString *sipUri = [[url resourceSpecifier] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"/"]];
[VIEW(DialerView) setAddress:sipUri];
} else if ([scheme isEqualToString:@"linphone-widget"]) {
printf("cparla\n");
if ([[url host] isEqualToString:@"call_log"] &&
[[url path] isEqualToString:@"/show"]) {
[VIEW(HistoryDetailsView) setCallLogId:[url query]];
[PhoneMainView.instance changeCurrentView:HistoryDetailsView.compositeViewDescription];
} else if ([[url host] isEqualToString:@"chatroom"] &&
[[url path] isEqualToString:@"/show"]) {
LinphoneChatRoom *cr = linphone_core_get_chat_room_from_uri(LC, url.query.UTF8String);
} else if ([[url host] isEqualToString:@"chatroom"] && [[url path] isEqualToString:@"/show"]) {
NSURLComponents *urlComponents = [NSURLComponents componentsWithURL:url
resolvingAgainstBaseURL:NO];
NSArray *queryItems = urlComponents.queryItems;
NSString *peerAddress = [self valueForKey:@"peer" fromQueryItems:queryItems];
NSString *localAddress = [self valueForKey:@"local" fromQueryItems:queryItems];
LinphoneAddress *peer = linphone_address_new(peerAddress.UTF8String);
LinphoneAddress *local = linphone_address_new(localAddress.UTF8String);
LinphoneChatRoom *cr = linphone_core_find_chat_room(LC, peer, local);
linphone_address_unref(peer);
linphone_address_unref(local);
// TODO : Find a better fix
VIEW(ChatConversationView).markAsRead = FALSE;
[PhoneMainView.instance goToChatRoom:cr];
}
}
return YES;
}
- (NSString *)valueForKey:(NSString *)key fromQueryItems:(NSArray *)queryItems {
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name=%@", key];
NSURLQueryItem *queryItem = [[queryItems filteredArrayUsingPredicate:predicate] firstObject];
return queryItem.value;
}
- (void)fixRing {
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
// iOS7 fix for notification sound not stopping.

View file

@ -36,7 +36,7 @@
<action selector="firstButtonTapped" destination="M4Y-Lb-cyx" eventType="touchUpInside" id="hiI-LE-Zgn"/>
</connections>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ZCh-k6-wlC">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" " textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ZCh-k6-wlC">
<rect key="frame" x="0.0" y="70.5" width="60" height="17"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
@ -62,7 +62,7 @@
<action selector="secondButtonTapped" destination="M4Y-Lb-cyx" eventType="touchUpInside" id="VD4-JL-D57"/>
</connections>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="vzp-zG-86G">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" " textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="vzp-zG-86G">
<rect key="frame" x="0.0" y="70" width="60" height="17.5"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
@ -87,7 +87,7 @@
<action selector="thirdButtonTapped" destination="M4Y-Lb-cyx" eventType="touchUpInside" id="A6r-gZ-0Be"/>
</connections>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="1km-2d-H8g">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" " textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="1km-2d-H8g">
<rect key="frame" x="0.0" y="70" width="60" height="17.5"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
@ -112,7 +112,7 @@
<action selector="fourthButtonTapped" destination="M4Y-Lb-cyx" eventType="touchUpInside" id="MfV-kR-GEH"/>
</connections>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Z4D-W4-T9E">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" " textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Z4D-W4-T9E">
<rect key="frame" x="0.0" y="70" width="60" height="17.5"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>

View file

@ -25,7 +25,7 @@
<rect key="frame" x="0.0" y="0.0" width="60" height="87.5"/>
<subviews>
<button opaque="NO" contentMode="scaleAspectFit" contentHorizontalAlignment="center" contentVerticalAlignment="center" showsTouchWhenHighlighted="YES" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="dGY-Wo-tng">
<rect key="frame" x="0.0" y="0.0" width="60" height="60"/>
<rect key="frame" x="0.0" y="0.0" width="60" height="60.5"/>
<constraints>
<constraint firstAttribute="width" constant="60" id="a43-Du-y1b"/>
<constraint firstAttribute="height" constant="60" id="gNd-AG-oLn"/>
@ -35,8 +35,8 @@
<action selector="firstButtonTapped" destination="M4Y-Lb-cyx" eventType="touchUpInside" id="n6M-cY-cWU"/>
</connections>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="fpJ-Wl-BT1">
<rect key="frame" x="0.0" y="70" width="60" height="17.5"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" " textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="fpJ-Wl-BT1">
<rect key="frame" x="0.0" y="70.5" width="60" height="17"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
@ -50,7 +50,7 @@
<rect key="frame" x="76" y="0.0" width="60" height="87.5"/>
<subviews>
<button opaque="NO" contentMode="scaleAspectFit" contentHorizontalAlignment="center" contentVerticalAlignment="center" showsTouchWhenHighlighted="YES" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="aiZ-1q-Ssd">
<rect key="frame" x="0.0" y="0.0" width="60" height="60.5"/>
<rect key="frame" x="0.0" y="0.0" width="60" height="60"/>
<constraints>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="60" id="0Me-vh-jt4"/>
<constraint firstAttribute="height" constant="60" id="9hj-Pa-s8F"/>
@ -61,8 +61,8 @@
<action selector="secondButtonTapped" destination="M4Y-Lb-cyx" eventType="touchUpInside" id="e09-4G-NJf"/>
</connections>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="fEo-fa-uyD">
<rect key="frame" x="0.0" y="70.5" width="60" height="17"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" " textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="fEo-fa-uyD">
<rect key="frame" x="0.0" y="70" width="60" height="17.5"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
@ -76,7 +76,7 @@
<rect key="frame" x="152" y="0.0" width="60" height="87.5"/>
<subviews>
<button opaque="NO" contentMode="scaleAspectFit" contentHorizontalAlignment="center" contentVerticalAlignment="center" showsTouchWhenHighlighted="YES" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="VgA-lq-CQL">
<rect key="frame" x="0.0" y="0.0" width="60" height="60.5"/>
<rect key="frame" x="0.0" y="0.0" width="60" height="60"/>
<constraints>
<constraint firstAttribute="width" constant="60" id="TEZ-z7-Yce"/>
<constraint firstAttribute="height" constant="60" id="rtD-OM-bmH"/>
@ -86,8 +86,8 @@
<action selector="thirdButtonTapped" destination="M4Y-Lb-cyx" eventType="touchUpInside" id="OtO-nr-X1J"/>
</connections>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="zM6-aO-Pes">
<rect key="frame" x="0.0" y="70.5" width="60" height="17"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" " textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="zM6-aO-Pes">
<rect key="frame" x="0.0" y="70" width="60" height="17.5"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
@ -101,7 +101,7 @@
<rect key="frame" x="228" y="0.0" width="60" height="87.5"/>
<subviews>
<button opaque="NO" contentMode="scaleAspectFit" contentHorizontalAlignment="center" contentVerticalAlignment="center" showsTouchWhenHighlighted="YES" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="7je-G1-IfQ">
<rect key="frame" x="0.0" y="0.0" width="60" height="60.5"/>
<rect key="frame" x="0.0" y="0.0" width="60" height="60"/>
<constraints>
<constraint firstAttribute="width" constant="60" id="Pm8-lw-PB4"/>
<constraint firstAttribute="height" constant="60" id="SYf-Yl-EDf"/>
@ -111,8 +111,8 @@
<action selector="fourthButtonTapped" destination="M4Y-Lb-cyx" eventType="touchUpInside" id="a2u-BT-Fkp"/>
</connections>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="bpY-VL-FDz">
<rect key="frame" x="0.0" y="70.5" width="60" height="17"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" " textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="bpY-VL-FDz">
<rect key="frame" x="0.0" y="70" width="60" height="17.5"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>

View file

@ -10,6 +10,7 @@
@interface TodayViewController : UIViewController
@property (strong, nonatomic) IBOutletCollection(UIStackView) NSArray *stackViews;
@property (strong, nonatomic) NSMutableArray *addresses;
@property (strong, nonatomic) NSMutableArray *localAddress;
@property (strong, nonatomic) NSMutableArray *displayNames;
@property (strong, nonatomic) NSMutableArray *isConf;
@property (strong, nonatomic) NSMutableArray *imgs;

View file

@ -18,11 +18,13 @@
NSUserDefaults *mySharedDefaults = [[NSUserDefaults alloc] initWithSuiteName: @"group.belledonne-communications.linphone.widget"];
[_imgs removeAllObjects];
[_addresses removeAllObjects];
[_localAddress removeAllObjects];
[_displayNames removeAllObjects];
[_isConf removeAllObjects];
NSMutableArray *chatrooms = [NSMutableArray arrayWithArray:[mySharedDefaults objectForKey:@"chatrooms"]];
for (NSDictionary *dict in chatrooms) {
[_addresses addObject:[dict objectForKey:@"address"]];
[_addresses addObject:[dict objectForKey:@"peer"]];
[_localAddress addObject:[dict objectForKey:@"local"]];
[_displayNames addObject:[dict objectForKey:@"display"]];
[_isConf addObject:(NSNumber *)[dict objectForKey:@"nbParticipants"]];
[_imgs addObject:[dict objectForKey:@"img"]?:[NSNull null]];
@ -66,6 +68,7 @@
}
_addresses = [NSMutableArray array];
_localAddress = [NSMutableArray array];
_displayNames = [NSMutableArray array];
_imgs = [NSMutableArray array];
_isConf = [NSMutableArray array];
@ -94,23 +97,23 @@
completionHandler:nil];
}
- (void)launchOnChatConversationViewWithAddress:(NSString *)chatAddress {
[self launchAppWithURL:[NSURL URLWithString:[@"linphone-widget://chatroom/show?" stringByAppendingString:chatAddress]]];
- (void)launchOnChatConversationViewWithPeerAddress:(NSString *)peerAddress andLocalAddress:(NSString *)localAddress {
[self launchAppWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"linphone-widget://chatroom/show?peer=%@&local=%@", peerAddress, localAddress]]];
}
- (IBAction)firstButtonTapped {
[self launchOnChatConversationViewWithAddress:_addresses[0]];
[self launchOnChatConversationViewWithPeerAddress:_addresses[0] andLocalAddress:_localAddress[0]];
}
- (IBAction)secondButtonTapped {
[self launchOnChatConversationViewWithAddress:_addresses[1]];
[self launchOnChatConversationViewWithPeerAddress:_addresses[1] andLocalAddress:_localAddress[1]];
}
- (IBAction)thirdButtonTapped {
[self launchOnChatConversationViewWithAddress:_addresses[2]];
[self launchOnChatConversationViewWithPeerAddress:_addresses[2] andLocalAddress:_localAddress[2]];
}
- (IBAction)fourthButtonTapped {
[self launchOnChatConversationViewWithAddress:_addresses[3]];
[self launchOnChatConversationViewWithPeerAddress:_addresses[3] andLocalAddress:_localAddress[3]];
}
@end