return Optional.of(createAttachment(file));
}
+ private GroupInfo getGroupForSending(byte[] groupId) throws GroupNotFoundException, NotAGroupMemberException {
+ GroupInfo g = groupStore.getGroup(groupId);
+ if (g == null) {
+ throw new GroupNotFoundException(groupId);
+ }
+ for (String member : g.members) {
+ if (member.equals(this.username)) {
+ return g;
+ }
+ }
+ throw new NotAGroupMemberException(groupId, g.name);
+ }
+
@Override
public void sendGroupMessage(String messageText, List<String> attachments,
byte[] groupId)
}
SignalServiceDataMessage message = messageBuilder.build();
- GroupInfo g = groupStore.getGroup(groupId);
- if (g == null) {
- throw new GroupNotFoundException(groupId);
- }
+ final GroupInfo g = getGroupForSending(groupId);
// Don't send group message to ourself
final List<String> membersSend = new ArrayList<>(g.members);
.asGroupMessage(group)
.build();
- final GroupInfo g = groupStore.getGroup(groupId);
- if (g == null) {
- throw new GroupNotFoundException(groupId);
- }
+ final GroupInfo g = getGroupForSending(groupId);
g.members.remove(this.username);
groupStore.updateGroup(g);
g = new GroupInfo(Util.getSecretBytes(16));
g.members.add(username);
} else {
- g = groupStore.getGroup(groupId);
- if (g == null) {
- throw new GroupNotFoundException(groupId);
- }
+ g = getGroupForSending(groupId);
}
if (name != null) {