Skip to content

Commit

Permalink
Delete pending scheduled messages when leaving a group.
Browse files Browse the repository at this point in the history
  • Loading branch information
cody-signal committed Feb 2, 2023
1 parent a12a246 commit fe2d71f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@
import java.util.UUID;
import java.util.function.Function;

import kotlin.Unit;

import static org.thoughtcrime.securesms.contactshare.Contact.Avatar;

public class MessageTable extends DatabaseTable implements MessageTypes, RecipientIdDatabaseReference, ThreadIdDatabaseReference {
Expand Down Expand Up @@ -3110,6 +3112,22 @@ public void deleteScheduledMessage(long messageId) {
ApplicationDependencies.getDatabaseObserver().notifyScheduledMessageObservers(threadId);
}

public void deleteScheduledMessages(@NonNull RecipientId recipientId) {
Log.d(TAG, "deleteScheduledMessages(" + recipientId + ")");
Long threadId = SignalDatabase.threads().getThreadIdFor(recipientId);
if (threadId != null) {
SQLiteDatabaseExtensionsKt.withinTransaction(getWritableDatabase(), d -> {
List<MessageRecord> scheduledMessages = getScheduledMessagesInThread(threadId);
for (MessageRecord record : scheduledMessages) {
deleteScheduledMessage(record.getId());
}
return Unit.INSTANCE;
});
} else {
Log.i(TAG, "No thread exists for " + recipientId);
}
}

public void deleteThread(long threadId) {
Log.d(TAG, "deleteThread(" + threadId + ")");
Set<Long> singleThreadSet = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ public static void leaveGroup(@NonNull Context context, @NonNull GroupId.Push gr
throw new GroupChangeFailedException();
}
}

SignalDatabase.recipients().getByGroupId(groupId).ifPresent(id -> SignalDatabase.messages().deleteScheduledMessages(id));
}

@WorkerThread
Expand Down

0 comments on commit fe2d71f

Please sign in to comment.