private void UpdateRaid(RaidTarget target, DbSet <RaidParticipation> coll, RaidParticipation raid) { _log.Info($"Updating raid {raid.PublicID} / {raid.Raid.Raid} / {raid.Raid.Gym} in channel {target.Description}"); lock (UpdatePublishedRaidsInChannels.SharedUpdateLock) { raid = coll.Find(x => x.UniqueID == raid.UniqueID).FirstOrDefault(); if (raid.Raid.TelegramMessageID != null && raid.Raid.TelegramMessageID != 0 && raid.Raid.TelegramMessageID != -1) { raid.LastRefresh = DateTime.UtcNow; coll.Update(raid); } else { return; } } try { RaidEventHandler.UpdateRaidMessage(target.ChannelID, raid.Raid.TelegramMessageID, null, raid.PublicID, "channel"); } catch (Exception ex) { _log.Error(ex, "Failed to update raid message, marking as modified."); lock (UpdatePublishedRaidsInChannels.SharedUpdateLock) { // error publishing, assume it wasn't updated and try again raid = coll.Find(x => x.UniqueID == raid.UniqueID).FirstOrDefault(); raid.LastModificationTime = DateTime.UtcNow; coll.Update(raid); } } }
private void PostRaid(RaidTarget target, DbSet <RaidParticipation> coll, RaidParticipation raid) { _log.Info($"Posting raid {raid.PublicID} / {raid.Raid.Raid} / {raid.Raid.Gym} in channel {target.Description}"); lock (UpdatePublishedRaidsInChannels.SharedUpdateLock) { // Mark the raid as updated with posting in progress, by setting the telegram message ID to -1 raid = coll.Find(x => x.UniqueID == raid.UniqueID).FirstOrDefault(); raid.Raid.TelegramMessageID = -1; // hardcoded to indicate the message was not sent coll.Update(raid); } try { var message = RaidEventHandler.ShareRaidToChat(raid, target.ChannelID); long messageID = message?.MessageID ?? default(long); lock (UpdatePublishedRaidsInChannels.SharedUpdateLock) { // The record may have changed by now, so load it again, then update tge nessage ID raid = coll.Find(x => x.UniqueID == raid.UniqueID).FirstOrDefault(); raid.Raid.TelegramMessageID = messageID; coll.Update(raid); } } catch (Exception ex) { _log.Error(ex, "Failed to post new raid message, marking as 'new'."); lock (UpdatePublishedRaidsInChannels.SharedUpdateLock) { // error publishing, assume it wasn't published and try again raid = coll.Find(x => x.UniqueID == raid.UniqueID).FirstOrDefault(); raid.Raid.TelegramMessageID = 0; coll.Update(raid); } } }