Skip to content

Commit

Permalink
Tweaks to codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Rarisma committed Jul 20, 2024
1 parent efb8338 commit 383735b
Show file tree
Hide file tree
Showing 10 changed files with 275 additions and 51 deletions.
22 changes: 21 additions & 1 deletion ArticleDB.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,24 @@ CREATE TABLE IF NOT EXISTS ARTICLES (
EXECUTIVES_MENTIONED LONGTEXT -- List of executives
);

select * from ARTICLES;
DELIMITER //
CREATE PROCEDURE IncrementClickbaitCount(IN p_url VARCHAR(255))
BEGIN
UPDATE Articles
SET TimesReportedAsClickbait = TimesReportedAsClickbait + 1
WHERE URL = p_url;
END //
DELIMITER ;

DELIMITER //
CREATE PROCEDURE IncrementSummaryReportCount(IN p_url VARCHAR(255))
BEGIN
UPDATE Articles
SET TimesReportedAsSummaryReported = TimesReportedAsSummaryReported + 1
WHERE URL = p_url;
END //
DELIMITER ;

select * from Articles;
SELECT ARTICLE_TEXT FROM ARTICLES WHERE URL =

11 changes: 11 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,33 @@
<PackageVersion Include="DSharpPlus.SlashCommands" Version="5.0.0-nightly-02298" />
<PackageVersion Include="Google.Apis.YouTube.v3" Version="1.68.0.3421" />
<PackageVersion Include="HtmlAgilityPack" Version="1.11.61" />
<PackageVersion Include="JetBrains.Annotations" Version="2024.2.0" />
<PackageVersion Include="LLamaSharp" Version="0.11.2" />
<PackageVersion Include="LLamaSharp.Backend.Cuda12" Version="0.11.2" />
<PackageVersion Include="Lofcz.Forks.YoutubeTranscriptApi" Version="0.4.2" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
<PackageVersion Include="Microsoft.Maui.Controls" Version="8.0.70" />
<PackageVersion Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.70" />
<PackageVersion Include="Microsoft.ML.OnnxRuntime" Version="1.18.1" />
<PackageVersion Include="Microsoft.OpenApi" Version="1.6.15" />
<PackageVersion Include="Microsoft.Windows.Compatibility" Version="8.0.6" />
<PackageVersion Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.1" />
<PackageVersion Include="Microsoft.WindowsAppSDK" Version="1.5.240428000" />
<PackageVersion Include="MySql.Data" Version="8.4.0" />
<PackageVersion Include="MySqlConnector" Version="2.3.7" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="OpenAI" Version="2.0.0-beta.7" />
<PackageVersion Include="OpenGraph-Net" Version="4.0.1" />
<PackageVersion Include="PdfPig" Version="0.1.8" />
<PackageVersion Include="PDFsharp" Version="6.1.1" />
<PackageVersion Include="SkiaSharp.Skottie" Version="2.88.8" />
<PackageVersion Include="SkiaSharp.Views.Uno.WinUI" Version="2.88.8" />
<PackageVersion Include="SmartReader" Version="0.9.5" />
<PackageVersion Include="Svg.Skia" Version="1.0.0.18" />
<PackageVersion Include="System.Drawing.Common" Version="4.7.3" />
<PackageVersion Include="System.Management" Version="8.0.0" />
<PackageVersion Include="Terminal.Gui" Version="2.0.0-prealpha.1829" />
<PackageVersion Include="Uno.Core.Extensions.Logging.Singleton" Version="4.0.1" />
<PackageVersion Include="Uno.Extensions.Logging.OSLog" Version="1.7.0" />
<PackageVersion Include="Uno.Extensions.Logging.WebAssembly.Console" Version="1.7.0" />
Expand All @@ -53,5 +62,7 @@
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.6.2" />
<PackageVersion Include="System.ServiceModel.Syndication" Version="8.0.0" />
<PackageVersion Include="YahooFinanceApi" Version="2.3.3" />
<PackageVersion Include="Xamarin.GooglePlayServices.Ads.Lite" Version="122.3.0.5" />
<PackageVersion Include="Plugin.MauiMTAdmob" />
</ItemGroup>
</Project>
1 change: 0 additions & 1 deletion Firehose/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using CommunityToolkit.Mvvm.DependencyInjection;
using Firehose.Preferences;
using Firehose.UI;
Expand Down
11 changes: 9 additions & 2 deletions Firehose/UI/Controls/CommonNavigationBar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" MaxHeight="50" Loaded="CommonNavigationBar_OnLoaded">
mc:Ignorable="d" MaxHeight="50" Loaded="SetBookmarkIcon">

<Grid.Resources>
<Style x:Key="AppButton" TargetType="Button">
Expand All @@ -25,6 +25,7 @@
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>

<Button Style="{StaticResource NavigationBackButtonNormalStyle}"
Expand All @@ -48,11 +49,17 @@
</Button.Flyout>
</Button>

