From 799094f61e4759a9121232e2341d8941853664d6 Mon Sep 17 00:00:00 2001 From: saeedrooyekhat Date: Mon, 20 Aug 2018 13:11:48 +0430 Subject: [PATCH] Fix - Message Options show correct message options in alert action --- .../Controller/IGMessageViewController.swift | 95 +++++++++++++------ .../Model/CellSizeCalculator.swift | 4 +- iGap/SupportingFiles/Info.plist | 4 +- 3 files changed, 72 insertions(+), 31 deletions(-) diff --git a/iGap/Libraries/Chat Screen/Controller/IGMessageViewController.swift b/iGap/Libraries/Chat Screen/Controller/IGMessageViewController.swift index c7df618..2b0d0ec 100644 --- a/iGap/Libraries/Chat Screen/Controller/IGMessageViewController.swift +++ b/iGap/Libraries/Chat Screen/Controller/IGMessageViewController.swift @@ -925,6 +925,59 @@ class IGMessageViewController: UIViewController, DidSelectLocationDelegate, UIGe return false } + /************************** Alert Action Permissions **************************/ + func allowCopy(_ message: IGRoomMessage) -> Bool{ + var finalMessage = message + if let forward = message.forwardedFrom { + finalMessage = forward + } + if (finalMessage.type == .text) || + finalMessage.type == .gifAndText || + finalMessage.type == .fileAndText || + finalMessage.type == .audioAndText || + finalMessage.type == .videoAndText || + finalMessage.type == .imageAndText { + return true + } + return false + } + + func allowPin() -> Bool{ + return groupPinGranted() || channelPinGranted() + } + + func allowReply() -> Bool{ + if !(room!.isReadOnly){ + return true + } + return false + } + + func allowEdit(_ message: IGRoomMessage) -> Bool{ + if message.authorHash == currentLoggedInUserAuthorHash || + (self.room!.type == .channel && self.room!.channelRoom!.role == .owner) || + (self.room!.type == .group && self.room!.groupRoom!.role == .owner) { + return true + } + return false + } + + func allowDelete(_ message: IGRoomMessage) -> (singleDelete: Bool, bothDelete: Bool){ + var singleDelete = false + var bothDelete = false + if (message.authorHash == currentLoggedInUserAuthorHash) || + (self.room!.type == .channel && self.room!.channelRoom!.role == .owner) || + (self.room!.type == .group && self.room!.groupRoom!.role == .owner) { + //If user can delete message for all participants + if (self.room!.type == .chat) && (message.creationTime != nil) && (Date().timeIntervalSince1970 - message.creationTime!.timeIntervalSince1970 < 2 * 3600) { + bothDelete = true + } + singleDelete = true + } + return (singleDelete,bothDelete) + } + + @IBAction func didTapOnPinClose(_ sender: UIButton) { if groupPinGranted() { self.groupPin() @@ -2412,14 +2465,16 @@ extension IGMessageViewController: IGMessageGeneralCollectionViewCellDelegate { }) //Copy - alertC.addAction(copy) + if allowCopy(cellMessage){ + alertC.addAction(copy) + } - if groupPinGranted() || channelPinGranted() { + if allowPin() { alertC.addAction(pin) } //Reply - if !(room!.isReadOnly){ + if allowReply(){ alertC.addAction(reply) } @@ -2427,42 +2482,26 @@ extension IGMessageViewController: IGMessageGeneralCollectionViewCellDelegate { alertC.addAction(forward) //Edit - if cellMessage.authorHash == currentLoggedInUserAuthorHash || - (self.room!.type == .channel && self.room!.channelRoom!.role == .owner) || - (self.room!.type == .group && self.room!.groupRoom!.role == .owner) - { + if self.allowEdit(cellMessage){ alertC.addAction(edit) } alertC.addAction(report) - //More (Temporary Disabled) - //alertC.addAction(more) - //Delete - if cellMessage.authorHash == currentLoggedInUserAuthorHash || - (self.room!.type == .channel && self.room!.channelRoom!.role == .owner) || - (self.room!.type == .group && self.room!.groupRoom!.role == .owner) - { - //If user can delete message for all participants - if (self.room!.type == .chat) && - (cellMessage.creationTime != nil) && - (Date().timeIntervalSince1970 - cellMessage.creationTime!.timeIntervalSince1970 < 2 * 3600) - { - alertC.addAction(deleteForMe) - alertC.addAction(deleteForBoth) - } else { - alertC.addAction(deleteForMe) - } + let delete = allowDelete(cellMessage) + if delete.singleDelete { + alertC.addAction(deleteForMe) + } + if delete.bothDelete { + alertC.addAction(deleteForBoth) } alertC.addAction(cancel) - self.present(alertC, animated: true, completion: { - - }) + self.present(alertC, animated: true, completion: nil) } - + /******* overrided method for show file attachment (use from UIDocumentInteractionControllerDelegate) *******/ func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController { return self diff --git a/iGap/Libraries/Chat Screen/Model/CellSizeCalculator.swift b/iGap/Libraries/Chat Screen/Model/CellSizeCalculator.swift index 0164ff6..7c986d9 100644 --- a/iGap/Libraries/Chat Screen/Model/CellSizeCalculator.swift +++ b/iGap/Libraries/Chat Screen/Model/CellSizeCalculator.swift @@ -261,7 +261,9 @@ class CellSizeCalculator: NSObject { finalSize.width = 200 finalSize.height -= 10 } else if message.forwardedFrom?.type == .video || message.forwardedFrom?.type == .videoAndText { - finalSize.width += 50 + if finalSize.height > finalSize.width { + finalSize.width += 50 + } } else if message.forwardedFrom?.type == .audio || message.forwardedFrom?.type == .audioAndText { finalSize.width = 220 } else if message.forwardedFrom?.type == .file || message.forwardedFrom?.type == .fileAndText { diff --git a/iGap/SupportingFiles/Info.plist b/iGap/SupportingFiles/Info.plist index 8501214..821b614 100644 --- a/iGap/SupportingFiles/Info.plist +++ b/iGap/SupportingFiles/Info.plist @@ -15,9 +15,9 @@ CFBundlePackageType APPL CFBundleShortVersionString - 0.6.2 + 0.6.3 CFBundleVersion - 469 + 470 Fabric APIKey