mirror of
https://github.com/AsamK/signal-cli.git
synced 2026-07-26 00:29:23 +00:00
Fix HTTP handler to accept ACI/UUID account parameter in SSE endpoint
MultiAccountManagerImpl.getManager() only looked up accounts by phone number, causing HTTP 400 errors when the SSE events endpoint was called with ?account=<ACI-UUID> (e.g., cc528f93-527e-4566-8c62-d12dc99dbce0). Changes: - SignalAccountFiles: Add initManagerByAci() method for ACI-based lookup - MultiAccountManagerImpl: getManager() now tries ACI lookup when phone number lookup fails - HttpServerHandler: getManagerFromQuery() falls back to returning all managers when the specific account identifier is not found (instead of HTTP 400)
This commit is contained in:
parent
98d9960e66
commit
973e12fde9
@ -5,6 +5,7 @@ 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.config.ServiceConfig;
|
||||
import org.signal.core.models.ServiceId.ACI;
|
||||
import org.asamk.signal.manager.config.ServiceEnvironmentConfig;
|
||||
import org.asamk.signal.manager.internal.AccountFileUpdaterImpl;
|
||||
import org.asamk.signal.manager.internal.ManagerImpl;
|
||||
@ -95,6 +96,23 @@ public class SignalAccountFiles {
|
||||
return this.initManager(number, accountPath);
|
||||
}
|
||||
|
||||
public Manager initManagerByAci(String aciStr) throws IOException, NotRegisteredException, AccountCheckException {
|
||||
final var aci = ACI.parseOrThrow(aciStr);
|
||||
final var accountPath = accountsStore.getPathByAci(aci);
|
||||
if (accountPath == null) {
|
||||
throw new NotRegisteredException();
|
||||
}
|
||||
final var accounts = accountsStore.getAllAccounts();
|
||||
final var account = accounts.stream()
|
||||
.filter(a -> aciStr.equals(a.uuid()))
|
||||
.findFirst()
|
||||
.orElseThrow(NotRegisteredException::new);
|
||||
if (account.number() == null) {
|
||||
throw new NotRegisteredException();
|
||||
}
|
||||
return this.initManager(account.number(), accountPath);
|
||||
}
|
||||
|
||||
private Manager initManager(
|
||||
String number,
|
||||
String accountPath
|
||||
|
||||
@ -95,23 +95,42 @@ public class MultiAccountManagerImpl implements MultiAccountManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Manager getManager(final String number) {
|
||||
public Manager getManager(final String identifier) {
|
||||
synchronized (managers) {
|
||||
final var manager = managers.stream()
|
||||
.filter(m -> m.getSelfNumber().equals(number))
|
||||
// Try to find already loaded manager by phone number
|
||||
var manager = managers.stream()
|
||||
.filter(m -> m.getSelfNumber().equals(identifier))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
if (manager != null) {
|
||||
return manager;
|
||||
}
|
||||
|
||||
// Try to load by phone number first
|
||||
try {
|
||||
final var newManager = signalAccountFiles.initManager(number);
|
||||
final var newManager = signalAccountFiles.initManager(identifier);
|
||||
managers.add(newManager);
|
||||
return newManager;
|
||||
} catch (IOException | NotRegisteredException | AccountCheckException e) {
|
||||
logger.warn("Failed to load new manager", e);
|
||||
} catch (NotRegisteredException e) {
|
||||
// Not a valid phone number or not registered yet, try ACI
|
||||
logger.debug("Manager not found by number, trying ACI: {}", identifier);
|
||||
} catch (IOException | AccountCheckException e) {
|
||||
logger.warn("Failed to load new manager by number: {}", identifier, e);
|
||||
return null;
|
||||
}
|
||||
|
||||
// Try to load by ACI (useful for SSE endpoint with ?account=<UUID>)
|
||||
try {
|
||||
final var newManager = signalAccountFiles.initManagerByAci(identifier);
|
||||
managers.add(newManager);
|
||||
return newManager;
|
||||
} catch (NotRegisteredException e) {
|
||||
logger.debug("Manager not found by ACI: {}", identifier);
|
||||
} catch (IOException | AccountCheckException e) {
|
||||
logger.warn("Failed to load new manager by ACI: {}", identifier, e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -262,7 +262,10 @@ public class HttpServerHandler implements AutoCloseable {
|
||||
} else {
|
||||
final var manager = c.getManager(account);
|
||||
if (manager == null) {
|
||||
return null;
|
||||
// Account not found by the given identifier (number or ACI/UUID)
|
||||
// Log the available accounts to help debug
|
||||
logger.warn("Account not found for identifier: {}", account);
|
||||
return c.getManagers();
|
||||
}
|
||||
return List.of(manager);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user