You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
760 B
JavaScript
30 lines
760 B
JavaScript
3 years ago
|
"use strict";
|
||
|
|
||
|
const syncpipe = require("syncpipe");
|
||
|
const flatten = require("flatten");
|
||
|
const matchValue = require("match-value");
|
||
|
|
||
|
module.exports = function mapReceiptEvent(event, _context) {
|
||
|
return syncpipe(event, [
|
||
|
(_) => Object.entries(_.content),
|
||
|
(_) => _.map(([ eventID, receiptSets ]) => syncpipe(receiptSets, [
|
||
|
(_) => Object.entries(_),
|
||
|
(_) => _.map(([ receiptType, receipts ]) => syncpipe(receipts, [
|
||
|
(_) => Object.entries(_),
|
||
|
(_) => _.map(([ user, receiptData ]) => {
|
||
|
return {
|
||
|
type: "receiptReceived",
|
||
|
receiptType: matchValue(receiptType, {
|
||
|
"m.read": "readReceipt"
|
||
|
}),
|
||
|
user: user,
|
||
|
timestamp: receiptData.ts,
|
||
|
eventID: eventID
|
||
|
};
|
||
|
})
|
||
|
]))
|
||
|
])),
|
||
|
(_) => flatten(_)
|
||
|
]);
|
||
|
};
|