Fix bug where the message might be too long

This commit is contained in:
Pieter Vander Vennet 2023-03-12 11:45:09 +01:00
parent 65921d2d11
commit 5adc37b2db

View file

@ -308,13 +308,13 @@ export class Postbuilder {
} = await this.prepareImages(changesets) } = await this.prepareImages(changesets)
const imageUploader = new ImageUploader(randomImages, this._poster, this._globalConfig) const imageUploader = new ImageUploader(randomImages, this._poster, this._globalConfig)
let timePeriod = "Yesterday" let timePeriod = "yesterday"
if (this._config.numberOfDays > 1) { if (this._config.numberOfDays > 1) {
timePeriod = "In the past " + this._config.numberOfDays + " days" timePeriod = "in the past " + this._config.numberOfDays + " days"
} }
const singleTheme = this._config?.themeWhitelist?.length === 1 ? "/" + this._config.themeWhitelist[0] : "" const singleTheme = this._config?.themeWhitelist?.length === 1 ? "/" + this._config.themeWhitelist[0] : ""
let toSend: string[] = [ let toSend: string[] = [
`${timePeriod}, ${perContributor.keys().length} people made ${totalStats.total} changes to #OpenStreetMap using https://mapcomplete.osm.be${singleTheme}`, `${perContributor.keys().length} people made ${totalStats.total} changes ${timePeriod} to #OpenStreetMap using https://mapcomplete.osm.be${singleTheme}`,
"" ""
] ]
@ -344,7 +344,7 @@ export class Postbuilder {
continue continue
} }
const overview = await this.createOverviewForContributor(uid, changesetsMade) const overview = await this.createOverviewForContributor(uid, changesetsMade)
if (overview.length + toSend.join("\n").length > 500) { if (overview.length + toSend.join("\n").length + 1 /*+1 for the separating \n*/ > 500) {
break break
} }
toSend.push(overview) toSend.push(overview)