diff --git a/entourage.xcworkspace/contents.xcworkspacedata b/entourage.xcworkspace/contents.xcworkspacedata index fdae694c9..b7896ced0 100644 --- a/entourage.xcworkspace/contents.xcworkspacedata +++ b/entourage.xcworkspace/contents.xcworkspacedata @@ -1,6 +1,9 @@ + + diff --git a/entourage/MainTabbarViewController.swift b/entourage/MainTabbarViewController.swift index 98bf4efeb..c842c0eaf 100644 --- a/entourage/MainTabbarViewController.swift +++ b/entourage/MainTabbarViewController.swift @@ -83,7 +83,7 @@ class MainTabbarViewController: UITabBarController { @objc func showMyEvents() { if let vc = eventsVC.topViewController as? EventMainHomeViewController { - vc.setMyFirst() + vc.setDiscoverFirst() } self.selectedIndex = 4 self.boldSelectedItem() diff --git a/entourage/Managers/DeeplinkManager.swift b/entourage/Managers/DeeplinkManager.swift index 1b8df396a..58e61e727 100644 --- a/entourage/Managers/DeeplinkManager.swift +++ b/entourage/Managers/DeeplinkManager.swift @@ -352,9 +352,21 @@ struct DeepLinkManager { } static func showContribListUniversalLink() { - if let vc = AppState.getTopViewController(){ - if let _tabbar = vc.tabBarController as? MainTabbarViewController { - _tabbar.showActionsContrib() + if let vc = AppState.getTopViewController() { + // Verifier si le viewController est présenté comme modal + if vc.isModal { + // Fermer le modal avant de lancer la commande + vc.dismiss(animated: true) { + if let _vc = AppState.getTopViewController() { + if let _tabbar = _vc.tabBarController as? MainTabbarViewController { + _tabbar.showActionsContrib() + } + } + } + } else { + if let _tabbar = vc.tabBarController as? MainTabbarViewController { + _tabbar.showActionsContrib() + } } } } diff --git a/entourage/Scenes/Groups - Neighborhoods/NeighborhoodDetailMessagesViewController.swift b/entourage/Scenes/Groups - Neighborhoods/NeighborhoodDetailMessagesViewController.swift index 2f1d74cac..a06400341 100644 --- a/entourage/Scenes/Groups - Neighborhoods/NeighborhoodDetailMessagesViewController.swift +++ b/entourage/Scenes/Groups - Neighborhoods/NeighborhoodDetailMessagesViewController.swift @@ -166,10 +166,15 @@ class NeighborhoodDetailMessagesViewController: UIViewController { self.ui_textview_message.text = nil ui_iv_bt_send.image = UIImage.init(named: "ic_send_comment_off") NeighborhoodService.postCommentFor(neighborhoodId: neighborhoodId, parentPostId: parentCommentId, message: message) { error in - + if error == nil { if isRetry { - self.messagesForRetry.remove(at: positionForRetry) + // Ensure positionForRetry is in valid range before removing from array + if positionForRetry >= 0 && positionForRetry < self.messagesForRetry.count { + self.messagesForRetry.remove(at: positionForRetry) + } else { + print("Error: positionForRetry out of range. Value: \(positionForRetry), Array Count: \(self.messagesForRetry.count)") + } } self.getMessages() return @@ -181,13 +186,13 @@ class NeighborhoodDetailMessagesViewController: UIViewController { postMsg.content = message postMsg.user = UserLightNeighborhood() postMsg.isRetryMsg = true - + self.messagesForRetry.append(postMsg) - + self.isStartEditing = false self.ui_view_empty.isHidden = true self.ui_tableview.reloadData() - + if self.messages.count + self.messagesForRetry.count > 0 { DispatchQueue.main.async { let indexPath = IndexPath(row: self.messages.count + self.messagesForRetry.count - 1, section: 0) @@ -197,6 +202,7 @@ class NeighborhoodDetailMessagesViewController: UIViewController { } } } + func getDetailPost() { NeighborhoodService.getDetailPostMessage(neighborhoodId: neighborhoodId, parentPostId: parentCommentId) { message, error in diff --git a/entourage/Scenes/Groups - Neighborhoods/NeighborhoodDetailViewController.swift b/entourage/Scenes/Groups - Neighborhoods/NeighborhoodDetailViewController.swift index a41694c4a..018c0d482 100644 --- a/entourage/Scenes/Groups - Neighborhoods/NeighborhoodDetailViewController.swift +++ b/entourage/Scenes/Groups - Neighborhoods/NeighborhoodDetailViewController.swift @@ -482,80 +482,100 @@ extension NeighborhoodDetailViewController: UITableViewDataSource, UITableViewDe } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + guard let neighborhood = self.neighborhood else { + return UITableViewCell() + } + if indexPath.section == 0 { if indexPath.row == 0 { - if self.neighborhood!.isMember && !isAfterCreation { - let cell = tableView.dequeueReusableCell(withIdentifier: NeighborhoodDetailTopMemberCell.identifier, for: indexPath) as! NeighborhoodDetailTopMemberCell - cell.populateCell(neighborhood: self.neighborhood,isFollowingGroup: true, delegate: self) - return cell - } - else { - let cell = tableView.dequeueReusableCell(withIdentifier: NeighborhoodDetailTopCell.identifier, for: indexPath) as! NeighborhoodDetailTopCell - cell.populateCell(neighborhood: self.neighborhood, isFollowingGroup: false, delegate: self) - return cell + let isMember = neighborhood.isMember && !isAfterCreation + let identifier = isMember ? NeighborhoodDetailTopMemberCell.identifier : NeighborhoodDetailTopCell.identifier + let cell = tableView.dequeueReusableCell(withIdentifier: identifier, for: indexPath) + if isMember, let memberCell = cell as? NeighborhoodDetailTopMemberCell { + memberCell.populateCell(neighborhood: neighborhood, isFollowingGroup: true, delegate: self) + } else if let topCell = cell as? NeighborhoodDetailTopCell { + topCell.populateCell(neighborhood: neighborhood, isFollowingGroup: false, delegate: self) } - } - else { - if neighborhood?.futureEvents?.count ?? 0 > 0 { - let cell = tableView.dequeueReusableCell(withIdentifier: NeighborhoodEventsTableviewCell.identifier, for: indexPath) as! NeighborhoodEventsTableviewCell - cell.populateCell(events:neighborhood!.futureEvents!, delegate: self) - return cell + return cell + } else { + let events = neighborhood.futureEvents ?? [] + let identifier = events.count > 0 ? NeighborhoodEventsTableviewCell.identifier : NeighborhoodEmptyEventCell.identifier + let cell = tableView.dequeueReusableCell(withIdentifier: identifier, for: indexPath) + if events.count > 0, let eventsCell = cell as? NeighborhoodEventsTableviewCell { + eventsCell.populateCell(events: events, delegate: self) } - let cell = tableView.dequeueReusableCell(withIdentifier: NeighborhoodEmptyEventCell.identifier, for: indexPath) return cell } } - - if self.neighborhood?.messages?.count ?? 0 == 0 { + + if neighborhood.messages?.count ?? 0 == 0 { let cell = tableView.dequeueReusableCell(withIdentifier: NeighborhoodEmptyPostCell.identifier, for: indexPath) return cell } - + if hasNewAndOldSections && indexPath.section == 2 { if indexPath.row == 0 { let cell = tableView.dequeueReusableCell(withIdentifier: EventListSectionCell.identifier, for: indexPath) as! EventListSectionCell - cell.populateCell(title: "neighborhood_post_group_section_old_posts_title".localized, isTopHeader: false) return cell } - let postmessage:PostMessage = messagesOld[indexPath.row - 1] - var identifier = postmessage.isPostImage ? NeighborhoodPostImageCell.identifier : NeighborhoodPostTextCell.identifier - if postmessage.status == "deleted" { - identifier = NeighborhoodPostDeletedCell.identifier + if indexPath.row - 1 < messagesOld.count { + let postmessage = messagesOld[indexPath.row - 1] + var identifier = postmessage.isPostImage ? NeighborhoodPostImageCell.identifier : NeighborhoodPostTextCell.identifier + if postmessage.status == "deleted" { + identifier = NeighborhoodPostDeletedCell.identifier + } + let cell = tableView.dequeueReusableCell(withIdentifier: identifier, for: indexPath) as! NeighborhoodPostCell + cell.populateCell(message: postmessage,delegate: self,currentIndexPath: indexPath, userId: postmessage.user?.sid) + return cell + } else { + return UITableViewCell() } - let cell = tableView.dequeueReusableCell(withIdentifier: identifier, for: indexPath) as! NeighborhoodPostCell - cell.populateCell(message: postmessage,delegate: self,currentIndexPath: indexPath, userId: postmessage.user?.sid) - return cell } - + if indexPath.row == 0 { let cell = tableView.dequeueReusableCell(withIdentifier: EventListSectionCell.neighborhoodHeaderIdentifier, for: indexPath) as! EventListSectionCell cell.populateCell(title: "neighborhood_post_group_section_title".localized, isTopHeader: true) return cell } - - //If not member we dont' show new/old post header + let countToAdd = countToAdd() - if countToAdd == 2 { - if indexPath.row == 1 { - let titleSection = hasNewAndOldSections || self.messagesOld.count == 0 ? "neighborhood_post_group_section_new_posts_title".localized : "neighborhood_post_group_section_old_posts_title".localized - - let cell = tableView.dequeueReusableCell(withIdentifier: EventListSectionCell.identifier, for: indexPath) as! EventListSectionCell - cell.populateCell(title: titleSection , isTopHeader: false) + if countToAdd == 2 && indexPath.row == 1 { + let titleSection = hasNewAndOldSections || self.messagesOld.count == 0 ? "neighborhood_post_group_section_new_posts_title".localized : "neighborhood_post_group_section_old_posts_title".localized + + let cell = tableView.dequeueReusableCell(withIdentifier: EventListSectionCell.identifier, for: indexPath) as! EventListSectionCell + cell.populateCell(title: titleSection , isTopHeader: false) + return cell + } + + if hasNewAndOldSections { + if indexPath.row - countToAdd < self.messagesNew.count { + let postmessage = self.messagesNew[indexPath.row - countToAdd] + var identifier = postmessage.isPostImage ? NeighborhoodPostImageCell.identifier : NeighborhoodPostTextCell.identifier + if postmessage.status == "deleted" { + identifier = NeighborhoodPostDeletedCell.identifier + } + let cell = tableView.dequeueReusableCell(withIdentifier: identifier, for: indexPath) as! NeighborhoodPostCell + cell.populateCell(message: postmessage,delegate: self,currentIndexPath: indexPath, userId: postmessage.user?.sid) return cell + } else { + return UITableViewCell() } } - - let postmessage:PostMessage = hasNewAndOldSections ? self.messagesNew[indexPath.row - countToAdd] : self.neighborhood!.messages![indexPath.row - countToAdd] - - var identifier = postmessage.isPostImage ? NeighborhoodPostImageCell.identifier : NeighborhoodPostTextCell.identifier - if postmessage.status == "deleted" { - identifier = NeighborhoodPostDeletedCell.identifier + + if let messages = neighborhood.messages, indexPath.row - countToAdd < messages.count { + let postmessage = messages[indexPath.row - countToAdd] + var identifier = postmessage.isPostImage ? NeighborhoodPostImageCell.identifier : NeighborhoodPostTextCell.identifier + if postmessage.status == "deleted" { + identifier = NeighborhoodPostDeletedCell.identifier + } + let cell = tableView.dequeueReusableCell(withIdentifier: identifier, for: indexPath) as! NeighborhoodPostCell + cell.populateCell(message: postmessage,delegate: self,currentIndexPath: indexPath, userId: postmessage.user?.sid) + return cell } - let cell = tableView.dequeueReusableCell(withIdentifier: identifier, for: indexPath) as! NeighborhoodPostCell - cell.populateCell(message: postmessage,delegate: self,currentIndexPath: indexPath, userId: postmessage.user?.sid) - return cell + + return UITableViewCell() } func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { diff --git a/entourage/Scenes/Groups - Neighborhoods/NeighborhoodHomeViewController.swift b/entourage/Scenes/Groups - Neighborhoods/NeighborhoodHomeViewController.swift index dc5b02196..a3b7600e4 100644 --- a/entourage/Scenes/Groups - Neighborhoods/NeighborhoodHomeViewController.swift +++ b/entourage/Scenes/Groups - Neighborhoods/NeighborhoodHomeViewController.swift @@ -558,69 +558,76 @@ class NeighborhoodHomeViewController: UIViewController { extension NeighborhoodHomeViewController: UITableViewDataSource, UITableViewDelegate { func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - if (isGroupsSelected && myNeighborhoods.isEmpty && !isfirstLoadingMyGroup) || (isSearch && neighborhoodsSearch.isEmpty && isSendedSearch) || (!isGroupsSelected && neighborhoodsDiscovered.isEmpty) { - // showEmptyView() - } - else { - hideEmptyView() + if (isGroupsSelected && myNeighborhoods.isEmpty && !isfirstLoadingMyGroup) || (isSearch && neighborhoodsSearch.isEmpty && isSendedSearch) || (!isGroupsSelected && neighborhoodsDiscovered.isEmpty) { + // showEmptyView() + } + else { + hideEmptyView() + } + + return isGroupsSelected ? myNeighborhoods.count : isSearch ? neighborhoodsSearch.count + 1 : neighborhoodsDiscovered.count + 1 //Search } - return isGroupsSelected ? myNeighborhoods.count : isSearch ? neighborhoodsSearch.count + 1 : neighborhoodsDiscovered.count + 1 //Search - } - - func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - if isGroupsSelected { - let neighborhood = myNeighborhoods[indexPath.row] - - var cellName = "cellGroup" - - if neighborhood.creator.uid == UserDefaults.currentUser?.sid { - cellName = "cellGroupMy" + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + if isGroupsSelected { + guard let neighborhood = myNeighborhoods[safe: indexPath.row] else { + return UITableViewCell() + } + + let cellName = (neighborhood.creator.uid == UserDefaults.currentUser?.sid) ? "cellGroupMy" : "cellGroup" + + guard let cell = tableView.dequeueReusableCell(withIdentifier: cellName, for: indexPath) as? NeighborhoodHomeGroupCell else { + return UITableViewCell() + } + + cell.populateCell(neighborhood: neighborhood) + + return cell } - let cell = tableView.dequeueReusableCell(withIdentifier: cellName, for: indexPath) as! NeighborhoodHomeGroupCell + if indexPath.row == 0 { + guard let cell = tableView.dequeueReusableCell(withIdentifier: "cellSearch", for: indexPath) as? NeighborhoodHomeSearchCell else { + return UITableViewCell() + } + + cell.populateCell(delegate: self, isSearch:isSearch,isCellUserSearch: false) + + return cell + } + guard let cell = tableView.dequeueReusableCell(withIdentifier: "cellGroup", for: indexPath) as? NeighborhoodHomeGroupCell, + let neighborhood = isSearch ? neighborhoodsSearch[safe: indexPath.row - 1] : neighborhoodsDiscovered[safe: indexPath.row - 1] else { + return UITableViewCell() + } + cell.populateCell(neighborhood: neighborhood) return cell } - if indexPath.row == 0 { - let cell = tableView.dequeueReusableCell(withIdentifier: "cellSearch", for: indexPath) as! NeighborhoodHomeSearchCell - - cell.populateCell(delegate: self, isSearch:isSearch,isCellUserSearch: false) - - return cell - } - - let cell = tableView.dequeueReusableCell(withIdentifier: "cellGroup", for: indexPath)as! NeighborhoodHomeGroupCell - let neighborhood = isSearch ? neighborhoodsSearch[indexPath.row - 1] : neighborhoodsDiscovered[indexPath.row - 1] - cell.populateCell(neighborhood: neighborhood) - return cell - } - - func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { - var neighborhood:Neighborhood - - if isGroupsSelected { - neighborhood = myNeighborhoods[indexPath.row] - AnalyticsLoggerManager.logEvent(name: Action_Group_MyGroup_Card) - } - else { - if indexPath.row == 0 { return } - neighborhood = isSearch ? neighborhoodsSearch[indexPath.row - 1] : neighborhoodsDiscovered[indexPath.row - 1] + func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + var neighborhood: Neighborhood? - if isSearch { - AnalyticsLoggerManager.logEvent(name: Action_Group_Search_SeeResult) + if isGroupsSelected { + neighborhood = myNeighborhoods[safe: indexPath.row] + AnalyticsLoggerManager.logEvent(name: Action_Group_MyGroup_Card) } else { - AnalyticsLoggerManager.logEvent(name: Action_Group_Discover_Card) + if indexPath.row == 0 { return } + neighborhood = isSearch ? neighborhoodsSearch[safe: indexPath.row - 1] : neighborhoodsDiscovered[safe: indexPath.row - 1] + + if isSearch { + AnalyticsLoggerManager.logEvent(name: Action_Group_Search_SeeResult) + } + else { + AnalyticsLoggerManager.logEvent(name: Action_Group_Discover_Card) + } } + + guard let neighborhoodId = neighborhood?.uid else { return } + + self.showNeighborhood(neighborhoodId: neighborhoodId, neighborhood: neighborhood) } - - self.showNeighborhood(neighborhoodId: neighborhood.uid,neighborhood:neighborhood) - - } func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) { if isLoading { return } @@ -706,3 +713,10 @@ extension NeighborhoodHomeViewController: NeighborhoodHomeSearchDelegate { } } } + + +extension Array { + subscript(safe index: Int) -> Element? { + return indices.contains(index) ? self[index] : nil + } +} diff --git a/entourage/Tools/Extensions/Extensions_UIViewController.swift b/entourage/Tools/Extensions/Extensions_UIViewController.swift index fc3f7d69a..e09a67e84 100644 --- a/entourage/Tools/Extensions/Extensions_UIViewController.swift +++ b/entourage/Tools/Extensions/Extensions_UIViewController.swift @@ -118,3 +118,24 @@ extension UIApplication { return self.keyWindow?.rootViewController?.topFrontViewController } } + + +extension UIViewController { + var isModal: Bool { + if let navigationController = self.navigationController { + if navigationController.viewControllers.first != self { + return false + } + } + if self.presentingViewController != nil { + return true + } + if self.navigationController?.presentingViewController?.presentedViewController == self.navigationController { + return true + } + if self.tabBarController?.presentingViewController is UITabBarController { + return true + } + return false + } +} diff --git a/entourage/entourage-Info.plist b/entourage/entourage-Info.plist index c7d4589f4..975f4667e 100644 --- a/entourage/entourage-Info.plist +++ b/entourage/entourage-Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType $(PRODUCT_BUNDLE_PACKAGE_TYPE) CFBundleShortVersionString - 8.8.buildNumberNotSet + 8.9.buildNumberNotSet CFBundleURLTypes