Browse Source

deduplicate some bits

cyberta 2 years ago
parent
commit
866237bba2

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

@@ -131,4 +131,15 @@ public struct DcUtils {
           return String.localized("connectivity_not_connected")
         }
     }
+
+    public static func showRecentlySeen(context: DcContext, chat: DcChat) -> Bool {
+        var recentlySeen = false
+        if !chat.isSelfTalk && !chat.isGroup && !chat.isMailinglist && !chat.isDeviceTalk {
+            let contactIds = chat.getContactIds(context)
+            if contactIds.count == 1 {
+                recentlySeen = context.getContact(id: contactIds[0]).wasSeenRecently
+            }
+        }
+        return recentlySeen
+    }
 }

+ 1 - 7
DcShare/View/ChatListCell.swift

@@ -107,13 +107,7 @@ 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
-                }
-            }
+            let recentlySeen = DcUtils.showRecentlySeen(context: cellViewModel.dcContext, chat: chat)
             avatar.setRecentlySeen(recentlySeen)
 
         case .contact(let contactData):

+ 1 - 7
deltachat-ios/Chat/ChatViewController.swift

@@ -1024,13 +1024,7 @@ 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
-            }
-        }
+        let recentlySeen = DcUtils.showRecentlySeen(context: dcContext, chat: dcChat)
         initialsBadge.setRecentlySeen(recentlySeen)
 
         var rightBarButtonItems = [badgeItem]

+ 1 - 7
deltachat-ios/View/ContactCell.swift

@@ -334,13 +334,7 @@ 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
-                }
-            }
+            let recentlySeen = DcUtils.showRecentlySeen(context: cellViewModel.dcContext, chat: chat)
             avatar.setRecentlySeen(recentlySeen)
             setTimeLabel(chatData.summary.timestamp)
             setStatusIndicators(unreadCount: chatData.unreadMessages,