+ try {
+ DeviceGroupsInputStream s = new DeviceGroupsInputStream(retrieveAttachmentAsStream(syncMessage.getGroups().get().asPointer()));
+ DeviceGroup g;
+ while ((g = s.read()) != null) {
+ GroupInfo syncGroup;
+ try {
+ syncGroup = groupStore.getGroup(g.getId());
+ } catch (GroupNotFoundException e) {
+ syncGroup = new GroupInfo(g.getId());
+ }
+ if (g.getName().isPresent()) {
+ syncGroup.name = g.getName().get();
+ }
+ syncGroup.members.addAll(g.getMembers());
+ syncGroup.active = g.isActive();
+
+ if (g.getAvatar().isPresent()) {
+ byte[] ava = new byte[(int) g.getAvatar().get().getLength()];
+ org.whispersystems.signalservice.internal.util.Util.readFully(g.getAvatar().get().getInputStream(), ava);
+ // TODO store group avatar in /avatar/groups folder
+ }
+ groupStore.updateGroup(syncGroup);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ if (syncMessage.getContacts().isPresent()) {
+ try {
+ DeviceContactsInputStream s = new DeviceContactsInputStream(retrieveAttachmentAsStream(syncMessage.getContacts().get().asPointer()));
+ DeviceContact c;
+ while ((c = s.read()) != null) {
+ // TODO implement when we have contact storage
+ if (c.getName().isPresent()) {
+ c.getName().get();
+ }
+ c.getNumber();
+
+ if (c.getAvatar().isPresent()) {
+ byte[] ava = new byte[(int) c.getAvatar().get().getLength()];
+ org.whispersystems.signalservice.internal.util.Util.readFully(c.getAvatar().get().getInputStream(), ava);
+ // TODO store contact avatar in /avatar/contacts folder
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }