consolodating subject extraction

This commit is contained in:
Roland Osborne 2023-02-28 12:41:29 -08:00
parent 499ce44328
commit cc0c43817c

View File

@ -0,0 +1,67 @@
import { getCardByGuid } from 'context/cardUtil';
export function getChannelSubjectLogo(cardId, profileGuid, channel, cards, cardImageUrl) {
let subject;
try {
if (channel?.detail?.dataType === 'sealed') {
subject = channel?.unsealedDetail?.subject;
}
if (channel?.detail?.dataType === 'superbasic') {
subject = JSON.parse(channel.detail.data)?.subject;
}
}
catch(err) {
console.log(err);
}
const contacts = [];
if (cardId) {
contacts.push(cardId);
}
if (channel?.detail?.members?.length) {
channel.detail.members.forEach(guid => {
if (guid !== profileGuid) {
const contact = getCardByGuid(cards, guid)?.card;
contacts.push(contact);
}
})
}
if (!subject) {
if (contacts.length === 0) {
subject = 'Notes';
}
else {
const names = [];
contacts.forEach(contact => {
if (contact?.profile?.name) {
names.push(contact.profile.name);
}
else if (contact?.profile?.handle) {
names.push(contact.profile.handle);
}
});
subject = names.join(', ');
}
}
let logo;
if (contacts.length === 0) {
logo = 'solution';
}
else if (contacts.length === 1) {
const contact = contacts[0];
if (contact?.profile?.imageSet) {
logo = cardImageUrl(contact.cardId)
}
else {
logo = 'avatar';
}
}
else {
logo = 'appstore';
}
return { logo, subject };
}