diff --git a/src/BirdsiteLive.Domain/MigrationService.cs b/src/BirdsiteLive.Domain/MigrationService.cs index f534f3c..bc1c73e 100644 --- a/src/BirdsiteLive.Domain/MigrationService.cs +++ b/src/BirdsiteLive.Domain/MigrationService.cs @@ -105,7 +105,7 @@ namespace BirdsiteLive.Domain return result; } - public async Task MigrateAccountAsync(ValidatedFediverseUser validatedUser, string acct) + public async Task MigrateAccountAsync(ValidatedFediverseUser validatedUser, string acct, bool notify) { // Apply moved to var twitterAccount = await _twitterUserDal.GetTwitterUserAsync(acct); @@ -120,11 +120,14 @@ namespace BirdsiteLive.Domain await _twitterUserDal.UpdateTwitterUserAsync(twitterAccount); // Notify Followers - var message = $@"

[BSL MIRROR SERVICE NOTIFICATION]
+ if (notify) + { + var message = $@"

[BSL MIRROR SERVICE NOTIFICATION]
This bot has been disabled by it's original owner.
It has been redirected to {validatedUser.FediverseAcct}.

"; - NotifyFollowers(acct, twitterAccount, message); + NotifyFollowers(acct, twitterAccount, message); + } } private void NotifyFollowers(string acct, SyncTwitterUser twitterAccount, string message) @@ -169,7 +172,7 @@ namespace BirdsiteLive.Domain }); } - public async Task DeleteAccountAsync(string acct) + public async Task DeleteAccountAsync(string acct, bool notify) { // Apply moved to var twitterAccount = await _twitterUserDal.GetTwitterUserAsync(acct); @@ -184,10 +187,13 @@ namespace BirdsiteLive.Domain // Notify Followers - var message = $@"

[BSL MIRROR SERVICE NOTIFICATION]
+ if (notify) + { + var message = $@"

[BSL MIRROR SERVICE NOTIFICATION]
This bot has been deleted by it's original owner.

"; - NotifyFollowers(acct, twitterAccount, message); + NotifyFollowers(acct, twitterAccount, message); + } } public async Task TriggerRemoteMigrationAsync(string id, string tweetid, string handle) diff --git a/src/BirdsiteLive/Controllers/MigrationController.cs b/src/BirdsiteLive/Controllers/MigrationController.cs index 8593cb2..0c1d580 100644 --- a/src/BirdsiteLive/Controllers/MigrationController.cs +++ b/src/BirdsiteLive/Controllers/MigrationController.cs @@ -53,7 +53,7 @@ namespace BirdsiteLive.Controllers public async Task MigrateMove(string id, string tweetid, string handle) { var migrationCode = _migrationService.GetMigrationCode(id); - + var data = new MigrationData() { Acct = id, @@ -80,12 +80,12 @@ namespace BirdsiteLive.Controllers { data.ErrorMessage = e.Message; } - + if (data.IsAcctValid && data.IsTweetValid && fediverseUserValidation != null) { try { - await _migrationService.MigrateAccountAsync(fediverseUserValidation, id); + await _migrationService.MigrateAccountAsync(fediverseUserValidation, id, true); await _migrationService.TriggerRemoteMigrationAsync(id, tweetid, handle); data.MigrationSuccess = true; } @@ -129,7 +129,7 @@ namespace BirdsiteLive.Controllers { try { - await _migrationService.DeleteAccountAsync(id); + await _migrationService.DeleteAccountAsync(id, true); await _migrationService.TriggerRemoteDeleteAsync(id, tweetid); data.MigrationSuccess = true; } @@ -148,34 +148,42 @@ namespace BirdsiteLive.Controllers public async Task RemoteMigrateMove(string id, string tweetid, string handle) { var fediverseUserValidation = await _migrationService.ValidateFediverseAcctAsync(handle); - var isTweetValid = _migrationService.ValidateTweet(id, tweetid, MigrationTypeEnum.Deletion); + var isTweetValid = _migrationService.ValidateTweet(id, tweetid, MigrationTypeEnum.Migration); if (fediverseUserValidation.IsValid && isTweetValid) { - await _migrationService.MigrateAccountAsync(fediverseUserValidation, id); + await _migrationService.MigrateAccountAsync(fediverseUserValidation, id, false); return Ok(); } - return StatusCode(500); + return StatusCode(400); } [HttpPost] [Route("/migration/delete/{id}/{tweetid}/{handle}")] - public async Task RemoteDeleteMove(string id, string tweetid, string handle) + public async Task RemoteMigrateDelete(string id, string tweetid) { - throw new NotImplementedException(); + var isTweetValid = _migrationService.ValidateTweet(id, tweetid, MigrationTypeEnum.Deletion); + + if (isTweetValid) + { + await _migrationService.DeleteAccountAsync(id, true); + return Ok(); + } + + return StatusCode(400); } } - + public class MigrationData { public string Acct { get; set; } - + public string FediverseAccount { get; set; } public string TweetId { get; set; } - + public string MigrationCode { get; set; } public bool IsTweetProvided { get; set; }