Untitled

mail@pastecode.io avatar
unknown
swift
2 months ago
8.1 kB
2
Indexable
Never
//
//  EventMessageVC.swift
//  JILLII
//
//  Created by Chetan_iMAC on 21/04/22.
//

import UIKit

class EventMessageVC: UIViewController {

    @IBOutlet weak var lblNavTitle:UILabel!
    @IBOutlet weak var btnBack: UIButton!
    @IBOutlet weak var tblEventMessages:UITableView!
    @IBOutlet weak var firstMessageUpperVw : UIView!
    @IBOutlet weak var btnEventGroup : UIButton!
    @IBOutlet weak var imageViewProfile: UIImageView!
    @IBOutlet weak var viewProfile: UIView!
    @IBOutlet weak var lblNoGuestFound: UILabel!
    @IBOutlet weak var viewSendMessages: UIView!
    
    var isFromApprovePictire = false
    var arrPostToPrroved:[Post]?
    var objEventDetail:EventDetail?
    var arrEventChatListing : CreatePost?
    var isFromEventMessage = false
    var isEditInvitation : Bool = false
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        self.tblEventMessages.register(UINib(nibName: "EventMessageConVTblCell", bundle: nil), forCellReuseIdentifier: "EventMessageConVTblCell")
        self.firstMessageUpperVw.btnGradiantBorderToview(5.0)
       
        self.lblNavTitle.text = ToString(self.arrEventChatListing?.title).isEmpty ? self.objEventDetail?.title : self.arrEventChatListing?.title
        self.viewProfile.setCornerRaduisToRound()
        self.viewProfile.btnGradiantBorderToview(7.0)
        self.imageViewProfile.setImage(strUrl: ToString(self.arrEventChatListing?.icon).isEmpty ? ToString(self.objEventDetail?.icon) :  ToString(self.arrEventChatListing?.icon), placeholder: UIImage(named: "user_images_login")!)
        
        if isEditInvitation {
            self.lblNavTitle.text = self.objEventDetail?.title
            self.imageViewProfile.setImage(strUrl: ToString(self.objEventDetail?.icon), placeholder: UIImage(named: "user_images_login")!)
        }
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.JSONShowMessageList()
    }
    
    @IBAction func btnBackPressed(_ sender:UIButton) {
        self.navigationController?.popViewController(animated: true)
    }
    
    @IBAction func btnsendMsgToAllPressed(_ sender : UIButton){
        
        var objUserProfile = UserData()
        objUserProfile.first_name = ToString(self.objEventDetail?.title)
        objUserProfile.image = ToString(self.objEventDetail?.icon)
        
        let vc = StoryBoard.Activity.instantiateViewController(withIdentifier: "ChatDetailVC") as! ChatDetailVC
        vc.isGroupOfEventByHost = true
        vc.objRsvpData = self.objEventDetail
        vc.siGroup = true
        vc.isThemeYellow = true
//        vc.isFromEventMessage = self.isFromEventMessage
//        vc.userIDChat = ToString(self.objEventDetail?.id)
//        vc.objUserProfile = objUserProfile
//        vc.objEventDetail = self.objEventDetail
//        vc.arrEventChatListing = self.arrEventChatListing
//        
        if let objChatData = arrPostToPrroved{
            let objChatConversation = ChatConversation(["group_id" : objChatData.map({$0.group_id}).joined(separator: ",")])
            vc.objChatConversation = objChatConversation
        }
//        
//        vc.isEventGroup = true
        self.navigationController?.pushViewController(vc, animated: true)
    }
}

//MARK: - TableView Delegate and Datasource

extension EventMessageVC:UITableViewDelegate,UITableViewDataSource {

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.arrPostToPrroved?.count ?? 0
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

        let cell = tableView.dequeueReusableCell(withIdentifier: "EventMessageConVTblCell", for: indexPath) as! EventMessageConVTblCell
        cell.selectionStyle = .none

