adding support for out of band avatars

This commit is contained in:
or-else
2021-05-10 11:38:53 -07:00
parent 02e1a28e89
commit 74d5473a8b
16 changed files with 115 additions and 78 deletions
+26 -14
View File
@@ -19,23 +19,35 @@ export function updateFavicon(count) {
document.title = (count > 0 ? '('+count+') ' : '') + 'Tinode';
}
// Create theCard which represents topic 'public' info.
export function theCard(fn, imageDataUrl) {
// Create theCard which represents user's or topic's "public" info.
export function theCard(fn, imageUrl, imageMimeType) {
let card = null;
fn = fn && fn.trim();
if ((fn && fn.trim()) || imageDataUrl) {
card = {};
if (fn) {
card.fn = fn.trim();
}
if (imageDataUrl) {
const dataStart = imageDataUrl.indexOf(',');
card.photo = dataStart >= 0 ? {
data: imageDataUrl.substring(dataStart+1),
type: 'jpg'
} : imageDataUrl;
}
if (fn) {
card = {
fn: fn
};
}
if (imageUrl) {
card = card || {};
let mimeType = imageMimeType;
// Is this a data URL "data:[<mediatype>][;base64],<data>"?
const matches = /^data:(image\/[-a-z0-9+.]+)(;base64)?,/i.exec(imageUrl);
if (matches) {
mimeType = matches[1];
card.photo = {
data: imageUrl.substring(imageUrl.indexOf(',') + 1)
};
} else {
card.photo = {
ref: imageUrl
};
}
card.photo.type = (mimeType || 'image/jpeg').substring('image/'.length);
}
return card;
}