|
|
|
@ -5,13 +5,21 @@ import android.content.Context;
|
|
|
|
|
import android.support.annotation.NonNull;
|
|
|
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.ApplicationContext;
|
|
|
|
|
import org.thoughtcrime.securesms.database.Address;
|
|
|
|
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
|
|
|
|
import org.thoughtcrime.securesms.database.ThreadDatabase;
|
|
|
|
|
import org.thoughtcrime.securesms.jobs.TypingSendJob;
|
|
|
|
|
import org.thoughtcrime.securesms.loki.MultiDeviceUtilKt;
|
|
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
|
|
|
|
import org.thoughtcrime.securesms.util.Util;
|
|
|
|
|
import org.whispersystems.signalservice.loki.api.LokiStorageAPI;
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
import kotlin.Unit;
|
|
|
|
|
|
|
|
|
|
@SuppressLint("UseSparseArrays")
|
|
|
|
|
public class TypingStatusSender {
|
|
|
|
|
|
|
|
|
@ -74,7 +82,25 @@ public class TypingStatusSender {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void sendTyping(long threadId, boolean typingStarted) {
|
|
|
|
|
ApplicationContext.getInstance(context).getJobManager().add(new TypingSendJob(threadId, typingStarted));
|
|
|
|
|
LokiStorageAPI storageAPI = LokiStorageAPI.Companion.getShared();
|
|
|
|
|
ThreadDatabase threadDatabase = DatabaseFactory.getThreadDatabase(context);
|
|
|
|
|
Recipient originalRecipient = threadDatabase.getRecipientForThreadId(threadId);
|
|
|
|
|
|
|
|
|
|
// Send normal message if storage api wasn't found
|
|
|
|
|
if (storageAPI == null || originalRecipient == null) {
|
|
|
|
|
ApplicationContext.getInstance(context).getJobManager().add(new TypingSendJob(threadId, typingStarted));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MultiDeviceUtilKt.getAllDevices(context, originalRecipient.getAddress().serialize(), storageAPI, (devicePubKey, isFriend, friendCount) -> {
|
|
|
|
|
Recipient device = Recipient.from(context, Address.fromSerialized(devicePubKey), false);
|
|
|
|
|
long deviceThreadId = threadDatabase.getThreadIdIfExistsFor(device);
|
|
|
|
|
if (deviceThreadId > -1) {
|
|
|
|
|
ApplicationContext.getInstance(context).getJobManager().add(new TypingSendJob(deviceThreadId, typingStarted));
|
|
|
|
|
}
|
|
|
|
|
return Unit.INSTANCE;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class StartRunnable implements Runnable {
|
|
|
|
|