forked from SoDOff-Project/sodoff
implement `BlockBuddy
`
messaging bug fix
This commit is contained in:
parent
766c4b8884
commit
e10f80580a
@ -1198,6 +1198,44 @@ public class ContentController : Controller {
|
|||||||
else return Ok(false);
|
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]
|
[HttpPost]
|
||||||
[Produces("application/xml")]
|
[Produces("application/xml")]
|
||||||
[Route("ContentWebService.asmx/ApproveBuddy")]
|
[Route("ContentWebService.asmx/ApproveBuddy")]
|
||||||
|
@ -133,6 +133,30 @@ public class BuddyService
|
|||||||
|
|
||||||
if (buddy != null)
|
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
|
// remove it
|
||||||
ctx.Buddies.Remove(buddy);
|
ctx.Buddies.Remove(buddy);
|
||||||
ctx.SaveChanges();
|
ctx.SaveChanges();
|
||||||
@ -150,9 +174,12 @@ public class BuddyService
|
|||||||
List<Schema.Buddy> schemaBuddies = new();
|
List<Schema.Buddy> schemaBuddies = new();
|
||||||
foreach (var buddy in buddies)
|
foreach (var buddy in buddies)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
Schema.Buddy schemaBuddy = new Schema.Buddy();
|
||||||
|
|
||||||
// show differently depending on requester
|
// show differently depending on requester
|
||||||
if (buddy.VikingId == viking.Id)
|
if (buddy.VikingId == viking.Id)
|
||||||
schemaBuddies.Add(new Schema.Buddy
|
schemaBuddy = new Schema.Buddy
|
||||||
{
|
{
|
||||||
UserID = buddy.BuddyViking.Uid.ToString(),
|
UserID = buddy.BuddyViking.Uid.ToString(),
|
||||||
DisplayName = XmlUtil.DeserializeXml<AvatarData>(buddy.BuddyViking.AvatarSerialized).DisplayName,
|
DisplayName = XmlUtil.DeserializeXml<AvatarData>(buddy.BuddyViking.AvatarSerialized).DisplayName,
|
||||||
@ -161,9 +188,9 @@ public class BuddyService
|
|||||||
Online = buddy.BuddyViking.Online ?? false,
|
Online = buddy.BuddyViking.Online ?? false,
|
||||||
OnMobile = false,
|
OnMobile = false,
|
||||||
BestBuddy = buddy.IsBestFriend2
|
BestBuddy = buddy.IsBestFriend2
|
||||||
});
|
};
|
||||||
else
|
else
|
||||||
schemaBuddies.Add(new Schema.Buddy
|
schemaBuddy = new Schema.Buddy
|
||||||
{
|
{
|
||||||
UserID = buddy.Viking.Uid.ToString(),
|
UserID = buddy.Viking.Uid.ToString(),
|
||||||
DisplayName = XmlUtil.DeserializeXml<AvatarData>(buddy.Viking.AvatarSerialized).DisplayName,
|
DisplayName = XmlUtil.DeserializeXml<AvatarData>(buddy.Viking.AvatarSerialized).DisplayName,
|
||||||
@ -172,7 +199,10 @@ public class BuddyService
|
|||||||
Online = buddy.Viking.Online ?? false,
|
Online = buddy.Viking.Online ?? false,
|
||||||
OnMobile = false,
|
OnMobile = false,
|
||||||
BestBuddy = buddy.IsBestFriend1
|
BestBuddy = buddy.IsBestFriend1
|
||||||
});
|
};
|
||||||
|
|
||||||
|
// add buddy
|
||||||
|
schemaBuddies.Add(schemaBuddy);
|
||||||
}
|
}
|
||||||
|
|
||||||
// return buddy list
|
// return buddy list
|
||||||
|
@ -115,7 +115,7 @@ public class MessagingService
|
|||||||
public ArrayOfCombinedListMessage ConstructCombinedMessageArray(Viking viking, Viking publicViking)
|
public ArrayOfCombinedListMessage ConstructCombinedMessageArray(Viking viking, Viking publicViking)
|
||||||
{
|
{
|
||||||
// get all messages in viking board
|
// 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>();
|
List<CombinedListMessage> combinedListMessages = new List<CombinedListMessage>();
|
||||||
ArrayOfCombinedListMessage response = new ArrayOfCombinedListMessage();
|
ArrayOfCombinedListMessage response = new ArrayOfCombinedListMessage();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user