Browse Source

revert hashflags, for now

master
Pasture Pastureson 3 months ago
parent
commit
d286933398
12 changed files with 17 additions and 114 deletions
  1. +0
    -1
      VARIABLES.md
  2. +0
    -2
      src/BirdsiteLive.Common/Settings/InstanceSettings.cs
  3. +0
    -52
      src/BirdsiteLive.Domain/HashflagService.cs
  4. +2
    -23
      src/BirdsiteLive.Domain/Tools/StatusExtractor.cs
  5. +1
    -1
      src/BirdsiteLive.Pipeline/Contracts/IRetrieveTwitterUsersProcessor.cs
  6. +3
    -13
      src/BirdsiteLive.Pipeline/Processors/RetrieveTwitterUsersProcessor.cs
  7. +1
    -1
      src/BirdsiteLive.Pipeline/StatusPublicationPipeline.cs
  8. +1
    -7
      src/BirdsiteLive/Services/FederationService.cs
  9. +1
    -5
      src/BirdsiteLive/Startup.cs
  10. +1
    -2
      src/BirdsiteLive/appsettings.json
  11. +6
    -6
      src/Tests/BirdsiteLive.Pipeline.Tests/Processors/RetrieveTwitterUsersProcessorTests.cs
  12. +1
    -1
      src/Tests/BirdsiteLive.Pipeline.Tests/StatusPublicationPipelineTests.cs

+ 0
- 1
VARIABLES.md View File

@ -53,7 +53,6 @@ If both whitelisting and blacklisting are set, only the whitelisting will be act
* `Instance:ShowAboutInstanceOnProfiles` (default: true) show "About [instance name]" on profiles with a link to /About
* `Instance:MaxFollowsPerUser` (default: 0 - no limit) limit the number of follows per user - any follow count above this number will be Rejected
* `Instance:DiscloseInstanceRestrictions` (default: false) disclose your instance's restrictions on its About page
* `Instance:EnableHashflags` (default: false) show hashflags as toot:Emojis next to qualifying hashtags
# Docker Compose full example


+ 0
- 2
src/BirdsiteLive.Common/Settings/InstanceSettings.cs View File

@ -23,7 +23,5 @@
public bool DiscloseInstanceRestrictions { get; set; }
public bool EnableHashflags { get; set; }
}
}

+ 0
- 52
src/BirdsiteLive.Domain/HashflagService.cs View File

@ -1,52 +0,0 @@
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace BirdsiteLive.Domain
{
public interface IHashflagService
{
Task ExecuteAsync();
Dictionary<string, string> Hashflags { get; }
}
public class HashflagService : IHashflagService
{
private DateTime lastFetch = default(DateTime);
public Dictionary<string, string> Hashflags { get; private set; }
private readonly IHttpClientFactory _httpClientFactory;
private readonly ILogger _logger;
public HashflagService(IHttpClientFactory httpClientFactory/* , ILogger logger */)
{
_httpClientFactory = httpClientFactory;
/* _logger = logger; */
}
public async Task ExecuteAsync()
{
if(DateTime.Now - lastFetch >= new TimeSpan(1, 0, 0))
{
try
{
var client = _httpClientFactory.CreateClient();
var result = await client.GetAsync("https://hashflags.blob.core.windows.net/json/activeHashflags");
var content = await result.Content.ReadAsStringAsync();
Hashflags = JsonConvert.DeserializeObject<Dictionary<string, string>>(content);
} catch(Exception e)
{
Console.WriteLine(e);
/* _logger.LogCritical("Error fetching hashflags: {exception}", e); */
}
}
}
}
}

+ 2
- 23
src/BirdsiteLive.Domain/Tools/StatusExtractor.cs View File

@ -18,14 +18,12 @@ namespace BirdsiteLive.Domain.Tools
{
private readonly InstanceSettings _instanceSettings;
private readonly ILogger<StatusExtractor> _logger;
private readonly IHashflagService _hashflagService;
#region Ctor
public StatusExtractor(InstanceSettings instanceSettings, ILogger<StatusExtractor> logger, IHashflagService hashflagService)
public StatusExtractor(InstanceSettings instanceSettings, ILogger<StatusExtractor> logger)
{
_instanceSettings = instanceSettings;
_logger = logger;
_hashflagService = hashflagService;
}
#endregion
@ -84,8 +82,6 @@ namespace BirdsiteLive.Domain.Tools
var url = $"https://{_instanceSettings.Domain}/tags/{tag}";
var flagsInPost = new List<string>();
if (tags.All(x => x.href != url))
{
tags.Add(new Tag
@ -94,27 +90,10 @@ namespace BirdsiteLive.Domain.Tools
href = url,
type = "Hashtag"
});
if(_hashflagService.Hashflags.TryGetValue(tag, out string hashflagUrl))
{
tags.Add(new Tag
{
icon = new TagResource
{
url = hashflagUrl,
type = "Image"
},
id = hashflagUrl,
name = $":{tag}:",
type = "Emoji"
});
flagsInPost.Add(tag);
}
}
messageContent = Regex.Replace(messageContent, Regex.Escape(m.Groups[0].ToString()),
$@"{m.Groups[1]}<a href=""{url}"" class=""mention hashtag"" rel=""tag"">#<span>{tag}</span></a>{(flagsInPost.IndexOf(tag) > -1 ? $" :{tag}:" : "")}{m.Groups[3]}");
$@"{m.Groups[1]}<a href=""{url}"" class=""mention hashtag"" rel=""tag"">#<span>{tag}</span></a>{m.Groups[3]}");
}
// Extract Mentions


+ 1
- 1
src/BirdsiteLive.Pipeline/Contracts/IRetrieveTwitterUsersProcessor.cs View File

@ -7,6 +7,6 @@ namespace BirdsiteLive.Pipeline.Contracts
{
public interface IRetrieveTwitterUsersProcessor
{
Task UpdateTwitterAsync(BufferBlock<SyncTwitterUser[]> twitterUsersBufferBlock, CancellationToken ct);
Task GetTwitterUsersAsync(BufferBlock<SyncTwitterUser[]> twitterUsersBufferBlock, CancellationToken ct);
}
}

+ 3
- 13
src/BirdsiteLive.Pipeline/Processors/RetrieveTwitterUsersProcessor.cs View File

