use of com.xabber.android.data.entity.AccountJid in project xabber-android by redsolution.
the class AttentionManager method onStanza.
@Override
public void onStanza(ConnectionItem connection, Stanza stanza) {
if (!(stanza instanceof Message)) {
return;
}
if (!SettingsManager.chatsAttention()) {
return;
}
final AccountJid account = connection.getAccount();
UserJid from;
try {
from = UserJid.from(stanza.getFrom());
} catch (UserJid.UserJidCreateException e) {
e.printStackTrace();
return;
}
for (ExtensionElement packetExtension : stanza.getExtensions()) {
if (packetExtension instanceof AttentionExtension) {
MessageManager.getInstance().openChat(account, from);
MessageManager.getInstance().getOrCreateChat(account, from).newAction(null, null, ChatAction.attention_requested);
attentionRequestProvider.add(new AttentionRequest(account, from.getBareUserJid()), true);
}
}
}
use of com.xabber.android.data.entity.AccountJid in project xabber-android by redsolution.
the class BlockingManager method getBlockedContacts.
public List<UserJid> getBlockedContacts(AccountJid account) {
List<UserJid> blockedContacts = new ArrayList<>();
Boolean supported = isSupported(account);
BlockingCommandManager blockingCommandManager = getBlockingCommandManager(account);
if (blockingCommandManager != null && supported != null && supported) {
try {
List<Jid> blockedJids = blockingCommandManager.getBlockList();
for (Jid jid : blockedJids) {
blockedContacts.add(UserJid.from(jid));
}
} catch (SmackException.NoResponseException | XMPPException.XMPPErrorException | InterruptedException | SmackException.NotConnectedException | UserJid.UserJidCreateException e) {
LogManager.exception(LOG_TAG, e);
}
}
updateCachedBlockedContacts(account, blockedContacts);
return blockedContacts;
}
use of com.xabber.android.data.entity.AccountJid in project xabber-android by redsolution.
the class BlockingManager method onAuthorized.
public void onAuthorized(final ConnectionItem connection) {
final AccountJid account = connection.getAccount();
BlockingCommandManager blockingCommandManager = BlockingCommandManager.getInstanceFor(connection.getConnection());
try {
boolean supportedByServer = blockingCommandManager.isSupportedByServer();
if (supportedByServer) {
// cache block list inside
List<UserJid> blockedContacts = new ArrayList<>();
try {
List<Jid> blockedJids = blockingCommandManager.getBlockList();
for (Jid jid : blockedJids) {
blockedContacts.add(UserJid.from(jid));
}
} catch (SmackException.NoResponseException | XMPPException.XMPPErrorException | InterruptedException | SmackException.NotConnectedException | UserJid.UserJidCreateException e) {
LogManager.exception(LOG_TAG, e);
}
// Cache block inside manager
// For contact list building used only this list of blocked contacts
updateCachedBlockedContacts(account, blockedContacts);
}
addBlockedListener(blockingCommandManager, account);
addUnblockedListener(blockingCommandManager, account);
addUnblockedAllListener(blockingCommandManager, account);
// block list already cached successfully
supportForAccounts.put(account, supportedByServer);
BlockingManager.notify(account);
} catch (SmackException.NotConnectedException | XMPPException.XMPPErrorException | SmackException.NoResponseException | InterruptedException e) {
LogManager.exception(this, e);
}
}
use of com.xabber.android.data.entity.AccountJid in project xabber-android by redsolution.
the class ClientStateManager method sendClientState.
protected static void sendClientState(Nonza nonza) {
AccountManager accountManager = AccountManager.getInstance();
for (AccountJid accountName : accountManager.getEnabledAccounts()) {
AccountItem accountItem = accountManager.getAccount(accountName);
if (accountItem == null) {
continue;
}
AbstractXMPPConnection xmppConnection = accountItem.getConnection();
if (!xmppConnection.isAuthenticated()) {
continue;
}
if (xmppConnection.hasFeature("csi", ClientStateIndication.NAMESPACE))
try {
xmppConnection.sendNonza(nonza);
} catch (SmackException.NotConnectedException | InterruptedException e) {
LogManager.exception(LOG_TAG, e);
}
}
}
use of com.xabber.android.data.entity.AccountJid in project xabber-android by redsolution.
the class HttpFileUploadManager method uploadFile.
public void uploadFile(final AccountJid account, final UserJid user, final String filePath) {
final Jid uploadServerUrl = uploadServers.get(account);
if (uploadServerUrl == null) {
return;
}
AccountItem accountItem = AccountManager.getInstance().getAccount(account);
if (accountItem == null) {
return;
}
final File file = new File(filePath);
final com.xabber.xmpp.httpfileupload.Request httpFileUpload = new com.xabber.xmpp.httpfileupload.Request();
httpFileUpload.setFilename(file.getName());
httpFileUpload.setSize(String.valueOf(file.length()));
httpFileUpload.setTo(uploadServerUrl);
try {
accountItem.getConnection().sendIqWithResponseCallback(httpFileUpload, new StanzaListener() {
@Override
public void processStanza(Stanza packet) throws SmackException.NotConnectedException, InterruptedException {
if (!(packet instanceof Slot)) {
return;
}
uploadFileToSlot(account, (Slot) packet);
}
private void uploadFileToSlot(final AccountJid account, final Slot slot) {
SSLSocketFactory sslSocketFactory = null;
MemorizingTrustManager mtm = CertificateManager.getInstance().getNewFileUploadManager(account);
final SSLContext sslContext;
try {
sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, new X509TrustManager[] { mtm }, new java.security.SecureRandom());
sslSocketFactory = sslContext.getSocketFactory();
} catch (NoSuchAlgorithmException | KeyManagementException e) {
return;
}
OkHttpClient client = new OkHttpClient().newBuilder().sslSocketFactory(sslSocketFactory).hostnameVerifier(mtm.wrapHostnameVerifier(new org.apache.http.conn.ssl.StrictHostnameVerifier())).writeTimeout(5, TimeUnit.MINUTES).connectTimeout(5, TimeUnit.MINUTES).readTimeout(5, TimeUnit.MINUTES).build();
Request request = new Request.Builder().url(slot.getPutUrl()).put(RequestBody.create(CONTENT_TYPE, file)).build();
final String fileMessageId;
fileMessageId = MessageManager.getInstance().createFileMessage(account, user, file);
LogManager.i(HttpFileUploadManager.this, "starting upload file to " + slot.getPutUrl() + " size " + file.length());
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
LogManager.i(HttpFileUploadManager.this, "onFailure " + e.getMessage());
MessageManager.getInstance().updateMessageWithError(fileMessageId, e.toString());
}
@Override
public void onResponse(Call call, Response response) throws IOException {
LogManager.i(HttpFileUploadManager.this, "onResponse " + response.isSuccessful() + " " + response.body().string());
if (response.isSuccessful()) {
MessageManager.getInstance().updateFileMessage(account, user, fileMessageId, slot.getGetUrl());
} else {
MessageManager.getInstance().updateMessageWithError(fileMessageId, response.message());
}
}
});
}
}, new ExceptionCallback() {
@Override
public void processException(Exception exception) {
LogManager.i(this, "On HTTP file upload slot error");
LogManager.exception(this, exception);
Application.getInstance().onError(R.string.http_file_upload_slot_error);
}
});
} catch (SmackException.NotConnectedException | InterruptedException e) {
LogManager.exception(this, e);
}
}
Aggregations