fixed #52. thanks @strb

This commit is contained in:
Daniel Gultsch 2014-04-07 23:58:59 +02:00
parent 3f403fb8a9
commit 78bd6c423f
2 changed files with 16 additions and 1 deletions

View file

@ -41,6 +41,11 @@
android:key="notify_in_conversation_when_highlighted" android:key="notify_in_conversation_when_highlighted"
android:title="Conference notification" android:title="Conference notification"
android:summary="Always notify when a new conference message arrives instead of only when highlighted"/> android:summary="Always notify when a new conference message arrives instead of only when highlighted"/>
<CheckBoxPreference
android:key="notification_grace_period_after_carbon_received"
android:title="Notification grace period"
android:summary="Disable notifications for a short time after a carbon copy was received"
android:defaultValue="true"/>
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory <PreferenceCategory
android:title="UI Options"> android:title="UI Options">

View file

@ -84,6 +84,7 @@ public class XmppConnectionService extends Service {
private static final int PING_MIN_INTERVAL = 10; private static final int PING_MIN_INTERVAL = 10;
private static final int PING_TIMEOUT = 5; private static final int PING_TIMEOUT = 5;
private static final int CONNECT_TIMEOUT = 60; private static final int CONNECT_TIMEOUT = 60;
private static final long CARBON_GRACE_PERIOD = 60000L;
private List<Account> accounts; private List<Account> accounts;
private List<Conversation> conversations = null; private List<Conversation> conversations = null;
@ -101,6 +102,8 @@ public class XmppConnectionService extends Service {
private Random mRandom = new Random(System.currentTimeMillis()); private Random mRandom = new Random(System.currentTimeMillis());
private long lastCarbonMessageReceived = -CARBON_GRACE_PERIOD;
private ContentObserver contactObserver = new ContentObserver(null) { private ContentObserver contactObserver = new ContentObserver(null) {
@Override @Override
public void onChange(boolean selfChange) { public void onChange(boolean selfChange) {
@ -120,6 +123,12 @@ public class XmppConnectionService extends Service {
MessagePacket packet) { MessagePacket packet) {
Message message = null; Message message = null;
boolean notify = true; boolean notify = true;
if(PreferenceManager
.getDefaultSharedPreferences(getApplicationContext())
.getBoolean("notification_grace_period_after_carbon_received", true)){
notify=(SystemClock.elapsedRealtime() - lastCarbonMessageReceived) > CARBON_GRACE_PERIOD;
}
if ((packet.getType() == MessagePacket.TYPE_CHAT)) { if ((packet.getType() == MessagePacket.TYPE_CHAT)) {
String pgpBody = MessageParser.getPgpBody(packet); String pgpBody = MessageParser.getPgpBody(packet);
if (pgpBody != null) { if (pgpBody != null) {
@ -143,6 +152,7 @@ public class XmppConnectionService extends Service {
service); service);
if (message != null) { if (message != null) {
if (message.getStatus() == Message.STATUS_SEND) { if (message.getStatus() == Message.STATUS_SEND) {
lastCarbonMessageReceived = SystemClock.elapsedRealtime();
notify = false; notify = false;
message.getConversation().markRead(); message.getConversation().markRead();
} else { } else {
@ -1351,4 +1361,4 @@ public class XmppConnectionService extends Service {
} }
} }
} }