B. Petersen 5 лет назад
Родитель
Сommit
aab14f3bac

+ 0 - 1
deltachat-ios/AppDelegate.swift

@@ -174,7 +174,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         dc_set_stock_translation(mailboxPointer, UInt32(DC_STR_ARCHIVEDCHATS), String.localized("chat_archived_chats_title"))
         dc_set_stock_translation(mailboxPointer, UInt32(DC_STR_AC_SETUP_MSG_SUBJECT), String.localized("autocrypt_asm_subject"))
         dc_set_stock_translation(mailboxPointer, UInt32(DC_STR_AC_SETUP_MSG_BODY), String.localized("autocrypt_asm_general_body"))
-        dc_set_stock_translation(mailboxPointer, UInt32(DC_STR_SELFTALK_SUBTITLE), String.localized("chat_self_talk_subtitle"))
         dc_set_stock_translation(mailboxPointer, UInt32(DC_STR_CANNOT_LOGIN), String.localized("login_error_cannot_login"))
         dc_set_stock_translation(mailboxPointer, UInt32(DC_STR_SERVER_RESPONSE), String.localized("login_error_server_response"))
         dc_set_stock_translation(mailboxPointer, UInt32(DC_STR_MSGACTIONBYUSER), String.localized("systemmsg_action_by_user"))

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

@@ -87,7 +87,20 @@ class ChatViewController: MessagesViewController {
         let chat = DcChat(id: chatId)
         if showCustomNavBar {
             let titleView =  ChatTitleView()
-            titleView.updateTitleView(title: chat.name, subtitle: chat.subtitle)
+
+            var subtitle = "ErrSubtitle"
+            let chatContactIds = chat.contactIds
+            if chat.isGroup {
+                subtitle = String.localizedStringWithFormat(NSLocalizedString("n_members", comment: ""), chatContactIds.count)
+            } else if chatContactIds.count >= 1 {
+                if chat.isSelfTalk {
+                    subtitle = String.localized("chat_self_talk_subtitle")
+                } else {
+                    subtitle = DcContact(id: chatContactIds[0]).email
+                }
+            }
+
+            titleView.updateTitleView(title: chat.name, subtitle: subtitle)
             navigationItem.titleView = titleView
 
             let badge: InitialsBadge

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

@@ -114,7 +114,7 @@ extension GroupChatDetailViewController: UITableViewDelegate, UITableViewDataSou
     func tableView(_: UITableView, viewForHeaderInSection section: Int) -> UIView? {
         if section == sectionConfig {
             let header = ContactDetailHeader()
-            header.updateDetails(title: chat.name, subtitle: chat.subtitle)
+            header.updateDetails(title: chat.name, subtitle: String.localizedStringWithFormat(NSLocalizedString("n_members", comment: ""), chat.contactIds.count))
             if let img = chat.profileImage {
                 header.setImage(img)
             } else {

+ 9 - 9
deltachat-ios/DC/Wrapper.swift

@@ -388,6 +388,15 @@ class DcChat {
         return UIColor(netHex: Int(dc_chat_get_color(chatPointer)))
     }
 
+    var isGroup: Bool {
+        let type = Int(dc_chat_get_type(chatPointer))
+        return type == DC_CHAT_TYPE_GROUP || type == DC_CHAT_TYPE_VERIFIED_GROUP
+    }
+
+    var isSelfTalk: Bool {
+        return Int(dc_chat_is_self_talk(chatPointer)) != 0
+    }
+
     var isVerified: Bool {
         return dc_chat_is_verified(chatPointer) > 0
     }
@@ -413,15 +422,6 @@ class DcChat {
         }
         return nil
         }()
-
-    var subtitle: String? {
-        if let cString = dc_chat_get_subtitle(chatPointer) {
-            let str = String(cString: cString)
-            dc_str_unref(cString)
-            return str.isEmpty ? nil : str
-        }
-        return nil
-    }
 }
 
 class DcMsg: MessageType {

+ 1 - 12
deltachat-ios/View/ChatTitleView.swift

@@ -47,17 +47,6 @@ class ChatTitleView: UIView {
         subtitleLabel.textColor = baseColor.withAlphaComponent(0.95)
         titleLabel.textColor = baseColor
         titleLabel.text = title
-        subtitleLabel.text = hackPluralsString(string: subtitle)
+        subtitleLabel.text = subtitle
     }
 }
-
-func hackPluralsString(string: String?) -> String? {
-    // the rust-core does not care about plural forms (there is just once case that was not worth the effort up to now)
-    // therefore, we check if the returned string has the form "N member(s)" and localized the corrently to one/few/many/other
-    guard var string = string else { return nil }
-    if string.hasSuffix(" member(s)") {
-        guard let value = Int(string.components(separatedBy: " ")[0]) else { return string }
-        string = String.localizedStringWithFormat(NSLocalizedString("n_members", comment: ""), value)
-    }
-    return string
-}