diff options
Diffstat (limited to 'src/main/java/eu/siacs')
4 files changed, 22 insertions, 7 deletions
diff --git a/src/main/java/eu/siacs/conversations/Config.java b/src/main/java/eu/siacs/conversations/Config.java index bbfedb22a..68ad2c122 100644 --- a/src/main/java/eu/siacs/conversations/Config.java +++ b/src/main/java/eu/siacs/conversations/Config.java @@ -67,7 +67,6 @@ public final class Config { public static final int SOCKET_TIMEOUT = 15; public static final int CONNECT_TIMEOUT = 60; public static final int CONNECT_DISCO_TIMEOUT = 30; - public static final int CARBON_GRACE_PERIOD = 90; public static final int MINI_GRACE_PERIOD = 750; diff --git a/src/main/java/eu/siacs/conversations/entities/Account.java b/src/main/java/eu/siacs/conversations/entities/Account.java index bea7f8a14..dec3bd1a4 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 7ae89c7ef..887b9124a 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.Set; import java.util.UUID; @@ -53,7 +55,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 { @@ -500,7 +502,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(); @@ -641,4 +643,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/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index b50b8eec7..79f4d51f3 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -540,8 +540,9 @@ public class XmppConnectionService extends Service { refreshAllPresences(); } break; - case Intent.ACTION_SCREEN_OFF: case Intent.ACTION_SCREEN_ON: + deactivateGracePeriod(); + case Intent.ACTION_SCREEN_OFF: if (awayWhenScreenOff()) { refreshAllPresences(); } @@ -3054,6 +3055,12 @@ public class XmppConnectionService extends Service { sendPresencePacket(account, packet); } + private void deactivateGracePeriod() { + for(Account account : getAccounts()) { + account.deactivateGracePeriod(); + } + } + public void refreshAllPresences() { for (Account account : getAccounts()) { if (!account.isOptionSet(Account.OPTION_DISABLED)) { |