@ -7,7 +7,6 @@ using BirdsiteLive.Common.Extensions;
using BirdsiteLive.Common.Settings;
using BirdsiteLive.DAL.Contracts;
using BirdsiteLive.DAL.Models;
using BirdsiteLive.Domain;
using BirdsiteLive.Pipeline.Contracts;
using BirdsiteLive.Pipeline.Tools;
using Microsoft.Extensions.Logging;
@ -19,23 +18,19 @@ namespace BirdsiteLive.Pipeline.Processors
private readonly ITwitterUserDal _twitterUserDal;
private readonly IMaxUsersNumberProvider _maxUsersNumberProvider;
private readonly ILogger<RetrieveTwitterUsersProcessor> _logger;
private readonly IHashflagService _hashflagService;
private readonly InstanceSettings _instanceSettings;
public int WaitFactor = 1000 * 60; //1 min
#region Ctor
public RetrieveTwitterUsersProcessor(ITwitterUserDal twitterUserDal, IMaxUsersNumberProvider maxUsersNumberProvider, ILogger<RetrieveTwitterUsersProcessor> logger, IHashflagService hashflagService, InstanceSettings instanceSettings)
public RetrieveTwitterUsersProcessor(ITwitterUserDal twitterUserDal, IMaxUsersNumberProvider maxUsersNumberProvider, ILogger<RetrieveTwitterUsersProcessor> logger)
{
_twitterUserDal = twitterUserDal;
_maxUsersNumberProvider = maxUsersNumberProvider;
_logger = logger;
_hashflagService = hashflagService;
_instanceSettings = instanceSettings;
}
#endregion
public async Task UpdateTwitterAsync(BufferBlock<SyncTwitterUser[]> twitterUsersBufferBlock, CancellationToken ct)
public async Task GetTwitterUsersAsync(BufferBlock<SyncTwitterUser[]> twitterUsersBufferBlock, CancellationToken ct)
{
for (; ; )
{
@ -43,11 +38,6 @@ namespace BirdsiteLive.Pipeline.Processors
try
{
if(_instanceSettings.EnableHashflags)
{
await _hashflagService.ExecuteAsync();
}
var maxUsersNumber = await _maxUsersNumberProvider.GetMaxUsersNumberAsync();
var users = await _twitterUserDal.GetAllTwitterUsersAsync(maxUsersNumber);


+ 1
- 1
src/BirdsiteLive.Pipeline/StatusPublicationPipeline.cs View File

@ -58,7 +58,7 @@ namespace BirdsiteLive.Pipeline
sendTweetsToFollowersBufferBlock.LinkTo(saveProgressionBlock, new DataflowLinkOptions { PropagateCompletion = true });
// Launch twitter user retriever
var retrieveTwitterAccountsTask = _retrieveTwitterAccountsProcessor.UpdateTwitterAsync(twitterUsersBufferBlock, ct);
var retrieveTwitterAccountsTask = _retrieveTwitterAccountsProcessor.GetTwitterUsersAsync(twitterUsersBufferBlock, ct);
// Wait
await Task.WhenAny(new[] { retrieveTwitterAccountsTask, saveProgressionBlock.Completion });


+ 1
- 7
src/BirdsiteLive/Services/FederationService.cs View File

@ -2,10 +2,8 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using BirdsiteLive.Common.Settings;
using BirdsiteLive.DAL;
using BirdsiteLive.DAL.Contracts;
using BirdsiteLive.Domain;
using BirdsiteLive.Moderation;
using BirdsiteLive.Pipeline;
using Microsoft.Extensions.Hosting;
@ -18,18 +16,14 @@ namespace BirdsiteLive.Services
private readonly IModerationPipeline _moderationPipeline;
private readonly IStatusPublicationPipeline _statusPublicationPipeline;
private readonly IHostApplicationLifetime _applicationLifetime;
private readonly IHashflagService _hashflagService;
private readonly InstanceSettings _instanceSettings;
#region Ctor
public FederationService(IDatabaseInitializer databaseInitializer, IModerationPipeline moderationPipeline, IStatusPublicationPipeline statusPublicationPipeline, IHostApplicationLifetime applicationLifetime, IHashflagService hashflagService, InstanceSettings instanceSettings)
public FederationService(IDatabaseInitializer databaseInitializer, IModerationPipeline moderationPipeline, IStatusPublicationPipeline statusPublicationPipeline, IHostApplicationLifetime applicationLifetime)
{
_databaseInitializer = databaseInitializer;
_moderationPipeline = moderationPipeline;
_statusPublicationPipeline = statusPublicationPipeline;
_applicationLifetime = applicationLifetime;
_hashflagService = hashflagService;
_instanceSettings = instanceSettings;
}
#endregion


+ 1
- 5
src/BirdsiteLive/Startup.cs View File

@ -8,9 +8,7 @@ using BirdsiteLive.Common.Structs;
using BirdsiteLive.DAL.Contracts;
using BirdsiteLive.DAL.Postgres.DataAccessLayers;
using BirdsiteLive.DAL.Postgres.Settings;
using BirdsiteLive.Domain;
using BirdsiteLive.Models;
using BirdsiteLive.Services;
using BirdsiteLive.Twitter;
using BirdsiteLive.Twitter.Tools;
using Lamar;
@ -57,8 +55,6 @@ namespace BirdsiteLive
public void ConfigureContainer(ServiceRegistry services)
{
services.For<IHashflagService>().Use<HashflagService>().Singleton();
var twitterSettings = Configuration.GetSection("Twitter").Get<TwitterSettings>();
services.For<TwitterSettings>().Use(x => twitterSettings);
@ -91,7 +87,7 @@ namespace BirdsiteLive
{
throw new NotImplementedException($"{dbSettings.Type} is not supported");
}
services.For<ITwitterUserService>().DecorateAllWith<CachedTwitterUserService>();
services.For<ITwitterUserService>().Use<TwitterUserService>().Singleton();


+ 1
- 2
src/BirdsiteLive/appsettings.json View File

@ -27,8 +27,7 @@
"InfoBanner": "",
"ShowAboutInstanceOnProfiles": true,
"MaxFollowsPerUser": 0,
"DiscloseInstanceRestrictions": false,
"EnableHashflags": false
"DiscloseInstanceRestrictions": false
},
"Db": {
"Type": "postgres",


+ 6
- 6
src/Tests/BirdsiteLive.Pipeline.Tests/Processors/RetrieveTwitterUsersProcessorTests.cs View File

@ -48,7 +48,7 @@ namespace BirdsiteLive.Pipeline.Tests.Processors
var processor = new RetrieveTwitterUsersProcessor(twitterUserDalMock.Object, maxUsersNumberProviderMock.Object, loggerMock.Object);
processor.WaitFactor = 10;
var t = processor.UpdateTwitterAsync(buffer, CancellationToken.None);
var t = processor.GetTwitterUsersAsync(buffer, CancellationToken.None);
await Task.WhenAny(t, Task.Delay(50));
@ -95,7 +95,7 @@ namespace BirdsiteLive.Pipeline.Tests.Processors
var processor = new RetrieveTwitterUsersProcessor(twitterUserDalMock.Object, maxUsersNumberProviderMock.Object, loggerMock.Object);
processor.WaitFactor = 2;
var t = processor.UpdateTwitterAsync(buffer, CancellationToken.None);
var t = processor.GetTwitterUsersAsync(buffer, CancellationToken.None);
await Task.WhenAny(t, Task.Delay(300));
@ -142,7 +142,7 @@ namespace BirdsiteLive.Pipeline.Tests.Processors
var processor = new RetrieveTwitterUsersProcessor(twitterUserDalMock.Object, maxUsersNumberProviderMock.Object, loggerMock.Object);
processor.WaitFactor = 2;
var t = processor.UpdateTwitterAsync(buffer, CancellationToken.None);
var t = processor.GetTwitterUsersAsync(buffer, CancellationToken.None);
var t2 = Task.Run(async () =>
{
while (buffer.Count < 11)
@ -186,7 +186,7 @@ namespace BirdsiteLive.Pipeline.Tests.Processors
var processor = new RetrieveTwitterUsersProcessor(twitterUserDalMock.Object, maxUsersNumberProviderMock.Object, loggerMock.Object);
processor.WaitFactor = 1;
var t =processor.UpdateTwitterAsync(buffer, CancellationToken.None);
var t =processor.GetTwitterUsersAsync(buffer, CancellationToken.None);
await Task.WhenAny(t, Task.Delay(50));
@ -223,7 +223,7 @@ namespace BirdsiteLive.Pipeline.Tests.Processors
var processor = new RetrieveTwitterUsersProcessor(twitterUserDalMock.Object, maxUsersNumberProviderMock.Object, loggerMock.Object);
processor.WaitFactor = 10;
var t = processor.UpdateTwitterAsync(buffer, CancellationToken.None);
var t = processor.GetTwitterUsersAsync(buffer, CancellationToken.None);
await Task.WhenAny(t, Task.Delay(50));
@ -259,7 +259,7 @@ namespace BirdsiteLive.Pipeline.Tests.Processors
var processor = new RetrieveTwitterUsersProcessor(twitterUserDalMock.Object, maxUsersNumberProviderMock.Object, loggerMock.Object);
processor.WaitFactor = 1;
await processor.UpdateTwitterAsync(buffer, canTokenS.Token);
await processor.GetTwitterUsersAsync(buffer, canTokenS.Token);
}
private static async Task<T> DelayFaultedTask<T>(Exception e)


+ 1
- 1
src/Tests/BirdsiteLive.Pipeline.Tests/StatusPublicationPipelineTests.cs View File

@ -22,7 +22,7 @@ namespace BirdsiteLive.Pipeline.Tests
#region Mocks
var retrieveTwitterUsersProcessor = new Mock<IRetrieveTwitterUsersProcessor>(MockBehavior.Strict);
retrieveTwitterUsersProcessor
.Setup(x => x.UpdateTwitterAsync(
.Setup(x => x.GetTwitterUsersAsync(
It.IsAny<BufferBlock<SyncTwitterUser[]>>(),
It.IsAny<CancellationToken>()))
.Returns(Task.Delay(0));


Loading…
Cancel
Save