Mark group as active when the user hasn't left it

Fixes #269
This commit is contained in:
AsamK 2020-03-22 18:20:52 +01:00
parent 67f6378f7f
commit bb06ae9d9a
3 changed files with 15 additions and 9 deletions

View file

@ -12,13 +12,13 @@ import java.util.List;
public class ListGroupsCommand implements LocalCommand {
private static void printGroup(GroupInfo group, boolean detailed) {
private static void printGroup(GroupInfo group, boolean detailed, String username) {
if (detailed) {
System.out.println(String.format("Id: %s Name: %s Active: %s Blocked: %b Members: %s",
Base64.encodeBytes(group.groupId), group.name, group.active, group.blocked, group.members));
Base64.encodeBytes(group.groupId), group.name, group.members.contains(username), group.blocked, group.members));
} else {
System.out.println(String.format("Id: %s Name: %s Active: %s Blocked: %b",
Base64.encodeBytes(group.groupId), group.name, group.active, group.blocked));
Base64.encodeBytes(group.groupId), group.name, group.members.contains(username), group.blocked));
}
}
@ -40,7 +40,7 @@ public class ListGroupsCommand implements LocalCommand {
boolean detailed = ns.getBoolean("detailed");
for (GroupInfo group : groups) {
printGroup(group, detailed);
printGroup(group, detailed, m.getUsername());
}
return 0;
}

View file

@ -1450,7 +1450,9 @@ public class Manager implements Signal {
syncGroup.name = g.getName().get();
}
syncGroup.addMembers(g.getMembers());
syncGroup.active = g.isActive();
if (!g.isActive()) {
syncGroup.members.remove(username);
}
syncGroup.blocked = g.isBlocked();
if (g.getColor().isPresent()) {
syncGroup.color = g.getColor().get();
@ -1666,7 +1668,7 @@ public class Manager implements Signal {
ThreadInfo info = account.getThreadStore().getThread(Base64.encodeBytes(record.groupId));
out.write(new DeviceGroup(record.groupId, Optional.fromNullable(record.name),
new ArrayList<>(record.getMembers()), createGroupAvatarAttachment(record.groupId),
record.active, Optional.fromNullable(info != null ? info.messageExpirationTime : null),
record.members.contains(username), Optional.fromNullable(info != null ? info.messageExpirationTime : null),
Optional.fromNullable(record.color), record.blocked, Optional.fromNullable(record.inboxPosition), record.archived));
}
}

View file

@ -20,8 +20,6 @@ public class GroupInfo {
@JsonProperty
public Set<String> members = new HashSet<>();
@JsonProperty
public boolean active;
@JsonProperty
public String color;
@JsonProperty(defaultValue = "false")
public boolean blocked;
@ -32,17 +30,23 @@ public class GroupInfo {
private long avatarId;
@JsonProperty
@JsonIgnore
private boolean active;
public GroupInfo(byte[] groupId) {
this.groupId = groupId;
}
public GroupInfo(@JsonProperty("groupId") byte[] groupId, @JsonProperty("name") String name, @JsonProperty("members") Collection<String> members, @JsonProperty("avatarId") long avatarId, @JsonProperty("color") String color, @JsonProperty("blocked") boolean blocked) {
public GroupInfo(@JsonProperty("groupId") byte[] groupId, @JsonProperty("name") String name, @JsonProperty("members") Collection<String> members, @JsonProperty("avatarId") long avatarId, @JsonProperty("color") String color, @JsonProperty("blocked") boolean blocked, @JsonProperty("inboxPosition") Integer inboxPosition, @JsonProperty("archived") boolean archived) {
this.groupId = groupId;
this.name = name;
this.members.addAll(members);
this.avatarId = avatarId;
this.color = color;
this.blocked = blocked;
this.inboxPosition = inboxPosition;
this.archived = archived;
}
@JsonIgnore