forked from mirror/monocles_chat
catch all Exceptions during settings import (Christian Schneppe), fix: retract message if end to end encryption is enabled (mightypop), fix message retraction if no body is available (mightypop)
This commit is contained in:
parent
027b5cbb46
commit
668f76bd67
3 changed files with 42 additions and 32 deletions
|
@ -513,7 +513,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
|
|||
if (timestamp == null) {
|
||||
timestamp = AbstractParser.parseTimestamp(original, AbstractParser.parseTimestamp(packet));
|
||||
}
|
||||
final LocalizedContent body = packet.getBody();
|
||||
|
||||
final Element mucUserElement = packet.findChild("x", Namespace.MUC_USER);
|
||||
final String pgpEncrypted = packet.findChildContent("x", "jabber:x:encrypted");
|
||||
final Element replaceElement = packet.findChild("replace", "urn:xmpp:message-correct:0");
|
||||
|
@ -523,6 +523,13 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
|
|||
|
||||
final Element applyToElement = packet.findChild("apply-to", "urn:xmpp:fasten:0");
|
||||
final String retractId = applyToElement != null && applyToElement.findChild("retract", "urn:xmpp:message-retract:0") != null ? applyToElement.getAttribute("id") : null;
|
||||
if (packet.getBody()==null && retractId != null)
|
||||
{ //It's RECOMMENDED that you include a Fallback Indication (XEP-0428) [6] tag with fallback text in the <body/>, so that older clients can still indicate the intent to retract and so that older servers will archive the retraction.
|
||||
//Otherwhise the following code will not execute the retraction, because it searchs for body content!
|
||||
packet.setBody("This person attempted to retract a previous message, but it's unsupported by your client.");
|
||||
}
|
||||
|
||||
final LocalizedContent body = packet.getBody();
|
||||
|
||||
final Element axolotlEncrypted = packet.findChildEnsureSingle(XmppAxolotlMessage.CONTAINERTAG, AxolotlService.PEP_PREFIX);
|
||||
int status;
|
||||
|
@ -801,6 +808,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
|
|||
final Message retractedMessage = conversation.findSentMessageWithUuidOrRemoteId(retractId, true, true);
|
||||
if (retractedMessage != null) {
|
||||
final boolean fingerprintsMatch = retractedMessage.getFingerprint() == null
|
||||
|| message.getFingerprint() == null
|
||||
|| retractedMessage.getFingerprint().equals(message.getFingerprint());
|
||||
final boolean trueCountersMatch = retractedMessage.getTrueCounterpart() != null
|
||||
&& message.getTrueCounterpart() != null
|
||||
|
|
|
@ -303,22 +303,27 @@ public class ExportBackupService extends Service {
|
|||
Log.d(Config.LOGTAG, "exporting " + size + " messages for account " + uuid);
|
||||
int i = 0;
|
||||
int p = 0;
|
||||
while (cursor != null && cursor.moveToNext()) {
|
||||
writer.write(cursorToString(Message.TABLENAME, cursor, PAGE_SIZE, false));
|
||||
if (i + PAGE_SIZE > size) {
|
||||
i = size;
|
||||
} else {
|
||||
i += PAGE_SIZE;
|
||||
try {
|
||||
while (cursor != null && cursor.moveToNext()) {
|
||||
writer.write(cursorToString(Message.TABLENAME, cursor, PAGE_SIZE, false));
|
||||
if (i + PAGE_SIZE > size) {
|
||||
i = size;
|
||||
} else {
|
||||
i += PAGE_SIZE;
|
||||
}
|
||||
final int percentage = i * 100 / size;
|
||||
if (p < percentage) {
|
||||
p = percentage;
|
||||
notificationManager.notify(EXPORT_BACKUP_NOTIFICATION_ID, progress.build(p));
|
||||
}
|
||||
}
|
||||
final int percentage = i * 100 / size;
|
||||
if (p < percentage) {
|
||||
p = percentage;
|
||||
notificationManager.notify(EXPORT_BACKUP_NOTIFICATION_ID, progress.build(p));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
|
||||
private List<File> export() throws Exception {
|
||||
|
|
|
@ -23,7 +23,6 @@ import androidx.core.content.ContextCompat;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.security.KeyStoreException;
|
||||
|
@ -591,6 +590,7 @@ public class SettingsActivity extends XmppActivity implements
|
|||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
if (grantResults.length > 0) {
|
||||
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
if (requestCode == REQUEST_CREATE_BACKUP) {
|
||||
|
@ -617,7 +617,7 @@ public class SettingsActivity extends XmppActivity implements
|
|||
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
private boolean importSettings() {
|
||||
boolean success = false;
|
||||
boolean success;
|
||||
ObjectInputStream input = null;
|
||||
try {
|
||||
final File file = new File(FileBackend.getBackupDirectory(null) + "settings.dat");
|
||||
|
@ -626,27 +626,24 @@ public class SettingsActivity extends XmppActivity implements
|
|||
prefEdit.clear();
|
||||
Map<String, ?> entries = (Map<String, ?>) input.readObject();
|
||||
for (Map.Entry<String, ?> entry : entries.entrySet()) {
|
||||
Object v = entry.getValue();
|
||||
Object value = entry.getValue();
|
||||
String key = entry.getKey();
|
||||
|
||||
if (v instanceof Boolean)
|
||||
prefEdit.putBoolean(key, ((Boolean) v).booleanValue());
|
||||
else if (v instanceof Float)
|
||||
prefEdit.putFloat(key, ((Float) v).floatValue());
|
||||
else if (v instanceof Integer)
|
||||
prefEdit.putInt(key, ((Integer) v).intValue());
|
||||
else if (v instanceof Long)
|
||||
prefEdit.putLong(key, ((Long) v).longValue());
|
||||
else if (v instanceof String)
|
||||
prefEdit.putString(key, ((String) v));
|
||||
if (value instanceof Boolean)
|
||||
prefEdit.putBoolean(key, ((Boolean) value).booleanValue());
|
||||
else if (value instanceof Float)
|
||||
prefEdit.putFloat(key, ((Float) value).floatValue());
|
||||
else if (value instanceof Integer)
|
||||
prefEdit.putInt(key, ((Integer) value).intValue());
|
||||
else if (value instanceof Long)
|
||||
prefEdit.putLong(key, ((Long) value).longValue());
|
||||
else if (value instanceof String)
|
||||
prefEdit.putString(key, ((String) value));
|
||||
}
|
||||
prefEdit.commit();
|
||||
success = true;
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ClassNotFoundException e) {
|
||||
} catch (Exception e) {
|
||||
success = false;
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
|
|
Loading…
Add table
Reference in a new issue