Skip to content

Instantly share code, notes, and snippets.

@thebells1111
Created August 29, 2021 03:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thebells1111/de14cf5e15e94b8ef7c9ec0a69bdcf83 to your computer and use it in GitHub Desktop.
Save thebells1111/de14cf5e15e94b8ef7c9ec0a69bdcf83 to your computer and use it in GitHub Desktop.
TLV Max Message
let record = {
7629169: {
podcast:
$playingPodcast.title.length < 101
? $playingPodcast.title
: $playingPodcast.title.substring(0, 100) + '...',
feedID: $playingPodcast.id,
episode:
$playingEpisode.title.length < 101
? $playingEpisode.title
: $playingEpisode.title.substring(0, 100) + '...',
action: 'boost',
ts: Math.floor($playerTime),
boost_link: createBoostLink(Math.floor($playerTime)),
app_name: 'CurioCaster',
url: $playingPodcast.url,
},
};
let baseLength = new Blob([JSON.stringify(record, null, 0)]).size;
let longestName = '';
let longestNameLength = 0;
let recordNameLength = 0;
destinations = $playingPodcast.value.destinations;
for (let dest of destinations) {
if (dest?.name?.length > longestNameLength) {
longestNameLength = dest?.name?.length;
longestName = dest?.name;
}
}
recordNameLength = new Blob([
JSON.stringify({ name: longestName }, null, 0),
]).size;
let tipLength = new Blob([
JSON.stringify(
{ value_msat: satValue * 1000, value_msat_total: satValue * 1000 },
null,
0
),
]).size;
let senderLength = new Blob([JSON.stringify({ sender: sender }, null, 0)])
.size;
let maxTextLength =
Math.floor(
(1200 - (baseLength + tipLength + recordNameLength + senderLength)) / 100
) * 100;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment