sync roster to disk after roster push
This commit is contained in:
parent
ff2b1fad51
commit
9908af6286
|
@ -98,8 +98,7 @@ public class IqGenerator extends AbstractGenerator {
|
||||||
|
|
||||||
protected IqPacket publish(final String node, final Element item, final Bundle options) {
|
protected IqPacket publish(final String node, final Element item, final Bundle options) {
|
||||||
final IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
|
final IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
|
||||||
final Element pubsub = packet.addChild("pubsub",
|
final Element pubsub = packet.addChild("pubsub",Namespace.PUBSUB);
|
||||||
"http://jabber.org/protocol/pubsub");
|
|
||||||
final Element publish = pubsub.addChild("publish");
|
final Element publish = pubsub.addChild("publish");
|
||||||
publish.setAttribute("node", node);
|
publish.setAttribute("node", node);
|
||||||
publish.addChild(item);
|
publish.addChild(item);
|
||||||
|
@ -116,8 +115,7 @@ public class IqGenerator extends AbstractGenerator {
|
||||||
|
|
||||||
protected IqPacket retrieve(String node, Element item) {
|
protected IqPacket retrieve(String node, Element item) {
|
||||||
final IqPacket packet = new IqPacket(IqPacket.TYPE.GET);
|
final IqPacket packet = new IqPacket(IqPacket.TYPE.GET);
|
||||||
final Element pubsub = packet.addChild("pubsub",
|
final Element pubsub = packet.addChild("pubsub",Namespace.PUBSUB);
|
||||||
"http://jabber.org/protocol/pubsub");
|
|
||||||
final Element items = pubsub.addChild("items");
|
final Element items = pubsub.addChild("items");
|
||||||
items.setAttribute("node", node);
|
items.setAttribute("node", node);
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
|
@ -397,7 +395,7 @@ public class IqGenerator extends AbstractGenerator {
|
||||||
enable.setAttribute("jid",jid.toString());
|
enable.setAttribute("jid",jid.toString());
|
||||||
enable.setAttribute("node", node);
|
enable.setAttribute("node", node);
|
||||||
Data data = new Data();
|
Data data = new Data();
|
||||||
data.setFormType("http://jabber.org/protocol/pubsub#publish-options");
|
data.setFormType(Namespace.PUBSUB_PUBLISH_OPTIONS);
|
||||||
data.put("secret",secret);
|
data.put("secret",secret);
|
||||||
data.submit();
|
data.submit();
|
||||||
enable.addChild(data);
|
enable.addChild(data);
|
||||||
|
|
|
@ -82,11 +82,11 @@ public class IqParser extends AbstractParser implements OnIqPacketReceived {
|
||||||
mXmppConnectionService.updateConversationUi();
|
mXmppConnectionService.updateConversationUi();
|
||||||
mXmppConnectionService.updateRosterUi();
|
mXmppConnectionService.updateRosterUi();
|
||||||
mXmppConnectionService.getShortcutService().refresh();
|
mXmppConnectionService.getShortcutService().refresh();
|
||||||
|
mXmppConnectionService.syncRoster(account);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String avatarData(final IqPacket packet) {
|
public String avatarData(final IqPacket packet) {
|
||||||
final Element pubsub = packet.findChild("pubsub",
|
final Element pubsub = packet.findChild("pubsub", Namespace.PUBSUB);
|
||||||
"http://jabber.org/protocol/pubsub");
|
|
||||||
if (pubsub == null) {
|
if (pubsub == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -98,8 +98,7 @@ public class IqParser extends AbstractParser implements OnIqPacketReceived {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Element getItem(final IqPacket packet) {
|
public Element getItem(final IqPacket packet) {
|
||||||
final Element pubsub = packet.findChild("pubsub",
|
final Element pubsub = packet.findChild("pubsub", Namespace.PUBSUB);
|
||||||
"http://jabber.org/protocol/pubsub");
|
|
||||||
if (pubsub == null) {
|
if (pubsub == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import android.database.DatabaseUtils;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.database.sqlite.SQLiteOpenHelper;
|
import android.database.sqlite.SQLiteOpenHelper;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
|
import android.os.SystemClock;
|
||||||
import android.util.Base64;
|
import android.util.Base64;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
@ -850,6 +851,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeRoster(final Roster roster) {
|
public void writeRoster(final Roster roster) {
|
||||||
|
long start = SystemClock.elapsedRealtime();
|
||||||
final Account account = roster.getAccount();
|
final Account account = roster.getAccount();
|
||||||
final SQLiteDatabase db = this.getWritableDatabase();
|
final SQLiteDatabase db = this.getWritableDatabase();
|
||||||
db.beginTransaction();
|
db.beginTransaction();
|
||||||
|
@ -866,6 +868,8 @@ public class DatabaseBackend extends SQLiteOpenHelper {
|
||||||
db.endTransaction();
|
db.endTransaction();
|
||||||
account.setRosterVersion(roster.getVersion());
|
account.setRosterVersion(roster.getVersion());
|
||||||
updateAccount(account);
|
updateAccount(account);
|
||||||
|
long duration = SystemClock.elapsedRealtime() - start;
|
||||||
|
Log.d(Config.LOGTAG,account.getJid().asBareJid()+": persisted roster in "+duration+"ms");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteMessagesInConversation(Conversation conversation) {
|
public void deleteMessagesInConversation(Conversation conversation) {
|
||||||
|
|
|
@ -184,9 +184,7 @@ public class XmppConnectionService extends Service {
|
||||||
private OnMessagePacketReceived mMessageParser = new MessageParser(this);
|
private OnMessagePacketReceived mMessageParser = new MessageParser(this);
|
||||||
private OnPresencePacketReceived mPresenceParser = new PresenceParser(this);
|
private OnPresencePacketReceived mPresenceParser = new PresenceParser(this);
|
||||||
private IqParser mIqParser = new IqParser(this);
|
private IqParser mIqParser = new IqParser(this);
|
||||||
private OnIqPacketReceived mDefaultIqHandler = new OnIqPacketReceived() {
|
private final OnIqPacketReceived mDefaultIqHandler = (account, packet) -> {
|
||||||
@Override
|
|
||||||
public void onIqPacketReceived(Account account, IqPacket packet) {
|
|
||||||
if (packet.getType() != IqPacket.TYPE.RESULT) {
|
if (packet.getType() != IqPacket.TYPE.RESULT) {
|
||||||
Element error = packet.findChild("error");
|
Element error = packet.findChild("error");
|
||||||
String text = error != null ? error.findChildContent("text") : null;
|
String text = error != null ? error.findChildContent("text") : null;
|
||||||
|
@ -194,13 +192,9 @@ public class XmppConnectionService extends Service {
|
||||||
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": received iq error - " + text);
|
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": received iq error - " + text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
private MessageGenerator mMessageGenerator = new MessageGenerator(this);
|
private MessageGenerator mMessageGenerator = new MessageGenerator(this);
|
||||||
public OnContactStatusChanged onContactStatusChanged = new OnContactStatusChanged() {
|
public OnContactStatusChanged onContactStatusChanged = (contact, online) -> {
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onContactStatusChanged(Contact contact, boolean online) {
|
|
||||||
Conversation conversation = find(getConversations(), contact);
|
Conversation conversation = find(getConversations(), contact);
|
||||||
if (conversation != null) {
|
if (conversation != null) {
|
||||||
if (online) {
|
if (online) {
|
||||||
|
@ -209,7 +203,6 @@ public class XmppConnectionService extends Service {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
private PresenceGenerator mPresenceGenerator = new PresenceGenerator(this);
|
private PresenceGenerator mPresenceGenerator = new PresenceGenerator(this);
|
||||||
private List<Account> accounts;
|
private List<Account> accounts;
|
||||||
|
@ -966,7 +959,7 @@ public class XmppConnectionService extends Service {
|
||||||
restoreFromDatabase();
|
restoreFromDatabase();
|
||||||
|
|
||||||
getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI, true, contactObserver);
|
getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI, true, contactObserver);
|
||||||
new Thread(() -> fileObserver.startWatching()).start();
|
new Thread(fileObserver::startWatching).start();
|
||||||
if (Config.supportOpenPgp()) {
|
if (Config.supportOpenPgp()) {
|
||||||
this.pgpServiceConnection = new OpenPgpServiceConnection(this, "org.sufficientlysecure.keychain", new OpenPgpServiceConnection.OnBound() {
|
this.pgpServiceConnection = new OpenPgpServiceConnection(this, "org.sufficientlysecure.keychain", new OpenPgpServiceConnection.OnBound() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -1464,6 +1457,11 @@ public class XmppConnectionService extends Service {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void syncRoster(final Account account) {
|
||||||
|
mDatabaseWriterExecutor.execute(() -> databaseBackend.writeRoster(account.getRoster()));
|
||||||
|
}
|
||||||
|
|
||||||
public List<Conversation> getConversations() {
|
public List<Conversation> getConversations() {
|
||||||
return this.conversations;
|
return this.conversations;
|
||||||
}
|
}
|
||||||
|
@ -2706,13 +2704,13 @@ public class XmppConnectionService extends Service {
|
||||||
iq.query(Namespace.ROSTER).addChild(contact.asElement());
|
iq.query(Namespace.ROSTER).addChild(contact.asElement());
|
||||||
account.getXmppConnection().sendIqPacket(iq, mDefaultIqHandler);
|
account.getXmppConnection().sendIqPacket(iq, mDefaultIqHandler);
|
||||||
if (sendUpdates) {
|
if (sendUpdates) {
|
||||||
sendPresencePacket(account,
|
sendPresencePacket(account, mPresenceGenerator.sendPresenceUpdatesTo(contact));
|
||||||
mPresenceGenerator.sendPresenceUpdatesTo(contact));
|
|
||||||
}
|
}
|
||||||
if (ask) {
|
if (ask) {
|
||||||
sendPresencePacket(account,
|
sendPresencePacket(account, mPresenceGenerator.requestPresenceUpdatesFrom(contact));
|
||||||
mPresenceGenerator.requestPresenceUpdatesFrom(contact));
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
syncRoster(contact.getAccount());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -619,7 +619,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
|
||||||
}
|
}
|
||||||
|
|
||||||
private void hidePrepareFileToast(final Toast prepareFileToast) {
|
private void hidePrepareFileToast(final Toast prepareFileToast) {
|
||||||
if (prepareFileToast != null) {
|
if (prepareFileToast != null && activity != null) {
|
||||||
activity.runOnUiThread(prepareFileToast::cancel);
|
activity.runOnUiThread(prepareFileToast::cancel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,8 +14,9 @@ public final class Namespace {
|
||||||
public static final String OOB = "jabber:x:oob";
|
public static final String OOB = "jabber:x:oob";
|
||||||
public static final String SASL = "urn:ietf:params:xml:ns:xmpp-sasl";
|
public static final String SASL = "urn:ietf:params:xml:ns:xmpp-sasl";
|
||||||
public static final String TLS = "urn:ietf:params:xml:ns:xmpp-tls";
|
public static final String TLS = "urn:ietf:params:xml:ns:xmpp-tls";
|
||||||
public static final String PUBSUB_PUBLISH_OPTIONS = "http://jabber.org/protocol/pubsub#publish-options";
|
public static final String PUBSUB = "http://jabber.org/protocol/pubsub";
|
||||||
public static final String PUBSUB_ERROR = "http://jabber.org/protocol/pubsub#errors";
|
public static final String PUBSUB_PUBLISH_OPTIONS = PUBSUB+"#publish-options";
|
||||||
|
public static final String PUBSUB_ERROR = PUBSUB+"#errors";
|
||||||
public static final String NICK = "http://jabber.org/protocol/nick";
|
public static final String NICK = "http://jabber.org/protocol/nick";
|
||||||
public static final String FLEXIBLE_OFFLINE_MESSAGE_RETRIEVAL = "http://jabber.org/protocol/offline";
|
public static final String FLEXIBLE_OFFLINE_MESSAGE_RETRIEVAL = "http://jabber.org/protocol/offline";
|
||||||
public static final String BIND = "urn:ietf:params:xml:ns:xmpp-bind";
|
public static final String BIND = "urn:ietf:params:xml:ns:xmpp-bind";
|
||||||
|
|
Loading…
Reference in a new issue