fix notification

This commit is contained in:
Nicolas Constant
2022-12-14 00:17:00 -05:00
parent 9a6971c6bc
commit 8840d1007c
2 changed files with 32 additions and 18 deletions

View File

@ -105,7 +105,7 @@ namespace BirdsiteLive.Domain
return result; return result;
} }
public async Task MigrateAccountAsync(ValidatedFediverseUser validatedUser, string acct) public async Task MigrateAccountAsync(ValidatedFediverseUser validatedUser, string acct, bool notify)
{ {
// Apply moved to // Apply moved to
var twitterAccount = await _twitterUserDal.GetTwitterUserAsync(acct); var twitterAccount = await _twitterUserDal.GetTwitterUserAsync(acct);
@ -120,12 +120,15 @@ namespace BirdsiteLive.Domain
await _twitterUserDal.UpdateTwitterUserAsync(twitterAccount); await _twitterUserDal.UpdateTwitterUserAsync(twitterAccount);
// Notify Followers // Notify Followers
if (notify)
{
var message = $@"<p>[BSL MIRROR SERVICE NOTIFICATION]<br/> var message = $@"<p>[BSL MIRROR SERVICE NOTIFICATION]<br/>
This bot has been disabled by it's original owner.<br/> This bot has been disabled by it's original owner.<br/>
It has been redirected to {validatedUser.FediverseAcct}. It has been redirected to {validatedUser.FediverseAcct}.
</p>"; </p>";
NotifyFollowers(acct, twitterAccount, message); NotifyFollowers(acct, twitterAccount, message);
} }
}
private void NotifyFollowers(string acct, SyncTwitterUser twitterAccount, string 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 // Apply moved to
var twitterAccount = await _twitterUserDal.GetTwitterUserAsync(acct); var twitterAccount = await _twitterUserDal.GetTwitterUserAsync(acct);
@ -184,11 +187,14 @@ namespace BirdsiteLive.Domain
// Notify Followers // Notify Followers
if (notify)
{
var message = $@"<p>[BSL MIRROR SERVICE NOTIFICATION]<br/> var message = $@"<p>[BSL MIRROR SERVICE NOTIFICATION]<br/>
This bot has been deleted by it's original owner.<br/> This bot has been deleted by it's original owner.<br/>
</p>"; </p>";
NotifyFollowers(acct, twitterAccount, message); NotifyFollowers(acct, twitterAccount, message);
} }
}
public async Task TriggerRemoteMigrationAsync(string id, string tweetid, string handle) public async Task TriggerRemoteMigrationAsync(string id, string tweetid, string handle)
{ {

View File

@ -85,7 +85,7 @@ namespace BirdsiteLive.Controllers
{ {
try try
{ {
await _migrationService.MigrateAccountAsync(fediverseUserValidation, id); await _migrationService.MigrateAccountAsync(fediverseUserValidation, id, true);
await _migrationService.TriggerRemoteMigrationAsync(id, tweetid, handle); await _migrationService.TriggerRemoteMigrationAsync(id, tweetid, handle);
data.MigrationSuccess = true; data.MigrationSuccess = true;
} }
@ -129,7 +129,7 @@ namespace BirdsiteLive.Controllers
{ {
try try
{ {
await _migrationService.DeleteAccountAsync(id); await _migrationService.DeleteAccountAsync(id, true);
await _migrationService.TriggerRemoteDeleteAsync(id, tweetid); await _migrationService.TriggerRemoteDeleteAsync(id, tweetid);
data.MigrationSuccess = true; data.MigrationSuccess = true;
} }
@ -148,22 +148,30 @@ namespace BirdsiteLive.Controllers
public async Task<IActionResult> RemoteMigrateMove(string id, string tweetid, string handle) public async Task<IActionResult> RemoteMigrateMove(string id, string tweetid, string handle)
{ {
var fediverseUserValidation = await _migrationService.ValidateFediverseAcctAsync(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) if (fediverseUserValidation.IsValid && isTweetValid)
{ {
await _migrationService.MigrateAccountAsync(fediverseUserValidation, id); await _migrationService.MigrateAccountAsync(fediverseUserValidation, id, false);
return Ok(); return Ok();
} }
return StatusCode(500); return StatusCode(400);
} }
[HttpPost] [HttpPost]
[Route("/migration/delete/{id}/{tweetid}/{handle}")] [Route("/migration/delete/{id}/{tweetid}/{handle}")]
public async Task<IActionResult> RemoteDeleteMove(string id, string tweetid, string handle) public async Task<IActionResult> 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);
} }
} }