diff --git a/app/mobile/src/context/channelUtil.js b/app/mobile/src/context/channelUtil.js new file mode 100644 index 00000000..f315f2b5 --- /dev/null +++ b/app/mobile/src/context/channelUtil.js @@ -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 }; +}