Skip to content

Commit

Permalink
fix some issues with chat search feature
Browse files Browse the repository at this point in the history
  • Loading branch information
RaidMax committed Aug 27, 2023
1 parent 4025cbc commit a2e5e94
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 118 deletions.
66 changes: 0 additions & 66 deletions Plugins/Stats/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public static class Extensions
{
private const int ZScoreRange = 3;
private const int RankIconDivisions = 24;
private const int MaxMessages = 100;

public class LogParams
{
Expand Down Expand Up @@ -127,70 +126,5 @@ public static int RankIconIndexForZScore(this double? zScore)

return 0;
}

/// <summary>
/// todo: lets abstract this out to a generic buildable query
/// this is just a dirty PoC
/// </summary>
/// <param name="query"></param>
/// <returns></returns>
public static ChatSearchQuery ParseSearchInfo(this string query, int count, int offset)
{
string[] filters = query.Split('|');
var searchRequest = new ChatSearchQuery
{
Filter = query,
Count = count,
Offset = offset
};

// sanity checks
searchRequest.Count = Math.Min(searchRequest.Count, MaxMessages);
searchRequest.Count = Math.Max(searchRequest.Count, 0);
searchRequest.Offset = Math.Max(searchRequest.Offset, 0);

if (filters.Length > 1)
{
if (filters[0].ToLower() != "chat")
{
throw new ArgumentException("Query is not compatible with chat");
}

foreach (string filter in filters.Skip(1))
{
string[] args = filter.Split(' ');

if (args.Length > 1)
{
string recombinedArgs = string.Join(' ', args.Skip(1));
switch (args[0].ToLower())
{
case "before":
searchRequest.SentBefore = DateTime.Parse(recombinedArgs);
break;
case "after":
searchRequest.SentAfter = DateTime.Parse(recombinedArgs);
break;
case "server":
searchRequest.ServerId = args[1];
break;
case "client":
searchRequest.ClientId = int.Parse(args[1]);
break;
case "contains":
searchRequest.MessageContains = string.Join(' ', args.Skip(1));
break;
case "sort":
searchRequest.Direction = Enum.Parse<SortDirection>(args[1], ignoreCase: true);
break;
}
}
}

return searchRequest;
}

throw new ArgumentException("No filters specified for chat search");
}
}
}
4 changes: 2 additions & 2 deletions SharedLibraryCore/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public static class Utilities
public static char[] DirectorySeparatorChars = { '\\', '/' };
public static char CommandPrefix { get; set; } = '!';

public static string ToStandardFormat(this DateTime? time) => time?.ToString("yyyy-MM-dd H:mm:ss UTC");
public static string ToStandardFormat(this DateTime time) => time.ToString("yyyy-MM-dd H:mm:ss UTC");
public static string ToStandardFormat(this DateTime? time) => time?.ToString("yyyy-MM-dd HH:mm:ss UTC");
public static string ToStandardFormat(this DateTime time) => time.ToString("yyyy-MM-dd HH:mm:ss UTC");

public static EFClient IW4MAdminClient(Server server = null)
{
Expand Down
24 changes: 2 additions & 22 deletions WebfrontCore/Controllers/Client/Legacy/StatsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,29 +137,9 @@ public async Task<IActionResult> FindMessage([FromQuery] ChatResourceRequest que
}

[HttpGet("Message/FindNext")]
public async Task<IActionResult> FindNextMessages([FromQuery] string query, [FromQuery] int count,
[FromQuery] int offset)
public async Task<IActionResult> FindNextMessages(ChatResourceRequest query)
{
ChatSearchQuery searchRequest;

try
{
searchRequest = query.ParseSearchInfo(count, offset);
}

catch (ArgumentException e)
{
_logger.LogWarning(e, "Could not parse chat message search query {query}", query);
throw;
}

catch (FormatException e)
{
_logger.LogWarning(e, "Could not parse chat message search query filter format {query}", query);
throw;
}

var result = await _chatResourceQueryHelper.QueryResource(searchRequest);
var result = await _chatResourceQueryHelper.QueryResource(query);
return PartialView("~/Views/Client/Message/_Item.cshtml", result.Results);
}

Expand Down
4 changes: 2 additions & 2 deletions WebfrontCore/Views/Client/Message/Find.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ else
</tbody>
</table>

<div id="loaderLoad" class="mt-10 m-auto text-center d-none d-lg-block">
<div id="loaderLoad" class="mt-10 m-auto text-center">
<i class="loader-load-more oi oi-chevron-bottom"></i>
</div>

@section scripts {
<script>
$(document).ready(function () {
initLoader('/Message/FindNext?query=@ViewBag.Query', '#message_table_body', @Model.RetrievedResultCount, @ViewBag.QueryLimit);
initLoader(`/Message/FindNext${window.location.search}`, '#message_table_body', @Model.RetrievedResultCount, 30);
});
</script>
}
Expand Down
4 changes: 3 additions & 1 deletion WebfrontCore/Views/Shared/Partials/Search/_ChatSearch.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
@foreach (var server in manager!.GetServers())
{
<option value="@server.Id" selected="@(server.Id == existingChatFilter?.ServerId)">
[@server.GameName.ToString()] @server.ServerName
[@server.GameName.ToString()] @server.ServerName.StripColors()
</option>
}
</select>
Expand All @@ -62,6 +62,7 @@
value="@afterDate.ToString("s", CultureInfo.InvariantCulture)"/>
<input type="time" class="form-control w-half ml-10" name="sentAfterTime"
id="sentAfterTime@(Model)"
style="color-scheme: dark;"
value="@afterDate.ToString("HH:mm")"/>

</div>
Expand All @@ -78,6 +79,7 @@
value="@beforeDate.ToString("s", CultureInfo.InvariantCulture)"/>
<input type="time" class="form-control w-half ml-10" name="sentBeforeTime"
id="sentBeforeTime@(Model)"
style="color-scheme: dark;"
value="@beforeDate.ToString("HH:mm")"/>
</div>
</div>
Expand Down
25 changes: 0 additions & 25 deletions WebfrontCore/wwwroot/js/search.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,4 @@
$(document).ready(function () {
$('.form-inline').submit(function (e) {
const id = $(e.currentTarget).find('input');
if ($(id).val().length < 3) {
e.preventDefault();
$(id)
.addClass('input-text-danger')
.delay(25)
.queue(function () {
$(this).addClass('input-border-transition').dequeue();
})
.delay(1000)
.queue(function () {
$(this).removeClass('input-text-danger').dequeue();
})
.delay(500)
.queue(function () {
$(this).removeClass('input-border-transition').dequeue();
});
} else if ($(id).val().startsWith("chat|")) {
e.preventDefault();
window.location = "/Message/Find?query=" + $(id).val();
}
});

$('.date-picker-input').each((index, selector) => {
new Datepicker(selector, {
buttonClass: 'btn',
Expand All @@ -33,7 +9,6 @@
});
});


const clientSearchWrapper = $('*[id^="clientSearchWrapper"]');
const chatSearchWrapper = $('*[id^="chatSearchWrapper"]');
const searchTypeSelector = $('#searchTypeSelectorParent select');
Expand Down

0 comments on commit a2e5e94

Please sign in to comment.