Skip to content

Commit

Permalink
Another attemp to fix the usage stats in support of #377.
Browse files Browse the repository at this point in the history
  • Loading branch information
uncheckederror committed Aug 4, 2023
1 parent d0ba933 commit 8ef5129
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions Messaging/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -361,11 +361,21 @@
foreach (var reg in registrations)
{
var checkAsDialed = PhoneNumbersNA.PhoneNumber.TryParse(reg.AsDialed, out var asDialedNumber);
int inboundMMS = await db.Messages.Where(x => (x.From == reg.AsDialed || x.To.Contains(reg.AsDialed)) && x.MessageSource == MessageSource.Incoming && x.MessageType == MessageType.MMS).CountAsync();
int outboundMMS = await db.Messages.Where(x => (x.From == reg.AsDialed || x.To.Contains(reg.AsDialed)) && x.MessageSource == MessageSource.Outgoing && x.MessageType == MessageType.MMS).CountAsync();
int inboundSMS = await db.Messages.Where(x => (x.From == reg.AsDialed || x.To.Contains(reg.AsDialed)) && x.MessageSource == MessageSource.Incoming && x.MessageType == MessageType.SMS).CountAsync();
int outboundSMS = await db.Messages.Where(x => (x.From == reg.AsDialed || x.To.Contains(reg.AsDialed)) && x.MessageSource == MessageSource.Outgoing && x.MessageType == MessageType.SMS).CountAsync();
if (asDialedNumber.Type is not PhoneNumbersNA.NumberType.ShortCode)
{
asDialed = $"1{asDialedNumber.DialedNumber}";
}
else
{
asDialed = asDialedNumber.DialedNumber;
}
int inboundMMS = await db.Messages.Where(x => (x.From == asDialed || x.To.Contains(reg.AsDialed)) && x.MessageSource == MessageSource.Incoming && x.MessageType == MessageType.MMS).CountAsync();
int outboundMMS = await db.Messages.Where(x => (x.From == asDialed || x.To.Contains(reg.AsDialed)) && x.MessageSource == MessageSource.Outgoing && x.MessageType == MessageType.MMS).CountAsync();
int inboundSMS = await db.Messages.Where(x => (x.From == asDialed || x.To.Contains(reg.AsDialed)) && x.MessageSource == MessageSource.Incoming && x.MessageType == MessageType.SMS).CountAsync();
int outboundSMS = await db.Messages.Where(x => (x.From == asDialed || x.To.Contains(reg.AsDialed)) && x.MessageSource == MessageSource.Outgoing && x.MessageType == MessageType.SMS).CountAsync();
summary.Add(new UsageSummary { AsDialed = reg.AsDialed, InboundMMSCount = inboundMMS, OutboundMMSCount = outboundMMS, InboundSMSCount = inboundSMS, OutboundSMSCount = outboundSMS });
}
Expand Down Expand Up @@ -399,11 +409,19 @@
if (reg is not null && !string.IsNullOrWhiteSpace(reg.AsDialed))
{
var inboundMMS = await db.Messages.Where(x => x.To == reg.AsDialed && x.MessageSource == MessageSource.Incoming && x.MessageType == MessageType.MMS).CountAsync();
var outboundMMS = await db.Messages.Where(x => x.To == reg.AsDialed && x.MessageSource == MessageSource.Outgoing && x.MessageType == MessageType.MMS).CountAsync();
var inboundSMS = await db.Messages.Where(x => x.To == reg.AsDialed && x.MessageSource == MessageSource.Incoming && x.MessageType == MessageType.SMS).CountAsync();
var outboundSMS = await db.Messages.Where(x => x.To == reg.AsDialed && x.MessageSource == MessageSource.Outgoing && x.MessageType == MessageType.SMS).CountAsync();
if (asDialedNumber.Type is not PhoneNumbersNA.NumberType.ShortCode)
{
asDialed = $"1{asDialedNumber.DialedNumber}";
}
else
{
asDialed = asDialedNumber.DialedNumber;
}
var inboundMMS = await db.Messages.Where(x => (x.To.Contains(asDialed) || x.From == asDialed) && x.MessageSource == MessageSource.Incoming && x.MessageType == MessageType.MMS).CountAsync();
var outboundMMS = await db.Messages.Where(x => (x.To.Contains(asDialed) || x.From == asDialed) && x.MessageSource == MessageSource.Outgoing && x.MessageType == MessageType.MMS).CountAsync();
var inboundSMS = await db.Messages.Where(x => (x.To.Contains(asDialed) || x.From == asDialed) && x.MessageSource == MessageSource.Incoming && x.MessageType == MessageType.SMS).CountAsync();
var outboundSMS = await db.Messages.Where(x => (x.To.Contains(asDialed) || x.From == asDialed) && x.MessageSource == MessageSource.Outgoing && x.MessageType == MessageType.SMS).CountAsync();
var summary = new UsageSummary { AsDialed = reg.AsDialed, InboundMMSCount = inboundMMS, OutboundMMSCount = outboundMMS, InboundSMSCount = inboundSMS, OutboundSMSCount = outboundSMS };
return TypedResults.Ok(new UsageSummary[] { summary });
}
Expand Down

0 comments on commit 8ef5129

Please sign in to comment.