Comparing version 1.1.9-rc.7 to 1.1.9-rc.8
{ | ||
"name": "puregram", | ||
"version": "1.1.9-rc.7", | ||
"version": "1.1.9-rc.8", | ||
"main": "src/index.js", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -251,2 +251,4 @@ let { inspect } = require('util'); | ||
get attachments() { | ||
if (this.newAttachments) return this.newAttachments; | ||
let attachments = []; | ||
@@ -271,2 +273,6 @@ | ||
set attachments(newAttachments) { | ||
this.newAttachments = newAttachments; | ||
} | ||
hasAttachments(type = null) { | ||
@@ -273,0 +279,0 @@ if (type === null) return this.attachments.length > 0; |
@@ -251,2 +251,4 @@ let { inspect } = require('util'); | ||
get attachments() { | ||
if (this.newAttachments) return this.newAttachments; | ||
let attachments = []; | ||
@@ -271,2 +273,6 @@ | ||
set attachments(newAttachments) { | ||
this.newAttachments = newAttachments; | ||
} | ||
hasAttachments(type = null) { | ||
@@ -273,0 +279,0 @@ if (type === null) return this.attachments.length > 0; |
@@ -251,2 +251,4 @@ let { inspect } = require('util'); | ||
get attachments() { | ||
if (this.newAttachments) return this.newAttachments; | ||
let attachments = []; | ||
@@ -271,2 +273,6 @@ | ||
set attachments(newAttachments) { | ||
this.newAttachments = newAttachments; | ||
} | ||
hasAttachments(type = null) { | ||
@@ -273,0 +279,0 @@ if (type === null) return this.attachments.length > 0; |
@@ -310,2 +310,4 @@ let { inspect } = require('util'); | ||
get attachments() { | ||
if (this.newAttachments) return this.newAttachments; | ||
let attachments = []; | ||
@@ -330,2 +332,6 @@ | ||
set attachments(newAttachments) { | ||
this.newAttachments = newAttachments; | ||
} | ||
hasAttachments(type = null) { | ||
@@ -332,0 +338,0 @@ if (type === null) return this.attachments.length > 0; |
@@ -14,3 +14,4 @@ let https = require('https'); | ||
keepAliveMsecs: 1000, | ||
}) | ||
}), | ||
mergeEvents = false | ||
}) { | ||
@@ -20,2 +21,3 @@ this.token = token; | ||
this.agent = agent; | ||
this.mergeEvents = mergeEvents; | ||
@@ -22,0 +24,0 @@ if (this.baseApiUrl.startsWith('http://')) { |
@@ -175,14 +175,22 @@ let middlewareIo = require('middleware-io'); | ||
updates.forEach( | ||
async (update) => { | ||
try { | ||
await this.pollingHandler(update); | ||
} catch (e) { | ||
console.error('Handle polling update error:', e); | ||
if (this.telegram.mergeEvents) { | ||
try { | ||
await this.mergePollingHandler(updates); | ||
} catch (e) { | ||
console.error('Handle polling update merging error:', e); | ||
} | ||
} else { | ||
updates.forEach( | ||
async (update) => { | ||
try { | ||
await this.pollingHandler(update); | ||
} catch (e) { | ||
console.error('Handle polling update error:', e); | ||
} | ||
} | ||
}, | ||
); | ||
); | ||
} | ||
} | ||
async pollingHandler(update) { | ||
async pollingHandler(update, merging = false) { | ||
this.offset = update.update_id + 1 || this.offset; | ||
@@ -221,5 +229,71 @@ | ||
return this.dispatchMiddleware(context); | ||
if (!merging) return this.dispatchMiddleware(context); | ||
return context; | ||
} | ||
async mergePollingHandler(updates) { | ||
// eslint-cringe-code-linter-enable | ||
const kContexts = await Promise.all( | ||
updates.map( | ||
update => this.pollingHandler(update, true) | ||
) | ||
); | ||
const fContexts = kContexts.filter( | ||
xContext => xContext.mediaGroupId | ||
); | ||
if (!fContexts.length) { | ||
return updates.forEach( | ||
async (update) => { | ||
try { | ||
await this.pollingHandler(update); | ||
} catch (e) { | ||
console.error('Handle polling update error:', e); | ||
} | ||
} | ||
); | ||
} | ||
const mediaGroupIds = {}; | ||
fContexts.forEach( | ||
(update) => { | ||
if (!mediaGroupIds[update.mediaGroupId]) { | ||
mediaGroupIds[update.mediaGroupId] = []; | ||
} | ||
mediaGroupIds[update.mediaGroupId].push( | ||
update | ||
); | ||
} | ||
); | ||
const actualContexts = []; | ||
// Array<Context> | ||
for (const arrayOfContexts of Object.values(mediaGroupIds)) { | ||
let mainContext = arrayOfContexts[0]; | ||
arrayOfContexts.slice(1).forEach( | ||
(context) => { | ||
mainContext.attachments = [ | ||
...mainContext.attachments, | ||
...context.attachments | ||
]; | ||
} | ||
) | ||
actualContexts.push(mainContext); | ||
} | ||
return actualContexts.forEach( | ||
context => this.dispatchMiddleware(context) | ||
); | ||
// eslint-cringe-code-linter-disable | ||
} | ||
dispatchMiddleware(context) { | ||
@@ -226,0 +300,0 @@ return this.stackMiddleware(context, middlewareIo.noopNext); |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
784845
23679