Added sendStoryMessage

This commit is contained in:
Scott Lewis 2025-01-27 16:45:20 -08:00
parent fab1b96c21
commit 811dc0dcf3
5 changed files with 601 additions and 607 deletions

View file

@ -189,6 +189,10 @@ public interface Manager extends Closeable {
Message message, Set<RecipientIdentifier> recipients, boolean notifySelf Message message, Set<RecipientIdentifier> recipients, boolean notifySelf
) throws IOException, AttachmentInvalidException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException, UnregisteredRecipientException, InvalidStickerException; ) throws IOException, AttachmentInvalidException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException, UnregisteredRecipientException, InvalidStickerException;
SendMessageResults sendStoryMessage(
Message message, Set<RecipientIdentifier> recipients, boolean notifySelf
) throws IOException, AttachmentInvalidException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException, UnregisteredRecipientException, InvalidStickerException;
SendMessageResults sendEditMessage( SendMessageResults sendEditMessage(
Message message, Set<RecipientIdentifier> recipients, long editTargetTimestamp Message message, Set<RecipientIdentifier> recipients, long editTargetTimestamp
) throws IOException, AttachmentInvalidException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException, UnregisteredRecipientException, InvalidStickerException; ) throws IOException, AttachmentInvalidException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException, UnregisteredRecipientException, InvalidStickerException;

View file

