Skip to content

Commit beee837

Browse files
T19745917 : MEET-2619 revert refactor and simplify feature
1 parent ae76712 commit beee837

File tree

7 files changed

+102
-115
lines changed

7 files changed

+102
-115
lines changed

iMEGA/Chat Messages/ViewModel/ChatContentRouter.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ enum ChatContentRoutingStyle: Int {
4949
self.presenter = presenter
5050
self.publicLink = publicLink
5151
self.showShareLinkViewAfterOpenChat = showShareLinkViewAfterOpenChat
52-
self.tracker = DIContainer.tracker
5352
self.chatContentRoutingStyle = chatContentRoutingStyle
53+
self.tracker = DIContainer.tracker
5454
}
5555

5656
@objc static func chatViewController(

iMEGA/Chat/ArchivedChatRoomsViewController.m

+6-1
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,12 @@ - (void)showChatRoomAtIndexPath:(NSIndexPath *)indexPath {
338338
MEGAChatRoom *chatRoom = [MEGAChatSdk.shared chatRoomForChatId:chatListItem.chatId];
339339

340340
if (chatRoom != nil) {
341-
[[ChatContentRouter.alloc initWithChatRoom:chatRoom presenter:self.navigationController publicLink:nil showShareLinkViewAfterOpenChat:NO chatContentRoutingStyle:ChatContentRoutingStylePush] start];
341+
[[ChatContentRouter.alloc initWithChatRoom:chatRoom
342+
presenter:self.navigationController
343+
publicLink:nil
344+
showShareLinkViewAfterOpenChat:NO
345+
chatContentRoutingStyle:ChatContentRoutingStylePush
346+
] start];
342347
}
343348
}
344349

iMEGA/My Account/Contacts/ContactDetailsViewController.m

+6-1
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,12 @@ - (void)openChatRoom:(MEGAChatRoom *)chatRoom {
484484
return;
485485
}
486486

487-
[[ChatContentRouter.alloc initWithChatRoom:chatRoom presenter:self.navigationController publicLink:nil showShareLinkViewAfterOpenChat:NO chatContentRoutingStyle:ChatContentRoutingStylePush] start];
487+
[[ChatContentRouter.alloc initWithChatRoom:chatRoom
488+
presenter:self.navigationController
489+
publicLink:nil
490+
showShareLinkViewAfterOpenChat:NO
491+
chatContentRoutingStyle:ChatContentRoutingStylePush
492+
] start];
488493
}
489494

490495
- (void)sendMessageToContact {

iMEGA/My Account/Contacts/ContactsViewController.m

+6-1
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,12 @@ - (void)openChatRoom:(MEGAChatRoom *)chatRoom {
10481048
return;
10491049
}
10501050

1051-
[[ChatContentRouter.alloc initWithChatRoom:chatRoom presenter:self.navigationController publicLink:nil showShareLinkViewAfterOpenChat:NO chatContentRoutingStyle:ChatContentRoutingStylePush] start];
1051+
[[ChatContentRouter.alloc initWithChatRoom:chatRoom
1052+
presenter:self.navigationController
1053+
publicLink:nil
1054+
showShareLinkViewAfterOpenChat:NO
1055+
chatContentRoutingStyle:ChatContentRoutingStylePush
1056+
] start];
10521057
}
10531058

