Ping all online MUCs every second max ping interval

Stephen Paul Weber created

Change summary

src/main/java/eu/siacs/conversations/services/XmppConnectionService.java | 10 
1 file changed, 10 insertions(+)

Detailed changes

src/main/java/eu/siacs/conversations/services/XmppConnectionService.java 🔗

@@ -230,6 +230,7 @@ public class XmppConnectionService extends Service {
     public DatabaseBackend databaseBackend;
     private final ReplacingSerialSingleThreadExecutor mContactMergerExecutor = new ReplacingSerialSingleThreadExecutor("ContactMerger");
     private long mLastActivity = 0;
+    private long mLastMucPing = 0;
     private final FileBackend fileBackend = new FileBackend(this);
     private MemorizingTrustManager mMemorizingTrustManager;
     private final NotificationService mNotificationService = new NotificationService(this);
@@ -921,6 +922,15 @@ public class XmppConnectionService extends Service {
                     Log.d(Config.LOGTAG, account.getJid().asBareJid() + " send ping (action=" + action + ",lowTimeout=" + lowTimeout + ")");
                     scheduleWakeUpCall(lowTimeout ? Config.LOW_PING_TIMEOUT : Config.PING_TIMEOUT, account.getUuid().hashCode());
                 }
+                long msToMucPing = (mLastMucPing + (Config.PING_MAX_INTERVAL * 2000L)) - SystemClock.elapsedRealtime();
+                if (msToMucPing <= 0) {
+                    mLastMucPing = SystemClock.elapsedRealtime();
+                    for (Conversation c : getConversations()) {
+                        if (c.getMode() == Conversation.MODE_MULTI && c.getMucOptions().online()) {
+                            mucSelfPingAndRejoin(c);
+                        }
+                    }
+                }
             }
             WakeLockHelper.release(wakeLock);
         }