mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-25 18:08:02 +01:00
New API to support multiple accounts per # (FREEBIE)
This commit is contained in:
@@ -27,11 +27,13 @@ import org.whispersystems.textsecuregcm.entities.MessageProtos;
|
||||
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 java.io.IOException;
|
||||
import java.security.KeyStoreException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.util.List;
|
||||
|
||||
public class PushSender {
|
||||
|
||||
@@ -42,9 +44,11 @@ public class PushSender {
|
||||
|
||||
private final GCMSender gcmSender;
|
||||
private final APNSender apnSender;
|
||||
private final StoredMessageManager storedMessageManager;
|
||||
|
||||
public PushSender(GcmConfiguration gcmConfiguration,
|
||||
ApnConfiguration apnConfiguration,
|
||||
StoredMessageManager storedMessageManager,
|
||||
AccountsManager accounts,
|
||||
DirectoryManager directory)
|
||||
throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException
|
||||
@@ -52,25 +56,27 @@ public class PushSender {
|
||||
this.accounts = accounts;
|
||||
this.directory = directory;
|
||||
|
||||
this.gcmSender = new GCMSender(gcmConfiguration.getApiKey());
|
||||
this.apnSender = new APNSender(apnConfiguration.getCertificate(), apnConfiguration.getKey());
|
||||
this.storedMessageManager = storedMessageManager;
|
||||
this.gcmSender = new GCMSender(gcmConfiguration.getApiKey());
|
||||
this.apnSender = new APNSender(apnConfiguration.getCertificate(), apnConfiguration.getKey());
|
||||
}
|
||||
|
||||
public void sendMessage(String destination, MessageProtos.OutgoingMessageSignal outgoingMessage)
|
||||
public void sendMessage(String destination, long destinationDeviceId, MessageProtos.OutgoingMessageSignal outgoingMessage)
|
||||
throws IOException, NoSuchUserException
|
||||
{
|
||||
Optional<Account> account = accounts.get(destination);
|
||||
Optional<Account> accountOptional = accounts.get(destination, destinationDeviceId);
|
||||
|
||||
if (!account.isPresent()) {
|
||||
directory.remove(destination);
|
||||
if (!accountOptional.isPresent()) {
|
||||
throw new NoSuchUserException("No such local destination: " + destination);
|
||||
}
|
||||
Account account = accountOptional.get();
|
||||
|
||||
String signalingKey = account.get().getSignalingKey();
|
||||
String signalingKey = account.getSignalingKey();
|
||||
EncryptedOutgoingMessage message = new EncryptedOutgoingMessage(outgoingMessage, signalingKey);
|
||||
|
||||
if (account.get().getGcmRegistrationId() != null) sendGcmMessage(account.get(), message);
|
||||
else if (account.get().getApnRegistrationId() != null) sendApnMessage(account.get(), message);
|
||||
if (account.getGcmRegistrationId() != null) sendGcmMessage(account, message);
|
||||
else if (account.getApnRegistrationId() != null) sendApnMessage(account, message);
|
||||
else if (account.getFetchesMessages()) storeFetchedMessage(account, message);
|
||||
else throw new NoSuchUserException("No push identifier!");
|
||||
}
|
||||
|
||||
@@ -100,4 +106,7 @@ public class PushSender {
|
||||
apnSender.sendMessage(account.getApnRegistrationId(), outgoingMessage);
|
||||
}
|
||||
|
||||
private void storeFetchedMessage(Account account, EncryptedOutgoingMessage outgoingMessage) {
|
||||
storedMessageManager.storeMessage(account, outgoingMessage);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user