10541059
- (void)setupContactsTableViewHeader {

iMEGA/Utils/MEGALinks/MEGALinkManager+Additions.swift

-80
Original file line numberDiff line numberDiff line change
@@ -273,86 +273,6 @@ extension MEGALinkManager: MEGALinkManagerProtocol {
273273
mainTabBar.showCameraUploadsSettings()
274274
}
275275

276-
@objc class func autoRejoinAndOpenChatVC(
277-
chatRoom: MEGAChatRoom,
278-
request: MEGAChatRequest,
279-
chatLinkUrl: URL
280-
) {
281-
282-
guard !chatRoom.isPreview && !chatRoom.isActive else {
283-
self.createChatAndShow(request.chatHandle, publicChatLink: chatLinkUrl)
284-
return
285-
}
286-
287-
let chatSDK = MEGAChatSdk.shared
288-
289-
chatSDK.autorejoinPublicChat(request.chatHandle,
290-
publicHandle: request.userHandle,
291-
delegate: ChatRequestDelegate(completion: { rejoinRequest, error in
292-
guard error == nil else {
293-
if let error {
294-
SVProgressHUD.setDefaultMaskType(.none)
295-
SVProgressHUD.showError(withStatus: "\(rejoinRequest?.requestString ?? "") \(NSLocalizedString(error.name ?? "", comment: ""))")
296-
}
297-
return
298-
}
299-
if let rejoinRequest {
300-
if let base64Handle = MEGASdk.base64Handle(forUserHandle: rejoinRequest.chatHandle) {
301-
MEGALinkManager.joiningOrLeavingChatBase64Handles.remove(base64Handle)
302-
}
303-
MEGALinkManager.createChatAndShow(rejoinRequest.chatHandle, publicChatLink: chatLinkUrl)
304-
}
305-
}))
306-
307-
if let base64Handle = MEGASdk.base64Handle(forUserHandle: request.chatHandle) {
308-
MEGALinkManager.joiningOrLeavingChatBase64Handles.add(base64Handle)
309-
}
310-
}
311-
312-
@objc class func createMeetingAndShow(chatId: UInt64, userHandle: UInt64, publicChatLink: URL) {
313-
guard let rootViewController = UIApplication.mnz_keyWindow()?.rootViewController else {
314-
return
315-
}
316-
317-
guard MEGAChatSdk.shared.chatRoom(forChatId: chatId) != nil else {
318-
return
319-
}
320-
321-
guard !MEGAChatSdk.shared.mnz_existsActiveCall else {
322-
MeetingAlreadyExistsAlert.show(presenter: rootViewController)
323-
return
324-
}
325-
326-
let type: MeetingConfigurationType = self.isLoggedIn() ? .join : .guestJoin
327-
guard let mainTabBar = UIApplication.mainTabBarVisibleController() as? MainTabBarController else {
328-
let router = MeetingCreatingViewRouter(
329-
viewControllerToPresent: UIApplication.mnz_visibleViewController(),
330-
type: type,
331-
link: publicChatLink.absoluteString,
332-
userhandle: userHandle
333-
)
334-
router.start()
335-
return
336-
}
337-
338-
let router = MeetingCreatingViewRouter(
339-
viewControllerToPresent: mainTabBar,
340-
type: type,
341-
link: publicChatLink.absoluteString,
342-
userhandle: userHandle
343-
)
344-
mainTabBar.selectedIndex = TabType.chat.rawValue
345-
346-
if mainTabBar.presentedViewController != nil {
347-
mainTabBar.dismiss(animated: false) {
348-
router.start()
349-
}
350-
} else {
351-
router.start()
352-
}
353-
354-
}
355-
356276
@objc class func showBackupLinkView() {
357277
guard Helper.hasSession_alertIfNot() else { return }
358278
RecoveryKeyViewRouter(presenter: UIApplication.mnz_visibleViewController()).presentView()

iMEGA/Utils/MEGALinks/MEGALinkManager.h

-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ NS_ASSUME_NONNULL_BEGIN
5050

5151
+ (void)createChatAndShow:(uint64_t)chatId publicChatLink:(NSURL *)publicChatLink;
5252

53-
+ (BOOL)isLoggedIn;
54-
5553
@end
5654

5755
NS_ASSUME_NONNULL_END

iMEGA/Utils/MEGALinks/MEGALinkManager.m

+83-29
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ + (void)processLinkURL:(NSURL * _Nullable)url {
308308
case URLTypeNewSignUpLink: {
309309
if ([SAMKeychain passwordForService:@"MEGA" account:@"sessionV3"]) {
310310
[MEGALinkManager resetLinkAndURLType];
311-
311+
312312
UIAlertController *alreadyLoggedInAlertController = [UIAlertController alertControllerWithTitle:LocalizedString(@"error", @"") message:LocalizedString(@"This link is not related to this account. Please log in with the correct account.", @"Error message shown when opening a link with an account that not corresponds to the link") preferredStyle:UIAlertControllerStyleAlert];
313313
[alreadyLoggedInAlertController addAction:[UIAlertAction actionWithTitle:LocalizedString(@"ok", @"Button title to accept something") style:UIAlertActionStyleDestructive handler:nil]];
314314

@@ -440,7 +440,7 @@ + (void)processLinkURL:(NSURL * _Nullable)url {
440440
[mainTBC showAddContact];
441441
}
442442
break;
443-
443+
444444
case URLTypePresentNode:
445445
self.nodeToPresentBase64Handle = [url.absoluteString componentsSeparatedByString:@"/"].lastObject;
446446
[self presentNode];
@@ -606,7 +606,7 @@ + (void)showFileLinkView {
606606
photoBrowserVC.publicLink = fileLinkURLString;
607607
photoBrowserVC.encryptedLink = MEGALinkManager.secondaryLinkURL.absoluteString;
608608
photoBrowserVC.needsReload = YES;
609-
609+
610610
[self presentViewControllerWithAds:photoBrowserVC adsSlotViewController:photoBrowserVC presentationStyle:UIModalPresentationAutomatic];
611611
} else if ([FileExtensionGroupOCWrapper verifyIsMultiMedia:node.name] && node.mnz_isPlayable) {
612612
[self initFullScreenPlayerWithNode:node fileLink:fileLinkURLString filePaths:nil isFolderLink:NO isFromSharedItem:NO presenter:UIApplication.mnz_visibleViewController];
@@ -663,7 +663,7 @@ + (void)handleContactLink {
663663
}
664664
NSString *contactLinkHandle = [path substringFromIndex:(rangeOfPrefix.location + rangeOfPrefix.length)];
665665
uint64_t handle = [MEGASdk handleForBase64Handle:contactLinkHandle];
666-
666+
667667
MEGAContactLinkQueryRequestDelegate *delegate = [[MEGAContactLinkQueryRequestDelegate alloc] initWithCompletion:^(MEGARequest *request) {
668668
NSString *fullName = [NSString stringWithFormat:@"%@ %@", request.name, request.text];
669669
[MEGALinkManager presentInviteModalForEmail:request.email fullName:fullName contactLinkHandle:request.nodeHandle image:request.file];
@@ -674,7 +674,7 @@ + (void)handleContactLink {
674674
} onError:^(MEGAError *error) {
675675
[SVProgressHUD showErrorWithStatus:LocalizedString(@"linkNotValid", @"Message shown when the user clicks on an link that is not valid")];
676676
}];
677-
677+
678678
[MEGASdk.shared contactLinkQueryWithHandle:handle delegate:delegate];
679679
}
680680

@@ -767,9 +767,22 @@ + (void)handlePublicChatLink {
767767
}
768768
} else { // Chat link
769769
MEGAChatRoom *chatRoom = [MEGAChatSdk.shared chatRoomForChatId:request.chatHandle];
770-
[MEGALinkManager autoRejoinAndOpenChatVCWithChatRoom:chatRoom
771-
request: request
772-
chatLinkUrl:chatLinkUrl];
770+
if (!chatRoom.isPreview && !chatRoom.isActive) {
771+
ChatRequestDelegate *autorejoinPublicChatDelegate = [[ChatRequestDelegate alloc] initWithCompletion:^(MEGAChatRequest * _Nonnull request, MEGAChatError * _Nonnull error) {
772+
if (error.type) {
773+
[SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeNone];
774+
[SVProgressHUD showErrorWithStatus:[NSString stringWithFormat:@"%@ %@", request.requestString, LocalizedString(error.name, @"")]];
775+
return;
776+
}
777+
[MEGALinkManager.joiningOrLeavingChatBase64Handles removeObject:[MEGASdk base64HandleForUserHandle:request.chatHandle]];
778+
[MEGALinkManager createChatAndShow:request.chatHandle publicChatLink:chatLinkUrl];
779+
}];
780+
[MEGAChatSdk.shared autorejoinPublicChat:request.chatHandle publicHandle:request.userHandle delegate:autorejoinPublicChatDelegate];
781+
[MEGALinkManager.joiningOrLeavingChatBase64Handles addObject:[MEGASdk base64HandleForUserHandle:request.chatHandle]];
782+
} else {
783+
[MEGALinkManager createChatAndShow:request.chatHandle publicChatLink:chatLinkUrl];
784+
}
785+
773786
[SVProgressHUD dismiss];
774787
}
775788
}];
@@ -822,30 +835,68 @@ + (void)openMeetingWithRequest:(MEGAChatRequest * _Nonnull)request chatLinkURL:(
822835
if ([self isHostInWaitingRoomWithRequest:request chatSdk:MEGAChatSdk.shared]) {
823836
[self joinCallWithRequest:request];
824837
} else {
825-
[self createMeetingAndShowWithChatId:request.chatHandle userHandle:request.userHandle publicChatLink:chatLinkUrl];
838+
[self createMeetingAndShow:request.chatHandle userHandle:request.userHandle publicChatLink:chatLinkUrl];
826839
}
827-
}
828-
else {
829-
// [MEET-2619] we jump straight to chat for ended or not began meetings
840+
} else {
841+
// Meeting ended or not yet began
830842
[SVProgressHUD dismiss];
831843
MEGAChatRoom *chatRoom = [[MEGAChatSdk shared] chatRoomForChatId:request.chatHandle];
832-
if (chatRoom == nil) {
833-
MEGALogError(@"Cannot join chat, missing chat room %llu", request.chatHandle);
834-
return;
844+
if (!chatRoom.isPreview && !chatRoom.isActive) {
845+
ChatRequestDelegate *autorejoinPublicChatDelegate = [[ChatRequestDelegate alloc] initWithCompletion:^(MEGAChatRequest * _Nonnull request, MEGAChatError * _Nonnull error) {
846+
if (error.type) {
847+
[SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeNone];
848+
[SVProgressHUD showErrorWithStatus:[NSString stringWithFormat:@"%@ %@", request.requestString, LocalizedString(error.name, @"")]];
849+
return;
850+
}
851+
[MEGALinkManager.joiningOrLeavingChatBase64Handles removeObject:[MEGASdk base64HandleForUserHandle:request.chatHandle]];
852+
[MEGALinkManager createChatAndShow:request.chatHandle publicChatLink:chatLinkUrl];
853+
}];
854+
[MEGAChatSdk.shared autorejoinPublicChat:request.chatHandle publicHandle:request.userHandle delegate:autorejoinPublicChatDelegate];
855+
[MEGALinkManager.joiningOrLeavingChatBase64Handles addObject:[MEGASdk base64HandleForUserHandle:request.chatHandle]];
856+
} else {
857+
[MEGALinkManager createChatAndShow:request.chatHandle publicChatLink:chatLinkUrl];
835858
}
836-
[MEGALinkManager autoRejoinAndOpenChatVCWithChatRoom:chatRoom
837-
request:request
838-
chatLinkUrl:chatLinkUrl];
839859
}
840860
}
841861

842-
+ (BOOL)isLoggedIn{
862+
+ (void)createMeetingAndShow:(uint64_t)chatId userHandle:(uint64_t)userHandle publicChatLink:(NSURL *)publicChatLink {
863+
864+
UIViewController *rootViewController = UIApplication.mnz_keyWindow.rootViewController;
865+
MEGAChatRoom *chatRoom = [MEGAChatSdk.shared chatRoomForChatId:chatId];
866+
if (chatRoom == nil) {
867+
return;
868+
} else if (MEGAChatSdk.shared.mnz_existsActiveCall) {
869+
[MeetingAlreadyExistsAlert showWithPresenter:rootViewController];
870+
return;
871+
}
843872

844873
// If the application was deleted when the user is logged and then reinstalled.
845874
// The sdk says the user is logged in but the session is cleared.
846875
NSString *sessionV3 = [SAMKeychain passwordForService:@"MEGA" account:@"sessionV3"];
847876
BOOL isLoggedIn = MEGASdk.shared.isLoggedIn && sessionV3 != nil && !sessionV3.mnz_isEmpty;
848-
return isLoggedIn;
877+
MeetingConfigurationType type = isLoggedIn ? MeetingConfigurationTypeJoin : MeetingConfigurationTypeGuestJoin;
878+
879+
if (UIApplication.mainTabBarRootViewController) {
880+
MainTabBarController *mainTBC = (MainTabBarController *)UIApplication.mainTabBarRootViewController;
881+
mainTBC.selectedIndex = TabTypeChat;
882+
MeetingCreatingViewRouter *router = [[MeetingCreatingViewRouter alloc] initWithViewControllerToPresent:mainTBC
883+
type:type
884+
link:publicChatLink.absoluteString
885+
userhandle:userHandle];
886+
if (mainTBC.presentedViewController) {
887+
[mainTBC dismissViewControllerAnimated:NO completion:^{
888+
[router start];
889+
}];
890+
} else {
891+
[router start];
892+
}
893+
} else {
894+
MeetingCreatingViewRouter *router = [[MeetingCreatingViewRouter alloc] initWithViewControllerToPresent:UIApplication.mnz_visibleViewController
895+
type:type
896+
link:publicChatLink.absoluteString
897+
userhandle:userHandle];
898+
[router start];
899+
}
849900
}
850901

851902
+ (void)createChatAndShow:(uint64_t)chatId publicChatLink:(NSURL *)publicChatLink {
@@ -877,14 +928,12 @@ + (void)createChatAndShow:(uint64_t)chatId publicChatLink:(NSURL *)publicChatLin
877928
} else {
878929
// there's no UINavigationController present when user is logged out
879930
// we do a present in that case
880-
UIViewController *presenter = UIApplication.mnz_visibleViewController;
881-
BOOL shouldPush = [presenter isKindOfClass:[UINavigationController class]];
882-
ChatContentRouter *router = [[ChatContentRouter alloc] initWithChatRoom:chatRoom
883-
presenter:presenter
884-
publicLink:publicChatLink.absoluteString
885-
showShareLinkViewAfterOpenChat:NO
886-
chatContentRoutingStyle:shouldPush ? ChatContentRoutingStylePush : ChatContentRoutingStylePresent];
887-
[router start];
931+
[[ChatContentRouter.alloc initWithChatRoom:chatRoom
932+
presenter:UIApplication.mnz_visibleViewController
933+
publicLink:publicChatLink.absoluteString
934+
showShareLinkViewAfterOpenChat:NO
935+
chatContentRoutingStyle:ChatContentRoutingStylePresent
936+
] start];
888937
}
889938
}
890939

@@ -899,7 +948,12 @@ + (void)pushChat:(MEGAChatRoom *)chatRoom publicChatLink:(NSURL *)publicChatLink
899948
}
900949

901950
[chatNC popToRootViewControllerAnimated:NO];
902-
[[ChatContentRouter.alloc initWithChatRoom:chatRoom presenter:chatNC publicLink:publicChatLink.absoluteString showShareLinkViewAfterOpenChat:NO chatContentRoutingStyle:ChatContentRoutingStylePush] start];
951+
[[ChatContentRouter.alloc initWithChatRoom:chatRoom
952+
presenter:chatNC
953+
publicLink:publicChatLink.absoluteString
954+
showShareLinkViewAfterOpenChat:NO
955+
chatContentRoutingStyle:ChatContentRoutingStylePush
956+
] start];
903957
}
904958

905959
+ (void)handleChatPeerOptionsLink {

0 commit comments

Comments
 (0)