Background poll for group messages

This commit is contained in:
Niels Andriesse 2020-01-22 11:57:16 +11:00
parent f5c0936cd8
commit b5cca49b54
8 changed files with 64 additions and 13 deletions

View File

@ -806,12 +806,19 @@
<intent-filter>
<action android:name="info.guardianproject.panic.action.TRIGGER" />
</intent-filter>
</receiver> <!-- Loki -->
</receiver>
<!-- Session -->
<receiver android:name="org.thoughtcrime.securesms.loki.BackgroundPollWorker">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver> <!-- Loki -->
</receiver>
<receiver android:name="org.thoughtcrime.securesms.loki.BackgroundPublicChatPollWorker">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<!-- Session -->
<service
android:name="org.thoughtcrime.securesms.jobmanager.JobSchedulerScheduler$SystemService"
android:enabled="@bool/enable_job_service"

View File

@ -67,6 +67,7 @@ import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.logging.PersistentLogger;
import org.thoughtcrime.securesms.logging.UncaughtExceptionLogger;
import org.thoughtcrime.securesms.loki.BackgroundPollWorker;
import org.thoughtcrime.securesms.loki.BackgroundPublicChatPollWorker;
import org.thoughtcrime.securesms.loki.LokiAPIDatabase;
import org.thoughtcrime.securesms.loki.LokiPublicChatManager;
import org.thoughtcrime.securesms.loki.LokiRSSFeedPoller;
@ -381,7 +382,8 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
DirectoryRefreshListener.schedule(this);
LocalBackupListener.schedule(this);
RotateSenderCertificateListener.schedule(this);
BackgroundPollWorker.schedule(this); // Loki
BackgroundPollWorker.schedule(this); // Session
BackgroundPublicChatPollWorker.schedule(this); // Session
if (BuildConfig.PLAY_STORE_DISABLED) {
UpdateApkRefreshListener.schedule(this);

View File

@ -2199,9 +2199,6 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
Context context = ConversationActivity.this;
List<MarkedMessageInfo> messageIds = DatabaseFactory.getThreadDatabase(context).setRead(params[0], false);
// Only send notifications for private chats
if (!getRecipient().isGroupRecipient()) { MessageNotifier.updateNotification(context); }
MarkReadReceiver.process(context, messageIds);
return null;

View File

@ -1045,8 +1045,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
if (smsMessageId.isPresent()) database.deleteMessage(smsMessageId.get());
boolean isGroupMessage = message.getGroupInfo().isPresent();
if (threadId != null && !isGroupMessage) {
if (threadId != null) {
MessageNotifier.updateNotification(context, threadId);
}

View File

@ -0,0 +1,38 @@
package org.thoughtcrime.securesms.loki
import android.content.Context
import android.content.Intent
import org.thoughtcrime.securesms.database.DatabaseFactory
import org.thoughtcrime.securesms.service.PersistentAlarmManagerListener
import org.thoughtcrime.securesms.util.TextSecurePreferences
import java.util.concurrent.TimeUnit
class BackgroundPublicChatPollWorker : PersistentAlarmManagerListener() {
companion object {
private val pollInterval = TimeUnit.MINUTES.toMillis(4)
@JvmStatic
fun schedule(context: Context) {
BackgroundPublicChatPollWorker().onReceive(context, Intent())
}
}
override fun getNextScheduledExecutionTime(context: Context): Long {
return TextSecurePreferences.getPublicChatBackgroundPollTime(context)
}
override fun onAlarm(context: Context, scheduledTime: Long): Long {
if (scheduledTime != 0L) {
val publicChats = DatabaseFactory.getLokiThreadDatabase(context).getAllPublicChats().map { it.value }
for (publicChat in publicChats) {
val poller = LokiPublicChatPoller(context, publicChat)
poller.stop()
poller.pollForNewMessages()
}
}
val nextTime = System.currentTimeMillis() + pollInterval
TextSecurePreferences.setPublicChatBackgroundPollTime(context, nextTime)
return nextTime
}
}

View File

@ -153,7 +153,7 @@ class LokiPublicChatPoller(private val context: Context, private val group: Loki
return SignalServiceDataMessage(message.timestamp, serviceGroup, attachments, body, false, 0, false, null, false, quote, null, signalLinkPreviews, null)
}
private fun pollForNewMessages() {
fun pollForNewMessages() {
fun processIncomingMessage(message: LokiPublicChatMessage) {
// If the sender of the current message is not a secondary device, we need to set the display name in the database
val primaryDevice = LokiStorageAPI.shared.getPrimaryDevicePublicKey(message.hexEncodedPublicKey).get()
@ -220,6 +220,9 @@ class LokiPublicChatPoller(private val context: Context, private val group: Loki
}
var userDevices = setOf<String>()
var uniqueDevices = setOf<String>()
val userPrivateKey = IdentityKeyUtil.getIdentityKeyPair(context).privateKey.serialize()
val database = DatabaseFactory.getLokiAPIDatabase(context)
LokiStorageAPI.configure(false, userHexEncodedPublicKey, userPrivateKey, database)
LokiStorageAPI.shared.getAllDevicePublicKeys(userHexEncodedPublicKey).bind { devices ->
userDevices = devices
api.getMessages(group.channel, group.server)

View File

@ -388,9 +388,6 @@ public class MessageNotifier {
}
private static void sendInThreadNotification(Context context, Recipient recipient) {
// Mute group chats
if (recipient.isGroupRecipient()) { return; }
if (!TextSecurePreferences.isInThreadNotifications(context) ||
ServiceUtil.getAudioManager(context).getRingerMode() != AudioManager.RINGER_MODE_NORMAL)
{
@ -471,7 +468,7 @@ public class MessageNotifier {
slideDeck = ((MediaMmsMessageRecord)record).getSlideDeck();
}
if ((threadRecipients == null || !threadRecipients.isMuted()) && (threadRecipients == null || !threadRecipients.isGroupRecipient())) {
if (threadRecipients == null || !threadRecipients.isMuted()) {
notificationState.addNotification(new NotificationItem(id, mms, recipient, conversationRecipient, threadRecipients, threadId, body, timestamp, slideDeck));
}
}

View File

@ -1179,6 +1179,14 @@ public class TextSecurePreferences {
setLongPreference(context, "background_poll_time", backgroundPollTime);
}
public static long getPublicChatBackgroundPollTime(Context context) {
return getLongPreference(context, "public_chat_background_poll_time", 0L);
}
public static void setPublicChatBackgroundPollTime(Context context, long backgroundPollTime) {
setLongPreference(context, "public_chat_background_poll_time", backgroundPollTime);
}
public static boolean isChatSetUp(Context context, String id) {
return getBooleanPreference(context, "is_chat_set_up" + "?chat=" + id, false);
}