use of de.pixart.messenger.entities.Account in project Pix-Art-Messenger by kriztan.
the class XmppConnectionService method getKnownConferenceHosts.
public List<String> getKnownConferenceHosts() {
final ArrayList<String> mucServers = new ArrayList<>();
for (final Account account : accounts) {
if (account.getXmppConnection() != null) {
final String server = account.getXmppConnection().getMucServer();
if (server != null && !mucServers.contains(server)) {
mucServers.add(server);
}
for (Bookmark bookmark : account.getBookmarks()) {
final Jid jid = bookmark.getJid();
final String s = jid == null ? null : jid.getDomainpart();
if (s != null && !mucServers.contains(s)) {
mucServers.add(s);
}
}
}
}
return mucServers;
}
use of de.pixart.messenger.entities.Account in project Pix-Art-Messenger by kriztan.
the class XmppConnectionService method fetchMamPreferences.
public void fetchMamPreferences(Account account, final OnMamPreferencesFetched callback) {
final boolean legacy = account.getXmppConnection().getFeatures().mamLegacy();
IqPacket request = new IqPacket(IqPacket.TYPE.GET);
request.addChild("prefs", legacy ? Namespace.MAM_LEGACY : Namespace.MAM);
sendIqPacket(account, request, new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(Account account, IqPacket packet) {
Element prefs = packet.findChild("prefs", legacy ? Namespace.MAM_LEGACY : Namespace.MAM);
if (packet.getType() == IqPacket.TYPE.RESULT && prefs != null) {
callback.onPreferencesFetched(prefs);
} else {
callback.onPreferencesFetchFailed();
}
}
});
}
use of de.pixart.messenger.entities.Account in project Pix-Art-Messenger by kriztan.
the class XmppConnectionService method loadMoreMessages.
public void loadMoreMessages(final Conversation conversation, final long timestamp, final OnMoreMessagesLoaded callback) {
if (XmppConnectionService.this.getMessageArchiveService().queryInProgress(conversation, callback)) {
return;
} else if (timestamp == 0) {
return;
}
Log.d(Config.LOGTAG, "load more messages for " + conversation.getName() + " prior to " + MessageGenerator.getTimestamp(timestamp));
final Runnable runnable = () -> {
final Account account = conversation.getAccount();
List<Message> messages = databaseBackend.getMessages(conversation, 50, timestamp);
if (messages.size() > 0) {
conversation.addAll(0, messages);
checkDeletedFiles(conversation);
callback.onMoreMessagesLoaded(messages.size(), conversation);
} else if (conversation.hasMessagesLeftOnServer() && account.isOnlineAndConnected() && conversation.getLastClearHistory().getTimestamp() == 0) {
final boolean mamAvailable;
if (conversation.getMode() == Conversation.MODE_SINGLE) {
mamAvailable = account.getXmppConnection().getFeatures().mam() && !conversation.getContact().isBlocked();
} else {
mamAvailable = conversation.getMucOptions().mamSupport();
}
if (mamAvailable) {
MessageArchiveService.Query query = getMessageArchiveService().query(conversation, new MamReference(0), timestamp, false);
if (query != null) {
query.setCallback(callback);
callback.informUser(R.string.fetching_history_from_server);
} else {
callback.informUser(R.string.not_fetching_history_retention_period);
}
}
}
};
mDatabaseReaderExecutor.execute(runnable);
}
use of de.pixart.messenger.entities.Account in project Pix-Art-Messenger by kriztan.
the class XmppConnectionService method createAccountFromKey.
public void createAccountFromKey(final String alias, final OnAccountCreated callback) {
new Thread(() -> {
try {
final X509Certificate[] chain = KeyChain.getCertificateChain(this, alias);
final X509Certificate cert = chain != null && chain.length > 0 ? chain[0] : null;
if (cert == null) {
callback.informUser(R.string.unable_to_parse_certificate);
return;
}
Pair<Jid, String> info = CryptoHelper.extractJidAndName(cert);
if (info == null) {
callback.informUser(R.string.certificate_does_not_contain_jid);
return;
}
if (findAccountByJid(info.first) == null) {
Account account = new Account(info.first, "");
account.setPrivateKeyAlias(alias);
account.setOption(Account.OPTION_DISABLED, true);
account.setDisplayName(info.second);
createAccount(account);
callback.onAccountCreated(account);
if (Config.X509_VERIFICATION) {
try {
getMemorizingTrustManager().getNonInteractive(account.getJid().getDomainpart()).checkClientTrusted(chain, "RSA");
} catch (CertificateException e) {
callback.informUser(R.string.certificate_chain_is_not_trusted);
}
}
} else {
callback.informUser(R.string.account_already_exists);
}
} catch (Exception e) {
e.printStackTrace();
callback.informUser(R.string.unable_to_parse_certificate);
}
}).start();
}
use of de.pixart.messenger.entities.Account in project Pix-Art-Messenger by kriztan.
the class XmppConnectionService method pushContactToServer.
public void pushContactToServer(final Contact contact) {
contact.resetOption(Contact.Options.DIRTY_DELETE);
contact.setOption(Contact.Options.DIRTY_PUSH);
final Account account = contact.getAccount();
if (account.getStatus() == Account.State.ONLINE) {
final boolean ask = contact.getOption(Contact.Options.ASKING);
final boolean sendUpdates = contact.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST) && contact.getOption(Contact.Options.PREEMPTIVE_GRANT);
final IqPacket iq = new IqPacket(IqPacket.TYPE.SET);
iq.query(Namespace.ROSTER).addChild(contact.asElement());
account.getXmppConnection().sendIqPacket(iq, mDefaultIqHandler);
if (sendUpdates) {
sendPresencePacket(account, mPresenceGenerator.sendPresenceUpdatesTo(contact));
}
if (ask) {
sendPresencePacket(account, mPresenceGenerator.requestPresenceUpdatesFrom(contact));
}
}
}
Aggregations