diff --git a/src/Controllers/Common/ContentController.cs b/src/Controllers/Common/ContentController.cs index a4ca9cd..4be9327 100644 --- a/src/Controllers/Common/ContentController.cs +++ b/src/Controllers/Common/ContentController.cs @@ -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")] diff --git a/src/Services/BuddyService.cs b/src/Services/BuddyService.cs index 6e68e0e..11fef4e 100644 --- a/src/Services/BuddyService.cs +++ b/src/Services/BuddyService.cs @@ -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 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(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(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 diff --git a/src/Services/MessagingService.cs b/src/Services/MessagingService.cs index 17c1fb5..e3f7f11 100644 --- a/src/Services/MessagingService.cs +++ b/src/Services/MessagingService.cs @@ -115,7 +115,7 @@ public class MessagingService public ArrayOfCombinedListMessage ConstructCombinedMessageArray(Viking viking, Viking publicViking) { // get all messages in viking board - List messages = ctx.Messages.Where(e => e.ToVikingId == viking.Id).ToList(); + List messages = ctx.Messages.Where(e => e.ToVikingId == publicViking.Id).ToList(); List combinedListMessages = new List(); ArrayOfCombinedListMessage response = new ArrayOfCombinedListMessage();