Bug fixes
This commit is contained in:
@ -105,7 +105,7 @@ public class OpenGraphController : Controller
|
|||||||
{
|
{
|
||||||
case (long)NostrKind.LiveEvent:
|
case (long)NostrKind.LiveEvent:
|
||||||
{
|
{
|
||||||
var host = ev.Tags.FirstOrDefault(a => a.Key is "p" && a.Values[3] is "host")?.Values[1] ?? ev.PubKey.ToHex();
|
var host = ev.Tags.FirstOrDefault(a => a is {Key: "p", Values: [_, _, "host", ..]})?.Values[1] ?? ev.PubKey.ToHex();
|
||||||
var hostProfile = await _redisStore.GetProfile(host);
|
var hostProfile = await _redisStore.GetProfile(host);
|
||||||
var hostName = hostProfile?.Name ?? profile?.Name ?? "Nostrich";
|
var hostName = hostProfile?.Name ?? profile?.Name ?? "Nostrich";
|
||||||
var stream = ev.GetFirstTagValue("streaming") ?? ev.GetFirstTagValue("recording") ?? "";
|
var stream = ev.GetFirstTagValue("streaming") ?? ev.GetFirstTagValue("recording") ?? "";
|
||||||
|
@ -11,7 +11,7 @@ namespace NostrServices.Services;
|
|||||||
|
|
||||||
public class RedisStore
|
public class RedisStore
|
||||||
{
|
{
|
||||||
private static readonly TimeSpan DefaultExpire = TimeSpan.FromDays(30);
|
private static readonly TimeSpan DefaultExpire = TimeSpan.FromDays(90);
|
||||||
private readonly IDatabase _database;
|
private readonly IDatabase _database;
|
||||||
|
|
||||||
public RedisStore(IDatabase database)
|
public RedisStore(IDatabase database)
|
||||||
@ -26,17 +26,35 @@ public class RedisStore
|
|||||||
|
|
||||||
public async Task<CompactEvent?> GetEvent(NostrIdentifier id)
|
public async Task<CompactEvent?> GetEvent(NostrIdentifier id)
|
||||||
{
|
{
|
||||||
return await _database.GetAsync<CompactEvent>(EventKey(id));
|
var ek = EventKey(id);
|
||||||
|
var ev = await _database.GetAsync<CompactEvent>(ek);
|
||||||
|
if (ev != default)
|
||||||
|
{
|
||||||
|
await _database.KeyExpireAsync(ek, DefaultExpire);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ev;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task StoreProfile(CompactProfile meta, TimeSpan? expiry = null)
|
public async Task StoreProfile(CompactProfile meta, TimeSpan? expiry = null)
|
||||||
{
|
{
|
||||||
await _database.SetAsync(ProfileKey(meta.PubKey.ToHex()), meta, expiry ?? DefaultExpire);
|
var oldProfile = await GetProfile(meta.PubKey.ToHex());
|
||||||
|
if ((oldProfile?.Created ?? new DateTime()) < meta.Created)
|
||||||
|
{
|
||||||
|
await _database.SetAsync(ProfileKey(meta.PubKey.ToHex()), meta, expiry ?? DefaultExpire);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<CompactProfile?> GetProfile(string id)
|
public async Task<CompactProfile?> GetProfile(string id)
|
||||||
{
|
{
|
||||||
return await _database.GetAsync<CompactProfile>(ProfileKey(id));
|
var pk = ProfileKey(id);
|
||||||
|
var profile = await _database.GetAsync<CompactProfile>(pk);
|
||||||
|
if (profile != default)
|
||||||
|
{
|
||||||
|
await _database.KeyExpireAsync(pk, DefaultExpire);
|
||||||
|
}
|
||||||
|
|
||||||
|
return profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string EventKey(NostrIdentifier id)
|
private string EventKey(NostrIdentifier id)
|
||||||
@ -48,7 +66,7 @@ public class RedisStore
|
|||||||
|
|
||||||
return $"event:{id.Special}";
|
return $"event:{id.Special}";
|
||||||
}
|
}
|
||||||
|
|
||||||
private string ProfileKey(string id) => $"profile:{id}";
|
private string ProfileKey(string id) => $"profile:{id}";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,6 +160,9 @@ public class CompactProfile
|
|||||||
[ProtoMember(7)]
|
[ProtoMember(7)]
|
||||||
public string? Banner { get; init; }
|
public string? Banner { get; init; }
|
||||||
|
|
||||||
|
[ProtoMember(8)]
|
||||||
|
public DateTime Created { get; init; }
|
||||||
|
|
||||||
public static CompactProfile? FromNostrEvent(NostrEvent ev)
|
public static CompactProfile? FromNostrEvent(NostrEvent ev)
|
||||||
{
|
{
|
||||||
var meta = NostrJson.Deserialize<NostrMetadata>(ev.Content);
|
var meta = NostrJson.Deserialize<NostrMetadata>(ev.Content);
|
||||||
@ -155,7 +176,8 @@ public class CompactProfile
|
|||||||
Picture = meta.Picture,
|
Picture = meta.Picture,
|
||||||
Nip05 = meta.Nip05,
|
Nip05 = meta.Nip05,
|
||||||
Lud16 = meta.Lud16,
|
Lud16 = meta.Lud16,
|
||||||
Banner = meta.Banner
|
Banner = meta.Banner,
|
||||||
|
Created = ev.CreatedAt!.Value
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user