        if let dicData = self.arrPostToPrroved?[indexPath.row] {
            cell.imgUser.setImage(strUrl: dicData.image, placeholder: UIImage(named: "user_images_login")!)
            cell.lblUserName.text = dicData.first_name + " \(dicData.last_name)"
            
            var space = " | "
            
            if self.arrPostToPrroved?[indexPath.row] == nil || self.arrEventChatListing?.created_at == nil {
                space = ""
                cell.lblDateTime.text = ""
            }
            
            if isFromEventMessage == false && self.isEditInvitation == false{

                cell.vieewCount.isHidden = ToInt(dicData.unread_message_count) == 0 ? true : false
                cell.lblCount.text = dicData.unread_message_count
                
                cell.lblDateTime.text = ToString(dicData.created_at).isEmpty ? "" : dateConvert_GlobalUTCToLocal(date: ToString(dicData.created_at), FromFormate : AppDateFormatNotification, ToGetFormate: "dd MMM YYYY | hh:mm a")
                
            }else{
                
                cell.vieewCount.isHidden = ToInt(dicData.unread_message_count) == 0 ? true : false
                cell.lblCount.text = dicData.unread_message_count
                
                cell.lblDateTime.text = ToString(dicData.created_at).isEmpty ? "" : dateConvert_GlobalUTCToLocal(date: ToString(dicData.created_at), FromFormate : AppDateFormatNotification, ToGetFormate: "dd MMM YYYY | hh:mm a")
            }
        }
        return cell
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return UITableView.automaticDimension;
    }

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        if let dicData = self.arrPostToPrroved?[indexPath.row]{
            let objUserData = UserData()
            objUserData.id = dicData.group_id
            objUserData.first_name = dicData.first_name
            objUserData.last_name = dicData.last_name
            objUserData.image = dicData.image
            
            let objChatConversation = ChatConversation(["group_id" : dicData.group_id])
            
            let vc = StoryBoard.Activity.instantiateViewController(withIdentifier: "ChatDetailVC") as! ChatDetailVC
            vc.siGroup = true
            vc.objUserProfile = objUserData
            vc.objChatConversation = objChatConversation
            vc.isEventGroup = true
            vc.isThemeYellow = true
            vc.isHostOfEventIndividual = true
            vc.isFromEventMessage = self.isFromEventMessage
            vc.objEventDetail = self.objEventDetail
            vc.objRsvpData = self.objEventDetail
            vc.isHostOfEventIndividual = true
//            vc.arrEventChatListing = self.arrEventChatListing
            vc.arrPostToPrroved = self.arrPostToPrroved?[indexPath.row]
            self.navigationController?.pushViewController(vc, animated: true)
        }
    }
}
//MARK: - Api calling

extension EventMessageVC{
    func JSONShowMessageList() {
        var  param = [String:String]()
        param["event_id"] = ToString(self.objEventDetail?.id).isEmpty ? self.arrEventChatListing?.id : ToString(self.objEventDetail?.id)
        
        WebService.shared.RequesURL(ServerURL.event_guest_message_list , Perameters: param, showProgress: true, completion: { (response, status) in

            print(response)
            
            if let dicData = response.object(forKey: "data") as? [[String:Any]] {
                self.arrPostToPrroved = dicData.map({Post.init($0)})
            }
            
            let sucess = ToString(response.object(forKey: "success"))
            if sucess == "0" {
                self.viewSendMessages.isHidden = true
                self.lblNoGuestFound.isHidden = false
            }else{
                self.viewSendMessages.isHidden = false
                self.lblNoGuestFound.isHidden = true
            }
            
            self.tblEventMessages.reloadData()

        }) { (err) in
            debugPrint(err.localizedDescription)
            ShowAlert(title: enumAlert.Alert.rawValue, message: ToString(err.localizedDescription), buttonTitle: "Ok", handlerCB: nil)
        }
    }
}

Leave a Comment