various logic fixes

This commit is contained in:
Nicolas Constant 2022-12-25 18:15:54 -05:00
parent d5a71bbaa6
commit c910edc6b3
No known key found for this signature in database
GPG key ID: 1E9F677FB01A5688
3 changed files with 21 additions and 10 deletions

View file

@ -65,13 +65,22 @@ namespace BirdsiteLive.Domain
throw new Exception($"Tweet not published by @{acct}");
if (!tweet.MessageContent.Contains(code))
throw new Exception("Tweet don't have migration code");
{
var message = "Tweet don't have migration code";
if (type == MigrationTypeEnum.Deletion)
message = "Tweet don't have deletion code";
throw new Exception(message);
}
return true;
}
private long ExtractedTweetId(string tweetId)
{
if (string.IsNullOrWhiteSpace(tweetId))
throw new ArgumentException("No provided Tweet ID");
long castedId;
if (long.TryParse(tweetId, out castedId))
return castedId;

View file

@ -29,7 +29,7 @@ namespace BirdsiteLive.Twitter.Extractors
IsThread = tweet.InReplyToUserId != null && tweet.InReplyToUserId == tweet.CreatedBy.Id,
IsRetweet = tweet.IsRetweet || tweet.QuotedStatusId != null,
RetweetUrl = ExtractRetweetUrl(tweet),
CreatorName = tweet.CreatedBy.Name
CreatorName = tweet.CreatedBy.UserIdentifier.ScreenName
};
return extractedTweet;

View file

@ -71,12 +71,14 @@ namespace BirdsiteLive.Controllers
//Verify can be migrated
var twitterAccount = await _twitterUserDal.GetTwitterUserAsync(id);
if (twitterAccount.Deleted)
if (twitterAccount != null && twitterAccount.Deleted)
{
data.ErrorMessage = "This account has been deleted, it can't be migrated";
return View("Index", data);
}
if (!string.IsNullOrWhiteSpace(twitterAccount.MovedTo) || !string.IsNullOrWhiteSpace(twitterAccount.MovedToAcct))
if (twitterAccount != null &&
(!string.IsNullOrWhiteSpace(twitterAccount.MovedTo)
|| !string.IsNullOrWhiteSpace(twitterAccount.MovedToAcct)))
{
data.ErrorMessage = "This account has been moved already, it can't be migrated again";
return View("Index", data);
@ -118,12 +120,12 @@ namespace BirdsiteLive.Controllers
[Route("/migration/delete/{id}")]
public async Task<IActionResult> MigrateDelete(string id, string tweetid)
{
var migrationCode = _migrationService.GetMigrationCode(id);
var deletionCode = _migrationService.GetDeletionCode(id);
var data = new MigrationData()
{
Acct = id,
MigrationCode = migrationCode,
MigrationCode = deletionCode,
IsTweetProvided = !string.IsNullOrWhiteSpace(tweetid),
@ -132,16 +134,16 @@ namespace BirdsiteLive.Controllers
//Verify can be deleted
var twitterAccount = await _twitterUserDal.GetTwitterUserAsync(id);
if (twitterAccount.Deleted)
if (twitterAccount != null && twitterAccount.Deleted)
{
data.ErrorMessage = "This account has been deleted, it can't be deleted again";
return View("Index", data);
return View("Delete", data);
}
// Start deletion
try
{
var isTweetValid = _migrationService.ValidateTweet(id, tweetid, MigrationTypeEnum.Migration);
var isTweetValid = _migrationService.ValidateTweet(id, tweetid, MigrationTypeEnum.Deletion);
data.IsTweetValid = isTweetValid;
}
catch (Exception e)
@ -164,7 +166,7 @@ namespace BirdsiteLive.Controllers
}
}
return View("Index", data);
return View("Delete", data);
}
[HttpPost]