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
8 changes: 1 addition & 7 deletions src/SIL.XForge.Scripture/Services/IParatextDataHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -12,11 +11,6 @@ namespace SIL.XForge.Scripture.Services;
public interface IParatextDataHelper
{
void CommitVersionedText(ScrText scrText, string comment);
IReadOnlyList<ParatextNote> GetNotes(
CommentManager? commentManager,
CommentTags? commentTags,
Func<CommentThread, bool>? predicate = null,
bool includeInactiveThreads = true
);
IReadOnlyList<ParatextNote> GetNotes(CommentManager commentManager, CommentTags commentTags);
Task MigrateResourceIfRequiredAsync(ScrText scrText, LanguageId? overrideLanguage, CancellationToken token);
}
39 changes: 12 additions & 27 deletions src/SIL.XForge.Scripture/Services/ParatextDataHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,13 @@ public void CommitVersionedText(ScrText scrText, string comment)
vText.Commit(comment, null, false);
}

public IReadOnlyList<ParatextNote> GetNotes(
CommentManager? commentManager,
CommentTags? commentTags,
Func<CommentThread, bool>? predicate = null,
bool includeInactiveThreads = true
)
public IReadOnlyList<ParatextNote> GetNotes(CommentManager commentManager, CommentTags commentTags)
{
if (commentManager == null)
return Array.Empty<ParatextNote>();

Func<CommentThread, bool> filter = predicate ?? (_ => true);
IEnumerable<CommentThread> threads = commentManager.FindThreads(filter, includeInactiveThreads);
// Only return note threads that are not resolved and active
IEnumerable<CommentThread> threads = commentManager.FindThreads(
t => t.Status != NoteStatus.Resolved,
activeOnly: true
);

var notes = new List<ParatextNote>();
foreach (CommentThread thread in threads)
Expand Down Expand Up @@ -156,7 +151,7 @@ CancellationToken token
}
}

private static ParatextNoteComment CreateNoteComment(ParatextComment comment, CommentTags? commentTags)
private static ParatextNoteComment CreateNoteComment(ParatextComment comment, CommentTags commentTags)
{
ParatextNoteTag? tag = null;
if (comment.TagsAdded is { Length: > 0 })
Expand All @@ -181,24 +176,14 @@ private static ParatextNoteComment CreateNoteComment(ParatextComment comment, Co
};
}

private static ParatextNoteTag CreateNoteTag(int tagId, CommentTags? commentTags)
private static ParatextNoteTag CreateNoteTag(int tagId, CommentTags commentTags)
{
if (commentTags != null)
{
CommentTag commentTag = commentTags.Get(tagId);
return new ParatextNoteTag
{
Id = commentTag.Id,
Name = commentTag.Name ?? string.Empty,
Icon = commentTag.Icon ?? string.Empty,
};
}

CommentTag commentTag = commentTags.Get(tagId);
return new ParatextNoteTag
{
Id = tagId,
Name = string.Empty,
Icon = string.Empty,
Id = commentTag.Id,
Name = commentTag.Name ?? string.Empty,
Icon = commentTag.Icon ?? string.Empty,
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/SIL.XForge.Scripture/Services/ParatextService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1276,7 +1276,7 @@ public async Task<int> PutBookText(
return null;

CommentManager manager = CommentManager.Get(scrText);
CommentTags? commentTags = CommentTags.Get(scrText);
CommentTags commentTags = CommentTags.Get(scrText);

return _paratextDataHelper.GetNotes(manager, commentTags);
}
Expand Down
22 changes: 10 additions & 12 deletions test/SIL.XForge.Scripture.Tests/Services/ParatextDataHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Paratext.Data.ProjectFileAccess;
using Paratext.Data.ProjectSettingsAccess;
using Paratext.Data.Repository;
using PtxUtils;
using SIL.WritingSystems;
using SIL.XForge.Scripture.Models;
using SIL.XForge.Services;
Expand Down Expand Up @@ -126,25 +127,20 @@ public void GetNotes_IncludesThreadsWithDeletedComments()
}

[Test]
public void GetNotes_FiltersThreadsWithPredicate()
public void GetNotes_ExcludeResolvedThreads()
{
var env = new TestEnvironment();
using MockScrText scrText = env.GetScrText(HexId.CreateNew().ToString());
var commentManager = CommentManager.Get(scrText);
var commentTags = new MockCommentTags(scrText);
commentTags.InitializeTagList([2]);
TestEnvironment.AddComment(scrText, "thread-05", "RUT 1:5", "First", "2");
TestEnvironment.AddComment(scrText, "thread-06", "RUT 1:6", "Second", "2");
commentTags.InitializeTagList([5]);
TestEnvironment.AddComment(scrText, "thread-04", "RUT 1:4", "Note to resolve", "5");
TestEnvironment.AddComment(scrText, "thread-04", "RUT 1:4", "This is resolved", "5", resolved: true);

// SUT
IReadOnlyList<ParatextNote> notes = env.Service.GetNotes(
commentManager,
commentTags,
thread => string.Equals(thread.Id, "thread-06", StringComparison.Ordinal)
);
IReadOnlyList<ParatextNote> notes = env.Service.GetNotes(commentManager, commentTags);

Assert.AreEqual(1, notes.Count);
Assert.AreEqual("thread-06", notes[0].Id);
Assert.AreEqual(0, notes.Count);
}

[Test]
Expand Down Expand Up @@ -345,7 +341,8 @@ public static void AddComment(
string verseRef,
string content,
string? tagValue,
bool deleted = false
bool deleted = false,
bool resolved = false
)
{
XmlDocument doc = new XmlDocument();
Expand All @@ -362,6 +359,7 @@ public static void AddComment(
Contents = root,
DateTime = DateTimeOffset.UtcNow,
Deleted = deleted,
Status = resolved ? NoteStatus.Resolved : NoteStatus.Todo,
SelectedText = string.Empty,
StartPosition = 0,
};
Expand Down
15 changes: 2 additions & 13 deletions test/SIL.XForge.Scripture.Tests/Services/ParatextServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -867,24 +867,13 @@ public void GetNoteThreads_ReturnsNotesFromDataHelper()
Comments = Array.Empty<ParatextNoteComment>(),
},
};
env.MockParatextDataHelper.GetNotes(
Arg.Any<CommentManager>(),
Arg.Any<CommentTags>(),
Arg.Any<Func<CommentThread, bool>>(),
Arg.Any<bool>()
)
.Returns(expectedNotes);
env.MockParatextDataHelper.GetNotes(Arg.Any<CommentManager>(), Arg.Any<CommentTags>()).Returns(expectedNotes);

IReadOnlyList<ParatextNote> actual = env.Service.GetNoteThreads(userSecret, paratextId);

Assert.AreSame(expectedNotes, actual);
env.MockParatextDataHelper.Received(1)
.GetNotes(
env.ProjectCommentManager,
Arg.Is<CommentTags>(tags => tags != null),
Arg.Any<Func<CommentThread, bool>>(),
true
);
.GetNotes(env.ProjectCommentManager, Arg.Is<CommentTags>(tags => tags != null));
}

[Test]
Expand Down
Loading