Fix for concurrent modification

(cherry picked from commit 101bd8570363e546db9bf97ed1d543f4cc2f26cb)
This commit is contained in:
Stephen Paul Weber 2024-12-16 23:31:05 -05:00 committed by Arne
parent fe81e690c9
commit b821e9b06e
2 changed files with 17 additions and 13 deletions

View file

@ -696,22 +696,26 @@ public class Account extends AbstractEntity implements AvatarService.Avatarable
}
public void refreshCapsFor(Contact contact) {
for (final var k : new HashSet<>(gateways.keySet())) {
gateways.remove(k, contact);
}
for (final var p : contact.getPresences().getPresences()) {
final var disco = p.getServiceDiscoveryResult();
if (disco == null) continue;
for (final var identity : disco.getIdentities()) {
if ("gateway".equals(identity.getCategory())) {
gateways.put(identity.getType(), contact);
synchronized (gateways) {
for (final var k : new HashSet<>(gateways.keySet())) {
gateways.remove(k, contact);
}
for (final var p : contact.getPresences().getPresences()) {
final var disco = p.getServiceDiscoveryResult();
if (disco == null) continue;
for (final var identity : disco.getIdentities()) {
if ("gateway".equals(identity.getCategory())) {
gateways.put(identity.getType(), contact);
}
}
}
}
}
public Set<Contact> getGateways(final String type) {
return gateways.get(type);
public Collection<Contact> getGateways(final String type) {
synchronized (gateways) {
return ImmutableList.copyOf(gateways.get(type));
}
}
public Collection<Bookmark> getBookmarks() {

View file

@ -114,8 +114,8 @@ public class QuickConversationsService extends AbstractQuickConversationsService
protected Set<String> gateways(final Account account) {
return Stream.concat(
ImmutableList.copyOf(account.getGateways("pstn")).stream(),
ImmutableList.copyOf(account.getGateways("sms")).stream()
account.getGateways("pstn").stream(),
account.getGateways("sms").stream()
).map(a -> a.getJid().asBareJid().toString()).collect(Collectors.toSet());
}