mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 02:20:39 +00:00
parent
cb06cbdcca
commit
3180eba836
2 changed files with 18 additions and 6 deletions
|
@ -2,6 +2,7 @@ package org.asamk.signal.manager;
|
||||||
|
|
||||||
import org.asamk.signal.manager.api.AccountCheckException;
|
import org.asamk.signal.manager.api.AccountCheckException;
|
||||||
import org.asamk.signal.manager.api.NotRegisteredException;
|
import org.asamk.signal.manager.api.NotRegisteredException;
|
||||||
|
import org.asamk.signal.manager.api.Pair;
|
||||||
import org.asamk.signal.manager.api.ServiceEnvironment;
|
import org.asamk.signal.manager.api.ServiceEnvironment;
|
||||||
import org.asamk.signal.manager.config.ServiceConfig;
|
import org.asamk.signal.manager.config.ServiceConfig;
|
||||||
import org.asamk.signal.manager.config.ServiceEnvironmentConfig;
|
import org.asamk.signal.manager.config.ServiceEnvironmentConfig;
|
||||||
|
@ -63,19 +64,28 @@ public class SignalAccountFiles {
|
||||||
return accountsStore.getAllNumbers();
|
return accountsStore.getAllNumbers();
|
||||||
}
|
}
|
||||||
|
|
||||||
public MultiAccountManager initMultiAccountManager() throws IOException {
|
public MultiAccountManager initMultiAccountManager() throws IOException, AccountCheckException {
|
||||||
final var managers = accountsStore.getAllAccounts().parallelStream().map(a -> {
|
final var managerPairs = accountsStore.getAllAccounts().parallelStream().map(a -> {
|
||||||
try {
|
try {
|
||||||
return initManager(a.number(), a.path());
|
return new Pair<Manager, Throwable>(initManager(a.number(), a.path()), null);
|
||||||
} catch (NotRegisteredException | IOException | AccountCheckException e) {
|
} catch (NotRegisteredException e) {
|
||||||
logger.warn("Ignoring {}: {} ({})", a.number(), e.getMessage(), e.getClass().getSimpleName());
|
logger.warn("Ignoring {}: {} ({})", a.number(), e.getMessage(), e.getClass().getSimpleName());
|
||||||
return null;
|
return null;
|
||||||
} catch (Throwable e) {
|
} catch (AccountCheckException | IOException e) {
|
||||||
logger.error("Failed to load {}: {} ({})", a.number(), e.getMessage(), e.getClass().getSimpleName());
|
logger.error("Failed to load {}: {} ({})", a.number(), e.getMessage(), e.getClass().getSimpleName());
|
||||||
throw e;
|
return new Pair<Manager, Throwable>(null, e);
|
||||||
}
|
}
|
||||||
}).filter(Objects::nonNull).toList();
|
}).filter(Objects::nonNull).toList();
|
||||||
|
|
||||||
|
for (final var pair : managerPairs) {
|
||||||
|
if (pair.second() instanceof IOException e) {
|
||||||
|
throw e;
|
||||||
|
} else if (pair.second() instanceof AccountCheckException e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final var managers = managerPairs.stream().map(Pair::first).toList();
|
||||||
return new MultiAccountManagerImpl(managers, this);
|
return new MultiAccountManagerImpl(managers, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -291,6 +291,8 @@ public class App {
|
||||||
commandHandler.handleMultiLocalCommand(command, multiAccountManager);
|
commandHandler.handleMultiLocalCommand(command, multiAccountManager);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new IOErrorException("Failed to load local accounts file", e);
|
throw new IOErrorException("Failed to load local accounts file", e);
|
||||||
|
} catch (AccountCheckException e) {
|
||||||
|
throw new UnexpectedErrorException("Failed to load local accounts file", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue