cyberta 4 lat temu
rodzic
commit
c6e787c76d

+ 11 - 74
DcCore/DcCore/DC/Wrapper.swift

@@ -4,9 +4,6 @@ import AVFoundation
 
 public class DcContext {
 
-    /// TODO: THIS global instance should be replaced in the future, for example for a multi-account scenario,
-    /// where we want to have more than one DcContext.
-    //static let dcContext: DcContext = DcContext()
     public var logger: Logger?
     var contextPointer: OpaquePointer?
     public var lastErrorString: String?
@@ -22,11 +19,17 @@ public class DcContext {
         contextPointer = nil
     }
 
-    /// Injection of DcContext is preferred over the usage of the shared variable
-/*    public static var shared: DcContext {
-        return .dcContext
-    }*/
-
+    /**
+        viewType: one of
+            DC_MSG_TEXT,
+            DC_MSG_IMAGE,
+            DC_MSG_GIF,
+            DC_MSG_STICKER,
+            DC_MSG_AUDIO,
+            DC_MSG_VOICE,
+            DC_MSG_VIDEO,
+            DC_MSG_FILE
+     */
     public func newMessage(viewType: Int32) -> DcMsg {
         let messagePointer = dc_msg_new(contextPointer, viewType)
         return DcMsg(pointer: messagePointer)
@@ -90,10 +93,6 @@ public class DcContext {
         dc_block_contact(contextPointer, UInt32(id), 0)
     }
 
-/*    public func getFromContact(messageId: Int): DcContact? {
-        DcContact(id: fromContactId)
-    }() */
-
     public func isFromCurrentSender(message: DcMsg) -> Bool {
         return message.fromContactId == getContact(id: Int(DC_CONTACT_ID_SELF)).id
     }
@@ -804,7 +803,6 @@ public class DcChat {
                 let image = UIImage(data: data)
                 return image
             } catch {
-                //DcContext.shared.logger?.warning("failed to load image: \(filename), \(error)")
                 return nil
             }
         }
@@ -843,25 +841,6 @@ public class DcArray {
 public class DcMsg {
     var messagePointer: OpaquePointer?
 
-    /**
-        viewType: one of
-            DC_MSG_TEXT,
-            DC_MSG_IMAGE,
-            DC_MSG_GIF,
-            DC_MSG_STICKER,
-            DC_MSG_AUDIO,
-            DC_MSG_VOICE,
-            DC_MSG_VIDEO,
-            DC_MSG_FILE
-     */
-    /*public init(viewType: Int32) {
-        messagePointer = dc_msg_new(DcContext.shared.contextPointer, viewType)
-    }
-
-    public init(id: Int) {
-        messagePointer = dc_get_msg(DcContext.shared.contextPointer, UInt32(id))
-    }*/
-
     init(pointer: OpaquePointer?) {
         messagePointer = pointer
     }
@@ -898,14 +877,6 @@ public class DcMsg {
         return Int(dc_msg_get_from_id(messagePointer))
     }
 
-/*    public lazy var fromContact: DcContact = {
-        DcContact(id: fromContactId)
-    }()
-
-    public var isFromCurrentSender: Bool {
-        return fromContact.id == DcContact(id: Int(DC_CONTACT_ID_SELF)).id
-    } */
-
     public var chatId: Int {
         return Int(dc_msg_get_chat_id(messagePointer))
     }
@@ -1013,7 +984,6 @@ public class DcMsg {
                     let image = UIImage(data: data)
                     return image
                 } catch {
-                    //DcContext.shared.logger?.warning("failed to load image: \(path), \(error)")
                     return nil
                 }
             }
@@ -1139,44 +1109,11 @@ public class DcMsg {
         return dc_msg_get_showpadlock(messagePointer) == 1
     }
 
-/*    public func sendInChat(_ dcContext: DcContext, id: Int) {
-        dc_send_msg(dcContext.contextPointer, UInt32(id), messagePointer)
-    } */
-
-/*    public func previousMediaURLs() -> [URL] {
-        var urls: [URL] = []
-        var prev: Int = Int(dc_get_next_media(DcContext.shared.contextPointer, UInt32(id), -1, Int32(type), 0, 0))
-        while prev != 0 {
-            let prevMessage = DcMsg(id: prev)
-            if let url = prevMessage.fileURL {
-                urls.insert(url, at: 0)
-            }
-            prev = Int(dc_get_next_media(DcContext.shared.contextPointer, UInt32(prevMessage.id), -1, Int32(prevMessage.type), 0, 0))
-        }
-        return urls
-    }
-
-    public func nextMediaURLs() -> [URL] {
-        var urls: [URL] = []
-        var next: Int = Int(dc_get_next_media(DcContext.shared.contextPointer, UInt32(id), 1, Int32(type), 0, 0))
-        while next != 0 {
-            let nextMessage = DcMsg(id: next)
-            if let url = nextMessage.fileURL {
-                urls.append(url)
-            }
-            next = Int(dc_get_next_media(DcContext.shared.contextPointer, UInt32(nextMessage.id), 1, Int32(nextMessage.type), 0, 0))
-        }
-        return urls
-    }*/
 }
 
 public class DcContact {
     private var contactPointer: OpaquePointer?
 
-    /*public init(id: Int) {
-        contactPointer = dc_get_contact(DcContext.shared.contextPointer, UInt32(id))
-    }*/
-
     public init(contactPointer: OpaquePointer?) {
         self.contactPointer = contactPointer
     }

+ 1 - 0
DcCore/DcCore/Helper/DcUtils.swift

@@ -86,6 +86,7 @@ public struct DcUtils {
         }
 
         dc_array_unref(inputArray)
+        print("got: \(from) \(length) \(lenArray) - \(acc)")
 
         return acc
     }

+ 18 - 20
DcShare/Helper/ShareAttachment.swift

@@ -81,19 +81,19 @@ class ShareAttachment {
                 self.dcContext.logger?.debug("Unexpected data: \(type(of: data))")
             }
             if let result = result {
-                let msg = self.dcContext.newMessage(viewType: DC_MSG_GIF)
                 let path = ImageFormat.saveImage(image: result)
-                    msg.setFile(filepath: path)
-                    self.messages.append(msg)
-                    self.delegate?.onAttachmentChanged()
-                    if self.imageThumbnail == nil {
-                        self.imageThumbnail = result
-                        self.delegate?.onThumbnailChanged()
-                    }
-                    if let error = error {
-                        self.dcContext.logger?.error("Could not load share item as image: \(error.localizedDescription)")
-                    }
+                let msg = self.dcContext.newMessage(viewType: DC_MSG_GIF)
+                msg.setFile(filepath: path)
+                self.messages.append(msg)
+                self.delegate?.onAttachmentChanged()
+                if self.imageThumbnail == nil {
+                    self.imageThumbnail = result
+                    self.delegate?.onThumbnailChanged()
                 }
+                if let error = error {
+                    self.dcContext.logger?.error("Could not load share item as image: \(error.localizedDescription)")
+                }
+            }
         }
     }
 
