Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Requires libsignal-client version 0.86.12.

- Add sendPollCreate, sendPollVote, sendPollTerminate commands for polls
- Add updateDevice command to set device name of linked devices
- Add --ignore-avatars flag to prevent downloading avatars
- Add --ignore-stickers flag to prevent downloading sticker packs

### Changed

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package org.asamk.signal.manager.api;

public record ReceiveConfig(boolean ignoreAttachments, boolean ignoreStories, boolean sendReadReceipts) {}
public record ReceiveConfig(boolean ignoreAttachments, boolean ignoreStories, boolean ignoreAvatars, boolean ignoreStickers, boolean sendReadReceipts) {}
14 changes: 10 additions & 4 deletions lib/src/main/java/org/asamk/signal/manager/helper/GroupHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ public boolean isGroupBlocked(final GroupId groupId) {
return group != null && group.isBlocked();
}

public void downloadGroupAvatar(GroupIdV1 groupId, SignalServiceAttachment avatar) {
public void downloadGroupAvatar(GroupIdV1 groupId, SignalServiceAttachment avatar, boolean ignoreAvatars) {
if (ignoreAvatars) {
return;
}
try {
context.getAvatarStore()
.storeGroupAvatar(groupId,
Expand Down Expand Up @@ -167,7 +170,7 @@ public GroupInfoV2 getOrMigrateGroup(
storeProfileKeysFromMembers(group);
final var avatar = group.avatar;
if (!avatar.isEmpty()) {
downloadGroupAvatar(groupId, groupSecretParams, avatar);
downloadGroupAvatar(groupId, groupSecretParams, avatar, false);
}
}
groupInfoV2.setGroup(group);
Expand Down Expand Up @@ -506,13 +509,16 @@ private void fillOrUpdateGroup(final GroupInfo group, final boolean forceUpdate)
storeProfileKeysFromMembers(decryptedGroup);
final var avatar = decryptedGroup.avatar;
if (!avatar.isEmpty()) {
downloadGroupAvatar(groupInfoV2.getGroupId(), groupSecretParams, avatar);
downloadGroupAvatar(groupInfoV2.getGroupId(), groupSecretParams, avatar, false);
}
groupInfoV2.setGroup(decryptedGroup);
account.getGroupStore().updateGroup(group);
}

private void downloadGroupAvatar(GroupIdV2 groupId, GroupSecretParams groupSecretParams, String cdnKey) {
private void downloadGroupAvatar(GroupIdV2 groupId, GroupSecretParams groupSecretParams, String cdnKey, boolean ignoreAvatars) {
if (ignoreAvatars) {
return;
}
try {
context.getAvatarStore()
.storeGroupAvatar(groupId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ public List<HandleAction> handleMessage(
false,
senderDeviceAddress,
destination,
receiveConfig.ignoreAttachments()));
receiveConfig));
}

if (content.getStoryMessage().isPresent()) {
Expand All @@ -382,7 +382,7 @@ public List<HandleAction> handleMessage(
actions.addAll(handleSyncMessage(envelope,
syncMessage,
senderDeviceAddress,
receiveConfig.ignoreAttachments()));
receiveConfig));
}

return actions;
Expand Down Expand Up @@ -475,7 +475,7 @@ private List<HandleAction> handleSyncMessage(
final SignalServiceEnvelope envelope,
final SignalServiceSyncMessage syncMessage,
final DeviceAddress sender,
final boolean ignoreAttachments
final ReceiveConfig receiveConfig
) {
var actions = new ArrayList<HandleAction>();
account.setMultiDevice(true);
Expand All @@ -491,12 +491,12 @@ private List<HandleAction> handleSyncMessage(
: new DeviceAddress(account.getRecipientResolver().resolveRecipient(destination),
destination.getServiceId(),
0),
ignoreAttachments));
receiveConfig));
}
if (message.getStoryMessage().isPresent()) {
actions.addAll(handleSignalServiceStoryMessage(message.getStoryMessage().get(),
sender.recipientId(),
ignoreAttachments));
receiveConfig.ignoreAttachments()));
}
}
if (syncMessage.getRequest().isPresent() && account.isPrimaryDevice()) {
Expand All @@ -522,7 +522,7 @@ private List<HandleAction> handleSyncMessage(
try {
final var groupsMessage = syncMessage.getGroups().get();
context.getAttachmentHelper()
.retrieveAttachment(groupsMessage, context.getSyncHelper()::handleSyncDeviceGroups);
.retrieveAttachment(groupsMessage, input -> context.getSyncHelper().handleSyncDeviceGroups(input, receiveConfig.ignoreAvatars()));
} catch (Exception e) {
logger.warn("Failed to handle received sync groups, ignoring: {}", e.getMessage());
}
Expand Down Expand Up @@ -550,7 +550,7 @@ private List<HandleAction> handleSyncMessage(
final var contactsMessage = syncMessage.getContacts().get();
context.getAttachmentHelper()
.retrieveAttachment(contactsMessage.getContactsStream(),
context.getSyncHelper()::handleSyncDeviceContacts);
input -> context.getSyncHelper().handleSyncDeviceContacts(input, receiveConfig.ignoreAvatars()));
} catch (Exception e) {
logger.warn("Failed to handle received sync contacts, ignoring: {}", e.getMessage());
}
Expand All @@ -576,7 +576,7 @@ private List<HandleAction> handleSyncMessage(
final var sticker = context.getStickerHelper()
.addOrUpdateStickerPack(stickerPackId, stickerPackKey, installed);

if (sticker != null && installed) {
if (sticker != null && installed && !receiveConfig.ignoreStickers()) {
context.getJobExecutor().enqueueJob(new RetrieveStickerPackJob(stickerPackId, sticker.packKey()));
}
}
Expand Down Expand Up @@ -738,7 +738,7 @@ private List<HandleAction> handleSignalServiceDataMessage(
boolean isSync,
DeviceAddress source,
DeviceAddress destination,
boolean ignoreAttachments
ReceiveConfig receiveConfig
) {
var actions = new ArrayList<HandleAction>();
if (message.getGroupContext().isPresent()) {
Expand All @@ -757,7 +757,7 @@ private List<HandleAction> handleSignalServiceDataMessage(

if (groupInfo.getAvatar().isPresent()) {
var avatar = groupInfo.getAvatar().get();
context.getGroupHelper().downloadGroupAvatar(groupV1.getGroupId(), avatar);
context.getGroupHelper().downloadGroupAvatar(groupV1.getGroupId(), avatar, receiveConfig.ignoreAvatars());
}

if (groupInfo.getName().isPresent()) {
Expand Down Expand Up @@ -830,7 +830,7 @@ private List<HandleAction> handleSignalServiceDataMessage(
message.getExpireTimerVersion());
}
}
if (!ignoreAttachments) {
if (!receiveConfig.ignoreAttachments()) {
if (message.getAttachments().isPresent()) {
for (var attachment : message.getAttachments().get()) {
context.getAttachmentHelper().downloadAttachment(attachment);
Expand Down Expand Up @@ -878,7 +878,9 @@ private List<HandleAction> handleSignalServiceDataMessage(
sticker = new StickerPack(stickerPackId, messageSticker.getPackKey());
account.getStickerStore().addStickerPack(sticker);
}
context.getJobExecutor().enqueueJob(new RetrieveStickerPackJob(stickerPackId, messageSticker.getPackKey()));
if (!receiveConfig.ignoreStickers()) {
context.getJobExecutor().enqueueJob(new RetrieveStickerPackJob(stickerPackId, messageSticker.getPackKey()));
}
}
return actions;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,19 +275,26 @@ private boolean isProfileRefreshRequired(final Profile profile) {
private Profile decryptProfileAndDownloadAvatar(
final RecipientId recipientId,
final ProfileKey profileKey,
final SignalServiceProfile encryptedProfile
final SignalServiceProfile encryptedProfile,
final boolean ignoreAvatars
) {
final var avatarPath = encryptedProfile.getAvatar();
downloadProfileAvatar(recipientId, avatarPath, profileKey);
if (!ignoreAvatars) {
downloadProfileAvatar(recipientId, avatarPath, profileKey, ignoreAvatars);
}

return ProfileUtils.decryptProfile(profileKey, encryptedProfile);
}

public void downloadProfileAvatar(
final RecipientId recipientId,
final String avatarPath,
final ProfileKey profileKey
final ProfileKey profileKey,
final boolean ignoreAvatars
) {
if (ignoreAvatars) {
return;
}
var profile = account.getProfileStore().getProfile(recipientId);
if (profile == null || !Objects.equals(avatarPath, profile.getAvatarUrlPath())) {
logger.trace("Downloading profile avatar for {}", recipientId);
Expand Down Expand Up @@ -341,7 +348,7 @@ private Single<ProfileAndCredential> retrieveProfile(
Profile newProfile = null;
if (profileKey.isPresent()) {
logger.trace("Decrypting profile");
newProfile = decryptProfileAndDownloadAvatar(recipientId, profileKey.get(), encryptedProfile);
newProfile = decryptProfileAndDownloadAvatar(recipientId, profileKey.get(), encryptedProfile, false);
}

if (newProfile == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class ReceiveHelper {
private final SignalDependencies dependencies;
private final Context context;

private ReceiveConfig receiveConfig = new ReceiveConfig(false, false, false);
private ReceiveConfig receiveConfig = new ReceiveConfig(false, false, false, false, false);
private boolean hasCaughtUpWithOldMessages = false;
private boolean isWaitingForMessage = false;
private boolean shouldStop = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ public SendMessageResult sendConfigurationMessage() {
return context.getSendHelper().sendSyncMessage(SignalServiceSyncMessage.forConfiguration(configurationMessage));
}

public void handleSyncDeviceGroups(final InputStream input) {
public void handleSyncDeviceGroups(final InputStream input, final boolean ignoreAvatars) {
final var s = new DeviceGroupsInputStream(input);
DeviceGroup g;
while (true) {
Expand Down Expand Up @@ -327,15 +327,15 @@ public void handleSyncDeviceGroups(final InputStream input) {
}

if (g.getAvatar().isPresent()) {
context.getGroupHelper().downloadGroupAvatar(syncGroup.getGroupId(), g.getAvatar().get());
context.getGroupHelper().downloadGroupAvatar(syncGroup.getGroupId(), g.getAvatar().get(), ignoreAvatars);
}
syncGroup.archived = g.isArchived();
account.getGroupStore().updateGroup(syncGroup);
}
}
}

public void handleSyncDeviceContacts(final InputStream input) throws IOException {
public void handleSyncDeviceContacts(final InputStream input, final boolean ignoreAvatars) throws IOException {
final var s = new DeviceContactsInputStream(input);
DeviceContact c;
while (true) {
Expand Down Expand Up @@ -381,7 +381,7 @@ public void handleSyncDeviceContacts(final InputStream input) throws IOException
account.getContactStore().storeContact(recipientId, builder.build());

if (c.getAvatar().isPresent()) {
storeContactAvatar(c.getAvatar().get(), address);
storeContactAvatar(c.getAvatar().get(), address, ignoreAvatars);
}
}
}
Expand Down Expand Up @@ -430,7 +430,10 @@ private Optional<DeviceContactAvatar> createContactAvatarAttachment(RecipientAdd
streamDetails.getContentType()));
}

private void storeContactAvatar(DeviceContactAvatar avatar, RecipientAddress address) {
private void storeContactAvatar(DeviceContactAvatar avatar, RecipientAddress address, boolean ignoreAvatars) {
if (ignoreAvatars) {
return;
}
try {
context.getAvatarStore()
.storeContactAvatar(address,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ public void run(Context context) {
logger.trace("Downloading profile avatar {}", avatarPath);
final var account = context.getAccount();
context.getProfileHelper()
.downloadProfileAvatar(account.getSelfRecipientId(), avatarPath, account.getProfileKey());
.downloadProfileAvatar(account.getSelfRecipientId(), avatarPath, account.getProfileKey(), false);
}
}
18 changes: 18 additions & 0 deletions man/signal-cli.1.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,12 @@ Don’t download attachments of received messages.
*--ignore-stories*::
Don’t receive story messages from the server.

*--ignore-avatars*::
Don't download avatars of received messages.

*--ignore-stickers*::
Don't download sticker packs of received messages.


*--send-read-receipts*::
Send read receipts for all incoming data messages (in addition to the default delivery receipts)
Expand Down Expand Up @@ -950,6 +956,12 @@ Don’t download attachments of received messages.
*--ignore-stories*::
Don’t receive story messages from the server.

*--ignore-avatars*::
Don't download avatars of received messages.

*--ignore-stickers*::
Don't download sticker packs of received messages.

*--send-read-receipts*::
Send read receipts for all incoming data messages (in addition to the default delivery receipts)

Expand All @@ -971,6 +983,12 @@ Don’t download attachments of received messages.
*--ignore-stories*::
Don’t receive story messages from the server.

*--ignore-avatars*::
Don't download avatars of received messages.

*--ignore-stickers*::
Don't download sticker packs of received messages.

*--send-read-receipts*::
Send read receipts for all incoming data messages (in addition to the default delivery receipts)

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/asamk/signal/commands/DaemonCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ public void attachToSubparser(final Subparser subparser) {
subparser.addArgument("--ignore-stories")
.help("Don’t receive story messages from the server.")
.action(Arguments.storeTrue());
subparser.addArgument("--ignore-avatars")
.help("Don't download avatars of received messages.")
.action(Arguments.storeTrue());
subparser.addArgument("--ignore-stickers")
.help("Don't download sticker packs of received messages.")
.action(Arguments.storeTrue());
subparser.addArgument("--send-read-receipts")
.help("Send read receipts for all incoming data messages (in addition to the default delivery receipts)")
.action(Arguments.storeTrue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ public void attachToSubparser(final Subparser subparser) {
subparser.addArgument("--ignore-stories")
.help("Don’t receive story messages from the server.")
.action(Arguments.storeTrue());
subparser.addArgument("--ignore-avatars")
.help("Don't download avatars of received messages.")
.action(Arguments.storeTrue());
subparser.addArgument("--ignore-stickers")
.help("Don't download sticker packs of received messages.")
.action(Arguments.storeTrue());
subparser.addArgument("--send-read-receipts")
.help("Send read receipts for all incoming data messages (in addition to the default delivery receipts)")
.action(Arguments.storeTrue());
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/org/asamk/signal/commands/ReceiveCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ public void attachToSubparser(final Subparser subparser) {
subparser.addArgument("--ignore-stories")
.help("Don’t receive story messages from the server.")
.action(Arguments.storeTrue());
subparser.addArgument("--ignore-avatars")
.help("Don't download avatars of received messages.")
.action(Arguments.storeTrue());
subparser.addArgument("--ignore-stickers")
.help("Don't download sticker packs of received messages.")
.action(Arguments.storeTrue());
subparser.addArgument("--send-read-receipts")
.help("Send read receipts for all incoming data messages (in addition to the default delivery receipts)")
.action(Arguments.storeTrue());
Expand All @@ -76,8 +82,10 @@ public void handleCommand(
final var maxMessagesRaw = ns.getInt("max-messages");
final var ignoreAttachments = Boolean.TRUE.equals(ns.getBoolean("ignore-attachments"));
final var ignoreStories = Boolean.TRUE.equals(ns.getBoolean("ignore-stories"));
final var ignoreAvatars = Boolean.TRUE.equals(ns.getBoolean("ignore-avatars"));
final var ignoreStickers = Boolean.TRUE.equals(ns.getBoolean("ignore-stickers"));
final var sendReadReceipts = Boolean.TRUE.equals(ns.getBoolean("send-read-receipts"));
m.setReceiveConfig(new ReceiveConfig(ignoreAttachments, ignoreStories, sendReadReceipts));
m.setReceiveConfig(new ReceiveConfig(ignoreAttachments, ignoreStories, ignoreAvatars, ignoreStickers, sendReadReceipts));
try {
final var handler = switch (outputWriter) {
case JsonWriter writer -> new JsonReceiveMessageHandler(m, writer);
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/asamk/signal/util/CommandUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,10 @@ public static String getRateLimitMessage(final RateLimitException e) {
public static ReceiveConfig getReceiveConfig(final Namespace ns) {
final var ignoreAttachments = Boolean.TRUE.equals(ns.getBoolean("ignore-attachments"));
final var ignoreStories = Boolean.TRUE.equals(ns.getBoolean("ignore-stories"));
final var ignoreAvatars = Boolean.TRUE.equals(ns.getBoolean("ignore-avatars"));
final var ignoreStickers = Boolean.TRUE.equals(ns.getBoolean("ignore-stickers"));
final var sendReadReceipts = Boolean.TRUE.equals(ns.getBoolean("send-read-receipts"));

return new ReceiveConfig(ignoreAttachments, ignoreStories, sendReadReceipts);
return new ReceiveConfig(ignoreAttachments, ignoreStories, ignoreAvatars, ignoreStickers, sendReadReceipts);
}
}
Loading