Maybe fixing the diplicate image problem?
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using CatsOfMastodonBot.Models;
|
||||
using JsonFlatFileDataStore;
|
||||
using Microsoft.AspNetCore.Mvc.Diagnostics;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using mstdnCats.Models;
|
||||
using Telegram.Bot;
|
||||
@@ -27,12 +28,15 @@ namespace mstdnCats.Services
|
||||
string mediaId = parts[1];
|
||||
|
||||
var post = _db.AsQueryable().FirstOrDefault(p => p.MediaAttachments.Any(m => m.MediaId == mediaId));
|
||||
// Extract Only media attachments into a list of media attachments
|
||||
|
||||
|
||||
if (post == null)
|
||||
{
|
||||
logger?.LogInformation("No matching post found.");
|
||||
return;
|
||||
}
|
||||
var allMediaAttachments = _db.AsQueryable().SelectMany(p => p.MediaAttachments).ToList();
|
||||
|
||||
// Approve the media attachment
|
||||
if (action == "approve")
|
||||
@@ -55,7 +59,7 @@ namespace mstdnCats.Services
|
||||
if (updated)
|
||||
{
|
||||
// Send the media attachment to the channel
|
||||
await _bot.SendPhoto(config.CHANNEL_NUMID, post.MediaAttachments.First().Url, caption: $"Post from " + $"<a href=\"" + post.Account.Url + "\">" + post.Account.DisplayName + " </a>", parseMode: ParseMode.Html
|
||||
await _bot.SendPhoto(config.CHANNEL_NUMID, allMediaAttachments.First(m => m.MediaId == mediaId).Url, caption: $"Post from " + $"<a href=\"" + post.Account.Url + "\">" + post.Account.DisplayName + " </a>", parseMode: ParseMode.Html
|
||||
, replyMarkup: new InlineKeyboardMarkup(InlineKeyboardButton.WithUrl("View on Mastodon", post.Url)));
|
||||
|
||||
await _bot.AnswerCallbackQuery(callbackQuery.Id, "Media attachment approved and sent to channel.");
|
||||
|
Reference in New Issue
Block a user