MCPcopy Create free account
hub / github.com/Treeki/BirdBridge / convertCard

Function convertCard

conversion.ts:214–284  ·  view source on GitHub ↗
(card: Record<string, any>, extendedEntities: any)

Source from the content-addressed store, hash-verified

212}
213
214export function convertCard(card: Record<string, any>, extendedEntities: any): Record<string, any> {
215 const pollMatch = card.name.match(/^poll(\d+)choice/);
216 if (pollMatch) {
217 const optionCount = parseInt(pollMatch[1], 10);
218 const options = [];
219 let totalVotes = 0;
220 for (let i = 1; i <= optionCount; i++) {
221 const votes = parseInt(card.binding_values[`choice${i}_count`].string_value, 10);
222 options.push({
223 title: card.binding_values[`choice${i}_label`].string_value,
224 votes_count: votes
225 });
226 totalVotes += votes;
227 }
228
229 const ownVotes = [];
230 if (card.binding_values.selected_choice?.string_value)
231 ownVotes.push(parseInt(card.binding_values.selected_choice.string_value, 10) - 1);
232
233 const poll = {
234 id: card.url.replace(/^card:\/\//, ''),
235 expires_at: convertPollTimestamp(card.binding_values.end_datetime_utc.string_value),
236 expired: card.binding_values.counts_are_final.boolean_value,
237 multiple: false,
238 votes_count: totalVotes,
239 voted: ownVotes.length > 0,
240 own_votes: ownVotes,
241 options,
242 emojis: []
243 };
244
245 return {poll};
246 } else if (card.name === 'summary' || card.name === 'summary_large_image') {
247 const newCard = {
248 url: tryExpandURL(card.binding_values.card_url.string_value, extendedEntities),
249 title: card.binding_values?.title?.string_value,
250 description: card.binding_values?.description?.string_value,
251 type: 'link',
252 author_name: '',
253 author_url: '',
254 provider_name: '',
255 provider_url: '',
256 html: '',
257 width: 1000,
258 height: 1,
259 // use a 1px image because Ivory won't render a card with no image
260 image: IMAGE_1PX,
261 embed_url: '',
262 blurhash: null
263 };
264
265 // the way that Ivory displays images is really obnoxious if they're square
266 // so, I'm making an executive decision to only show them if they're not too tall
267 try {
268 const image = card.binding_values.thumbnail_image_large;
269 const ratio = image.width / image.height;
270 if (ratio >= 1.5) {
271 newCard.width = image.width;

Callers 1

tweetToTootFunction · 0.85

Calls 2

convertPollTimestampFunction · 0.85
tryExpandURLFunction · 0.85

Tested by

no test coverage detected