@ -96,6 +96,7 @@ import org.slf4j.LoggerFactory;
import org.whispersystems.signalservice.api.SignalSessionLock; import org.whispersystems.signalservice.api.SignalSessionLock;
import org.whispersystems.signalservice.api.messages.SignalServiceAttachment; import org.whispersystems.signalservice.api.messages.SignalServiceAttachment;
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage; import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage.StoryContext;
import org.whispersystems.signalservice.api.messages.SignalServicePreview; import org.whispersystems.signalservice.api.messages.SignalServicePreview;
import org.whispersystems.signalservice.api.messages.SignalServiceReceiptMessage; import org.whispersystems.signalservice.api.messages.SignalServiceReceiptMessage;
import org.whispersystems.signalservice.api.messages.SignalServiceTypingMessage; import org.whispersystems.signalservice.api.messages.SignalServiceTypingMessage;
@ -736,6 +737,21 @@ public class ManagerImpl implements Manager {
return sendMessage(messageBuilder, recipients, notifySelf); return sendMessage(messageBuilder, recipients, notifySelf);
} }
@Override
public SendMessageResults sendStoryMessage(
Message message, Set<RecipientIdentifier> recipients, boolean notifySelf
) throws IOException, AttachmentInvalidException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException, UnregisteredRecipientException, InvalidStickerException {
final var selfProfile = context.getProfileHelper().getSelfProfile();
if (selfProfile == null || selfProfile.getDisplayName().isEmpty()) {
logger.warn(
"No profile name set. When sending a message it's recommended to set a profile name with the updateProfile command. This may become mandatory in the future.");
}
final var messageBuilder = SignalServiceDataMessage.newBuilder();
applyMessage(messageBuilder, message);
messageBuilder.withStoryContext(new StoryContext(account.getSelfAddress().getServiceId(), System.currentTimeMillis()));
return sendMessage(messageBuilder, recipients, notifySelf);
}
@Override @Override
public SendMessageResults sendEditMessage( public SendMessageResults sendEditMessage(
Message message, Set<RecipientIdentifier> recipients, long editTargetTimestamp Message message, Set<RecipientIdentifier> recipients, long editTargetTimestamp

View file

@ -15,8 +15,8 @@ import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
* DBus interface for the org.asamk.Signal service. * DBus interface for the org.asamk.Signal service. Including emitted Signals
* Including emitted Signals and returned Errors. * and returned Errors.
*/ */
public interface Signal extends DBusInterface { public interface Signal extends DBusInterface {
@ -26,41 +26,28 @@ public interface Signal extends DBusInterface {
void unsubscribeReceive(); void unsubscribeReceive();
long sendMessage( long sendMessage(String message, List<String> attachments, String recipient)
String message, List<String> attachments, String recipient throws Error.AttachmentInvalid, Error.Failure, Error.InvalidNumber, Error.UntrustedIdentity;
) throws Error.AttachmentInvalid, Error.Failure, Error.InvalidNumber, Error.UntrustedIdentity;
long sendMessage( long sendMessage(String message, List<String> attachments, List<String> recipients)
String message, List<String> attachments, List<String> recipients throws Error.AttachmentInvalid, Error.Failure, Error.InvalidNumber, Error.UntrustedIdentity;
) throws Error.AttachmentInvalid, Error.Failure, Error.InvalidNumber, Error.UntrustedIdentity;
void sendTyping( void sendTyping(String recipient, boolean stop) throws Error.Failure, Error.UntrustedIdentity;
String recipient, boolean stop
) throws Error.Failure, Error.UntrustedIdentity;
void sendReadReceipt( void sendReadReceipt(String recipient, List<Long> messageIds) throws Error.Failure, Error.UntrustedIdentity;
String recipient, List<Long> messageIds
) throws Error.Failure, Error.UntrustedIdentity;
void sendViewedReceipt( void sendViewedReceipt(String recipient, List<Long> messageIds) throws Error.Failure, Error.UntrustedIdentity;
String recipient, List<Long> messageIds
) throws Error.Failure, Error.UntrustedIdentity;
long sendRemoteDeleteMessage( long sendRemoteDeleteMessage(long targetSentTimestamp, String recipient) throws Error.Failure, Error.InvalidNumber;
long targetSentTimestamp, String recipient
) throws Error.Failure, Error.InvalidNumber;
long sendRemoteDeleteMessage( long sendRemoteDeleteMessage(long targetSentTimestamp, List<String> recipients)
long targetSentTimestamp, List<String> recipients throws Error.Failure, Error.InvalidNumber;
) throws Error.Failure, Error.InvalidNumber;
long sendMessageReaction( long sendMessageReaction(String emoji, boolean remove, String targetAuthor, long targetSentTimestamp,
String emoji, boolean remove, String targetAuthor, long targetSentTimestamp, String recipient String recipient) throws Error.InvalidNumber, Error.Failure;
) throws Error.InvalidNumber, Error.Failure;
long sendMessageReaction( long sendMessageReaction(String emoji, boolean remove, String targetAuthor, long targetSentTimestamp,
String emoji, boolean remove, String targetAuthor, long targetSentTimestamp, List<String> recipients List<String> recipients) throws Error.InvalidNumber, Error.Failure;
) throws Error.InvalidNumber, Error.Failure;
long sendPaymentNotification(byte[] receipt, String note, String recipient) throws Error.Failure; long sendPaymentNotification(byte[] receipt, String note, String recipient) throws Error.Failure;
@ -68,31 +55,28 @@ public interface Signal extends DBusInterface {
void sendSyncRequest() throws Error.Failure; void sendSyncRequest() throws Error.Failure;
long sendNoteToSelfMessage( long sendNoteToSelfMessage(String message, List<String> attachments) throws Error.AttachmentInvalid, Error.Failure;
String message, List<String> attachments
) throws Error.AttachmentInvalid, Error.Failure;
void sendEndSessionMessage(List<String> recipients) throws Error.Failure, Error.InvalidNumber, Error.UntrustedIdentity; void sendEndSessionMessage(List<String> recipients)
throws Error.Failure, Error.InvalidNumber, Error.UntrustedIdentity;
void deleteRecipient(final String recipient) throws Error.Failure; void deleteRecipient(final String recipient) throws Error.Failure;
void deleteContact(final String recipient) throws Error.Failure; void deleteContact(final String recipient) throws Error.Failure;
long sendGroupMessage( long sendGroupMessage(String message, List<String> attachments, byte[] groupId)
String message, List<String> attachments, byte[] groupId throws Error.GroupNotFound, Error.Failure, Error.AttachmentInvalid, Error.InvalidGroupId;
) throws Error.GroupNotFound, Error.Failure, Error.AttachmentInvalid, Error.InvalidGroupId;
void sendGroupTyping( long sendStoryMessage(String messageText, List<String> attachments, byte[] groupId);
final byte[] groupId, final boolean stop
) throws Error.Failure, Error.GroupNotFound, Error.UntrustedIdentity;
long sendGroupRemoteDeleteMessage( void sendGroupTyping(final byte[] groupId, final boolean stop)
long targetSentTimestamp, byte[] groupId throws Error.Failure, Error.GroupNotFound, Error.UntrustedIdentity;
) throws Error.Failure, Error.GroupNotFound, Error.InvalidGroupId;
long sendGroupMessageReaction( long sendGroupRemoteDeleteMessage(long targetSentTimestamp, byte[] groupId)
String emoji, boolean remove, String targetAuthor, long targetSentTimestamp, byte[] groupId throws Error.Failure, Error.GroupNotFound, Error.InvalidGroupId;
) throws Error.GroupNotFound, Error.Failure, Error.InvalidNumber, Error.InvalidGroupId;
long sendGroupMessageReaction(String emoji, boolean remove, String targetAuthor, long targetSentTimestamp,
byte[] groupId) throws Error.GroupNotFound, Error.Failure, Error.InvalidNumber, Error.InvalidGroupId;
String getContactName(String number) throws Error.InvalidNumber; String getContactName(String number) throws Error.InvalidNumber;
@ -118,14 +102,12 @@ public interface Signal extends DBusInterface {
@Deprecated @Deprecated
List<String> getGroupMembers(byte[] groupId) throws Error.InvalidGroupId; List<String> getGroupMembers(byte[] groupId) throws Error.InvalidGroupId;
byte[] createGroup( byte[] createGroup(String name, List<String> members, String avatar)
String name, List<String> members, String avatar throws Error.AttachmentInvalid, Error.Failure, Error.InvalidNumber;
) throws Error.AttachmentInvalid, Error.Failure, Error.InvalidNumber;
@Deprecated @Deprecated
byte[] updateGroup( byte[] updateGroup(byte[] groupId, String name, List<String> members, String avatar) throws Error.AttachmentInvalid,
byte[] groupId, String name, List<String> members, String avatar Error.Failure, Error.InvalidNumber, Error.GroupNotFound, Error.InvalidGroupId;
) throws Error.AttachmentInvalid, Error.Failure, Error.InvalidNumber, Error.GroupNotFound, Error.InvalidGroupId;
@Deprecated @Deprecated
boolean isRegistered() throws Error.Failure, Error.InvalidNumber; boolean isRegistered() throws Error.Failure, Error.InvalidNumber;
@ -146,18 +128,11 @@ public interface Signal extends DBusInterface {
DBusPath getThisDevice(); DBusPath getThisDevice();
void updateProfile( void updateProfile(String givenName, String familyName, String about, String aboutEmoji, String avatarPath,
String givenName, boolean removeAvatar) throws Error.Failure;
String familyName,
String about,
String aboutEmoji,
String avatarPath,
boolean removeAvatar
) throws Error.Failure;
void updateProfile( void updateProfile(String name, String about, String aboutEmoji, String avatarPath, boolean removeAvatar)
String name, String about, String aboutEmoji, String avatarPath, boolean removeAvatar throws Error.Failure;
) throws Error.Failure;
void removePin(); void removePin();
@ -198,14 +173,8 @@ public interface Signal extends DBusInterface {
private final String message; private final String message;
private final Map<String, Variant<?>> extras; private final Map<String, Variant<?>> extras;
public MessageReceivedV2( public MessageReceivedV2(String objectpath, long timestamp, String sender, byte[] groupId, String message,
String objectpath, final Map<String, Variant<?>> extras) throws DBusException {
long timestamp,
String sender,
byte[] groupId,
String message,
final Map<String, Variant<?>> extras
) throws DBusException {
super(objectpath, timestamp, sender, groupId, message, extras); super(objectpath, timestamp, sender, groupId, message, extras);
this.timestamp = timestamp; this.timestamp = timestamp;
this.sender = sender; this.sender = sender;
@ -244,15 +213,8 @@ public interface Signal extends DBusInterface {
private final String message; private final String message;
private final Map<String, Variant<?>> extras; private final Map<String, Variant<?>> extras;
public EditMessageReceived( public EditMessageReceived(String objectpath, long timestamp, final long targetSentTimestamp, String sender,
String objectpath, byte[] groupId, String message, final Map<String, Variant<?>> extras) throws DBusException {
long timestamp,
final long targetSentTimestamp,
String sender,
byte[] groupId,
String message,
final Map<String, Variant<?>> extras
) throws DBusException {
super(objectpath, timestamp, targetSentTimestamp, sender, groupId, message, extras); super(objectpath, timestamp, targetSentTimestamp, sender, groupId, message, extras);
this.timestamp = timestamp; this.timestamp = timestamp;
this.targetSentTimestamp = targetSentTimestamp; this.targetSentTimestamp = targetSentTimestamp;
@ -295,14 +257,8 @@ public interface Signal extends DBusInterface {
private final String message; private final String message;
private final List<String> attachments; private final List<String> attachments;
public MessageReceived( public MessageReceived(String objectpath, long timestamp, String sender, byte[] groupId, String message,
String objectpath, List<String> attachments) throws DBusException {
long timestamp,
String sender,
byte[] groupId,
String message,
List<String> attachments
) throws DBusException {
super(objectpath, timestamp, sender, groupId, message, attachments); super(objectpath, timestamp, sender, groupId, message, attachments);
this.timestamp = timestamp; this.timestamp = timestamp;
this.sender = sender; this.sender = sender;
@ -359,13 +315,8 @@ public interface Signal extends DBusInterface {
private final String type; private final String type;
private final Map<String, Variant<?>> extras; private final Map<String, Variant<?>> extras;
public ReceiptReceivedV2( public ReceiptReceivedV2(String objectpath, long timestamp, String sender, final String type,
String objectpath, final Map<String, Variant<?>> extras) throws DBusException {
long timestamp,
String sender,
final String type,
final Map<String, Variant<?>> extras
) throws DBusException {
super(objectpath, timestamp, sender, type, extras); super(objectpath, timestamp, sender, type, extras);
this.timestamp = timestamp; this.timestamp = timestamp;
this.sender = sender; this.sender = sender;
@ -399,15 +350,8 @@ public interface Signal extends DBusInterface {
private final String message; private final String message;
private final List<String> attachments; private final List<String> attachments;
public SyncMessageReceived( public SyncMessageReceived(String objectpath, long timestamp, String source, String destination, byte[] groupId,
String objectpath, String message, List<String> attachments) throws DBusException {
long timestamp,
String source,
String destination,
byte[] groupId,
String message,
List<String> attachments
) throws DBusException {
super(objectpath, timestamp, source, destination, groupId, message, attachments); super(objectpath, timestamp, source, destination, groupId, message, attachments);
this.timestamp = timestamp; this.timestamp = timestamp;
this.source = source; this.source = source;
@ -451,15 +395,8 @@ public interface Signal extends DBusInterface {
private final String message; private final String message;
private final Map<String, Variant<?>> extras; private final Map<String, Variant<?>> extras;
public SyncMessageReceivedV2( public SyncMessageReceivedV2(String objectpath, long timestamp, String source, String destination,
String objectpath, byte[] groupId, String message, final Map<String, Variant<?>> extras) throws DBusException {
long timestamp,
String source,
String destination,
byte[] groupId,
String message,
final Map<String, Variant<?>> extras
) throws DBusException {
super(objectpath, timestamp, source, destination, groupId, message, extras); super(objectpath, timestamp, source, destination, groupId, message, extras);
this.timestamp = timestamp; this.timestamp = timestamp;
this.source = source; this.source = source;
@ -537,7 +474,8 @@ public interface Signal extends DBusInterface {
@DBusProperty(name = "UnidentifiedDeliveryIndicators", type = Boolean.class) @DBusProperty(name = "UnidentifiedDeliveryIndicators", type = Boolean.class)
@DBusProperty(name = "TypingIndicators", type = Boolean.class) @DBusProperty(name = "TypingIndicators", type = Boolean.class)
@DBusProperty(name = "LinkPreviews", type = Boolean.class) @DBusProperty(name = "LinkPreviews", type = Boolean.class)
interface Configuration extends DBusInterface, Properties {} interface Configuration extends DBusInterface, Properties {
}
class StructGroup extends Struct { class StructGroup extends Struct {
@ -734,4 +672,5 @@ public interface Signal extends DBusInterface {
} }
} }
} }
} }

View file

@ -420,6 +420,16 @@ public class DbusManagerImpl implements Manager {
groupId -> signal.sendGroupMessage(message.messageText(), message.attachments(), groupId)); groupId -> signal.sendGroupMessage(message.messageText(), message.attachments(), groupId));
} }
@Override
public SendMessageResults sendStoryMessage(
final Message message, final Set<RecipientIdentifier> recipients, final boolean notifySelf
) throws IOException, AttachmentInvalidException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException {
return handleMessage(recipients,
numbers -> signal.sendMessage(message.messageText(), message.attachments(), numbers),
() -> signal.sendNoteToSelfMessage(message.messageText(), message.attachments()),
groupId -> signal.sendStoryMessage(message.messageText(), message.attachments(), groupId));
}
@Override @Override
public SendMessageResults sendEditMessage( public SendMessageResults sendEditMessage(
final Message message, final Set<RecipientIdentifier> recipients, final long editTargetTimestamp final Message message, final Set<RecipientIdentifier> recipients, final long editTargetTimestamp

View file

@ -459,6 +459,31 @@ public class DbusSignalImpl implements Signal, AutoCloseable {
} }
} }
@Override
public long sendStoryMessage(final String messageText, final List<String> attachments, final byte[] groupId) {
try {
final var message = new Message(messageText,
attachments,
List.of(),
Optional.empty(),
Optional.empty(),
List.of(),
Optional.empty(),
List.of());
var results = m.sendStoryMessage(message, Set.of(getGroupRecipientIdentifier(groupId)), false);
checkSendMessageResults(results);
return results.timestamp();
} catch (IOException | InvalidStickerException e) {
throw new Error.Failure(e.getMessage());
} catch (GroupNotFoundException | NotAGroupMemberException | GroupSendingNotAllowedException e) {
throw new Error.GroupNotFound(e.getMessage());
} catch (AttachmentInvalidException e) {
throw new Error.AttachmentInvalid(e.getMessage());
} catch (UnregisteredRecipientException e) {
throw new Error.UntrustedIdentity(e.getSender().getIdentifier() + " is not registered.");
}
}
@Override @Override
public void sendGroupTyping( public void sendGroupTyping(
final byte[] groupId, final boolean stop final byte[] groupId, final boolean stop