use of de.pixart.messenger.entities.Account in project Pix-Art-Messenger by kriztan.
the class MessageArchiveService method execute.
private void execute(final Query query) {
final Account account = query.getAccount();
if (account.getStatus() == Account.State.ONLINE) {
Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": running mam query " + query.toString());
IqPacket packet = this.mXmppConnectionService.getIqGenerator().queryMessageArchiveManagement(query);
this.mXmppConnectionService.sendIqPacket(account, packet, (a, p) -> {
Element fin = p.findChild("fin", Namespace.MAM);
if (p.getType() == IqPacket.TYPE.TIMEOUT) {
synchronized (MessageArchiveService.this.queries) {
MessageArchiveService.this.queries.remove(query);
if (query.hasCallback()) {
query.callback(false);
}
}
} else if (p.getType() == IqPacket.TYPE.RESULT && fin != null) {
processFin(query, fin);
} else if (p.getType() == IqPacket.TYPE.RESULT && query.isLegacy()) {
// do nothing
} else {
Log.d(Config.LOGTAG, a.getJid().toBareJid().toString() + ": error executing mam: " + p.toString());
finalizeQuery(query, true);
}
});
} else {
synchronized (this.pendingQueries) {
this.pendingQueries.add(query);
}
}
}
use of de.pixart.messenger.entities.Account in project Pix-Art-Messenger by kriztan.
the class NotificationService method createForegroundNotification.
public Notification createForegroundNotification() {
final NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mXmppConnectionService);
List<Account> accounts = mXmppConnectionService.getAccounts();
String status;
Account mAccount = null;
Log.d(Config.LOGTAG, "Accounts size " + accounts.size());
if (accounts.size() == 1) {
mAccount = accounts.get(0);
if (mAccount.getStatus() == Account.State.ONLINE) {
status = "(" + mXmppConnectionService.getString(R.string.account_status_online) + ")";
} else if (mAccount.getStatus() == Account.State.CONNECTING) {
status = "(" + mXmppConnectionService.getString(R.string.account_status_connecting) + ")";
} else {
status = "(" + mXmppConnectionService.getString(R.string.account_status_offline) + ")";
}
} else if (accounts.size() > 1) {
// todo: status for multiple accounts???
status = "";
} else {
status = "(" + mXmppConnectionService.getString(R.string.account_status_offline) + ")";
}
status = " " + status;
Log.d(Config.LOGTAG, "Status: " + status);
mBuilder.setContentTitle(mXmppConnectionService.getString(R.string.conversations_foreground_service) + status);
if (Config.SHOW_CONNECTED_ACCOUNTS) {
int enabled = 0;
int connected = 0;
for (Account account : accounts) {
if (account.isOnlineAndConnected()) {
connected++;
enabled++;
} else if (account.isEnabled()) {
enabled++;
}
}
mBuilder.setContentText(mXmppConnectionService.getString(R.string.connected_accounts, connected, enabled));
} else {
mBuilder.setContentText(mXmppConnectionService.getString(R.string.touch_to_open_conversations));
}
mBuilder.setContentIntent(createOpenConversationsIntent());
mBuilder.setWhen(0);
mBuilder.setPriority(Config.SHOW_CONNECTED_ACCOUNTS ? NotificationCompat.PRIORITY_DEFAULT : NotificationCompat.PRIORITY_MIN);
if (accounts.size() == 1 && accounts.get(0).getStatus() == Account.State.ONLINE) {
mBuilder.setSmallIcon(R.drawable.ic_link_white_24dp);
} else if (accounts.size() > 1) {
// todo: status for multiple accounts???
mBuilder.setSmallIcon(R.drawable.ic_link_white_24dp);
} else {
mBuilder.setSmallIcon(R.drawable.ic_unlink_white_24dp);
}
return mBuilder.build();
}
use of de.pixart.messenger.entities.Account in project Pix-Art-Messenger by kriztan.
the class NotificationService method updateErrorNotification.
public void updateErrorNotification() {
final NotificationManagerCompat notificationManager = NotificationManagerCompat.from(mXmppConnectionService);
final List<Account> errors = new ArrayList<>();
for (final Account account : mXmppConnectionService.getAccounts()) {
if (account.hasErrorStatus() && account.showErrorNotification()) {
errors.add(account);
}
}
if (mXmppConnectionService.showForegroundService()) {
notificationManager.notify(FOREGROUND_NOTIFICATION_ID, createForegroundNotification());
}
final NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mXmppConnectionService);
if (errors.size() == 0) {
notificationManager.cancel(ERROR_NOTIFICATION_ID);
return;
} else if (errors.size() == 1) {
mBuilder.setContentTitle(mXmppConnectionService.getString(R.string.problem_connecting_to_account));
mBuilder.setContentText(errors.get(0).getJid().toBareJid().toString());
} else {
mBuilder.setContentTitle(mXmppConnectionService.getString(R.string.problem_connecting_to_accounts));
mBuilder.setContentText(mXmppConnectionService.getString(R.string.touch_to_fix));
}
mBuilder.addAction(R.drawable.ic_autorenew_white_24dp, mXmppConnectionService.getString(R.string.try_again), createTryAgainIntent());
mBuilder.setDeleteIntent(createDismissErrorIntent());
mBuilder.setVisibility(NotificationCompat.VISIBILITY_PRIVATE);
mBuilder.setSmallIcon(R.drawable.ic_warning_white_24dp);
mBuilder.setLocalOnly(true);
mBuilder.setPriority(NotificationCompat.PRIORITY_LOW);
if (errors.size() == 1) {
Intent intent = new Intent(mXmppConnectionService, EditAccountActivity.class);
Account mAccount = mXmppConnectionService.getAccounts().get(0);
intent.putExtra("jid", mAccount.getJid().toBareJid().toString());
intent.putExtra("init", false);
mBuilder.setContentIntent(PendingIntent.getActivity(mXmppConnectionService, 145, intent, PendingIntent.FLAG_UPDATE_CURRENT));
} else {
mBuilder.setContentIntent(PendingIntent.getActivity(mXmppConnectionService, 145, new Intent(mXmppConnectionService, ManageAccountActivity.class), PendingIntent.FLAG_UPDATE_CURRENT));
}
notificationManager.notify(ERROR_NOTIFICATION_ID, mBuilder.build());
}
use of de.pixart.messenger.entities.Account in project Pix-Art-Messenger by kriztan.
the class XmppConnectionService method publishDisplayName.
public void publishDisplayName(Account account) {
String displayName = account.getDisplayName();
if (displayName != null && !displayName.isEmpty()) {
IqPacket publish = mIqGenerator.publishNick(displayName);
sendIqPacket(account, publish, new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(Account account, IqPacket packet) {
if (packet.getType() == IqPacket.TYPE.ERROR) {
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could not publish nick");
}
}
});
}
}
use of de.pixart.messenger.entities.Account in project Pix-Art-Messenger by kriztan.
the class XmppConnectionService method onStartCommand.
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
final String action = intent == null ? null : intent.getAction();
String pushedAccountHash = null;
boolean interactive = false;
if (action != null) {
final String uuid = intent.getStringExtra("uuid");
switch(action) {
case ConnectivityManager.CONNECTIVITY_ACTION:
if (hasInternetConnection() && Config.RESET_ATTEMPT_COUNT_ON_NETWORK_CHANGE) {
resetAllAttemptCounts(true, false);
}
break;
case ACTION_MERGE_PHONE_CONTACTS:
if (restoredFromDatabaseLatch.getCount() == 0) {
loadPhoneContacts();
}
return START_STICKY;
case Intent.ACTION_SHUTDOWN:
logoutAndSave(true);
return START_NOT_STICKY;
case ACTION_CLEAR_NOTIFICATION:
mNotificationExecutor.execute(() -> {
try {
final Conversation c = findConversationByUuid(uuid);
if (c != null) {
mNotificationService.clear(c);
} else {
mNotificationService.clear();
}
restoredFromDatabaseLatch.await();
} catch (InterruptedException e) {
Log.d(Config.LOGTAG, "unable to process clear notification");
}
});
break;
case ACTION_DISMISS_ERROR_NOTIFICATIONS:
dismissErrorNotifications();
break;
case ACTION_TRY_AGAIN:
resetAllAttemptCounts(false, true);
interactive = true;
break;
case ACTION_REPLY_TO_CONVERSATION:
Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
if (remoteInput == null) {
break;
}
final CharSequence body = remoteInput.getCharSequence("text_reply");
final boolean dismissNotification = intent.getBooleanExtra("dismiss_notification", false);
if (body == null || body.length() <= 0) {
break;
}
mNotificationExecutor.execute(() -> {
try {
restoredFromDatabaseLatch.await();
final Conversation c = findConversationByUuid(uuid);
if (c != null) {
directReply(c, body.toString(), dismissNotification);
}
} catch (InterruptedException e) {
Log.d(Config.LOGTAG, "unable to process direct reply");
}
});
break;
case ACTION_MARK_AS_READ:
mNotificationExecutor.execute(() -> {
final Conversation c = findConversationByUuid(uuid);
if (c == null) {
Log.d(Config.LOGTAG, "received mark read intent for unknown conversation (" + uuid + ")");
return;
}
try {
restoredFromDatabaseLatch.await();
sendReadMarker(c);
} catch (InterruptedException e) {
Log.d(Config.LOGTAG, "unable to process notification read marker for conversation " + c.getName());
}
});
break;
case ACTION_SNOOZE:
mNotificationExecutor.execute(() -> {
final Conversation c = findConversationByUuid(uuid);
if (c == null) {
Log.d(Config.LOGTAG, "received snooze intent for unknown conversation (" + uuid + ")");
return;
}
c.setMutedTill(System.currentTimeMillis() + 30 * 60 * 1000);
mNotificationService.clear(c);
updateConversation(c);
});
case AudioManager.RINGER_MODE_CHANGED_ACTION:
if (dndOnSilentMode()) {
refreshAllPresences();
}
break;
case Intent.ACTION_SCREEN_ON:
deactivateGracePeriod();
case Intent.ACTION_SCREEN_OFF:
if (awayWhenScreenOff()) {
refreshAllPresences();
}
break;
case ACTION_GCM_TOKEN_REFRESH:
refreshAllGcmTokens();
break;
case ACTION_IDLE_PING:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
scheduleNextIdlePing();
}
break;
case ACTION_GCM_MESSAGE_RECEIVED:
Log.d(Config.LOGTAG, "gcm push message arrived in service. extras=" + intent.getExtras());
pushedAccountHash = intent.getStringExtra("account");
break;
case Intent.ACTION_SEND:
Uri uri = intent.getData();
if (uri != null) {
Log.d(Config.LOGTAG, "received uri permission for " + uri.toString());
}
return START_STICKY;
}
}
synchronized (this) {
this.wakeLock.acquire();
boolean pingNow = ConnectivityManager.CONNECTIVITY_ACTION.equals(action);
HashSet<Account> pingCandidates = new HashSet<>();
for (Account account : accounts) {
pingNow |= processAccountState(account, interactive, "ui".equals(action), CryptoHelper.getAccountFingerprint(account).equals(pushedAccountHash), pingCandidates);
}
if (pingNow) {
for (Account account : pingCandidates) {
List<Conversation> conversations = getConversations();
for (Conversation conversation : conversations) {
if (conversation.getAccount() == account && !account.pendingConferenceJoins.contains(conversation)) {
resendFailedFileMessages(conversation);
}
}
final boolean lowTimeout = isInLowPingTimeoutMode(account);
account.getXmppConnection().sendPing();
Log.d(Config.LOGTAG, account.getJid().toBareJid() + " send ping (action=" + action + ", lowTimeout=" + Boolean.toString(lowTimeout) + ")");
scheduleWakeUpCall(lowTimeout ? Config.LOW_PING_TIMEOUT : Config.PING_TIMEOUT, account.getUuid().hashCode());
}
}
if (wakeLock.isHeld()) {
try {
wakeLock.release();
} catch (final RuntimeException ignored) {
}
}
}
if (SystemClock.elapsedRealtime() - mLastExpiryRun.get() >= Config.EXPIRY_INTERVAL) {
expireOldMessages();
}
return START_STICKY;
}
Aggregations