Skip to content

Commit

Permalink
Silence: make use of delay timestamp for grace period
Browse files Browse the repository at this point in the history
  • Loading branch information
ge0rg committed Oct 23, 2019
1 parent f396fa9 commit bebc9ef
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
11 changes: 9 additions & 2 deletions src/org/yaxim/androidclient/service/GenericService.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.yaxim.androidclient.service;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -108,8 +110,13 @@ public int onStartCommand(Intent intent, int flags, int startId) {
return START_STICKY;
}

public void setGracePeriod(boolean silence) {
gracePeriodStart = silence ? System.currentTimeMillis() : 0;
public void setGracePeriod(long when) {
if (when > gracePeriodStart || when == 0) {
String when_s = (when == 0) ? "cleared" :
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date(when));
Log.d(TAG, "user activity from different device: " + when_s);
gracePeriodStart = when;
}
}

private void addNotificationMGR() {
Expand Down
10 changes: 3 additions & 7 deletions src/org/yaxim/androidclient/service/SmackableImp.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public class SmackableImp implements Smackable {
private static final String PONG_TIMEOUT_ALARM = "org.yaxim.androidclient.PONG_TIMEOUT_ALARM";
private Intent mPingAlarmIntent = new Intent(PING_ALARM);
private Intent mPongTimeoutAlarmIntent = new Intent(PONG_TIMEOUT_ALARM);
private Service mService;
private XMPPService mService;

private PongTimeoutAlarmReceiver mPongTimeoutAlarmReceiver = new PongTimeoutAlarmReceiver();
private BroadcastReceiver mPingAlarmReceiver = new PingAlarmReceiver();
Expand All @@ -205,7 +205,7 @@ public class SmackableImp implements Smackable {

public SmackableImp(YaximConfiguration config,
ContentResolver contentResolver,
Service service) {
XMPPService service) {
this.mConfig = config;
this.mContentResolver = contentResolver;
this.mService = service;
Expand Down Expand Up @@ -1842,11 +1842,7 @@ private void processMessage(Message msg, boolean is_history_sync) {
// perform a message-replace on self-sent MUC message, abort further processing
if (is_muc && matchOutgoingMucReflection(msg, withJID))
return;
if (timestamp == null) {
// delayed messages don't trigger active
Log.d(TAG, "user is active on different device --> Silent mode");
mServiceCallBack.setGracePeriod(true);
}
mService.setGracePeriod(ts);
}

// handle MUC-PMs: messages from a nick from a known MUC or with
Expand Down
7 changes: 1 addition & 6 deletions src/org/yaxim/androidclient/service/XMPPService.java
Original file line number Diff line number Diff line change
Expand Up @@ -590,11 +590,6 @@ public void run() {
}});
}

@Override
public void setGracePeriod(boolean silence) {
XMPPService.this.setGracePeriod(silence);
}

public void connectionStateChanged(ConnectionState connection_state) {
// TODO: OFFLINE is sometimes caused by XMPPConnection calling
// connectionClosed() callback on an error, need to catch that?
Expand Down Expand Up @@ -671,7 +666,7 @@ private void userStartedWatching() {
logInfo("userStartedWatching: " + number_of_eyes);
if (mSmackable != null)
mSmackable.setUserWatching(true);
setGracePeriod(false);
setGracePeriod(0);
}

private void userStoppedWatching() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
public interface XMPPServiceCallback {
void notifyMessage(String[] from, String messageBody, boolean silent_notification, Message.Type msgType, long timestamp, boolean still_loading);
void displayPendingNotifications(String jid);
void setGracePeriod(boolean activate);
void connectionStateChanged(ConnectionState connection_state);
void mucInvitationReceived(String roomname, String room, String password, String invite_from, String roomdescription);
}

0 comments on commit bebc9ef

Please sign in to comment.