adding support for out of band avatars
This commit is contained in:
+26
-14
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user