Browse Source

Merge pull request #1171 from deltachat/add_day_marker

add daymarkers to chats
cyBerta 4 years ago
parent
commit
55561a9713

+ 1 - 1
DcCore/DcCore/DC/Wrapper.swift

@@ -256,7 +256,7 @@ public class DcContext {
     }
 
     private func getChatMessages(chatId: Int) -> OpaquePointer {
-        return dc_get_chat_msgs(contextPointer, UInt32(chatId), 0, 0)
+        return dc_get_chat_msgs(contextPointer, UInt32(chatId), UInt32(DC_GCM_ADDDAYMARKER), 0)
     }
     
     public func getMsgInfo(msgId: Int) -> String {

+ 6 - 0
DcCore/DcCore/Helper/DateUtils.swift

@@ -23,6 +23,12 @@ public class DateUtils {
         formatter.locale = .current
         return formatter
     }
+    
+    public static func getDateString(date: Date) -> String {
+        let formatter = getLocalDateFormatter()
+        formatter.dateStyle = .full
+        return formatter.string(from: date)
+    }
 
     public static func getExtendedRelativeTimeSpanString(timeStamp: Double) -> String {
         let seconds = getRelativeTimeInSeconds(timeStamp: timeStamp)

+ 13 - 2
deltachat-ios/Chat/ChatViewController.swift

@@ -509,11 +509,22 @@ class ChatViewController: UITableViewController {
         _ = handleUIMenu()
 
         let id = messageIds[indexPath.row]
+        if id == DC_MSG_ID_DAYMARKER {
+            let cell = tableView.dequeueReusableCell(withIdentifier: "info", for: indexPath) as? InfoMessageCell ?? InfoMessageCell()
+            if messageIds.count > indexPath.row + 1 {
+                let nextMessageId = messageIds[indexPath.row + 1]
+                let nextMessage = DcMsg(id: nextMessageId)
+                cell.update(text: DateUtils.getDateString(date: nextMessage.sentDate))
+            } else {
+                cell.update(text: "ErrDaymarker")
+            }
+            return cell
+        }
+        
         let message = DcMsg(id: id)
-
         if message.isInfo {
             let cell = tableView.dequeueReusableCell(withIdentifier: "info", for: indexPath) as? InfoMessageCell ?? InfoMessageCell()
-            cell.update(msg: message)
+            cell.update(text: message.text)
             return cell
         }
 

+ 2 - 2
deltachat-ios/Chat/Views/Cells/InfoMessageCell.swift

@@ -51,8 +51,8 @@ class InfoMessageCell: UITableViewCell {
         selectionStyle = .none
     }
 
-    func update(msg: DcMsg) {
-        messageLabel.text = msg.text
+    func update(text: String?) {
+        messageLabel.text = text
         var corners: UIRectCorner = []
         corners.formUnion(.topLeft)
         corners.formUnion(.bottomLeft)