fix notification
This commit is contained in:
parent
9a6971c6bc
commit
8840d1007c
2 changed files with 32 additions and 18 deletions
|
@ -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 = $@"<p>[BSL MIRROR SERVICE NOTIFICATION]<br/>
|
||||
if (notify)
|
||||
{
|
||||
var message = $@"<p>[BSL MIRROR SERVICE NOTIFICATION]<br/>
|
||||
This bot has been disabled by it's original owner.<br/>
|
||||
It has been redirected to {validatedUser.FediverseAcct}.
|
||||
</p>";
|
||||
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 = $@"<p>[BSL MIRROR SERVICE NOTIFICATION]<br/>
|
||||
if (notify)
|
||||
{
|
||||
var message = $@"<p>[BSL MIRROR SERVICE NOTIFICATION]<br/>
|
||||
This bot has been deleted by it's original owner.<br/>
|
||||
</p>";
|
||||
NotifyFollowers(acct, twitterAccount, message);
|
||||
NotifyFollowers(acct, twitterAccount, message);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task TriggerRemoteMigrationAsync(string id, string tweetid, string handle)
|
||||
|
|
|
@ -53,7 +53,7 @@ namespace BirdsiteLive.Controllers
|
|||
public async Task<IActionResult> 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<IActionResult> 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<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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
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; }
|
||||
|
|
Reference in a new issue