+ public void handleSyncDeviceGroups(final InputStream input) {
+ final var s = new DeviceGroupsInputStream(input);
+ DeviceGroup g;
+ while (true) {
+ try {
+ g = s.read();
+ } catch (IOException e) {
+ logger.warn("Sync groups contained invalid group, ignoring: {}", e.getMessage());
+ continue;
+ }
+ if (g == null) {
+ break;
+ }
+ var syncGroup = account.getGroupStore().getOrCreateGroupV1(GroupId.v1(g.getId()));
+ if (syncGroup != null) {
+ if (g.getName().isPresent()) {
+ syncGroup.name = g.getName().get();
+ }
+ syncGroup.addMembers(g.getMembers()
+ .stream()
+ .map(account.getRecipientResolver()::resolveRecipient)
+ .collect(Collectors.toSet()));
+ if (!g.isActive()) {
+ syncGroup.removeMember(account.getSelfRecipientId());
+ } else {
+ // Add ourself to the member set as it's marked as active
+ syncGroup.addMembers(List.of(account.getSelfRecipientId()));
+ }
+ syncGroup.blocked = g.isBlocked();
+ if (g.getColor().isPresent()) {
+ syncGroup.color = g.getColor().get();
+ }
+
+ if (g.getAvatar().isPresent()) {
+ context.getGroupHelper().downloadGroupAvatar(syncGroup.getGroupId(), g.getAvatar().get());
+ }
+ syncGroup.archived = g.isArchived();
+ account.getGroupStore().updateGroup(syncGroup);
+ }
+ }
+ }
+