<!-- Bookmarks -->
<Button Grid.Row="0" Grid.Column="3" Click="BookmarkClick" Style="{StaticResource AppButton}">
<FontIcon Name="Glyphy" FontFamily="{ThemeResource SymbolThemeFontFamily}"/>
</Button>

<Button Grid.Row="0" Content="· · ·" Grid.Column="4" Style="{StaticResource AppButton}">
<!-- Share button -->
<Button Grid.Column="4" Click="Share" Style="{StaticResource AppButton}">
<FontIcon FontFamily="{ThemeResource SymbolThemeFontFamily}" Glyph="&#xE72D;" />
</Button>

<Button Grid.Row="0" Content="· · ·" Grid.Column="5" Style="{StaticResource AppButton}">
<Button.Flyout>
<MenuFlyout>
<MenuFlyoutItem Text="Open in Browser" Click="OpenBrowser"/>
Expand Down
98 changes: 72 additions & 26 deletions Firehose/UI/Controls/CommonNavigationBar.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using Firehose.UI.Dialogs;
using HYDRANT;
using HYDRANT.Definitions;
using Windows.ApplicationModel.DataTransfer;
using WinRT.Interop;

namespace Firehose.UI.Controls;
public sealed partial class CommonNavigationBar : Grid
Expand Down Expand Up @@ -30,26 +32,9 @@ public CommonNavigationBar()
{
InitializeComponent();
}

private async void ReportSummary(object sender, RoutedEventArgs e)
{
ContentDialog d = new()
{
Title = "Report issue with summary for " + ItemSource.Title,
XamlRoot = XamlRoot,
Content = new AIFeedbackDialog(ItemSource),
PrimaryButtonText = "Send Feedback",
SecondaryButtonText = "Close"
};
var Res = await Glob.OpenContentDialog(d);

if (Res == ContentDialogResult.Primary) //Send feedback clicked
{
int reason = (((d.Content as AIFeedbackDialog)!.Content as Grid)!.Children[3] as ComboBox)!.SelectedIndex;
await new API().ReportArticle(ItemSource, reason);

}
}

private void ReportSummary(object sender, RoutedEventArgs e) =>
AIFeedbackDialog.ReportSummary(ItemSource);

/// <summary>
/// Opens article in the users browser
Expand All @@ -68,14 +53,17 @@ private async void ReportSummary(object sender, RoutedEventArgs e)
/// </summary>
private void GoBack(object sender, RoutedEventArgs e) { Glob.GoBack(); }

public void SetBookmarkIcon()
/// <summary>
/// Ran when loaded, checks the users bookmarks for if the Article is bookmarked.
/// </summary>
public void SetBookmarkIcon(object? sender = null, RoutedEventArgs? e = null)
{
//Handle bookmarked status
if (Glob.Model.BookmarkedArticles.Count(article => article.Url == ItemSource.Url) != 0)
{
Glyphy.Glyph = "\xE735";
Glyphy.Glyph = "\xE735"; // Filled Star
}
else { Glyphy.Glyph = "\xE734"; }
else { Glyphy.Glyph = "\xE734"; } // Empty star
}

private void BookmarkClick(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -104,9 +92,67 @@ private void ReportClickbait(object sender, RoutedEventArgs e)
ClickbaitButton.IsEnabled = false; //Prevent multiple reports.
}

private void CommonNavigationBar_OnLoaded(object sender, RoutedEventArgs e)
private async void Share(object sender, RoutedEventArgs e)
{
SetBookmarkIcon();

if (DataTransferManager.IsSupported())
{
#if WINDOWS //Sharing workarounds
// Retrieve the window handle (HWND) of the current WinUI 3 window.
var hWnd = WindowNative.GetWindowHandle(App.MainWindow);

//Do Interop magic
IDataTransferManagerInterop interop = DataTransferManager.As<IDataTransferManagerInterop>();
IntPtr result = interop.GetForWindow(hWnd, _dtm_iid);

//Create DataManager and show UI
var dataTransferManager = WinRT.MarshalInterface<DataTransferManager>.FromAbi(result);
dataTransferManager.DataRequested += ShareStarted;
interop.ShowShareUIForWindow(hWnd);
#else //Non-windows platforms.
var dataTransferManager = DataTransferManager.GetForCurrentView();
dataTransferManager.DataRequested += ShareStarted;
DataTransferManager.ShowShareUI();
#endif
}
else
{
//This shouldn't happen.
await Glob.OpenContentDialog(new()
{
Title = "Your system doesn't support sharing.",
Content = "Sorry, but your system somehow doesn't support sharing." +
"\nThis shouldn't happen but if you see this, let us know",
PrimaryButtonText = "Close"
});
}
}

/// <summary>
/// This event is called when the device sharing menu is opened
/// </summary>
private void ShareStarted(DataTransferManager manager, DataRequestedEventArgs args)
{
args.Request.Data.Properties.Title = $"Sharing {ItemSource.Title}";
args.Request.Data.Properties.Description = "Summary Text";
args.Request.Data.SetText(ItemSource.Summary);
args.Request.Data.SetWebLink(new Uri(ItemSource.Url));
}

