mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-21 09:20:19 +01:00
Rename OutgoingMediaMessage -> OutgoingMessage.
This commit is contained in:
@@ -67,7 +67,7 @@ import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
||||
import org.thoughtcrime.securesms.linkpreview.LinkPreview;
|
||||
import org.thoughtcrime.securesms.mediasend.Media;
|
||||
import org.thoughtcrime.securesms.mms.MmsException;
|
||||
import org.thoughtcrime.securesms.mms.OutgoingMediaMessage;
|
||||
import org.thoughtcrime.securesms.mms.OutgoingMessage;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientId;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientUtil;
|
||||
@@ -107,7 +107,7 @@ public class MessageSender {
|
||||
}
|
||||
|
||||
public static void sendStories(@NonNull final Context context,
|
||||
@NonNull final List<OutgoingMediaMessage> messages,
|
||||
@NonNull final List<OutgoingMessage> messages,
|
||||
@Nullable final String metricId,
|
||||
@Nullable final MessageTable.InsertListener insertListener)
|
||||
{
|
||||
@@ -121,7 +121,7 @@ public class MessageSender {
|
||||
try {
|
||||
database.beginTransaction();
|
||||
|
||||
for (OutgoingMediaMessage message : messages) {
|
||||
for (OutgoingMessage message : messages) {
|
||||
long allocatedThreadId = threadTable.getOrCreateValidThreadId(message.getRecipient(), -1L, message.getDistributionType());
|
||||
long messageId = database.insertMessageOutbox(message.stripAttachments(), allocatedThreadId, false, insertListener);
|
||||
|
||||
@@ -136,9 +136,9 @@ public class MessageSender {
|
||||
}
|
||||
|
||||
for (int i = 0; i < messageIds.size(); i++) {
|
||||
long messageId = messageIds.get(i);
|
||||
OutgoingMediaMessage message = messages.get(i);
|
||||
Recipient recipient = message.getRecipient();
|
||||
long messageId = messageIds.get(i);
|
||||
OutgoingMessage message = messages.get(i);
|
||||
Recipient recipient = message.getRecipient();
|
||||
|
||||
if (recipient.isDistributionList()) {
|
||||
DistributionId distributionId = Objects.requireNonNull(SignalDatabase.distributionLists().getDistributionId(recipient.requireDistributionListId()));
|
||||
@@ -162,7 +162,7 @@ public class MessageSender {
|
||||
|
||||
for (int i = 0; i < messageIds.size(); i++) {
|
||||
long messageId = messageIds.get(i);
|
||||
OutgoingMediaMessage message = messages.get(i);
|
||||
OutgoingMessage message = messages.get(i);
|
||||
List<UploadDependencyGraph.Node> nodes = dependencyGraph.getDependencyMap().get(message);
|
||||
|
||||
if (nodes == null || nodes.isEmpty()) {
|
||||
@@ -196,9 +196,9 @@ public class MessageSender {
|
||||
}
|
||||
|
||||
for (int i = 0; i < messageIds.size(); i++) {
|
||||
long messageId = messageIds.get(i);
|
||||
OutgoingMediaMessage message = messages.get(i);
|
||||
Recipient recipient = message.getRecipient();
|
||||
long messageId = messageIds.get(i);
|
||||
OutgoingMessage message = messages.get(i);
|
||||
Recipient recipient = message.getRecipient();
|
||||
List<UploadDependencyGraph.Node> dependencies = dependencyGraph.getDependencyMap().get(message);
|
||||
|
||||
List<String> jobDependencyIds = (dependencies != null) ? dependencies.stream().map(UploadDependencyGraph.Node::getJobId).collect(Collectors.toList())
|
||||
@@ -219,7 +219,7 @@ public class MessageSender {
|
||||
}
|
||||
|
||||
public static long send(final Context context,
|
||||
final OutgoingMediaMessage message,
|
||||
final OutgoingMessage message,
|
||||
final long threadId,
|
||||
final boolean forceSms,
|
||||
@Nullable final String metricId,
|
||||
@@ -252,7 +252,7 @@ public class MessageSender {
|
||||
}
|
||||
|
||||
public static long sendPushWithPreUploadedMedia(final Context context,
|
||||
final OutgoingMediaMessage message,
|
||||
final OutgoingMessage message,
|
||||
final Collection<PreUploadResult> preUploadResults,
|
||||
final long threadId,
|
||||
final MessageTable.InsertListener insertListener)
|
||||
@@ -296,7 +296,7 @@ public class MessageSender {
|
||||
}
|
||||
|
||||
public static void sendMediaBroadcast(@NonNull Context context,
|
||||
@NonNull List<OutgoingMediaMessage> messages,
|
||||
@NonNull List<OutgoingMessage> messages,
|
||||
@NonNull Collection<PreUploadResult> preUploadResults,
|
||||
boolean overwritePreUploadMessageIds)
|
||||
{
|
||||
@@ -304,15 +304,15 @@ public class MessageSender {
|
||||
Preconditions.checkArgument(messages.size() > 0, "No messages!");
|
||||
Preconditions.checkArgument(Stream.of(messages).allMatch(m -> m.getAttachments().isEmpty()), "Messages can't have attachments! They should be pre-uploaded.");
|
||||
|
||||
JobManager jobManager = ApplicationDependencies.getJobManager();
|
||||
AttachmentTable attachmentDatabase = SignalDatabase.attachments();
|
||||
MessageTable mmsDatabase = SignalDatabase.mms();
|
||||
ThreadTable threadTable = SignalDatabase.threads();
|
||||
List<AttachmentId> preUploadAttachmentIds = Stream.of(preUploadResults).map(PreUploadResult::getAttachmentId).toList();
|
||||
List<String> preUploadJobIds = Stream.of(preUploadResults).map(PreUploadResult::getJobIds).flatMap(Stream::of).toList();
|
||||
List<Long> messageIds = new ArrayList<>(messages.size());
|
||||
List<String> messageDependsOnIds = new ArrayList<>(preUploadJobIds);
|
||||
OutgoingMediaMessage primaryMessage = messages.get(0);
|
||||
JobManager jobManager = ApplicationDependencies.getJobManager();
|
||||
AttachmentTable attachmentDatabase = SignalDatabase.attachments();
|
||||
MessageTable mmsDatabase = SignalDatabase.mms();
|
||||
ThreadTable threadTable = SignalDatabase.threads();
|
||||
List<AttachmentId> preUploadAttachmentIds = Stream.of(preUploadResults).map(PreUploadResult::getAttachmentId).toList();
|
||||
List<String> preUploadJobIds = Stream.of(preUploadResults).map(PreUploadResult::getJobIds).flatMap(Stream::of).toList();
|
||||
List<Long> messageIds = new ArrayList<>(messages.size());
|
||||
List<String> messageDependsOnIds = new ArrayList<>(preUploadJobIds);
|
||||
OutgoingMessage primaryMessage = messages.get(0);
|
||||
|
||||
mmsDatabase.beginTransaction();
|
||||
try {
|
||||
@@ -337,14 +337,14 @@ public class MessageSender {
|
||||
.toList();
|
||||
|
||||
if (messages.size() > 0) {
|
||||
List<OutgoingMediaMessage> secondaryMessages = overwritePreUploadMessageIds ? messages.subList(1, messages.size()) : messages;
|
||||
List<List<AttachmentId>> attachmentCopies = new ArrayList<>();
|
||||
List<OutgoingMessage> secondaryMessages = overwritePreUploadMessageIds ? messages.subList(1, messages.size()) : messages;
|
||||
List<List<AttachmentId>> attachmentCopies = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < preUploadAttachmentIds.size(); i++) {
|
||||
attachmentCopies.add(new ArrayList<>(messages.size()));
|
||||
}
|
||||
|
||||
for (OutgoingMediaMessage secondaryMessage : secondaryMessages) {
|
||||
for (OutgoingMessage secondaryMessage : secondaryMessages) {
|
||||
long allocatedThreadId = threadTable.getOrCreateThreadIdFor(secondaryMessage.getRecipient(), secondaryMessage.getDistributionType());
|
||||
long messageId = mmsDatabase.insertMessageOutbox(applyUniversalExpireTimerIfNecessary(context, secondaryMessage.getRecipient(), secondaryMessage, allocatedThreadId),
|
||||
allocatedThreadId,
|
||||
@@ -376,9 +376,9 @@ public class MessageSender {
|
||||
}
|
||||
|
||||
for (int i = 0; i < messageIds.size(); i++) {
|
||||
long messageId = messageIds.get(i);
|
||||
OutgoingMediaMessage message = messages.get(i);
|
||||
Recipient recipient = message.getRecipient();
|
||||
long messageId = messageIds.get(i);
|
||||
OutgoingMessage message = messages.get(i);
|
||||
Recipient recipient = message.getRecipient();
|
||||
|
||||
if (recipient.isDistributionList()) {
|
||||
List<RecipientId> members = SignalDatabase.distributionLists().getMembers(recipient.requireDistributionListId());
|
||||
@@ -507,11 +507,11 @@ public class MessageSender {
|
||||
EventBus.getDefault().postSticky(MessageSentEvent.INSTANCE);
|
||||
}
|
||||
|
||||
private static @NonNull OutgoingMediaMessage applyUniversalExpireTimerIfNecessary(@NonNull Context context, @NonNull Recipient recipient, @NonNull OutgoingMediaMessage outgoingMediaMessage, long threadId) {
|
||||
if (!outgoingMediaMessage.isExpirationUpdate() && outgoingMediaMessage.getExpiresIn() == 0 && RecipientUtil.setAndSendUniversalExpireTimerIfNecessary(context, recipient, threadId)) {
|
||||
return outgoingMediaMessage.withExpiry(TimeUnit.SECONDS.toMillis(SignalStore.settings().getUniversalExpireTimer()));
|
||||
private static @NonNull OutgoingMessage applyUniversalExpireTimerIfNecessary(@NonNull Context context, @NonNull Recipient recipient, @NonNull OutgoingMessage outgoingMessage, long threadId) {
|
||||
if (!outgoingMessage.isExpirationUpdate() && outgoingMessage.getExpiresIn() == 0 && RecipientUtil.setAndSendUniversalExpireTimerIfNecessary(context, recipient, threadId)) {
|
||||
return outgoingMessage.withExpiry(TimeUnit.SECONDS.toMillis(SignalStore.settings().getUniversalExpireTimer()));
|
||||
}
|
||||
return outgoingMediaMessage;
|
||||
return outgoingMessage;
|
||||
}
|
||||
|
||||
private static void sendMediaMessage(Context context, Recipient recipient, boolean forceSms, long messageId, @NonNull Collection<String> uploadJobIds)
|
||||
@@ -624,9 +624,9 @@ public class MessageSender {
|
||||
try {
|
||||
ExpiringMessageManager expirationManager = ApplicationDependencies.getExpiringMessageManager();
|
||||
MessageTable mmsDatabase = SignalDatabase.mms();
|
||||
MmsSmsTable mmsSmsDatabase = SignalDatabase.mmsSms();
|
||||
OutgoingMediaMessage message = mmsDatabase.getOutgoingMessage(messageId);
|
||||
SyncMessageId syncId = new SyncMessageId(Recipient.self().getId(), message.getSentTimeMillis());
|
||||
MmsSmsTable mmsSmsDatabase = SignalDatabase.mmsSms();
|
||||
OutgoingMessage message = mmsDatabase.getOutgoingMessage(messageId);
|
||||
SyncMessageId syncId = new SyncMessageId(Recipient.self().getId(), message.getSentTimeMillis());
|
||||
List<Attachment> attachments = new LinkedList<>();
|
||||
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import org.thoughtcrime.securesms.jobs.AttachmentCompressionJob
|
||||
import org.thoughtcrime.securesms.jobs.AttachmentCopyJob
|
||||
import org.thoughtcrime.securesms.jobs.AttachmentUploadJob
|
||||
import org.thoughtcrime.securesms.jobs.ResumableUploadSpecJob
|
||||
import org.thoughtcrime.securesms.mms.OutgoingMediaMessage
|
||||
import org.thoughtcrime.securesms.mms.OutgoingMessage
|
||||
|
||||
/**
|
||||
* Helper alias for working with JobIds.
|
||||
@@ -27,7 +27,7 @@ private typealias JobId = String
|
||||
* @param deferredJobQueue A list of job chains that can be executed on the job manager when ready (outside of a database transaction).
|
||||
*/
|
||||
class UploadDependencyGraph private constructor(
|
||||
val dependencyMap: Map<OutgoingMediaMessage, List<Node>>,
|
||||
val dependencyMap: Map<OutgoingMessage, List<Node>>,
|
||||
private val deferredJobQueue: List<JobManager.Chain>
|
||||
) {
|
||||
|
||||
@@ -100,7 +100,7 @@ class UploadDependencyGraph private constructor(
|
||||
@JvmStatic
|
||||
@WorkerThread
|
||||
fun create(
|
||||
messages: List<OutgoingMediaMessage>,
|
||||
messages: List<OutgoingMessage>,
|
||||
jobManager: JobManager,
|
||||
insertAttachmentForPreUpload: (Attachment) -> DatabaseAttachment
|
||||
): UploadDependencyGraph {
|
||||
@@ -111,8 +111,8 @@ class UploadDependencyGraph private constructor(
|
||||
* Produce a mapping of AttachmentKey{DatabaseAttachment,TransformProperties} -> Set<OutgoingMediaMessage>
|
||||
* This map represents which messages require a specific attachment.
|
||||
*/
|
||||
private fun buildAttachmentMap(messages: List<OutgoingMediaMessage>, insertAttachmentForPreUpload: (Attachment) -> DatabaseAttachment): Map<AttachmentKey<DatabaseAttachment>, Set<OutgoingMediaMessage>> {
|
||||
val attachmentMap = mutableMapOf<AttachmentKey<DatabaseAttachment>, Set<OutgoingMediaMessage>>()
|
||||
private fun buildAttachmentMap(messages: List<OutgoingMessage>, insertAttachmentForPreUpload: (Attachment) -> DatabaseAttachment): Map<AttachmentKey<DatabaseAttachment>, Set<OutgoingMessage>> {
|
||||
val attachmentMap = mutableMapOf<AttachmentKey<DatabaseAttachment>, Set<OutgoingMessage>>()
|
||||
val preUploadCache = mutableMapOf<AttachmentKey<UriAttachment>, DatabaseAttachment>()
|
||||
|
||||
for (message in messages) {
|
||||
@@ -125,12 +125,12 @@ class UploadDependencyGraph private constructor(
|
||||
for (attachmentKey in uniqueAttachments) {
|
||||
when (val attachment = attachmentKey.attachment) {
|
||||
is DatabaseAttachment -> {
|
||||
val messageIdList: Set<OutgoingMediaMessage> = attachmentMap.getOrDefault(attachment.asDatabaseAttachmentKey(), emptySet())
|
||||
val messageIdList: Set<OutgoingMessage> = attachmentMap.getOrDefault(attachment.asDatabaseAttachmentKey(), emptySet())
|
||||
attachmentMap[attachment.asDatabaseAttachmentKey()] = messageIdList + message
|
||||
}
|
||||
is UriAttachment -> {
|
||||
val dbAttachmentKey: AttachmentKey<DatabaseAttachment> = preUploadCache.getOrPut(attachment.asUriAttachmentKey()) { insertAttachmentForPreUpload(attachment) }.asDatabaseAttachmentKey()
|
||||
val messageIdList: Set<OutgoingMediaMessage> = attachmentMap.getOrDefault(dbAttachmentKey, emptySet())
|
||||
val messageIdList: Set<OutgoingMessage> = attachmentMap.getOrDefault(dbAttachmentKey, emptySet())
|
||||
attachmentMap[dbAttachmentKey] = messageIdList + message
|
||||
}
|
||||
else -> {
|
||||
@@ -148,7 +148,7 @@ class UploadDependencyGraph private constructor(
|
||||
* Each attachment will be uploaded exactly once and copied N times, where N is the number of messages in its set, minus 1 (the upload)
|
||||
* The resulting object contains a list of jobs that a subsequent send job can depend on, as well as a list of Chains which can be
|
||||
* enqueued to perform uploading. Since a send job can depend on multiple chains, it's cleaner to give back a mapping of
|
||||
* [OutgoingMediaMessage] -> [List<Node>] instead of forcing the caller to try to weave new jobs into the original chains.
|
||||
* [OutgoingMessage] -> [List<Node>] instead of forcing the caller to try to weave new jobs into the original chains.
|
||||
*
|
||||
* Each chain consists of:
|
||||
* 1. Compression job
|
||||
@@ -157,23 +157,23 @@ class UploadDependencyGraph private constructor(
|
||||
* 1. O to 1 copy jobs
|
||||
*/
|
||||
private fun buildDependencyGraph(
|
||||
attachmentIdToOutgoingMessagesMap: Map<AttachmentKey<DatabaseAttachment>, Set<OutgoingMediaMessage>>,
|
||||
attachmentIdToOutgoingMessagesMap: Map<AttachmentKey<DatabaseAttachment>, Set<OutgoingMessage>>,
|
||||
jobManager: JobManager,
|
||||
insertAttachmentForPreUpload: (Attachment) -> DatabaseAttachment
|
||||
): UploadDependencyGraph {
|
||||
val resultMap = mutableMapOf<OutgoingMediaMessage, List<Node>>()
|
||||
val resultMap = mutableMapOf<OutgoingMessage, List<Node>>()
|
||||
val jobQueue = mutableListOf<JobManager.Chain>()
|
||||
|
||||
for ((attachmentKey, messages) in attachmentIdToOutgoingMessagesMap) {
|
||||
val (uploadJobId, uploadChain) = createAttachmentUploadChain(jobManager, attachmentKey.attachment)
|
||||
val uploadMessage: OutgoingMediaMessage = messages.first()
|
||||
val copyMessages: List<OutgoingMediaMessage> = messages.drop(1)
|
||||
val uploadMessage: OutgoingMessage = messages.first()
|
||||
val copyMessages: List<OutgoingMessage> = messages.drop(1)
|
||||
|
||||
val uploadMessageDependencies: List<Node> = resultMap.getOrDefault(uploadMessage, emptyList())
|
||||
resultMap[uploadMessage] = uploadMessageDependencies + Node(uploadJobId, attachmentKey.attachment.attachmentId)
|
||||
|
||||
if (copyMessages.isNotEmpty()) {
|
||||
val copyAttachments: Map<OutgoingMediaMessage, AttachmentId> = copyMessages.associateWith { insertAttachmentForPreUpload(attachmentKey.attachment).attachmentId }
|
||||
val copyAttachments: Map<OutgoingMessage, AttachmentId> = copyMessages.associateWith { insertAttachmentForPreUpload(attachmentKey.attachment).attachmentId }
|
||||
val copyJob = AttachmentCopyJob(attachmentKey.attachment.attachmentId, copyAttachments.values.toList())
|
||||
|
||||
copyAttachments.forEach { (message, attachmentId) ->
|
||||
|
||||
Reference in New Issue
Block a user