From 381237a3153f5a8d56377d4531525efef9bb58d6 Mon Sep 17 00:00:00 2001 From: Gavin Howard Date: Mon, 27 Mar 2017 16:41:16 -0600 Subject: [PATCH] Make plaintext export more compatible with SMS Backup and Restore This commit adds the contact name and the readable date (and time) to the plaintext export of every message. That's because that is how SMS Backup and Restore does it, so this commit makes Signal more compatible. Closes #6452 // FREEBIE --- .../database/PlaintextBackupExporter.java | 1 + .../securesms/database/XmlBackup.java | 25 +++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/org/thoughtcrime/securesms/database/PlaintextBackupExporter.java b/src/org/thoughtcrime/securesms/database/PlaintextBackupExporter.java index 7e9f10749a..46e019f58a 100644 --- a/src/org/thoughtcrime/securesms/database/PlaintextBackupExporter.java +++ b/src/org/thoughtcrime/securesms/database/PlaintextBackupExporter.java @@ -45,6 +45,7 @@ public class PlaintextBackupExporter { while ((record = reader.getNext()) != null) { XmlBackup.XmlBackupItem item = new XmlBackup.XmlBackupItem(0, record.getIndividualRecipient().getNumber(), + record.getIndividualRecipient().getName(), record.getDateReceived(), MmsSmsColumns.Types.translateToSystemBaseType(record.getType()), null, record.getDisplayBody().toString(), null, diff --git a/src/org/thoughtcrime/securesms/database/XmlBackup.java b/src/org/thoughtcrime/securesms/database/XmlBackup.java index 3bf178af14..6004438fa4 100644 --- a/src/org/thoughtcrime/securesms/database/XmlBackup.java +++ b/src/org/thoughtcrime/securesms/database/XmlBackup.java @@ -11,6 +11,7 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; +import java.text.SimpleDateFormat; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -18,7 +19,9 @@ public class XmlBackup { private static final String PROTOCOL = "protocol"; private static final String ADDRESS = "address"; + private static final String CONTACT_NAME = "contact_name"; private static final String DATE = "date"; + private static final String READABLE_DATE = "readable_date"; private static final String TYPE = "type"; private static final String SUBJECT = "subject"; private static final String BODY = "body"; @@ -29,6 +32,8 @@ public class XmlBackup { private static final String SC_TOA = "sc_toa"; private static final String LOCKED = "locked"; + private static final SimpleDateFormat dateFormatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z"); + private final XmlPullParser parser; public XmlBackup(String path) throws XmlPullParserException, FileNotFoundException { @@ -62,7 +67,9 @@ public class XmlBackup { if (attributeName.equals(PROTOCOL )) item.protocol = Integer.parseInt(parser.getAttributeValue(i)); else if (attributeName.equals(ADDRESS )) item.address = parser.getAttributeValue(i); + else if (attributeName.equals(CONTACT_NAME )) item.contactName = parser.getAttributeValue(i); else if (attributeName.equals(DATE )) item.date = Long.parseLong(parser.getAttributeValue(i)); + else if (attributeName.equals(READABLE_DATE )) item.readableDate = parser.getAttributeValue(i); else if (attributeName.equals(TYPE )) item.type = Integer.parseInt(parser.getAttributeValue(i)); else if (attributeName.equals(SUBJECT )) item.subject = parser.getAttributeValue(i); else if (attributeName.equals(BODY )) item.body = parser.getAttributeValue(i); @@ -80,7 +87,9 @@ public class XmlBackup { public static class XmlBackupItem { private int protocol; private String address; + private String contactName; private long date; + private String readableDate; private int type; private String subject; private String body; @@ -90,12 +99,14 @@ public class XmlBackup { public XmlBackupItem() {} - public XmlBackupItem(int protocol, String address, long date, int type, String subject, - String body, String serviceCenter, int read, int status) + public XmlBackupItem(int protocol, String address, String contactName, long date, int type, + String subject, String body, String serviceCenter, int read, int status) { this.protocol = protocol; this.address = address; + this.contactName = contactName; this.date = date; + this.readableDate = dateFormatter.format(date); this.type = type; this.subject = subject; this.body = body; @@ -112,10 +123,18 @@ public class XmlBackup { return address; } + public String getContactName() { + return contactName; + } + public long getDate() { return date; } + public String getReadableDate() { + return readableDate; + } + public int getType() { return type; } @@ -172,7 +191,9 @@ public class XmlBackup { stringBuilder.append(OPEN_TAG_SMS); appendAttribute(stringBuilder, PROTOCOL, item.getProtocol()); appendAttribute(stringBuilder, ADDRESS, escapeXML(item.getAddress())); + appendAttribute(stringBuilder, CONTACT_NAME, item.getContactName()); appendAttribute(stringBuilder, DATE, item.getDate()); + appendAttribute(stringBuilder, READABLE_DATE, item.getReadableDate()); appendAttribute(stringBuilder, TYPE, item.getType()); appendAttribute(stringBuilder, SUBJECT, escapeXML(item.getSubject())); appendAttribute(stringBuilder, BODY, escapeXML(item.getBody()));