mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
consolodating subject extraction
This commit is contained in:
parent
499ce44328
commit
cc0c43817c
67
app/mobile/src/context/channelUtil.js
Normal file
67
app/mobile/src/context/channelUtil.js
Normal 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 };
|
||||
}
|
Loading…
Reference in New Issue
Block a user