mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-25 22:38:04 +01:00
Rework messages API to fail if you miss some deviceIds per number
This commit is contained in:
@@ -28,19 +28,21 @@ import org.whispersystems.textsecuregcm.storage.Account;
|
||||
import org.whispersystems.textsecuregcm.storage.AccountsManager;
|
||||
import org.whispersystems.textsecuregcm.storage.DirectoryManager;
|
||||
import org.whispersystems.textsecuregcm.storage.StoredMessageManager;
|
||||
import org.whispersystems.textsecuregcm.util.Pair;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.KeyStoreException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class PushSender {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(PushSender.class);
|
||||
|
||||
private final AccountsManager accounts;
|
||||
private final DirectoryManager directory;
|
||||
|
||||
private final GCMSender gcmSender;
|
||||
private final APNSender apnSender;
|
||||
@@ -54,23 +56,44 @@ public class PushSender {
|
||||
throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException
|
||||
{
|
||||
this.accounts = accounts;
|
||||
this.directory = directory;
|
||||
|
||||
this.storedMessageManager = storedMessageManager;
|
||||
this.gcmSender = new GCMSender(gcmConfiguration.getApiKey());
|
||||
this.apnSender = new APNSender(apnConfiguration.getCertificate(), apnConfiguration.getKey());
|
||||
}
|
||||
|
||||
public void sendMessage(String destination, long destinationDeviceId, MessageProtos.OutgoingMessageSignal outgoingMessage)
|
||||
/**
|
||||
* For each local destination in destinations, either adds all its accounts to accountCache or adds the number to
|
||||
* numbersMissingDevices, if the deviceIds list don't match what is required.
|
||||
* @param destinations Map from number to Pair<localNumber, Set<deviceIds>>
|
||||
* @param accountCache Map from <number, deviceId> to account
|
||||
* @param numbersMissingDevices list of numbers missing devices
|
||||
*/
|
||||
public void fillLocalAccountsCache(Map<String, Pair<Boolean, Set<Long>>> destinations, Map<Pair<String, Long>, Account> accountCache, List<String> numbersMissingDevices) {
|
||||
for (Map.Entry<String, Pair<Boolean, Set<Long>>> destination : destinations.entrySet()) {
|
||||
if (destination.getValue().first()) {
|
||||
String number = destination.getKey();
|
||||
List<Account> accountList = accounts.getAllByNumber(number);
|
||||
Set<Long> deviceIdsIncluded = destination.getValue().second();
|
||||
if (accountList.size() != deviceIdsIncluded.size())
|
||||
numbersMissingDevices.add(number);
|
||||
else {
|
||||
for (Account account : accountList) {
|
||||
if (!deviceIdsIncluded.contains(account.getDeviceId())) {
|
||||
numbersMissingDevices.add(number);
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (Account account : accountList)
|
||||
accountCache.put(new Pair<>(number, account.getDeviceId()), account);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void sendMessage(Account account, MessageProtos.OutgoingMessageSignal outgoingMessage)
|
||||
throws IOException, NoSuchUserException
|
||||
{
|
||||
Optional<Account> accountOptional = accounts.get(destination, destinationDeviceId);
|
||||
|
||||
if (!accountOptional.isPresent()) {
|
||||
throw new NoSuchUserException("No such local destination: " + destination);
|
||||
}
|
||||
Account account = accountOptional.get();
|
||||
|
||||
String signalingKey = account.getSignalingKey();
|
||||
EncryptedOutgoingMessage message = new EncryptedOutgoingMessage(outgoingMessage, signalingKey);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user