Skip to content

Commit 1af2365

Browse files
committed
PR comments
1 parent 5d82840 commit 1af2365

15 files changed

+266
-422
lines changed
Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System;
21
using System.Collections.Generic;
32

43
namespace SIL.XForge.Scripture.Models;
@@ -8,33 +7,33 @@ namespace SIL.XForge.Scripture.Models;
87
/// </summary>
98
public class ParatextNote
109
{
11-
public string Id { get; set; } = string.Empty;
10+
public required string Id { get; init; }
1211

13-
public string VerseRef { get; set; } = string.Empty;
12+
public required string VerseRef { get; init; }
1413

15-
public IReadOnlyList<ParatextNoteComment> Comments { get; set; } = Array.Empty<ParatextNoteComment>();
14+
public required IReadOnlyList<ParatextNoteComment> Comments { get; init; }
1615
}
1716

1817
/// <summary>
1918
/// Represents a single comment that belongs to a Paratext note thread.
2019
/// </summary>
2120
public class ParatextNoteComment
2221
{
23-
public string VerseRef { get; set; } = string.Empty;
22+
public required string VerseRef { get; init; }
2423

25-
public string Content { get; set; } = string.Empty;
24+
public required string Content { get; init; }
2625

27-
public ParatextNoteTag? Tag { get; set; }
26+
public ParatextNoteTag? Tag { get; init; }
2827
}
2928

3029
/// <summary>
3130
/// Represents a Paratext comment tag that has been applied to a comment.
3231
/// </summary>
3332
public class ParatextNoteTag
3433
{
35-
public int Id { get; set; }
34+
public int Id { get; init; }
3635

37-
public string Name { get; set; } = string.Empty;
36+
public required string Name { get; init; }
3837

39-
public string Icon { get; set; } = string.Empty;
38+
public required string Icon { get; init; }
4039
}

src/SIL.XForge.Scripture/Models/Question.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ public class Question : ProjectData
1515
public DateTime? DateArchived { get; set; }
1616
public DateTime DateModified { get; set; }
1717
public DateTime DateCreated { get; set; }
18-
public string TransceleratorQuestionId { get; set; }
19-
public string ParatextNoteId { get; set; }
18+
public string? TransceleratorQuestionId { get; set; }
19+
public string? ParatextNoteId { get; set; }
2020
}

src/SIL.XForge.Scripture/Services/INotesService.cs

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1+
using System;
2+
using System.Collections.Generic;
13
using Paratext.Data;
4+
using Paratext.Data.ProjectComments;
5+
using SIL.XForge.Scripture.Models;
26

37
namespace SIL.XForge.Scripture.Services;
48

59
public interface IParatextDataHelper
610
{
711
void CommitVersionedText(ScrText scrText, string comment);
12+
13+
IReadOnlyList<ParatextNote> GetNotes(
14+
CommentManager? commentManager,
15+
CommentTags? commentTags,
16+
Func<CommentThread, bool>? predicate = null,
17+
bool includeInactiveThreads = true
18+
);
819
}

