Эх сурвалжийг харах

Merge branch 'fix/ios_form_js_bug' into 'develop'

修复滚动图片不显示的bug,im图片音频消息下载的问题

See merge request o2oa/o2oa!828
楼国栋 5 жил өмнө
parent
commit
dc6c8f7899

+ 16 - 40
o2ios/O2Platform/App/IM-聊天/IMChatViewController.swift

@@ -235,7 +235,7 @@ class IMChatViewController: UIViewController {
                             }
                             let localFilePath = self.storageLocalImage(imageData: newData, fileName: fileName)
                             let msgId = self.prepareForSendImageMsg(filePath: localFilePath)
-                            self.uploadImageAndSendMsg(messageId: msgId, imageData: newData, fileName: fileName)
+                            self.uploadFileAndSendMsg(messageId: msgId, data: newData, fileName: fileName, type: o2_im_msg_type_image)
                         }
                         break
                     default:
@@ -292,44 +292,15 @@ class IMChatViewController: UIViewController {
         return msgId
     }
 
-    //上传图片到服务器并发送消息
-    private func uploadImageAndSendMsg(messageId: String, imageData: Data, fileName: String) {
-        guard let cId = self.conversation?.id else {
-            return
-        }
-        self.viewModel.uploadFile(conversationId: cId, type: o2_im_msg_type_image, fileName: fileName, file: imageData).then { attachId in
-            DDLogDebug("上传图片成功: \(attachId)")
-            guard let message = self.chatMessageList.first (where: { (info) -> Bool in
-                return info.id == messageId
-            }) else {
-                DDLogDebug("没有找到对应的消息")
-                return
-            }
-            let body = IMMessageBodyInfo.deserialize(from: message.body)
-            body?.fileId = attachId
-            body?.fileTempPath = nil
-            message.body = body?.toJSONString()
-            //发送消息到服务器
-            self.viewModel.sendMsg(msg: message)
-                .then { (result) in
-                    DDLogDebug("图片消息 发送成功 \(result)")
-                    self.viewModel.readConversation(conversationId: self.conversation?.id)
-                }.catch { (error) in
-                    DDLogError(error.localizedDescription)
-                    self.showError(title: "发送消息失败!")
-            }
-        }.catch { err in
-            self.showError(title: "上传错误,\(err.localizedDescription)")
-        }
-    }
+     
 
     //上传图片 音频 等文件到服务器并发送消息
     private func uploadFileAndSendMsg(messageId: String, data: Data, fileName: String, type: String) {
         guard let cId = self.conversation?.id else {
             return
         }
-        self.viewModel.uploadFile(conversationId: cId, type: type, fileName: fileName, file: data).then { attachId in
-            DDLogDebug("上传图片成功: \(attachId)")
+        self.viewModel.uploadFile(conversationId: cId, type: type, fileName: fileName, file: data).then { back in
+            DDLogDebug("上传文件成功")
             guard let message = self.chatMessageList.first (where: { (info) -> Bool in
                 return info.id == messageId
             }) else {
@@ -337,13 +308,14 @@ class IMChatViewController: UIViewController {
                 return
             }
             let body = IMMessageBodyInfo.deserialize(from: message.body)
-            body?.fileId = attachId
+            body?.fileId = back.id
+            body?.fileExtension = back.fileExtension
             body?.fileTempPath = nil
             message.body = body?.toJSONString()
             //发送消息到服务器
             self.viewModel.sendMsg(msg: message)
                 .then { (result) in
-                    DDLogDebug("图片消息 发送成功 \(result)")
+                    DDLogDebug("消息 发送成功 \(result)")
                     self.viewModel.readConversation(conversationId: self.conversation?.id)
                 }.catch { (error) in
                     DDLogError(error.localizedDescription)
@@ -446,7 +418,7 @@ extension IMChatViewController: UIImagePickerControllerDelegate & UINavigationCo
             let newData = image.pngData()!
             let localFilePath = self.storageLocalImage(imageData: newData, fileName: fileName)
             let msgId = self.prepareForSendImageMsg(filePath: localFilePath)
-            self.uploadImageAndSendMsg(messageId: msgId, imageData: newData, fileName: fileName)
+            self.uploadFileAndSendMsg(messageId: msgId, data: newData, fileName: fileName, type: o2_im_msg_type_image)
         } else {
             DDLogError("没有选择到图片!")
         }
@@ -482,11 +454,15 @@ extension IMChatViewController: IMChatMessageDelegate {
         self.navigationController?.pushViewController(map, animated: false)
     }
     
-    func clickImageMessage(fileId: String?, tempPath: String?) {
-        if let id = fileId {
+    func clickImageMessage(info: IMMessageBodyInfo) {
+        if let id = info.fileId {
             self.showLoading()
+            var ext = info.fileExtension ?? "png"
+            if ext.isEmpty {
+                ext = "png"
+            }
             O2IMFileManager.shared
-                .getFileLocalUrl(fileId: id)
+                .getFileLocalUrl(fileId: id, fileExtension: ext)
                 .always {
                     self.hideLoading()
                 }.then { (path) in
@@ -506,7 +482,7 @@ extension IMChatViewController: IMChatMessageDelegate {
                     DDLogError(error.localizedDescription)
                     self.showError(title: "获取文件异常!")
             }
-        } else if let temp = tempPath {
+        } else if let temp = info.fileTempPath {
             let currentURL = NSURL(fileURLWithPath: temp)
             DDLogDebug(currentURL.description)
             DDLogDebug(temp)

+ 4 - 4
o2ios/O2Platform/App/IM-聊天/IMViewModel.swift

@@ -77,13 +77,13 @@ extension IMViewModel {
     }
     
     //上传文件
-    func uploadFile(conversationId: String, type: String, fileName: String, file: Data) -> Promise<String> {
+    func uploadFile(conversationId: String, type: String, fileName: String, file: Data) -> Promise<IMUploadBackModel> {
        return Promise { fulfill, reject in
            self.communicateAPI.request(.imUploadFile(conversationId, type, fileName, file), completion: { (result) in
-               let response = OOResult<BaseModelClass<OOCommonIdModel>>(result)
+               let response = OOResult<BaseModelClass<IMUploadBackModel>>(result)
                if response.isResultSuccess() {
-                   if let id = response.model?.data {
-                       fulfill(id.id ?? "")
+                   if let back = response.model?.data {
+                       fulfill(back)
                    }else {
                        reject(OOAppError.apiEmptyResultError)
                    }

+ 16 - 0
o2ios/O2Platform/App/IM-聊天/Model/IMConversationInfo.swift

@@ -63,6 +63,7 @@ class IMMessageBodyInfo: NSObject, DataModel {
     @objc var type: String?
     @objc var body: String?
     @objc var fileId: String? //文件id
+    @objc var fileExtension: String? //文件扩展
     @objc var fileTempPath: String? //本地临时文件地址
     @objc var audioDuration: String? // 音频文件时长
     @objc var address: String? //type=location的时候位置信息
@@ -78,6 +79,21 @@ class IMMessageBodyInfo: NSObject, DataModel {
     }
 }
 
+class IMUploadBackModel: NSObject, DataModel {
+    public override var description: String {
+        return "IMUploadBackModel"
+    }
+    
+    @objc var id:String?
+    @objc var fileExtension: String? //文件扩展
+    
+    required override init() { }
+
+    func mapping(mapper: HelpingMapper) {
+
+    }
+}
+
 //websocket 消息对象
 class WsMessage: NSObject, DataModel {
     @objc var type: String? //im_create

+ 5 - 5
o2ios/O2Platform/App/IM-聊天/O2IM.swift

@@ -51,13 +51,13 @@ class O2IMFileManager {
 
     private init() { }
     //根据id下载文件,并返回文件的本地url
-    func getFileLocalUrl(fileId: String) -> Promise<URL> {
+    func getFileLocalUrl(fileId: String, fileExtension: String) -> Promise<URL> {
         return Promise { fulfill, reject in
-            let url = self.localFilePath(fileId: fileId)
+            let url = self.localFilePath(fileId: fileId, ext: fileExtension)
             if FileUtil.share.fileExist(filePath: url.path) {
                 fulfill(url)
             } else {
-                self.communicateAPI.request(.imDownloadFullFile(fileId), completion: { result in
+                self.communicateAPI.request(.imDownloadFullFile(fileId, fileExtension), completion: { result in
                         switch result {
                         case .success(_):
                             DDLogError("下载成功。。。。。\(fileId)")
@@ -74,8 +74,8 @@ class O2IMFileManager {
 
     }
 
-    func localFilePath(fileId: String) -> URL {
-        return FileUtil.share.cacheDir().appendingPathComponent("\(fileId).png")
+    func localFilePath(fileId: String, ext: String) -> URL {
+        return FileUtil.share.cacheDir().appendingPathComponent("\(fileId).\(ext)")
     }
     
     //音频文件存储地址

+ 6 - 2
o2ios/O2Platform/App/IM-聊天/View/IMChatMessageSendViewCell.swift

@@ -107,7 +107,11 @@ class IMChatMessageSendViewCell: UITableViewCell {
     
     private func playAudio(info: IMMessageBodyInfo) {
         if let fileId = info.fileId {
-            O2IMFileManager.shared.getFileLocalUrl(fileId: fileId)
+            var ext = info.fileExtension ?? "mp3"
+            if ext.isEmpty {
+                ext = "mp3"
+            }
+            O2IMFileManager.shared.getFileLocalUrl(fileId: fileId, fileExtension: ext)
                 .then { (url) in
                     do {
                         let data = try Data(contentsOf: url)
@@ -166,7 +170,7 @@ class IMChatMessageSendViewCell: UITableViewCell {
         imageView.translatesAutoresizingMaskIntoConstraints = false
         self.messageBackgroundView.addSubview(imageView)
         imageView.addTapGesture { (tap) in
-            self.delegate?.clickImageMessage(fileId: info.fileId, tempPath: info.fileTempPath)
+            self.delegate?.clickImageMessage(info: info)
         }
         self.constraintWithContent(contentView: imageView)
     }

+ 7 - 3
o2ios/O2Platform/App/IM-聊天/View/IMChatMessageViewCell.swift

@@ -10,7 +10,7 @@ import UIKit
 import CocoaLumberjack
 
 protocol IMChatMessageDelegate {
-    func clickImageMessage(fileId: String?, tempPath: String?)
+    func clickImageMessage(info: IMMessageBodyInfo)
     func openLocatinMap(info: IMMessageBodyInfo)
 }
 
@@ -165,7 +165,11 @@ class IMChatMessageViewCell: UITableViewCell {
 
     private func playAudio(info: IMMessageBodyInfo) {
         if let fileId = info.fileId {
-            O2IMFileManager.shared.getFileLocalUrl(fileId: fileId)
+            var ext = info.fileExtension ?? "mp3"
+            if ext.isEmpty {
+                ext = "mp3"
+            }
+            O2IMFileManager.shared.getFileLocalUrl(fileId: fileId, fileExtension: ext)
                 .then { (url) in
                     do {
                         let data = try Data(contentsOf: url)
@@ -224,7 +228,7 @@ class IMChatMessageViewCell: UITableViewCell {
         imageView.translatesAutoresizingMaskIntoConstraints = false
         self.messageBackgroundView.addSubview(imageView)
         imageView.addTapGesture { (tap) in
-            self.delegate?.clickImageMessage(fileId: info.fileId, tempPath: info.fileTempPath)
+            self.delegate?.clickImageMessage(info: info)
         }
         self.constraintWithContent(contentView: imageView)
 

+ 2 - 1
o2ios/O2Platform/App/O2MainController.swift

@@ -42,7 +42,8 @@ class O2MainController: UITabBarController, UITabBarControllerDelegate {
         if UIDevice.deviceModelReadable() != "Simulator" {
             self.checkAppVersion()
         }
-
+        //
+        self.tabBar.tintColor = O2ThemeManager.color(for: "Base.base_color")!
         self.delegate = self
         _initControllers()
         selectedIndex = 2

+ 2 - 2
o2ios/O2Platform/App/Work-工作/c/MainTaskSecondViewController.swift

@@ -292,7 +292,7 @@ class MainTaskSecondViewController: UIViewController {
     //热点图片新闻
     private func loadPlayerList(){
         DDLogDebug("loadPlayerList ...........................")
-        self.taskImageshowEntitys.removeAll(keepingCapacity: true)
+//        self.taskImageshowEntitys.removeAll(keepingCapacity: true)
         let url = AppDelegate.o2Collect.generateURLWithAppContextKey(HotpicContext.hotpicContextKey, query: HotpicContext.hotpicAllListQuery, parameter: ["##page##":"0" as AnyObject,"##count##":"8" as AnyObject])
         Alamofire.request(url!, method: .put, parameters: nil, encoding: JSONEncoding.default, headers: nil).responseJSON { (response) in
             switch response.result {
@@ -302,7 +302,7 @@ class MainTaskSecondViewController: UIViewController {
                     let data = JSON(val)["data"]
                     let entrys = Mapper<TaskImageshowEntity>().mapArray(JSONString: data.description)
                     DispatchQueue.main.async {
-                        self.taskImageshowEntitys.append(contentsOf: entrys!)
+                        self.taskImageshowEntitys = entrys ?? []
                     }
                 }else{
                     

+ 20 - 18
o2ios/O2Platform/App/Work-工作/v/ImageSlidesShowView.swift

@@ -12,33 +12,35 @@ import Alamofire
 import AlamofireImage
 import AlamofireObjectMapper
 import ObjectMapper
+import CocoaLumberjack
 
 protocol ImageSlidesShowViewDelegate {
-    func  ImageSlidesShowClick(taskImageshowEntity:TaskImageshowEntity)
+    func ImageSlidesShowClick(taskImageshowEntity: TaskImageshowEntity)
 }
 
 class ImageSlidesShowView: UIView {
-    
-    private lazy var imageSlideshow:ImageSlideshow = ImageSlideshow()
 
-    var delegate:ImageSlidesShowViewDelegate?
-    
-    var imageshowEntitys:[TaskImageshowEntity] = [] {
-        
+    private lazy var imageSlideshow: ImageSlideshow = ImageSlideshow()
+
+    var delegate: ImageSlidesShowViewDelegate?
+
+    var imageshowEntitys: [TaskImageshowEntity] = [] {
+
         didSet {
             self.imageURLS.removeAll(keepingCapacity: true)
             imageshowEntitys.forEach { (taskImageshowEntity) in
-                                let imageURL = AppDelegate.o2Collect.generateURLWithAppContextKey(FileContext.fileContextKey, query: FileContext.fileDownloadPicItemIdQuery, parameter: ["##id##":taskImageshowEntity.picId as AnyObject])
+                let imageURL = AppDelegate.o2Collect.generateURLWithAppContextKey(FileContext.fileContextKey, query: FileContext.fileDownloadNoStreamIdQuery, parameter: ["##id##": taskImageshowEntity.picId as AnyObject])
+                DDLogDebug("hot image url : \(String(describing: imageURL))")
                 let afurl = O2AlamofireSource(urlString: imageURL!)
                 self.imageURLS.append(afurl!)
             }
             imageSlideshow.setImageInputs(imageURLS)
-            
+
         }
     }
-    
-    fileprivate var imageURLS:[O2AlamofireSource] = []
-    
+
+    fileprivate var imageURLS: [O2AlamofireSource] = []
+
     override init(frame: CGRect) {
         super.init(frame: frame)
         self.imageSlideshow.frame = CGRect(x: 0, y: 0, width: frame.width, height: frame.height)
@@ -53,19 +55,19 @@ class ImageSlidesShowView: UIView {
         self.addSubview(self.imageSlideshow)
 
     }
-    
+
     required init?(coder aDecoder: NSCoder) {
         fatalError("init(coder:) has not been implemented")
     }
-    
-    
-    @objc public func imageSlideshowClick(sender:ImageSlideshow?){
+
+
+    @objc public func imageSlideshowClick(sender: ImageSlideshow?) {
         //print(self.imageSlideshow.currentPage)
-        if delegate != nil{
+        if delegate != nil {
             let entity = self.imageshowEntitys[self.imageSlideshow.currentPage]
             self.delegate?.ImageSlidesShowClick(taskImageshowEntity: entity)
         }
-        
+
     }
 
 

+ 5 - 5
o2ios/O2Platform/Framework/O2API/Communicate/CommunicateAPI.swift

@@ -19,7 +19,7 @@ enum CommunicateAPI {
     case instantMessageList(Int)
     case createConversation(IMConversationInfo)
     case imUploadFile(String, String, String, Data)
-    case imDownloadFullFile(String)
+    case imDownloadFullFile(String, String)
     
     
 }
@@ -61,14 +61,14 @@ extension CommunicateAPI: TargetType {
             return "/jaxrs/im/conversation"
         case .imUploadFile(let conversationId, let type, _, _):
             return "/jaxrs/im/msg/upload/\(conversationId)/type/\(type)"
-        case .imDownloadFullFile(let id):
+        case .imDownloadFullFile(let id, _):
             return "/jaxrs/im/msg/download/\(id)"
         }
     }
     
     var method: Moya.Method {
         switch self {
-        case .myConversationList, .instantMessageList(_), .imDownloadFullFile(_):
+        case .myConversationList, .instantMessageList(_), .imDownloadFullFile(_, _):
             return .get
         case .msgListByPaging(_, _, _), .sendMsg(_), .createConversation(_), .imUploadFile(_, _, _, _):
             return .post
@@ -100,10 +100,10 @@ extension CommunicateAPI: TargetType {
             //文件类型
             let fileData = MultipartFormData(provider: .data(data), name: "file", fileName: fileName)
             return .uploadMultipart([fileData, fileNameData])
-        case .imDownloadFullFile(let id):
+        case .imDownloadFullFile(let id, let fileExtension):
             let myDest:DownloadDestination = { temporaryURL, response in
                 //本地存储
-                return (O2IMFileManager.shared.localFilePath(fileId: id), [.removePreviousFile, .createIntermediateDirectories])
+                return (O2IMFileManager.shared.localFilePath(fileId: id, ext: fileExtension), [.removePreviousFile, .createIntermediateDirectories])
             }
             return .downloadDestination(myDest)
         }

+ 1 - 1
o2ios/O2Platform/Info.plist

@@ -163,7 +163,7 @@
 		<key>centerContext</key>
 		<string>/x_program_center</string>
 		<key>centerHost</key>
-		<string>dd.o2oa.net</string>
+		<string>123.125.39.51</string>
 		<key>centerPort</key>
 		<integer>20030</integer>
 		<key>httpProtocol</key>

+ 1 - 0
o2ios/O2Platform/config/O2URLContext.swift

@@ -47,6 +47,7 @@ struct FileContext {
     static let fileDownloadCMSIdQuery = "servlet/download/##id##/stream"
     static let fileDownloadItemIdQuery = "jaxrs/attachment/##id##/download/stream"
     static let fileDownloadPicItemIdQuery = "jaxrs/file/##id##/download/stream"
+    static let fileDownloadNoStreamIdQuery = "jaxrs/file/##id##/download"
     static let fileUploadTopQuery = "jaxrs/attachment/upload/folder/(0)"
     static let fileUploadSubQuery = "jaxrs/attachment/upload/folder/##id##"
     static let fileUploadReference = "jaxrs/file/upload/referencetype/##referencetype##/reference/##reference##/scale/##scale##"