Kaynağa Gözat

implement ephemeral message indicator in a chat view

cyberta 5 yıl önce
ebeveyn
işleme
e19a5085e1

+ 11 - 0
DcCore/DcCore/DC/events.swift

@@ -10,6 +10,7 @@ public let dcNotificationSecureInviterProgress = Notification.Name(rawValue: "Mr
 public let dcNotificationViewChat = Notification.Name(rawValue: "MrEventViewChat")
 public let dcNotificationViewChat = Notification.Name(rawValue: "MrEventViewChat")
 public let dcNotificationContactChanged = Notification.Name(rawValue: "MrEventContactsChanged")
 public let dcNotificationContactChanged = Notification.Name(rawValue: "MrEventContactsChanged")
 public let dcNotificationChatModified = Notification.Name(rawValue: "dcNotificationChatModified")
 public let dcNotificationChatModified = Notification.Name(rawValue: "dcNotificationChatModified")
+public let dcEphemeralTimerModified =  Notification.Name(rawValue: "dcEphemeralTimerModified")
 
 
 public func handleEvent(event: DcEvent) {
 public func handleEvent(event: DcEvent) {
     let id = event.id
     let id = event.id
@@ -106,6 +107,16 @@ public func handleEvent(event: DcEvent) {
                 ]
                 ]
             )
             )
         }
         }
+    case DC_EVENT_CHAT_EPHEMERAL_TIMER_MODIFIED:
+        DcContext.shared.logger?.info("chat ephemeral timer modified: \(id)")
+        let nc = NotificationCenter.default
+        DispatchQueue.main.async {
+            nc.post(
+                name: dcEphemeralTimerModified,
+                object: nil,
+                userInfo: nil
+            )
+        }
 
 
     case DC_EVENT_INCOMING_MSG:
     case DC_EVENT_INCOMING_MSG:
         let nc = NotificationCenter.default
         let nc = NotificationCenter.default

+ 23 - 0
deltachat-ios/Assets.xcassets/ephemeral_timer.imageset/Contents.json

@@ -0,0 +1,23 @@
+{
+  "images" : [
+    {
+      "filename" : "outline_timer_white_24pt_1x.png",
+      "idiom" : "universal",
+      "scale" : "1x"
+    },
+    {
+      "filename" : "outline_timer_white_24pt_2x.png",
+      "idiom" : "universal",
+      "scale" : "2x"
+    },
+    {
+      "filename" : "outline_timer_white_24pt_3x.png",
+      "idiom" : "universal",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}

BIN
deltachat-ios/Assets.xcassets/ephemeral_timer.imageset/outline_timer_white_24pt_1x.png


BIN
deltachat-ios/Assets.xcassets/ephemeral_timer.imageset/outline_timer_white_24pt_2x.png


BIN
deltachat-ios/Assets.xcassets/ephemeral_timer.imageset/outline_timer_white_24pt_3x.png


+ 28 - 1
deltachat-ios/Controller/ChatViewController.swift

@@ -48,6 +48,7 @@ class ChatViewController: MessagesViewController {
 
 
     var msgChangedObserver: Any?
     var msgChangedObserver: Any?
     var incomingMsgObserver: Any?
     var incomingMsgObserver: Any?
+    var ephemeralTimerModifiedObserver: Any?
 
 
     private lazy var refreshControl: UIRefreshControl = {
     private lazy var refreshControl: UIRefreshControl = {
         let refreshControl = UIRefreshControl()
         let refreshControl = UIRefreshControl()
@@ -76,6 +77,16 @@ class ChatViewController: MessagesViewController {
         return UIBarButtonItem(customView: imageView)
         return UIBarButtonItem(customView: imageView)
     }()
     }()
 
 
+    private lazy var ephemeralMessageItem: UIBarButtonItem = {
+        let imageView = UIImageView()
+        imageView.tintColor = DcColors.defaultTextColor
+        imageView.image =  #imageLiteral(resourceName: "ephemeral_timer").withRenderingMode(.alwaysTemplate)
+        imageView.translatesAutoresizingMaskIntoConstraints = false
+        imageView.heightAnchor.constraint(equalToConstant: 20).isActive = true
+        imageView.widthAnchor.constraint(equalToConstant: 20).isActive = true
+        return UIBarButtonItem(customView: imageView)
+    }()
+
     private lazy var badgeItem: UIBarButtonItem = {
     private lazy var badgeItem: UIBarButtonItem = {
         let badge: InitialsBadge
         let badge: InitialsBadge
         let chat = dcContext.getChat(chatId: chatId)
         let chat = dcContext.getChat(chatId: chatId)
@@ -221,7 +232,7 @@ class ChatViewController: MessagesViewController {
         incomingMsgObserver = nc.addObserver(
         incomingMsgObserver = nc.addObserver(
             forName: dcNotificationIncoming,
             forName: dcNotificationIncoming,
             object: nil, queue: OperationQueue.main
             object: nil, queue: OperationQueue.main
-        ) {  [weak self] notification in
+        ) { [weak self] notification in
             guard let self = self else { return }
             guard let self = self else { return }
             if let ui = notification.userInfo {
             if let ui = notification.userInfo {
                 if self.chatId == ui["chat_id"] as? Int {
                 if self.chatId == ui["chat_id"] as? Int {
@@ -234,6 +245,14 @@ class ChatViewController: MessagesViewController {
             }
             }
         }
         }
 
 
+        ephemeralTimerModifiedObserver = nc.addObserver(
+            forName: dcEphemeralTimerModified,
+            object: nil, queue: OperationQueue.main
+        ) { [weak self] _ in
+            guard let self = self else { return }
+            self.updateTitle(chat: self.dcContext.getChat(chatId: self.chatId))
+        }
+
         loadFirstMessages()
         loadFirstMessages()
 
 
         if RelayHelper.sharedInstance.isForwarding() {
         if RelayHelper.sharedInstance.isForwarding() {
@@ -270,6 +289,9 @@ class ChatViewController: MessagesViewController {
         if let incomingMsgObserver = self.incomingMsgObserver {
         if let incomingMsgObserver = self.incomingMsgObserver {
             nc.removeObserver(incomingMsgObserver)
             nc.removeObserver(incomingMsgObserver)
         }
         }
+        if let ephemeralTimerModifiedObserver = self.ephemeralTimerModifiedObserver {
+            nc.removeObserver(ephemeralTimerModifiedObserver)
+        }
         audioController.stopAnyOngoingPlaying()
         audioController.stopAnyOngoingPlaying()
         stopTimer()
         stopTimer()
     }
     }
@@ -322,6 +344,11 @@ class ChatViewController: MessagesViewController {
         if chat.isMuted {
         if chat.isMuted {
             rightBarButtonItems.append(muteItem)
             rightBarButtonItems.append(muteItem)
         }
         }
+
+        if dcContext.getChatEphemeralTimer(chatId: chat.id) > 0 {
+            rightBarButtonItems.append(ephemeralMessageItem)
+        }
+
         navigationItem.rightBarButtonItems = rightBarButtonItems
         navigationItem.rightBarButtonItems = rightBarButtonItems
     }
     }