From 7fdf5407424849fe10d476ef7614f0561fdd4451 Mon Sep 17 00:00:00 2001 From: Alex Hart Date: Tue, 28 Jan 2020 15:48:24 -0400 Subject: [PATCH] Implement new reaction notifications. --- .../securesms/database/MessagingDatabase.java | 10 ++- .../notifications/MessageNotifier.java | 33 +++++++- app/src/main/res/values/strings.xml | 76 ++++++++++++++++++- 3 files changed, 115 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/MessagingDatabase.java b/app/src/main/java/org/thoughtcrime/securesms/database/MessagingDatabase.java index fe70ad880f..e8ebf9d964 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/MessagingDatabase.java +++ b/app/src/main/java/org/thoughtcrime/securesms/database/MessagingDatabase.java @@ -350,9 +350,15 @@ public abstract class MessagingDatabase extends Database implements MmsSmsColumn } private void setReactions(@NonNull SQLiteDatabase db, long messageId, @NonNull ReactionList reactionList) { - ContentValues values = new ContentValues(1); + ContentValues values = new ContentValues(1); + boolean hasReactions = reactionList.getReactionsCount() != 0; + values.put(REACTIONS, reactionList.getReactionsList().isEmpty() ? null : reactionList.toByteArray()); - values.put(REACTIONS_UNREAD, reactionList.getReactionsCount() != 0 ? 1 : 0); + values.put(REACTIONS_UNREAD, hasReactions ? 1 : 0); + + if (hasReactions) { + values.put(NOTIFIED, 0); + } String query = ID + " = ?"; String[] args = new String[] { String.valueOf(messageId) }; diff --git a/app/src/main/java/org/thoughtcrime/securesms/notifications/MessageNotifier.java b/app/src/main/java/org/thoughtcrime/securesms/notifications/MessageNotifier.java index fd1fc97540..aa73a1ff45 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/notifications/MessageNotifier.java +++ b/app/src/main/java/org/thoughtcrime/securesms/notifications/MessageNotifier.java @@ -63,6 +63,7 @@ import org.thoughtcrime.securesms.recipients.RecipientUtil; import org.thoughtcrime.securesms.service.IncomingMessageObserver; import org.thoughtcrime.securesms.service.KeyCachingService; import org.thoughtcrime.securesms.util.MediaUtil; +import org.thoughtcrime.securesms.util.MessageRecordUtil; import org.thoughtcrime.securesms.util.ServiceUtil; import org.thoughtcrime.securesms.util.SpanUtil; import org.thoughtcrime.securesms.util.TextSecurePreferences; @@ -550,7 +551,7 @@ public class MessageNotifier { if (KeyCachingService.isLocked(context)) { body = SpanUtil.italic(context.getString(R.string.MessageNotifier_locked_message)); } else { - String text = SpanUtil.italic(context.getString(R.string.MessageNotifier_reacted_to_your_message, EMOJI_REPLACEMENT_STRING)).toString(); + String text = SpanUtil.italic(getReactionMessageBody(context, record)).toString(); String[] parts = text.split(EMOJI_REPLACEMENT_STRING); SpannableStringBuilder builder = new SpannableStringBuilder(); @@ -580,6 +581,36 @@ public class MessageNotifier { return notificationState; } + private static CharSequence getReactionMessageBody(@NonNull Context context, @NonNull MessageRecord record) { + CharSequence body = record.getDisplayBody(context); + boolean bodyIsEmpty = TextUtils.isEmpty(body); + + if (MessageRecordUtil.hasSharedContact(record)) { + Contact contact = ((MmsMessageRecord) record).getSharedContacts().get(0); + CharSequence summary = ContactUtil.getStringSummary(context, contact); + + return context.getString(R.string.MessageNotifier_reacted_s_to_s, EMOJI_REPLACEMENT_STRING, summary); + } else if (MessageRecordUtil.hasSticker(record)) { + return context.getString(R.string.MessageNotifier_reacted_s_to_your_sticker, EMOJI_REPLACEMENT_STRING); + } else if (record.isMms() && record.isViewOnce() && MediaUtil.isVideoType(getMessageContentType((MmsMessageRecord) record))) { + return context.getString(R.string.MessageNotifier_reacted_s_to_your_view_once_video, EMOJI_REPLACEMENT_STRING); + } else if (record.isMms() && record.isViewOnce()){ + return context.getString(R.string.MessageNotifier_reacted_s_to_your_view_once_photo, EMOJI_REPLACEMENT_STRING); + } else if (!bodyIsEmpty) { + return context.getString(R.string.MessageNotifier_reacted_s_to_s, EMOJI_REPLACEMENT_STRING, body); + } else if (MessageRecordUtil.isMediaMessage(record) && MediaUtil.isVideoType(getMessageContentType((MmsMessageRecord) record))) { + return context.getString(R.string.MessageNotifier_reacted_s_to_your_video, EMOJI_REPLACEMENT_STRING); + } else if (MessageRecordUtil.isMediaMessage(record) && MediaUtil.isImageType(getMessageContentType((MmsMessageRecord) record))) { + return context.getString(R.string.MessageNotifier_reacted_s_to_your_image, EMOJI_REPLACEMENT_STRING); + } else if (MessageRecordUtil.isMediaMessage(record) && MediaUtil.isAudioType(getMessageContentType((MmsMessageRecord) record))) { + return context.getString(R.string.MessageNotifier_reacted_s_to_your_audio, EMOJI_REPLACEMENT_STRING); + } else if (MessageRecordUtil.isMediaMessage(record)) { + return context.getString(R.string.MessageNotifier_reacted_s_to_your_file, EMOJI_REPLACEMENT_STRING); + } else { + return context.getString(R.string.MessageNotifier_reacted_s_to_s, EMOJI_REPLACEMENT_STRING, body); + } + } + private static @StringRes int getViewOnceDescription(@NonNull MmsMessageRecord messageRecord) { final String contentType = getMessageContentType(messageRecord); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 144bed493b..5f2eb61d0b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -922,7 +922,14 @@ Open Signal to check for recent notifications. %1$s %2$s Contact - Reacted to your message: %1$s + Reacted %1$s to: \"%2$s\". + Reacted %1$s to your video. + Reacted %1$s to your image. + Reacted %1$s to your file. + Reacted %1$s to your audio. + Reacted %1$s to your view-once photo. + Reacted %1$s to your view-once video. + Reacted %1$s to your sticker. Default @@ -1653,6 +1660,69 @@ View Insights Invite + + + + Next + Create alphanumeric PIN + Create numeric PIN + + + PIN must be at least %1$d characters + PIN must be at least %1$d digits + Create a new PIN + Because you\'re still logged in, you can create a new PIN. When you\'re logged out, there is no way to recover your PIN. + Create your PIN + PINs add an extra layer of security to your account. Write your PIN down and keep it in a safe place. It can\'t be recovered. + + + PINs don\'t match. Try again. + Confirm your PIN. + PIN creation failed + Your PIN was not saved. We\'ll prompt you to create a PIN later. + PIN created. + + + Introducing PINs + Add another level of security to your account. %1$s + Read more here. + https://signal.org/blog/secure-value-recovery/ + Registration Lock = PIN + Your Registration Lock is now called a PIN, and it does more. Update it now. %1$s + Read more about PINs. + Update PIN + Create your PIN + Remind me later + + + Enter your Signal PIN + To help you memorize your PIN, we\'ll ask you to enter it periodically. We ask you less over time. + Skip + Submit + Forgot PIN? + Incorrect PIN. Try again. + + + Account locked + Your account has been locked to protect your privacy and security. After %1$d days of inactivity in your account you\'ll be able to re-register this phone number without needing your pin. All content will be deleted. + Next + Learn More + https://signal.org/blog/secure-value-recovery/ + + + Enter your PIN + Enter the PIN you created for your account. This is different from your SMS verification code. + Enter alphanumeric PIN + Enter numeric PIN + Next + Incorrect PIN. Try again. + Incorrect PIN. %1$d attempts remaining. + Forgot PIN? + Incorrect PIN + You have %1$d attempts remaining. If you run out of attempts your account will be locked for %2$d days. After %3$d days of inactivity, you can re-register without your PIN. Your account will be wiped and all content deleted. + Forgot your PIN? + For your privacy and security, there is no way to recover your PIN. If you run out of attempts, you can re-verify with SMS after %1$d days of inactivity. In this case, your account will be wiped and all content deleted. + Transport icon Loading… @@ -1711,6 +1781,10 @@ Screen lock Lock Signal access with Android screen lock or fingerprint Screen lock inactivity timeout + Signal PIN + PIN + Change + Your PIN adds an extra layer of security and backs up your account. You\'ll be asked for it when you register your phone number with Signal. If you forget your PIN, you\'ll be locked out of your account for 7 days. None The Registration Lock PIN is not the same as the SMS verification code you just received. Please enter the PIN you previously configured in the application. Registration Lock PIN