Skip to content
This repository has been archived by the owner on Oct 2, 2021. It is now read-only.

Commit

Permalink
Fix - Message Options
Browse files Browse the repository at this point in the history
show correct message options in alert action
  • Loading branch information
saeedmozaffariGithub committed Aug 20, 2018
1 parent cb5d1ec commit 799094f
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 31 deletions.
95 changes: 67 additions & 28 deletions iGap/Libraries/Chat Screen/Controller/IGMessageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -2412,57 +2465,43 @@ 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)
}

//Forward
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
Expand Down
4 changes: 3 additions & 1 deletion iGap/Libraries/Chat Screen/Model/CellSizeCalculator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions iGap/SupportingFiles/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.6.2</string>
<string>0.6.3</string>
<key>CFBundleVersion</key>
<string>469</string>
<string>470</string>
<key>Fabric</key>
<dict>
<key>APIKey</key>
Expand Down

0 comments on commit 799094f

Please sign in to comment.