made grace period on a per account basis
This commit is contained in:
parent
5e3caf9626
commit
3372e50155
|
@ -10,7 +10,7 @@ public final class Config {
|
||||||
public static final int PING_MIN_INTERVAL = 30;
|
public static final int PING_MIN_INTERVAL = 30;
|
||||||
public static final int PING_TIMEOUT = 10;
|
public static final int PING_TIMEOUT = 10;
|
||||||
public static final int CONNECT_TIMEOUT = 90;
|
public static final int CONNECT_TIMEOUT = 90;
|
||||||
public static final int CARBON_GRACE_PERIOD = 120;
|
public static final int CARBON_GRACE_PERIOD = 60;
|
||||||
|
|
||||||
public static final int AVATAR_SIZE = 192;
|
public static final int AVATAR_SIZE = 192;
|
||||||
public static final Bitmap.CompressFormat AVATAR_FORMAT = Bitmap.CompressFormat.WEBP;
|
public static final Bitmap.CompressFormat AVATAR_FORMAT = Bitmap.CompressFormat.WEBP;
|
||||||
|
|
|
@ -11,6 +11,7 @@ import net.java.otr4j.crypto.OtrCryptoException;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import eu.siacs.conversations.Config;
|
||||||
import eu.siacs.conversations.R;
|
import eu.siacs.conversations.R;
|
||||||
import eu.siacs.conversations.crypto.OtrEngine;
|
import eu.siacs.conversations.crypto.OtrEngine;
|
||||||
import eu.siacs.conversations.persistance.FileBackend;
|
import eu.siacs.conversations.persistance.FileBackend;
|
||||||
|
@ -21,6 +22,7 @@ import android.content.ContentValues;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
import android.os.SystemClock;
|
||||||
|
|
||||||
public class Account extends AbstractEntity {
|
public class Account extends AbstractEntity {
|
||||||
|
|
||||||
|
@ -64,16 +66,14 @@ public class Account extends AbstractEntity {
|
||||||
|
|
||||||
protected boolean online = false;
|
protected boolean online = false;
|
||||||
|
|
||||||
transient OtrEngine otrEngine = null;
|
private OtrEngine otrEngine = null;
|
||||||
transient XmppConnection xmppConnection = null;
|
private XmppConnection xmppConnection = null;
|
||||||
transient protected Presences presences = new Presences();
|
private Presences presences = new Presences();
|
||||||
|
private long mEndGracePeriod = 0L;
|
||||||
private String otrFingerprint;
|
private String otrFingerprint;
|
||||||
|
|
||||||
private Roster roster = null;
|
private Roster roster = null;
|
||||||
|
|
||||||
private List<Bookmark> bookmarks = new CopyOnWriteArrayList<Bookmark>();
|
private List<Bookmark> bookmarks = new CopyOnWriteArrayList<Bookmark>();
|
||||||
|
|
||||||
public List<Conversation> pendingConferenceJoins = new CopyOnWriteArrayList<Conversation>();
|
public List<Conversation> pendingConferenceJoins = new CopyOnWriteArrayList<Conversation>();
|
||||||
public List<Conversation> pendingConferenceLeaves = new CopyOnWriteArrayList<Conversation>();
|
public List<Conversation> pendingConferenceLeaves = new CopyOnWriteArrayList<Conversation>();
|
||||||
|
|
||||||
|
@ -401,4 +401,17 @@ public class Account extends AbstractEntity {
|
||||||
return R.string.account_status_unknown;
|
return R.string.account_status_unknown;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void activateGracePeriod() {
|
||||||
|
this.mEndGracePeriod = SystemClock.elapsedRealtime()
|
||||||
|
+ (Config.CARBON_GRACE_PERIOD * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deactivateGracePeriod() {
|
||||||
|
this.mEndGracePeriod = 0L;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean inGracePeriod() {
|
||||||
|
return SystemClock.elapsedRealtime() < this.mEndGracePeriod;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -417,8 +417,7 @@ public class MessageParser extends AbstractParser implements
|
||||||
message = this.parseCarbonMessage(packet, account);
|
message = this.parseCarbonMessage(packet, account);
|
||||||
if (message != null) {
|
if (message != null) {
|
||||||
if (message.getStatus() == Message.STATUS_SEND) {
|
if (message.getStatus() == Message.STATUS_SEND) {
|
||||||
mXmppConnectionService.getNotificationService()
|
account.activateGracePeriod();
|
||||||
.activateGracePeriod();
|
|
||||||
notify = false;
|
notify = false;
|
||||||
mXmppConnectionService.markRead(
|
mXmppConnectionService.markRead(
|
||||||
message.getConversation(), false);
|
message.getConversation(), false);
|
||||||
|
@ -440,8 +439,7 @@ public class MessageParser extends AbstractParser implements
|
||||||
} else {
|
} else {
|
||||||
mXmppConnectionService.markRead(message.getConversation(),
|
mXmppConnectionService.markRead(message.getConversation(),
|
||||||
false);
|
false);
|
||||||
mXmppConnectionService.getNotificationService()
|
account.activateGracePeriod();
|
||||||
.activateGracePeriod();
|
|
||||||
notify = false;
|
notify = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,8 +58,7 @@ public class PresenceParser extends AbstractParser implements
|
||||||
Presences.parseShow(packet.findChild("show")));
|
Presences.parseShow(packet.findChild("show")));
|
||||||
} else if (type.equals("unavailable")) {
|
} else if (type.equals("unavailable")) {
|
||||||
account.removePresence(fromParts[1]);
|
account.removePresence(fromParts[1]);
|
||||||
mXmppConnectionService.getNotificationService()
|
account.deactivateGracePeriod();
|
||||||
.deactivateGracePeriod();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -20,6 +20,7 @@ import android.text.Html;
|
||||||
|
|
||||||
import eu.siacs.conversations.Config;
|
import eu.siacs.conversations.Config;
|
||||||
import eu.siacs.conversations.R;
|
import eu.siacs.conversations.R;
|
||||||
|
import eu.siacs.conversations.entities.Account;
|
||||||
import eu.siacs.conversations.entities.Conversation;
|
import eu.siacs.conversations.entities.Conversation;
|
||||||
import eu.siacs.conversations.entities.Message;
|
import eu.siacs.conversations.entities.Message;
|
||||||
import eu.siacs.conversations.ui.ConversationActivity;
|
import eu.siacs.conversations.ui.ConversationActivity;
|
||||||
|
@ -35,8 +36,6 @@ public class NotificationService {
|
||||||
private Conversation mOpenConversation;
|
private Conversation mOpenConversation;
|
||||||
private boolean mIsInForeground;
|
private boolean mIsInForeground;
|
||||||
|
|
||||||
private long mEndGracePeriod = 0L;
|
|
||||||
|
|
||||||
public NotificationService(XmppConnectionService service) {
|
public NotificationService(XmppConnectionService service) {
|
||||||
this.mXmppConnectionService = service;
|
this.mXmppConnectionService = service;
|
||||||
this.mNotificationManager = (NotificationManager) service
|
this.mNotificationManager = (NotificationManager) service
|
||||||
|
@ -62,8 +61,9 @@ public class NotificationService {
|
||||||
notifications.put(conversationUuid, mList);
|
notifications.put(conversationUuid, mList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Account account = message.getConversation().getAccount();
|
||||||
updateNotification((!(this.mIsInForeground && this.mOpenConversation == null) || !isScreenOn)
|
updateNotification((!(this.mIsInForeground && this.mOpenConversation == null) || !isScreenOn)
|
||||||
&& !inGracePeriod());
|
&& !account.inGracePeriod());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clear() {
|
public void clear() {
|
||||||
|
@ -170,9 +170,7 @@ public class NotificationService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mBuilder.setDeleteIntent(createDeleteIntent());
|
mBuilder.setDeleteIntent(createDeleteIntent());
|
||||||
if (!inGracePeriod()) {
|
mBuilder.setLights(0xffffffff, 2000, 4000);
|
||||||
mBuilder.setLights(0xffffffff, 2000, 4000);
|
|
||||||
}
|
|
||||||
Notification notification = mBuilder.build();
|
Notification notification = mBuilder.build();
|
||||||
mNotificationManager.notify(NOTIFICATION_ID, notification);
|
mNotificationManager.notify(NOTIFICATION_ID, notification);
|
||||||
}
|
}
|
||||||
|
@ -231,17 +229,4 @@ public class NotificationService {
|
||||||
public void setIsInForeground(boolean foreground) {
|
public void setIsInForeground(boolean foreground) {
|
||||||
this.mIsInForeground = foreground;
|
this.mIsInForeground = foreground;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void activateGracePeriod() {
|
|
||||||
this.mEndGracePeriod = SystemClock.elapsedRealtime()
|
|
||||||
+ (Config.CARBON_GRACE_PERIOD * 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deactivateGracePeriod() {
|
|
||||||
this.mEndGracePeriod = 0L;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean inGracePeriod() {
|
|
||||||
return SystemClock.elapsedRealtime() < this.mEndGracePeriod;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -529,6 +529,7 @@ public class XmppConnectionService extends Service {
|
||||||
|
|
||||||
synchronized public void sendMessage(Message message) {
|
synchronized public void sendMessage(Message message) {
|
||||||
Account account = message.getConversation().getAccount();
|
Account account = message.getConversation().getAccount();
|
||||||
|
account.deactivateGracePeriod();
|
||||||
Conversation conv = message.getConversation();
|
Conversation conv = message.getConversation();
|
||||||
MessagePacket packet = null;
|
MessagePacket packet = null;
|
||||||
boolean saveInDb = true;
|
boolean saveInDb = true;
|
||||||
|
@ -1019,7 +1020,6 @@ public class XmppConnectionService extends Service {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
synchronized (this.convChangedListenerCount) {
|
synchronized (this.convChangedListenerCount) {
|
||||||
this.mNotificationService.deactivateGracePeriod();
|
|
||||||
if (checkListeners()) {
|
if (checkListeners()) {
|
||||||
switchToForeground();
|
switchToForeground();
|
||||||
}
|
}
|
||||||
|
@ -1049,7 +1049,6 @@ public class XmppConnectionService extends Service {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
synchronized (this.accountChangedListenerCount) {
|
synchronized (this.accountChangedListenerCount) {
|
||||||
this.mNotificationService.deactivateGracePeriod();
|
|
||||||
if (checkListeners()) {
|
if (checkListeners()) {
|
||||||
switchToForeground();
|
switchToForeground();
|
||||||
}
|
}
|
||||||
|
@ -1077,7 +1076,6 @@ public class XmppConnectionService extends Service {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
synchronized (this.rosterChangedListenerCount) {
|
synchronized (this.rosterChangedListenerCount) {
|
||||||
this.mNotificationService.deactivateGracePeriod();
|
|
||||||
if (checkListeners()) {
|
if (checkListeners()) {
|
||||||
switchToForeground();
|
switchToForeground();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue