Skip to content

Commit

Permalink
feed working
Browse files Browse the repository at this point in the history
  • Loading branch information
kfrancis committed May 18, 2023
1 parent 3ed8f65 commit 83b9f3b
Show file tree
Hide file tree
Showing 16 changed files with 946 additions and 268 deletions.
22 changes: 4 additions & 18 deletions src/NuSocial/AppShell.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
xmlns:viewModels="clr-namespace:NuSocial.ViewModels"
xmlns:views="clr-namespace:NuSocial.Views"
x:DataType="viewModels:ShellViewModel"
FlyoutBackdrop="{DynamicResource Gray500}"
FlyoutBackdrop="{DynamicResource Gray500Translucent}"
FlyoutBackgroundColor="{DynamicResource Primary}"
FlyoutIsPresented="{Binding IsPresented, Mode=TwoWay}"
Shell.BackgroundColor="{DynamicResource Primary}">
Expand Down Expand Up @@ -40,28 +40,14 @@
Title="{loc:Translate Home}"
Icon="{x:Static fa:FontAwesomeIcons.House}"
Route="main">
<ShellContent
Title="{loc:Translate Posts}"
ContentTemplate="{DataTemplate views:MainView}"
Route="posts" />
<ShellContent
Title="{loc:Translate PostsAndReplies}"
ContentTemplate="{DataTemplate views:MainView}"
Route="postsAndReplies" />
<ShellContent ContentTemplate="{DataTemplate views:MainView}" />
</Tab>

<Tab
Title="{loc:Translate DMs}"
Title="{loc:Translate Mssages}"
Icon="{x:Static fa:FontAwesomeIcons.Message}"
Route="messages">
<ShellContent
Title="{loc:Translate DMs}"
ContentTemplate="{DataTemplate views:MessagesView}"
Route="messages?set=dms" />
<ShellContent
Title="{loc:Translate Requests}"
ContentTemplate="{DataTemplate views:MessagesView}"
Route="messages?set=dmrequests" />
<ShellContent ContentTemplate="{DataTemplate views:MessagesView}" />
</Tab>
</TabBar>
<Shell.MenuItemTemplate>
Expand Down
34 changes: 34 additions & 0 deletions src/NuSocial/Converters/ContentStringToMarkdownHtmlConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Markdig;
using Markdig.Renderers.Roundtrip;
using Markdig.Syntax;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace NuSocial.Converters;

public class ContentStringToMarkdownHtmlConverter : IValueConverter
{
private static MarkdownPipeline Pipeline = new MarkdownPipelineBuilder().UseEmphasisExtras().UseGridTables().UsePipeTables().UseTaskLists().UseAutoLinks().Build();

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
try
{
return Markdown.Parse((string)value, true).ToHtml(Pipeline);
}
catch (Exception)
{
return (string)value;
}
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}

43 changes: 43 additions & 0 deletions src/NuSocial/GlobalSetting.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using CommunityToolkit.Mvvm.Messaging;
using Nostr.Client.Keys;
using NuSocial.Messages;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NuSocial
{
public class GlobalSetting
{
private User? _user;

public static GlobalSetting Instance { get; } = new GlobalSetting();

public User CurrentUser
{
get => _user;
set
{
if (value?.PublicKey != null)
{
_user = value;
UpdateUser(_user.PublicKey, _user.PrivateKey);
}
}
}

private static void UpdateUser(NostrPublicKey publicKey, NostrPrivateKey? privateKey)
{
if (privateKey != null)
{
WeakReferenceMessenger.Default.Send<NostrUserChangedMessage>(new((publicKey.Hex, privateKey.Hex)));
}
else
{
WeakReferenceMessenger.Default.Send<NostrUserChangedMessage>(new((publicKey.Hex, string.Empty)));
}
}
}
}
45 changes: 33 additions & 12 deletions src/NuSocial/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
using Microsoft.Extensions.Logging;
using Mopups.Hosting;
using NuSocial.Core.Threading;
using Serilog;
using Serilog.Events;
using Serilog.Sinks.FastConsole;
using SkiaSharp.Views.Maui.Controls.Hosting;
using System.Reflection;
using Volo.Abp;
Expand All @@ -16,9 +19,10 @@ public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
var builder = MauiApp.CreateBuilder();
SetupSerilog();
builder
.UseMauiApp<App>()
.UseMauiCommunityToolkit(options =>
{
options.SetShouldSuppressExceptionsInConverters(true);
Expand Down Expand Up @@ -46,15 +50,29 @@ public static MauiApp CreateMauiApp()
options.Services.ReplaceConfiguration(builder.Configuration);
});

AddDebugLogging(builder.Logging);
AddDebugLogging(builder.Logging);

var app = builder.Build();

app.Services.GetRequiredService<IAbpApplicationWithExternalServiceProvider>().Initialize(app.Services);

return app;
}

}

private static void SetupSerilog()
{
var flushInterval = new TimeSpan(0, 0, 1);
var file = Path.Combine(FileSystem.AppDataDirectory, "NuSocial.log");

Log.Logger = new LoggerConfiguration()
.MinimumLevel.Verbose()
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
.Enrich.FromLogContext()
//.WriteTo.File(file, flushToDiskInterval: flushInterval, encoding: System.Text.Encoding.UTF8, rollingInterval: RollingInterval.Day, retainedFileCountLimit: 22)
.WriteTo.FastConsole()
.CreateLogger();
}

[Conditional("DEBUG")]
private static void AddDebugLogging(ILoggingBuilder logging)
{
Expand Down Expand Up @@ -87,12 +105,15 @@ private static void ConfigureFromConfigurationOptions(MauiAppBuilder builder)
}

private static ContainerBuilder GetAutofacContainerBuilder(IServiceCollection services)
{
services.AddSingleton<IDatabase, LocalStorage>();
services.AddSingleton<ICustomDispatcher, MauiDispatcher>();
services.AddLocalization();

var builder = new Autofac.ContainerBuilder();
{
var db = new LocalStorage();
services.AddSingleton<IDatabase>(db);
services.AddSingleton<ICustomDispatcher, MauiDispatcher>();
services.AddSingleton<INostrService>(new NostrService(db));
services.AddLocalization();
services.AddLogging(logging => logging.AddSerilog());

var builder = new Autofac.ContainerBuilder();

SetupAutofacDebug(builder);

Expand Down
48 changes: 24 additions & 24 deletions src/NuSocial/Messages/LogoutMessage.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
using CommunityToolkit.Mvvm.Messaging.Messages;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NuSocial.Messages
{
public class LogoutMessage : ValueChangedMessage<bool?>
{
public LogoutMessage(bool? value = null) : base(value)
{
}
}

public class ResetNavMessage : ValueChangedMessage<string?>
{
public ResetNavMessage(string? route = null) : base(route)
{
}
}
}

using CommunityToolkit.Mvvm.Messaging.Messages;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NuSocial.Messages
{
public class LogoutMessage : ValueChangedMessage<bool?>
{
public LogoutMessage(bool? value = null) : base(value)
{
}
}

public class ResetNavMessage : ValueChangedMessage<string?>
{
public ResetNavMessage(string? route = null) : base(route)
{
}
}
}
20 changes: 20 additions & 0 deletions src/NuSocial/Messages/NostrMessages.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using CommunityToolkit.Mvvm.Messaging.Messages;
using Nostr.Client.Keys;

namespace NuSocial.Messages
{
public class NostrUserChangedMessage : ValueChangedMessage<(string pubKey, string privKey)>
{
public NostrUserChangedMessage((string pubKey, string privKey) value) : base(value)
{
}
}

public class NostrPostMessage : ValueChangedMessage<string?>
{
public NostrPostMessage(string? value = null) : base(value)
{
}
}
}

6 changes: 6 additions & 0 deletions src/NuSocial/Models/Relay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ public Uri? Uri

public class Post
{
[Ignore]
public Contact Contact { get; set; }

public string ContactId => Contact.PublicKey;

public string Content { get; set; }
public DateTime CreatedAt { get; set; }

[PrimaryKey]
public string Hash { get; set; }
Expand Down
Loading

0 comments on commit 83b9f3b

Please sign in to comment.