@@ -113,20 +113,18 @@ class ShareAttachment {
             }
             if let result = result {
                 let path: String? = ImageFormat.saveImage(image: result)
-                var msg: DcMsg?
+                var msg: DcMsg
                 if result.sd_imageFormat == .webP {
                     msg = self.dcContext.newMessage(viewType: DC_MSG_STICKER)
                 } else {
                     msg = self.dcContext.newMessage(viewType: DC_MSG_IMAGE)
                 }
-                if let msg = msg {
-                    msg.setFile(filepath: path)
-                    self.messages.append(msg)
-                    self.delegate?.onAttachmentChanged()
-                    if self.imageThumbnail == nil {
-                        self.imageThumbnail = result
-                        self.delegate?.onThumbnailChanged()
-                    }
+                msg.setFile(filepath: path)
+                self.messages.append(msg)
+                self.delegate?.onAttachmentChanged()
+                if self.imageThumbnail == nil {
+                    self.imageThumbnail = result
+                    self.delegate?.onThumbnailChanged()
                 }
             }
             if let error = error {

+ 1 - 1
DcShare/View/ChatListCell.swift

@@ -84,7 +84,7 @@ class ChatListCell: UITableViewCell {
         avatar.setName("")
     }
 
-    private func setBackupImage(name: String, color: UIColor?) {
+    private func setBackupImage(name: String, color: UIColor) {
         avatar.setColor(color)
         avatar.setName(name)
     }

+ 1 - 1
deltachat-ios/Helper/ImageFormat.swift

@@ -95,7 +95,7 @@ extension ImageFormat {
             try data.write(to: path)
             return path.relativePath
         } catch {
-            //DcContext.shared.logger?.info(error.localizedDescription)
+            print(error.localizedDescription)
             return nil
         }
     }

+ 2 - 2
deltachat-ios/View/ContactCell.swift

@@ -219,7 +219,7 @@ class ContactCell: UITableViewCell {
         avatar.setName("")
     }
 
-    func setBackupImage(name: String, color: UIColor?) {
+    func setBackupImage(name: String, color: UIColor) {
         avatar.setColor(color)
         avatar.setName(name)
     }
@@ -296,7 +296,7 @@ class ContactCell: UITableViewCell {
         case .deaddrop(let deaddropData):
             safe_assert(deaddropData.chatId == DC_CHAT_ID_DEADDROP)
             backgroundColor = DcColors.deaddropBackground
-            let contact = deaddropData.deaddropContact //DcContact(id: DcMsg(id: deaddropData.msgId).fromContactId)
+            let contact = deaddropData.deaddropContact
             if let img = contact.profileImage {
                 resetBackupImage()
                 setImage(img)

+ 1 - 1
deltachat-ios/View/ContactDetailHeader.swift

@@ -86,7 +86,7 @@ class ContactDetailHeader: UIView {
         avatar.setName("")
     }
 
-    func setBackupImage(name: String, color: UIColor?) {
+    func setBackupImage(name: String, color: UIColor) {
         avatar.setColor(color)
         avatar.setName(name)
     }