Read an intermediate delivery notification as a report, and keep it out of the merge
This commit is contained in:
+3
-2
@@ -41,7 +41,8 @@ const severity: Record<MessageState, number> = {
|
||||
* Merges the per-segment receipts of a multipart message into one report, but only when the peer
|
||||
* numbered its ids `<base>-<n>` off one base — the convention this library's own server follows. An
|
||||
* SMSC that hands out unrelated ids per segment cannot be merged, so nothing is reported for it.
|
||||
* A base is merged at most once: a reused id cannot be told apart from a straggler.
|
||||
* A base is merged at most once: a reused id cannot be told apart from a straggler, and a report the
|
||||
* peer marked intermediate is never counted — it would fill a slot before the real receipt arrives.
|
||||
*/
|
||||
export class DlrMerger {
|
||||
private readonly groups: ExpiringGroups<Group>;
|
||||
@@ -95,7 +96,7 @@ export class DlrMerger {
|
||||
collect(dlr: Dlr): MessageDlr | undefined {
|
||||
this.sweep();
|
||||
|
||||
if (dlr.smsId === undefined) return undefined;
|
||||
if (dlr.intermediate || dlr.smsId === undefined) return undefined;
|
||||
|
||||
const match = numbered.exec(dlr.smsId);
|
||||
const base = match?.[1];
|
||||
|
||||
+7
-5
@@ -50,6 +50,7 @@ export type Receipt = {
|
||||
export type Dlr = {
|
||||
doneDate: Date | undefined;
|
||||
errorCode: string | undefined;
|
||||
intermediate: boolean;
|
||||
receipt: Receipt | undefined;
|
||||
smsId: string | undefined;
|
||||
statusId: number;
|
||||
@@ -127,13 +128,12 @@ export function parseReceipt(message: string): Receipt {
|
||||
};
|
||||
}
|
||||
|
||||
type MessageType = 'other' | 'receipt' | 'unmarked';
|
||||
type MessageType = 'intermediate' | 'other' | 'receipt' | 'unmarked';
|
||||
|
||||
/** The message types the spec names that are not receipts. It reserves the remaining ten. */
|
||||
const notReceiptTypes: number[] = [
|
||||
/** The types the far-end SME writes, rather than the MC reporting. The spec reserves the remaining ten. */
|
||||
const smeMessageTypes: number[] = [
|
||||
consts.ESM_CLASS.CONVERSATION_ABORT,
|
||||
consts.ESM_CLASS.DELIVERY_ACKNOWLEDGEMENT,
|
||||
consts.ESM_CLASS.INTERMEDIATE_DELIVERY,
|
||||
consts.ESM_CLASS.USER_ACKNOWLEDGEMENT,
|
||||
];
|
||||
|
||||
@@ -145,7 +145,8 @@ function messageType(pduObj: PduObject): MessageType {
|
||||
const type = messageTypeOf(paramNumber(pduObj.params.esm_class, 0));
|
||||
|
||||
if (type === consts.ESM_CLASS.MC_DELIVERY_RECEIPT) return 'receipt';
|
||||
if (notReceiptTypes.includes(type)) return 'other';
|
||||
if (type === consts.ESM_CLASS.INTERMEDIATE_DELIVERY) return 'intermediate';
|
||||
if (smeMessageTypes.includes(type)) return 'other';
|
||||
|
||||
return nonEmptyText(pduObj.tlvs.receipted_message_id?.tagValue) === undefined ? 'unmarked' : 'receipt';
|
||||
}
|
||||
@@ -214,6 +215,7 @@ export function dlrFromPdu(pduObj: PduObject, format: SmsIdFormat = {}): Dlr | u
|
||||
return {
|
||||
doneDate: receiptDate(receipt?.doneDate),
|
||||
errorCode: receipt?.err,
|
||||
intermediate: type === 'intermediate',
|
||||
receipt,
|
||||
smsId,
|
||||
statusId,
|
||||
|
||||
Reference in New Issue
Block a user