src/SIL.XForge.Scripture/Services/IParatextService.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.Threading;
44
using System.Threading.Tasks;
55
using System.Xml.Linq;
6-
using Paratext.Data.ProjectComments;
76
using SIL.Converters.Usj;
87
using SIL.XForge.Models;
98
using SIL.XForge.Realtime;
@@ -54,9 +53,8 @@ Task<int> PutBookText(
5453
Dictionary<int, string> chapterAuthors = null
5554
);
5655
string GetNotes(UserSecret userSecret, string paratextId, int bookNum);
57-
IReadOnlyList<ParatextNote> GetNoteThreads(UserSecret userSecret, string paratextId);
56+
IReadOnlyList<ParatextNote>? GetNoteThreads(UserSecret userSecret, string paratextId);
5857
SyncMetricInfo PutNotes(UserSecret userSecret, string paratextId, XElement notesElement);
59-
CommentTags? GetCommentTags(UserSecret userSecret, string paratextId);
6058
Task<SyncMetricInfo> UpdateParatextCommentsAsync(
6159
UserSecret userSecret,
6260
string paratextId,

src/SIL.XForge.Scripture/Services/NotesFormatter.cs

Lines changed: 4 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
using System;
21
using System.Collections.Generic;
3-
using System.Globalization;
42
using System.Linq;
5-
using System.Reflection;
63
using System.Text;
74
using System.Text.RegularExpressions;
85
using System.Xml;
@@ -23,18 +20,16 @@ namespace SIL.XForge.Scripture.Services;
2320
/// * Additional null checking
2421
/// * Code reformatting
2522
/// </remarks>
26-
public static class NotesFormatter
23+
public static partial class NotesFormatter
2724
{
2825
private const string NotesSchemaVersion = "1.1";
2926

3027
/// <summary>
3128
/// The regular expression for finding whitespace before XML tags.
3229
/// </summary>
3330
/// <remarks>This is used by <see cref="ParseNotesToXElement"/>.</remarks>
34-
private static readonly Regex WhitespaceBeforeTagsRegex = new Regex(
35-
@"\n\s*<",
36-
RegexOptions.CultureInvariant | RegexOptions.Compiled
37-
);
31+
[GeneratedRegex(@"\n\s*<", RegexOptions.CultureInvariant)]
32+
private static partial Regex WhitespaceBeforeTagsRegex();
3833

3934
#region Public methods
4035
/// <summary>
@@ -71,33 +66,10 @@ public static List<List<Comment>> ParseNotes(XElement noteXml, ParatextUser ptUs
7166
public static XElement ParseNotesToXElement(string text)
7267
{
7368
text = text.Trim().Replace("\r\n", "\n");
74-
text = WhitespaceBeforeTagsRegex.Replace(text, "<");
69+
text = WhitespaceBeforeTagsRegex().Replace(text, "<");
7570
return XElement.Parse(text, LoadOptions.PreserveWhitespace);
7671
}
7772

78-
/// <summary>
79-
/// Replaces numeric tag identifiers in note XML with the corresponding Paratext comment tag data.
80-
/// </summary>
81-
/// <param name="notesElement">The notes XML element.</param>
82-
/// <param name="commentTags">The Paratext comment tag collection.</param>
83-
public static void ReplaceTagIdentifiersWithCommentTags(XElement notesElement, CommentTags commentTags)
84-
{
85-
if (notesElement == null || commentTags == null)
86-
return;
87-
88-
List<XElement> tagElements = [.. notesElement.Descendants("tagAdded")];
89-
foreach (XElement tagElement in tagElements)
90-
{
91-
string elementValue = tagElement.Value;
92-
if (!int.TryParse(elementValue, NumberStyles.Integer, CultureInfo.InvariantCulture, out int tagId))
93-
continue;
94-
95-
CommentTag mappedTag = commentTags.Get(tagId);
96-
XElement replacement = CreateTagElement(tagElement.Name, mappedTag);
97-
tagElement.ReplaceWith(replacement);
98-
}
99-
}
100-
10173
#endregion
10274

10375
#region Private helper methods for formatting
@@ -199,48 +171,6 @@ private static XElement FormatSelection(ScriptureSelection selection)
199171
return selElem;
200172
}
201173

202-
private static XElement CreateTagElement(XName elementName, CommentTag commentTag)
203-
{
204-
XElement element = new XElement(elementName);
205-
if (commentTag == null)
206-
return element;
207-
208-
PropertyInfo[] properties = typeof(CommentTag).GetProperties(BindingFlags.Instance | BindingFlags.Public);
209-
foreach (PropertyInfo property in properties.Where(property => property.CanRead))
210-
{
211-
object value = property.GetValue(commentTag);
212-
if (value == null)
213-
continue;
214-
215-
string propertyValue;
216-
if (value is string stringValue)
217-
{
218-
if (string.IsNullOrEmpty(stringValue))
219-
continue;
220-
propertyValue = stringValue;
221-
}
222-
else if (value is int intValue)
223-
{
224-
propertyValue = intValue.ToString(CultureInfo.InvariantCulture);
225-
}
226-
else if (value is bool boolValue)
227-
{
228-
propertyValue = boolValue ? bool.TrueString : bool.FalseString;
229-
}
230-
else if (value is Enum enumValue)
231-
{
232-
propertyValue = enumValue.ToString();
233-
}
234-
else
235-
{
236-
continue;
237-
}
238-
239-
element.Add(new XElement(property.Name, propertyValue));
240-
}
241-
242-
return element;
243-
}
244174
#endregion
245175

246176
#region Private helper methods for parsing

src/SIL.XForge.Scripture/Services/NotesService.cs

Lines changed: 0 additions & 96 deletions
This file was deleted.

0 commit comments

Comments
 (0)