Implement sendGroupTying dbus method

This commit is contained in:
AsamK 2021-12-11 19:26:15 +01:00
parent 4999487476
commit d9c8711eb0
4 changed files with 56 additions and 26 deletions

View file

@ -301,7 +301,8 @@ public class DbusManagerImpl implements Manager {
signal.sendTyping(signal.getSelfNumber(), action == TypingAction.STOP);
return 0L;
}, groupId -> {
throw new UnsupportedOperationException();
signal.sendGroupTyping(groupId, action == TypingAction.STOP);
return 0L;
});
}

View file

@ -238,22 +238,6 @@ public class DbusSignalImpl implements Signal {
}
}
@Override
public long sendGroupRemoteDeleteMessage(
final long targetSentTimestamp, final byte[] groupId
) {
try {
final var results = m.sendRemoteDeleteMessage(targetSentTimestamp,
Set.of(new RecipientIdentifier.Group(getGroupId(groupId))));
checkSendMessageResults(results.timestamp(), results.results());
return results.timestamp();
} catch (IOException e) {
throw new Error.Failure(e.getMessage());
} catch (GroupNotFoundException | NotAGroupMemberException | GroupSendingNotAllowedException e) {
throw new Error.GroupNotFound(e.getMessage());
}
}
@Override
public long sendMessageReaction(
final String emoji,
@ -401,7 +385,7 @@ public class DbusSignalImpl implements Signal {
public long sendGroupMessage(final String message, final List<String> attachments, final byte[] groupId) {
try {
var results = m.sendMessage(new Message(message, attachments, List.of(), Optional.empty()),
Set.of(new RecipientIdentifier.Group(getGroupId(groupId))));
Set.of(getGroupRecipientIdentifier(groupId)));
checkSendMessageResults(results.timestamp(), results.results());
return results.timestamp();
} catch (IOException e) {
@ -413,6 +397,37 @@ public class DbusSignalImpl implements Signal {
}
}
@Override
public void sendGroupTyping(
final byte[] groupId, final boolean stop
) throws Error.Failure, Error.GroupNotFound, Error.UntrustedIdentity {
try {
final var results = m.sendTypingMessage(stop ? TypingAction.STOP : TypingAction.START,
Set.of(getGroupRecipientIdentifier(groupId)));
checkSendMessageResults(results.timestamp(), results.results());
} catch (IOException e) {
throw new Error.Failure(e.getMessage());
} catch (GroupNotFoundException | NotAGroupMemberException | GroupSendingNotAllowedException e) {
throw new Error.GroupNotFound(e.getMessage());
}
}
@Override
public long sendGroupRemoteDeleteMessage(
final long targetSentTimestamp, final byte[] groupId
) {
try {
final var results = m.sendRemoteDeleteMessage(targetSentTimestamp,
Set.of(getGroupRecipientIdentifier(groupId)));
checkSendMessageResults(results.timestamp(), results.results());
return results.timestamp();
} catch (IOException e) {
throw new Error.Failure(e.getMessage());
} catch (GroupNotFoundException | NotAGroupMemberException | GroupSendingNotAllowedException e) {
throw new Error.GroupNotFound(e.getMessage());
}
}
@Override
public long sendGroupMessageReaction(
final String emoji,
@ -426,7 +441,7 @@ public class DbusSignalImpl implements Signal {
remove,
getSingleRecipientIdentifier(targetAuthor, m.getSelfNumber()),
targetSentTimestamp,
Set.of(new RecipientIdentifier.Group(getGroupId(groupId))));
Set.of(getGroupRecipientIdentifier(groupId)));
checkSendMessageResults(results.timestamp(), results.results());
return results.timestamp();
} catch (IOException e) {
@ -854,6 +869,10 @@ public class DbusSignalImpl implements Signal {
}
}
private RecipientIdentifier.Group getGroupRecipientIdentifier(final byte[] groupId) {
return new RecipientIdentifier.Group(getGroupId(groupId));
}
private static GroupId getGroupId(byte[] groupId) throws DBusExecutionException {
try {
return GroupId.unknownVersion(groupId);