//Required windows workarounds.
#if WINDOWS
[System.Runtime.InteropServices.ComImport]
[System.Runtime.InteropServices.Guid("3A3DCD6C-3EAB-43DC-BCDE-45671CE800C8")]
[System.Runtime.InteropServices.InterfaceType(
System.Runtime.InteropServices.ComInterfaceType.InterfaceIsIUnknown)]
interface IDataTransferManagerInterop
{
IntPtr GetForWindow([System.Runtime.InteropServices.In] IntPtr appWindow,
[System.Runtime.InteropServices.In] ref Guid riid);
void ShowShareUIForWindow(IntPtr appWindow);
}

static readonly Guid _dtm_iid =
new Guid(0xa5caee9b, 0x8708, 0x49d1, 0x8d, 0x36, 0x67, 0xd2, 0x5a, 0x8d, 0xa0, 0x0c);

#endif
}
28 changes: 25 additions & 3 deletions Firehose/UI/Dialogs/AIFeedbackDialog.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using CommunityToolkit.Mvvm.DependencyInjection;
using Firehose.Viewmodels;
using HYDRANT;
using HYDRANT.Definitions;

//Let it ride
//Whatever keeps you warm at night.
namespace Firehose.UI.Dialogs;

public sealed partial class AIFeedbackDialog : Page
Expand All @@ -14,6 +14,28 @@ public AIFeedbackDialog(Article Article)
this.InitializeComponent();
ItemSource = Article;
}


/// <summary>
/// Spawns a dialog showing this page
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public static async void ReportSummary(Article Item)
{
ContentDialog d = new()
{
Title = "Report issue with summary for " + Item.Title,
Content = new AIFeedbackDialog(Item),
PrimaryButtonText = "Send Feedback",
SecondaryButtonText = "Close"
};
var Res = await Glob.OpenContentDialog(d);

if (Res == ContentDialogResult.Primary) //Send feedback clicked
{
await new API().ReportArticle(Item);

}
}

}
5 changes: 4 additions & 1 deletion Firehose/UI/ReaderView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,21 @@
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="19*"/>
<RowDefinition Height="14*"/>
</Grid.RowDefinitions>
<controls:CommonNavigationBar ItemSource="{x:Bind Article}"/>

<ScrollViewer Grid.Row="1" Margin="10" HorizontalAlignment="Center" VerticalScrollBarVisibility="Visible">
<StackPanel>
<!-- Title and author -->
<TextBlock Text="{x:Bind Article.Title}" TextDecorations="Underline"
FontSize="20" Margin="0,10"/>
<StackPanel Orientation="Horizontal">
<TextBlock Text="By" Margin="0,5,5,0"/>
<TextBlock Text="{x:Bind Article.Author}" Margin="0,5,0,20"/>
</StackPanel>

<!-- Article Text -->
<TextBlock Text="{x:Bind Article.Text}" TextWrapping="WrapWholeWords"
MaxWidth="500" HorizontalAlignment="Left"/>
</StackPanel>
Expand Down
6 changes: 2 additions & 4 deletions Hydrant/API.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,10 @@ public async Task VoteClickbait(Article Article)
/// Reports an article summary as incorrect.
/// </summary>
/// <param name="Article">Article to report</param>
/// <param name="Reason">Reason to report.</param>
public async Task ReportArticle(Article Article, int Reason)
public async Task ReportArticle(Article Article)
{
using HttpClient client = new();
//client.DefaultRequestHeaders.Add("ApiKey", API_KEY);
string url = $"{Endpoint}/Articles/ReportArticleSummary?ArticleURL={Uri.EscapeDataString(Article.Url)}&ReportReason={Reason}";
string url = $"{Endpoint}/Articles/ReportArticleSummary?ArticleURL={Uri.EscapeDataString(Article.Url)}";
await client.GetAsync(url);
}
}
53 changes: 53 additions & 0 deletions Hydrant/Definitions/Article.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,58 @@ public class Article
/// Article already summarised.
/// </summary>
public int? TimeToRead { get; set; }


/// <summary>
/// Types of articles.
/// </summary>
public ArticleType Type
{
get
{
if (Url.Contains(".youtube.") || Url.Contains(".youtu.be"))
{
return ArticleType.Video;
}
else if (Url.Contains("http"))
{
return ArticleType.Article;
}
else if (Url.Contains(@"C:\"))
{
return ArticleType.File;
}
else
{
return ArticleType.Unknown;
}
}
}

/// <summary>
/// Used for different kinds of articles
/// </summary>
public enum ArticleType
{
/// <summary>
/// Article is a web article
/// </summary>
Article,

/// <summary>
/// Article is a video
/// </summary>
Video,

/// <summary>
/// Article is a PDF/DOCX/DOC file
/// </summary>
File,

/// <summary>
/// Type is unknown
/// </summary>
Unknown
}
#endregion
}
Loading

0 comments on commit 383735b

Please sign in to comment.