浏览代码

implement recently seen indicator

cyberta 2 年之前
父节点
当前提交
cc702fcd79

+ 4 - 0
DcCore/DcCore/DC/Wrapper.swift

@@ -1311,6 +1311,10 @@ public class DcContact {
         return Int64(dc_contact_get_last_seen(contactPointer))
     }
 
+    public var wasSeenRecently: Bool {
+        return dc_contact_was_seen_recently(contactPointer) == 1
+    }
+
     public var status: String {
         guard let cString = dc_contact_get_status(contactPointer) else { return "" }
         let swiftString = String(cString: cString)

+ 21 - 1
DcCore/DcCore/Views/InitialsBadge.swift

@@ -37,6 +37,15 @@ public class InitialsBadge: UIView {
         return imgView
     }()
 
+    private var recentlySeenView: UIView = {
+        let view = UIView()
+        view.translatesAutoresizingMaskIntoConstraints = false
+        view.backgroundColor = DcColors.checkmarkGreen
+        view.clipsToBounds = true
+        view.isHidden = true
+        return view
+    }()
+
     private var imageView: UIImageView = {
         let imageViewContainer = UIImageView()
         imageViewContainer.clipsToBounds = true
@@ -94,10 +103,17 @@ public class InitialsBadge: UIView {
         label.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true
 
         addSubview(verifiedView)
+        addSubview(recentlySeenView)
         let imgViewConstraints = [verifiedView.constraintAlignBottomTo(self, paddingBottom: -verificationViewPadding),
                                   verifiedView.constraintAlignTrailingTo(self, paddingTrailing: -verificationViewPadding),
                                   verifiedView.constraintAlignTopTo(self, paddingTop: radius + verificationViewPadding),
-                                  verifiedView.constraintAlignLeadingTo(self, paddingLeading: radius + verificationViewPadding)]
+                                  verifiedView.constraintAlignLeadingTo(self, paddingLeading: radius + verificationViewPadding),
+                                  recentlySeenView.constraintAlignBottomTo(self),
+                                  recentlySeenView.constraintAlignLeadingTo(self),
+                                  recentlySeenView.constraintHeightTo(radius / 2),
+                                  recentlySeenView.constraintWidthTo(radius / 2)
+        ]
+        recentlySeenView.layer.cornerRadius = radius / 4
         addConstraints(imgViewConstraints)
     }
 
@@ -134,6 +150,10 @@ public class InitialsBadge: UIView {
         verifiedView.isHidden = !verified
     }
 
+    public func setRecentlySeen(_ seen: Bool) {
+        recentlySeenView.isHidden = !seen
+    }
+
     public func reset() {
         verifiedView.isHidden = true
         imageView.image = nil

+ 9 - 0
DcShare/View/ChatListCell.swift

@@ -107,6 +107,14 @@ class ChatListCell: UITableViewCell {
                 setBackupImage(name: chat.name, color: chat.color)
             }
             subtitleLabel.attributedText = nil
+            var recentlySeen = false
+            if !chat.isSelfTalk && !chat.isGroup && !chat.isDeviceTalk && !chat.isMailinglist {
+                let contactIds = chat.getContactIds(cellViewModel.dcContext)
+                if contactIds.count == 1 {
+                    recentlySeen = cellViewModel.dcContext.getContact(id: contactIds[0]).wasSeenRecently
+                }
+            }
+            avatar.setRecentlySeen(recentlySeen)
 
         case .contact(let contactData):
             let contact = cellViewModel.dcContext.getContact(id: contactData.contactId)
@@ -116,6 +124,7 @@ class ChatListCell: UITableViewCell {
             } else {
                 setBackupImage(name: cellViewModel.title, color: contact.color)
             }
+            avatar.setRecentlySeen(contact.wasSeenRecently)
             subtitleLabel.attributedText = cellViewModel.subtitle.boldAt(indexes: cellViewModel.subtitleHighlightIndexes,
                                                                          fontSize: subtitleLabel.font.pointSize)
         default:

+ 9 - 0
deltachat-ios/Chat/ChatViewController.swift

@@ -1024,6 +1024,15 @@ class ChatViewController: UITableViewController {
         }
         initialsBadge.setVerified(dcChat.isProtected)
 
+        var recentlySeen = false
+        if !dcChat.isSelfTalk && !dcChat.isGroup && !dcChat.isMailinglist && !dcChat.isDeviceTalk {
+            let contactIds = dcChat.getContactIds(dcContext)
+            if contactIds.count == 1 {
+                recentlySeen = dcContext.getContact(id: contactIds[0]).wasSeenRecently
+            }
+        }
+        initialsBadge.setRecentlySeen(recentlySeen)
+
         var rightBarButtonItems = [badgeItem]
         if dcChat.isSendingLocations {
             rightBarButtonItems.append(locationStreamingItem)

+ 1 - 0
deltachat-ios/Controller/ContactDetailViewController.swift

@@ -12,6 +12,7 @@ class ContactDetailViewController: UITableViewController {
         headerCell.onAvatarTap = showContactAvatarIfNeeded
         headerCell.onMuteButtonTapped = toggleMuteChat
         headerCell.onSearchButtonTapped = showSearch
+        headerCell.setRecentlySeen(viewModel.contact.wasSeenRecently)
         return headerCell
     }()
 

+ 1 - 0
deltachat-ios/Controller/GroupChatDetailViewController.swift

@@ -92,6 +92,7 @@ class GroupChatDetailViewController: UIViewController {
         header.showSearchButton(show: true)
         header.onSearchButtonTapped = showSearch
         header.onMuteButtonTapped = toggleMuteChat
+        header.setRecentlySeen(false)
         return header
     }()
 

+ 10 - 0
deltachat-ios/View/ContactCell.swift

@@ -334,6 +334,14 @@ class ContactCell: UITableViewCell {
                 setBackupImage(name: chat.name, color: chat.color)
             }
             setVerified(isVerified: chat.isProtected)
+            var recentlySeen = false
+            if !chat.isSelfTalk && !chat.isGroup && !chat.isDeviceTalk && !chat.isMailinglist {
+                let contacts = chat.getContactIds(cellViewModel.dcContext)
+                if contacts.count == 1 {
+                    recentlySeen = cellViewModel.dcContext.getContact(id: contacts[0]).wasSeenRecently
+                }
+            }
+            avatar.setRecentlySeen(recentlySeen)
             setTimeLabel(chatData.summary.timestamp)
             setStatusIndicators(unreadCount: chatData.unreadMessages,
                                 status: chatData.summary.state,
@@ -352,6 +360,7 @@ class ContactCell: UITableViewCell {
                 avatar.setColor(contact.color)
             }
             setVerified(isVerified: contact.isVerified)
+            avatar.setRecentlySeen(contact.wasSeenRecently)
             setStatusIndicators(unreadCount: 0,
                                 status: 0,
                                 visibility: 0,
@@ -369,6 +378,7 @@ class ContactCell: UITableViewCell {
                 avatar.setColor(contact.color)
             }
             setVerified(isVerified: false)
+            avatar.setRecentlySeen(false)
             setStatusIndicators(unreadCount: 0,
             status: 0,
             visibility: 0,

+ 4 - 0
deltachat-ios/View/ContactDetailHeader.swift

@@ -128,6 +128,10 @@ class ContactDetailHeader: UIView {
         avatar.setImage(image)
     }
 
+    func setRecentlySeen(_ seen: Bool) {
+        avatar.setRecentlySeen(seen)
+    }
+
     func resetBackupImage() {
         avatar.setColor(UIColor.clear)
         avatar.setName("")