Search in sources :

Example 1 with IncomingJoinedMessage

use of org.thoughtcrime.securesms.sms.IncomingJoinedMessage in project Signal-Android by signalapp.

the class DirectoryHelper method notifyNewUsers.

private static void notifyNewUsers(@NonNull Context context, @NonNull List<Address> newUsers) {
    if (!TextSecurePreferences.isNewContactsNotificationEnabled(context))
        return;
    for (Address newUser : newUsers) {
        if (!SessionUtil.hasSession(context, newUser) && !Util.isOwnNumber(context, newUser)) {
            IncomingJoinedMessage message = new IncomingJoinedMessage(newUser);
            Optional<InsertResult> insertResult = DatabaseFactory.getSmsDatabase(context).insertMessageInbox(message);
            if (insertResult.isPresent()) {
                int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
                if (hour >= 9 && hour < 23) {
                    MessageNotifier.updateNotification(context, insertResult.get().getThreadId(), true);
                } else {
                    MessageNotifier.updateNotification(context, insertResult.get().getThreadId(), false);
                }
            }
        }
    }
}
Also used : InsertResult(org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult) Address(org.thoughtcrime.securesms.database.Address) IncomingJoinedMessage(org.thoughtcrime.securesms.sms.IncomingJoinedMessage)

Example 2 with IncomingJoinedMessage

use of org.thoughtcrime.securesms.sms.IncomingJoinedMessage in project Signal-Android by WhisperSystems.

the class DirectoryHelper method notifyNewUsers.

private static void notifyNewUsers(@NonNull Context context, @NonNull Collection<RecipientId> newUsers) {
    if (!SignalStore.settings().isNotifyWhenContactJoinsSignal())
        return;
    for (RecipientId newUser : newUsers) {
        Recipient recipient = Recipient.resolved(newUser);
        if (!recipient.isSelf() && recipient.hasAUserSetDisplayName(context) && !hasSession(recipient.getId())) {
            IncomingJoinedMessage message = new IncomingJoinedMessage(recipient.getId());
            Optional<InsertResult> insertResult = SignalDatabase.sms().insertMessageInbox(message);
            if (insertResult.isPresent()) {
                int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
                if (hour >= 9 && hour < 23) {
                    ApplicationDependencies.getMessageNotifier().updateNotification(context, insertResult.get().getThreadId(), true);
                } else {
                    Log.i(TAG, "Not notifying of a new user due to the time of day. (Hour: " + hour + ")");
                }
            }
        }
    }
}
Also used : InsertResult(org.thoughtcrime.securesms.database.MessageDatabase.InsertResult) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) Recipient(org.thoughtcrime.securesms.recipients.Recipient) IncomingJoinedMessage(org.thoughtcrime.securesms.sms.IncomingJoinedMessage)

Example 3 with IncomingJoinedMessage

use of org.thoughtcrime.securesms.sms.IncomingJoinedMessage in project Signal-Android by WhisperSystems.

the class DirectoryHelper method notifyNewUsers.

private static void notifyNewUsers(@NonNull Context context, @Nullable MasterSecret masterSecret, @NonNull List<String> newUsers) {
    if (!TextSecurePreferences.isNewContactsNotificationEnabled(context))
        return;
    for (String newUser : newUsers) {
        if (!SessionUtil.hasSession(context, masterSecret, newUser) && !Util.isOwnNumber(context, newUser)) {
            IncomingJoinedMessage message = new IncomingJoinedMessage(newUser);
            Optional<InsertResult> insertResult = DatabaseFactory.getSmsDatabase(context).insertMessageInbox(message);
            if (insertResult.isPresent()) {
                int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
                if (hour >= 9 && hour < 23) {
                    MessageNotifier.updateNotification(context, masterSecret, insertResult.get().getThreadId(), true);
                } else {
                    MessageNotifier.updateNotification(context, masterSecret, insertResult.get().getThreadId(), false);
                }
            }
        }
    }
}
Also used : InsertResult(org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult) IncomingJoinedMessage(org.thoughtcrime.securesms.sms.IncomingJoinedMessage)

Aggregations

IncomingJoinedMessage (org.thoughtcrime.securesms.sms.IncomingJoinedMessage)3 InsertResult (org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult)2 Address (org.thoughtcrime.securesms.database.Address)1 InsertResult (org.thoughtcrime.securesms.database.MessageDatabase.InsertResult)1 Recipient (org.thoughtcrime.securesms.recipients.Recipient)1 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)1