Fixed an issue with loading mails with infinite scroll.
This commit is contained in:
@@ -148,15 +148,15 @@ public class MailService : BaseDatabaseService, IMailService
|
|||||||
{
|
{
|
||||||
var sql = new StringBuilder();
|
var sql = new StringBuilder();
|
||||||
sql.Append("SELECT MailCopy.* FROM MailCopy INNER JOIN MailItemFolder ON MailCopy.FolderId = MailItemFolder.Id");
|
sql.Append("SELECT MailCopy.* FROM MailCopy INNER JOIN MailItemFolder ON MailCopy.FolderId = MailItemFolder.Id");
|
||||||
|
|
||||||
var whereClauses = new List<string>();
|
var whereClauses = new List<string>();
|
||||||
var parameters = new List<object>();
|
var parameters = new List<object>();
|
||||||
|
|
||||||
// Folder filter
|
// Folder filter
|
||||||
var folderPlaceholders = string.Join(",", options.Folders.Select(_ => "?"));
|
var folderPlaceholders = string.Join(",", options.Folders.Select(_ => "?"));
|
||||||
whereClauses.Add($"MailCopy.FolderId IN ({folderPlaceholders})");
|
whereClauses.Add($"MailCopy.FolderId IN ({folderPlaceholders})");
|
||||||
parameters.AddRange(options.Folders.Select(f => (object)f.Id));
|
parameters.AddRange(options.Folders.Select(f => (object)f.Id));
|
||||||
|
|
||||||
// Filter type
|
// Filter type
|
||||||
switch (options.FilterType)
|
switch (options.FilterType)
|
||||||
{
|
{
|
||||||
@@ -170,13 +170,13 @@ public class MailService : BaseDatabaseService, IMailService
|
|||||||
whereClauses.Add("MailCopy.HasAttachments = 1");
|
whereClauses.Add("MailCopy.HasAttachments = 1");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Focused filter
|
// Focused filter
|
||||||
if (options.IsFocusedOnly != null)
|
if (options.IsFocusedOnly != null)
|
||||||
{
|
{
|
||||||
whereClauses.Add($"MailCopy.IsFocused = {(options.IsFocusedOnly.Value ? "1" : "0")}");
|
whereClauses.Add($"MailCopy.IsFocused = {(options.IsFocusedOnly.Value ? "1" : "0")}");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Search query
|
// Search query
|
||||||
if (!string.IsNullOrEmpty(options.SearchQuery))
|
if (!string.IsNullOrEmpty(options.SearchQuery))
|
||||||
{
|
{
|
||||||
@@ -187,36 +187,36 @@ public class MailService : BaseDatabaseService, IMailService
|
|||||||
parameters.Add(searchPattern);
|
parameters.Add(searchPattern);
|
||||||
parameters.Add(searchPattern);
|
parameters.Add(searchPattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exclude existing items
|
// Exclude existing items
|
||||||
if (options.ExistingUniqueIds?.Any() ?? false)
|
if (options.ExistingUniqueIds?.Any() ?? false)
|
||||||
{
|
{
|
||||||
var excludePlaceholders = string.Join(",", options.ExistingUniqueIds.Select(_ => "?"));
|
var excludePlaceholders = string.Join(",", options.ExistingUniqueIds.Select(_ => "?"));
|
||||||
whereClauses.Add($"MailCopy.UniqueId NOT IN ({excludePlaceholders})");
|
whereClauses.Add($"MailCopy.UniqueId NOT IN ({excludePlaceholders})");
|
||||||
parameters.AddRange(options.ExistingUniqueIds.Select(id => (object)id));
|
parameters.AddRange(options.ExistingUniqueIds.Keys.Select(id => (object)id));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (whereClauses.Any())
|
if (whereClauses.Any())
|
||||||
{
|
{
|
||||||
sql.Append(" WHERE ");
|
sql.Append(" WHERE ");
|
||||||
sql.Append(string.Join(" AND ", whereClauses));
|
sql.Append(string.Join(" AND ", whereClauses));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sorting
|
// Sorting
|
||||||
if (options.SortingOptionType == SortingOptionType.ReceiveDate)
|
if (options.SortingOptionType == SortingOptionType.ReceiveDate)
|
||||||
sql.Append(" ORDER BY CreationDate DESC");
|
sql.Append(" ORDER BY CreationDate DESC");
|
||||||
else if (options.SortingOptionType == SortingOptionType.Sender)
|
else if (options.SortingOptionType == SortingOptionType.Sender)
|
||||||
sql.Append(" ORDER BY FromName ASC");
|
sql.Append(" ORDER BY FromName ASC");
|
||||||
|
|
||||||
// Pagination
|
// Pagination
|
||||||
var limit = options.Take > 0 ? options.Take : ItemLoadCount;
|
var limit = options.Take > 0 ? options.Take : ItemLoadCount;
|
||||||
sql.Append($" LIMIT {limit}");
|
sql.Append($" LIMIT {limit}");
|
||||||
|
|
||||||
if (options.Skip > 0)
|
if (options.Skip > 0)
|
||||||
{
|
{
|
||||||
sql.Append($" OFFSET {options.Skip}");
|
sql.Append($" OFFSET {options.Skip}");
|
||||||
}
|
}
|
||||||
|
|
||||||
return (sql.ToString(), parameters.ToArray());
|
return (sql.ToString(), parameters.ToArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -283,10 +283,10 @@ public class MailService : BaseDatabaseService, IMailService
|
|||||||
});
|
});
|
||||||
|
|
||||||
var processedThreadMails = await Task.WhenAll(tasks).ConfigureAwait(false);
|
var processedThreadMails = await Task.WhenAll(tasks).ConfigureAwait(false);
|
||||||
|
|
||||||
// Filter out items with no assigned account or folder
|
// Filter out items with no assigned account or folder
|
||||||
var validThreadMails = processedThreadMails.Where(m => m.AssignedAccount != null && m.AssignedFolder != null);
|
var validThreadMails = processedThreadMails.Where(m => m.AssignedAccount != null && m.AssignedFolder != null);
|
||||||
|
|
||||||
expandedMails.AddRange(validThreadMails);
|
expandedMails.AddRange(validThreadMails);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -939,13 +939,13 @@ public class MailService : BaseDatabaseService, IMailService
|
|||||||
if (!string.IsNullOrEmpty(referenceMessage.MessageId))
|
if (!string.IsNullOrEmpty(referenceMessage.MessageId))
|
||||||
{
|
{
|
||||||
message.InReplyTo = referenceMessage.MessageId;
|
message.InReplyTo = referenceMessage.MessageId;
|
||||||
|
|
||||||
// Add all previous References first
|
// Add all previous References first
|
||||||
if (referenceMessage.References != null && referenceMessage.References.Count > 0)
|
if (referenceMessage.References != null && referenceMessage.References.Count > 0)
|
||||||
{
|
{
|
||||||
message.References.AddRange(referenceMessage.References);
|
message.References.AddRange(referenceMessage.References);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Then add the message we're replying to
|
// Then add the message we're replying to
|
||||||
message.References.Add(referenceMessage.MessageId);
|
message.References.Add(referenceMessage.MessageId);
|
||||||
}
|
}
|
||||||
@@ -957,7 +957,7 @@ public class MailService : BaseDatabaseService, IMailService
|
|||||||
if (referenceMailCopy != null && !string.IsNullOrEmpty(referenceMailCopy.MessageId))
|
if (referenceMailCopy != null && !string.IsNullOrEmpty(referenceMailCopy.MessageId))
|
||||||
{
|
{
|
||||||
message.InReplyTo = referenceMailCopy.MessageId;
|
message.InReplyTo = referenceMailCopy.MessageId;
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(referenceMailCopy.References))
|
if (!string.IsNullOrEmpty(referenceMailCopy.References))
|
||||||
{
|
{
|
||||||
// Parse the References string and add them
|
// Parse the References string and add them
|
||||||
@@ -967,7 +967,7 @@ public class MailService : BaseDatabaseService, IMailService
|
|||||||
message.References.Add(reference.Trim());
|
message.References.Add(reference.Trim());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
message.References.Add(referenceMailCopy.MessageId);
|
message.References.Add(referenceMailCopy.MessageId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user