mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Refactor to use GroupId class to wrap the byte array
Helps distinguish between group v1 and v2 ids
This commit is contained in:
parent
67f62947c6
commit
9942d967a4
31 changed files with 358 additions and 228 deletions
|
@ -2,6 +2,7 @@ package org.asamk.signal.dbus;
|
|||
|
||||
import org.asamk.Signal;
|
||||
import org.asamk.signal.manager.AttachmentInvalidException;
|
||||
import org.asamk.signal.manager.GroupId;
|
||||
import org.asamk.signal.manager.GroupNotFoundException;
|
||||
import org.asamk.signal.manager.Manager;
|
||||
import org.asamk.signal.manager.NotAGroupMemberException;
|
||||
|
@ -92,7 +93,9 @@ public class DbusSignalImpl implements Signal {
|
|||
@Override
|
||||
public long sendGroupMessage(final String message, final List<String> attachments, final byte[] groupId) {
|
||||
try {
|
||||
Pair<Long, List<SendMessageResult>> results = m.sendGroupMessage(message, attachments, groupId);
|
||||
Pair<Long, List<SendMessageResult>> results = m.sendGroupMessage(message,
|
||||
attachments,
|
||||
GroupId.unknownVersion(groupId));
|
||||
checkSendMessageResults(results.first(), results.second());
|
||||
return results.first();
|
||||
} catch (IOException e) {
|
||||
|
@ -134,7 +137,7 @@ public class DbusSignalImpl implements Signal {
|
|||
@Override
|
||||
public void setGroupBlocked(final byte[] groupId, final boolean blocked) {
|
||||
try {
|
||||
m.setGroupBlocked(groupId, blocked);
|
||||
m.setGroupBlocked(GroupId.unknownVersion(groupId), blocked);
|
||||
} catch (GroupNotFoundException e) {
|
||||
throw new Error.GroupNotFound(e.getMessage());
|
||||
}
|
||||
|
@ -145,14 +148,14 @@ public class DbusSignalImpl implements Signal {
|
|||
List<GroupInfo> groups = m.getGroups();
|
||||
List<byte[]> ids = new ArrayList<>(groups.size());
|
||||
for (GroupInfo group : groups) {
|
||||
ids.add(group.groupId);
|
||||
ids.add(group.getGroupId().serialize());
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGroupName(final byte[] groupId) {
|
||||
GroupInfo group = m.getGroup(groupId);
|
||||
GroupInfo group = m.getGroup(GroupId.unknownVersion(groupId));
|
||||
if (group == null) {
|
||||
return "";
|
||||
} else {
|
||||
|
@ -162,7 +165,7 @@ public class DbusSignalImpl implements Signal {
|
|||
|
||||
@Override
|
||||
public List<String> getGroupMembers(final byte[] groupId) {
|
||||
GroupInfo group = m.getGroup(groupId);
|
||||
GroupInfo group = m.getGroup(GroupId.unknownVersion(groupId));
|
||||
if (group == null) {
|
||||
return Collections.emptyList();
|
||||
} else {
|
||||
|
@ -189,9 +192,11 @@ public class DbusSignalImpl implements Signal {
|
|||
if (avatar.isEmpty()) {
|
||||
avatar = null;
|
||||
}
|
||||
final Pair<byte[], List<SendMessageResult>> results = m.updateGroup(groupId, name, members, avatar);
|
||||
final Pair<GroupId, List<SendMessageResult>> results = m.updateGroup(groupId == null
|
||||
? null
|
||||
: GroupId.unknownVersion(groupId), name, members, avatar);
|
||||
checkSendMessageResults(0, results.second());
|
||||
return results.first();
|
||||
return results.first().serialize();
|
||||
} catch (IOException e) {
|
||||
throw new Error.Failure(e.getMessage());
|
||||
} catch (GroupNotFoundException | NotAGroupMemberException e) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue