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