mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-25 18:08:02 +01:00
Auto refactor Only: s/Account/Device/g
This commit is contained in:
@@ -23,7 +23,7 @@ import org.whispersystems.textsecuregcm.configuration.GcmConfiguration;
|
||||
import org.whispersystems.textsecuregcm.controllers.NoSuchUserException;
|
||||
import org.whispersystems.textsecuregcm.entities.EncryptedOutgoingMessage;
|
||||
import org.whispersystems.textsecuregcm.entities.MessageProtos;
|
||||
import org.whispersystems.textsecuregcm.storage.Account;
|
||||
import org.whispersystems.textsecuregcm.storage.Device;
|
||||
import org.whispersystems.textsecuregcm.storage.AccountsManager;
|
||||
import org.whispersystems.textsecuregcm.storage.DirectoryManager;
|
||||
import org.whispersystems.textsecuregcm.storage.StoredMessageManager;
|
||||
@@ -68,67 +68,67 @@ public class PushSender {
|
||||
* @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) {
|
||||
public void fillLocalAccountsCache(Map<String, Pair<Boolean, Set<Long>>> destinations, Map<Pair<String, Long>, Device> 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);
|
||||
List<Device> deviceList = accounts.getAllByNumber(number);
|
||||
Set<Long> deviceIdsIncluded = destination.getValue().second();
|
||||
if (accountList.size() != deviceIdsIncluded.size())
|
||||
if (deviceList.size() != deviceIdsIncluded.size())
|
||||
numbersMissingDevices.add(number);
|
||||
else {
|
||||
for (Account account : accountList) {
|
||||
if (!deviceIdsIncluded.contains(account.getDeviceId())) {
|
||||
for (Device device : deviceList) {
|
||||
if (!deviceIdsIncluded.contains(device.getDeviceId())) {
|
||||
numbersMissingDevices.add(number);
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (Account account : accountList)
|
||||
accountCache.put(new Pair<>(number, account.getDeviceId()), account);
|
||||
for (Device device : deviceList)
|
||||
accountCache.put(new Pair<>(number, device.getDeviceId()), device);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void sendMessage(Account account, MessageProtos.OutgoingMessageSignal outgoingMessage)
|
||||
public void sendMessage(Device device, MessageProtos.OutgoingMessageSignal outgoingMessage)
|
||||
throws IOException, NoSuchUserException
|
||||
{
|
||||
String signalingKey = account.getSignalingKey();
|
||||
String signalingKey = device.getSignalingKey();
|
||||
EncryptedOutgoingMessage message = new EncryptedOutgoingMessage(outgoingMessage, signalingKey);
|
||||
|
||||
if (account.getGcmRegistrationId() != null) sendGcmMessage(account, message);
|
||||
else if (account.getApnRegistrationId() != null) sendApnMessage(account, message);
|
||||
else if (account.getFetchesMessages()) storeFetchedMessage(account, message);
|
||||
if (device.getGcmRegistrationId() != null) sendGcmMessage(device, message);
|
||||
else if (device.getApnRegistrationId() != null) sendApnMessage(device, message);
|
||||
else if (device.getFetchesMessages()) storeFetchedMessage(device, message);
|
||||
else throw new NoSuchUserException("No push identifier!");
|
||||
}
|
||||
|
||||
private void sendGcmMessage(Account account, EncryptedOutgoingMessage outgoingMessage)
|
||||
private void sendGcmMessage(Device device, EncryptedOutgoingMessage outgoingMessage)
|
||||
throws IOException, NoSuchUserException
|
||||
{
|
||||
try {
|
||||
String canonicalId = gcmSender.sendMessage(account.getGcmRegistrationId(),
|
||||
String canonicalId = gcmSender.sendMessage(device.getGcmRegistrationId(),
|
||||
outgoingMessage);
|
||||
|
||||
if (canonicalId != null) {
|
||||
account.setGcmRegistrationId(canonicalId);
|
||||
accounts.update(account);
|
||||
device.setGcmRegistrationId(canonicalId);
|
||||
accounts.update(device);
|
||||
}
|
||||
|
||||
} catch (NoSuchUserException e) {
|
||||
logger.debug("No Such User", e);
|
||||
account.setGcmRegistrationId(null);
|
||||
accounts.update(account);
|
||||
device.setGcmRegistrationId(null);
|
||||
accounts.update(device);
|
||||
throw new NoSuchUserException("User no longer exists in GCM.");
|
||||
}
|
||||
}
|
||||
|
||||
private void sendApnMessage(Account account, EncryptedOutgoingMessage outgoingMessage)
|
||||
private void sendApnMessage(Device device, EncryptedOutgoingMessage outgoingMessage)
|
||||
throws IOException
|
||||
{
|
||||
apnSender.sendMessage(account.getApnRegistrationId(), outgoingMessage);
|
||||
apnSender.sendMessage(device.getApnRegistrationId(), outgoingMessage);
|
||||
}
|
||||
|
||||
private void storeFetchedMessage(Account account, EncryptedOutgoingMessage outgoingMessage) throws IOException {
|
||||
storedMessageManager.storeMessage(account, outgoingMessage);
|
||||
private void storeFetchedMessage(Device device, EncryptedOutgoingMessage outgoingMessage) throws IOException {
|
||||
storedMessageManager.storeMessage(device, outgoingMessage);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user