implement `BlockBuddy`

messaging bug fix
This commit is contained in:
Alan Moon 2025-03-11 14:36:16 -07:00
parent 766c4b8884
commit e10f80580a
3 changed files with 73 additions and 5 deletions

View File

@ -1198,6 +1198,44 @@ public class ContentController : Controller {
else return Ok(false);
}
[HttpPost]
[Produces("application/xml")]
[Route("ContentWebService.asmx/BlockBuddy")]
[VikingSession]
public IActionResult BlockBuddy(Viking viking, [FromForm] Guid buddyUserId)
{
// find viking
Viking? viking1 = ctx.Vikings.FirstOrDefault(e => e.Uid == buddyUserId);
if (viking1 != null)
{
// check if a relation exists already
Model.Buddy? buddy = ctx.Buddies.Where(e => e.VikingId == viking.Id || e.BuddyVikingId == viking.Id)
.FirstOrDefault(e => e.BuddyVikingId == viking1.Id || e.VikingId == viking1.Id);
if (buddy != null)
{
// update existing relation
if (buddy.BuddyStatus1 == BuddyStatus.BlockedBySelf || buddy.BuddyStatus2 == BuddyStatus.BlockedByOther
|| buddy.BuddyStatus1 == BuddyStatus.BlockedByOther || buddy.BuddyStatus2 == BuddyStatus.BlockedBySelf)
{
buddyService.UpdateBuddyRelation(viking, viking1, BuddyStatus.BlockedByBoth, BuddyStatus.BlockedByBoth);
} else if (buddy.VikingId == viking.Id)
buddyService.UpdateBuddyRelation(viking, viking1, BuddyStatus.BlockedBySelf, BuddyStatus.BlockedByOther);
else
buddyService.UpdateBuddyRelation(viking, viking1, BuddyStatus.BlockedByOther, BuddyStatus.BlockedBySelf);
} else
{
if (viking1.Id == viking.Id)
buddyService.CreateBuddyRelation(viking, viking1, BuddyStatus.BlockedBySelf, BuddyStatus.BlockedByOther);
else
buddyService.CreateBuddyRelation(viking, viking1, BuddyStatus.BlockedByOther, BuddyStatus.BlockedBySelf);
}
return Ok(true);
} else return Ok(false);
}
[HttpPost]
[Produces("application/xml")]
[Route("ContentWebService.asmx/ApproveBuddy")]

View File

@ -133,6 +133,30 @@ public class BuddyService
if (buddy != null)
{
// blocks that are of both need to be handled correctly
if (buddy.BuddyStatus1 == BuddyStatus.BlockedByBoth && buddy.BuddyStatus2 == BuddyStatus.BlockedByBoth)
{
// instead of removing, update the relationship correctly
if (buddy.VikingId == viking.Id)
{
// the relationship should be switched (this probably ain't the best way to do this but here we are)
buddy.BuddyVikingId = viking.Id;
buddy.BuddyStatus1 = BuddyStatus.BlockedByOther;
buddy.VikingId = buddyViking.Id;
buddy.BuddyStatus2 = BuddyStatus.BlockedBySelf;
}
else
{
buddy.BuddyVikingId = buddyViking.Id;
buddy.BuddyStatus1 = BuddyStatus.BlockedBySelf;
buddy.VikingId = viking.Id;
buddy.BuddyStatus2 = BuddyStatus.BlockedByOther;
}
ctx.SaveChanges();
return true;
}
// remove it
ctx.Buddies.Remove(buddy);
ctx.SaveChanges();
@ -150,9 +174,12 @@ public class BuddyService
List<Schema.Buddy> schemaBuddies = new();
foreach (var buddy in buddies)
{
Schema.Buddy schemaBuddy = new Schema.Buddy();
// show differently depending on requester
if (buddy.VikingId == viking.Id)
schemaBuddies.Add(new Schema.Buddy
schemaBuddy = new Schema.Buddy
{
UserID = buddy.BuddyViking.Uid.ToString(),
DisplayName = XmlUtil.DeserializeXml<AvatarData>(buddy.BuddyViking.AvatarSerialized).DisplayName,
@ -161,9 +188,9 @@ public class BuddyService
Online = buddy.BuddyViking.Online ?? false,
OnMobile = false,
BestBuddy = buddy.IsBestFriend2
});
};
else
schemaBuddies.Add(new Schema.Buddy
schemaBuddy = new Schema.Buddy
{
UserID = buddy.Viking.Uid.ToString(),
DisplayName = XmlUtil.DeserializeXml<AvatarData>(buddy.Viking.AvatarSerialized).DisplayName,
@ -172,7 +199,10 @@ public class BuddyService
Online = buddy.Viking.Online ?? false,
OnMobile = false,
BestBuddy = buddy.IsBestFriend1
});
};
// add buddy
schemaBuddies.Add(schemaBuddy);
}
// return buddy list

View File

@ -115,7 +115,7 @@ public class MessagingService
public ArrayOfCombinedListMessage ConstructCombinedMessageArray(Viking viking, Viking publicViking)
{
// get all messages in viking board
List<Model.Message> messages = ctx.Messages.Where(e => e.ToVikingId == viking.Id).ToList();
List<Model.Message> messages = ctx.Messages.Where(e => e.ToVikingId == publicViking.Id).ToList();
List<CombinedListMessage> combinedListMessages = new List<CombinedListMessage>();
ArrayOfCombinedListMessage response = new ArrayOfCombinedListMessage();