From 25211f13b37ecef64d6fa9a382a2c30d212452ae Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 2 Jun 2016 00:24:37 +0200 Subject: [PATCH] make grace period configurable --- .../java/eu/siacs/conversations/Config.java | 1 - .../siacs/conversations/entities/Account.java | 5 +-- .../conversations/parser/MessageParser.java | 14 +++++- src/main/res/values/arrays.xml | 12 +++++ src/main/res/values/strings.xml | 7 ++- src/main/res/xml/preferences.xml | 45 +++++++++++-------- 6 files changed, 58 insertions(+), 26 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/Config.java b/src/main/java/eu/siacs/conversations/Config.java index 48a08a4f3..ee2f3f195 100644 --- a/src/main/java/eu/siacs/conversations/Config.java +++ b/src/main/java/eu/siacs/conversations/Config.java @@ -58,7 +58,6 @@ public final class Config { public static final int SOCKET_TIMEOUT = 15; public static final int CONNECT_TIMEOUT = 90; public static final int CONNECT_DISCO_TIMEOUT = 20; - public static final int CARBON_GRACE_PERIOD = 90; public static final int MINI_GRACE_PERIOD = 750; public static final boolean CLOSE_TCP_WHEN_SWITCHING_TO_BACKGROUND = false; diff --git a/src/main/java/eu/siacs/conversations/entities/Account.java b/src/main/java/eu/siacs/conversations/entities/Account.java index 2f573c896..3e79fccd9 100644 --- a/src/main/java/eu/siacs/conversations/entities/Account.java +++ b/src/main/java/eu/siacs/conversations/entities/Account.java @@ -542,9 +542,8 @@ public class Account extends AbstractEntity { return this.avatar; } - public void activateGracePeriod() { - this.mEndGracePeriod = SystemClock.elapsedRealtime() - + (Config.CARBON_GRACE_PERIOD * 1000); + public void activateGracePeriod(long duration) { + this.mEndGracePeriod = SystemClock.elapsedRealtime() + duration; } public void deactivateGracePeriod() { diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java index 79be0bb5c..48862c47c 100644 --- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java +++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java @@ -7,8 +7,10 @@ import android.util.Pair; import net.java.otr4j.session.Session; import net.java.otr4j.session.SessionStatus; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; +import java.util.Date; import java.util.List; import java.util.Locale; import java.util.Set; @@ -54,7 +56,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece conversation.setOutgoingChatState(state); if (state == ChatState.ACTIVE || state == ChatState.COMPOSING) { mXmppConnectionService.markRead(conversation); - account.activateGracePeriod(); + activateGracePeriod(account); } return false; } else { @@ -498,7 +500,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece if (status == Message.STATUS_SEND || status == Message.STATUS_SEND_RECEIVED) { mXmppConnectionService.markRead(conversation); if (query == null) { - account.activateGracePeriod(); + activateGracePeriod(account); } } else { message.markUnread(); @@ -639,4 +641,12 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece mXmppConnectionService.sendMessagePacket(account, receipt); } } + + private static SimpleDateFormat TIME_FORMAT = new SimpleDateFormat("HH:mm:ss"); + + private void activateGracePeriod(Account account) { + long duration = mXmppConnectionService.getPreferences().getLong("race_period_length", 144) * 1000; + Log.d(Config.LOGTAG,account.getJid().toBareJid()+": activating grace period till "+TIME_FORMAT.format(new Date(System.currentTimeMillis() + duration))); + account.activateGracePeriod(duration); + } } diff --git a/src/main/res/values/arrays.xml b/src/main/res/values/arrays.xml index e887546ae..48dbaabf6 100644 --- a/src/main/res/values/arrays.xml +++ b/src/main/res/values/arrays.xml @@ -83,4 +83,16 @@ @string/presence_xa @string/presence_dnd + + + @string/gp_short + @string/gp_medium + @string/gp_long + + + + 144 + 610 + 2584 + diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 2decae45c..51c658ab0 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -117,8 +117,8 @@ Blink notification light when a new message arrives Ringtone Play sound when a new message arrives - Notification grace period - Disable notifications for a short time after a carbon copy was received + Grace Period + The length of time Conversations keeps quite after seeing activity on another device Advanced Never send crash reports By sending in stack traces you are helping the ongoing development of Conversations @@ -649,4 +649,7 @@ Choose participants Creating conferenceā€¦ Invite again + Short + Medium + Long diff --git a/src/main/res/xml/preferences.xml b/src/main/res/xml/preferences.xml index 80980417d..fb0103edd 100644 --- a/src/main/res/xml/preferences.xml +++ b/src/main/res/xml/preferences.xml @@ -36,6 +36,25 @@ android:key="show_notification" android:summary="@string/pref_notifications_summary" android:title="@string/pref_notifications"/> + + + - - - + android:key="grace_period_length" + android:title="@string/pref_notification_grace_period" + android:summary="@string/pref_notification_grace_period_summary" + android:defaultValue="144" + android:entries="@array/grace_periods" + android:entryValues="@array/grace_periods_values" + />