moving legacy message parse to common file

This commit is contained in:
balzack 2024-12-24 09:26:27 -08:00
parent 421963956b
commit 6506a49cf0
4 changed files with 112 additions and 103 deletions

View File

@ -34,6 +34,7 @@ import { getCardOpenMessage } from './net/getCardOpenMessage';
import { setCardOpenMessage } from './net/setCardOpenMessage';
import { getCardCloseMessage } from './net/getCardCloseMessage';
import { setCardCloseMessage } from './net/setCardCloseMessage';
import { getLegacyData } from './legacy';
const CLOSE_POLL_MS = 100;
const RETRY_POLL_MS = 2000;
@ -1028,6 +1029,7 @@ export class ContactModule implements Contact {
const { summary, detail } = item;
const channelData = detail.sealed ? item.unsealedDetail : detail.data || '{}';
const topicData = summary.sealed ? item.unsealedSummary : summary.data || '{}';
const parsed = this.parse(topicData);
return {
channelId,
@ -1036,7 +1038,7 @@ export class ContactModule implements Contact {
guid: summary.guid,
sealed: summary.sealed,
dataType: summary.dataType,
data: this.parse(topicData),
data: getLegacyData(parsed).data,
created: summary.created,
updated: summary.updated,
status: summary.status,

View File

@ -19,6 +19,7 @@ import { setChannelTopicSubject } from './net/setChannelTopicSubject';
import { setContactChannelTopicSubject } from './net/setContactChannelTopicSubject';
import { removeChannelTopic } from './net/removeChannelTopic';
import { removeContactChannelTopic } from './net/removeContactChannelTopic';
import { getLegacyData } from './legacy';
const BATCH_COUNT = 32;
const MIN_LOAD_SIZE = (BATCH_COUNT / 2);
@ -964,107 +965,7 @@ export class FocusModule implements Focus {
private getTopicData(item: TopicItem): { data: any, assets: AssetItem[] } {
const topicDetail = item.detail.sealed ? item.unsealedDetail : item.detail.data;
const { revision } = item.detail;
if (topicDetail == null) {
return { data: null, assets: [] };
}
// lagacy support for 'superbasictopic' and 'sealedtopic'
const { text, textColor, textSize, assets } = topicDetail;
let index: number = 0;
const assetItems = new Set<AssetItem>();
const dataAssets = !assets ? [] : assets.map(({ encrypted, image, audio, video, binary }: BasicAsset) => {
if (encrypted) {
const { type, thumb, label, extension, parts } = encrypted;
if (thumb) {
const asset = {
assetId: `${index}`,
hosting: HostingMode.Inline,
inline: thumb,
}
assetItems.add(asset);
index += 1;
}
const asset = {
assetId: `${index}`,
hosting: HostingMode.Split,
split: parts,
}
assetItems.add(asset);
index += 1;
if (thumb) {
return { encrypted: { type, thumb: `${index-2}`, parts: `${index-1}`, label, extension } }
} else {
return { encrypted: { type, parts: `${index-1}`, label, extension } }
}
} else {
if (image) {
const { thumb, full } = image;
const thumbAsset = {
assetId: `${index}`,
hosting: HostingMode.Basic,
basic: thumb,
}
assetItems.add(thumbAsset);
index += 1;
const fullAsset = {
assetId: `${index}`,
hosting: HostingMode.Basic,
basic: full,
}
assetItems.add(fullAsset);
index += 1;
return { image: { thumb: `${index-2}`, full: `${index-1}` }};
} else if (video) {
const { thumb, hd, lq } = video;
const thumbAsset = {
assetId: `${index}`,
hosting: HostingMode.Basic,
basic: thumb,
}
assetItems.add(thumbAsset);
index += 1;
const hdAsset = {
assetId: `${index}`,
hosting: HostingMode.Basic,
basic: hd,
}
assetItems.add(hdAsset);
index += 1;
const lqAsset = {
assetId: `${index}`,
hosting: HostingMode.Basic,
basic: lq,
}
assetItems.add(lqAsset);
index += 1;
return { video: { thumb: `${index-3}`, hd: `${index-2}`, lq: `${index-1}` }};
} else if (audio) {
const { label, full } = audio;
const fullAsset = {
assetId: `${index}`,
hosting: HostingMode.Basic,
basic: full,
}
assetItems.add(fullAsset);
index += 1;
return { audio: { label, full: `${index-1}` }};
} else {
const { label, extension, data } = binary;
const dataAsset = {
assetId: `${index}`,
hosting: HostingMode.Basic,
basic: data,
}
assetItems.add(dataAsset);
index += 1;
return { audio: { label, extension, data: `${index-1}` }};
}
}
})
return { data: { text, textColor, textSize, assets: dataAssets }, assets: Array.from(assetItems.values()) };
// end of legacy support block
return getLegacyData(topicDetail);
}
private setTopic(topicId: string, item: TopicItem): Topic {

104
app/sdk/src/legacy.ts Normal file
View File

@ -0,0 +1,104 @@
import type { AssetItem } from './items';
import { HostingMode } from './types';
export function getLegacyData(data: any): { data: any, assets: AssetItem[] } {
if (data == null) {
return { data: null, assets: [] };
}
const { text, textColor, textSize, assets } = data;
let index: number = 0;
const assetItems = new Set<AssetItem>();
const dataAssets = !assets ? [] : assets.map(({ encrypted, image, audio, video, binary }: BasicAsset) => {
if (encrypted) {
const { type, thumb, label, extension, parts } = encrypted;
if (thumb) {
const asset = {
assetId: `${index}`,
hosting: HostingMode.Inline,
inline: thumb,
}
assetItems.add(asset);
index += 1;
}
const asset = {
assetId: `${index}`,
hosting: HostingMode.Split,
split: parts,
}
assetItems.add(asset);
index += 1;
if (thumb) {
return { encrypted: { type, thumb: `${index-2}`, parts: `${index-1}`, label, extension } }
} else {
return { encrypted: { type, parts: `${index-1}`, label, extension } }
}
} else {
if (image) {
const { thumb, full } = image;
const thumbAsset = {
assetId: `${index}`,
hosting: HostingMode.Basic,
basic: thumb,
}
assetItems.add(thumbAsset);
index += 1;
const fullAsset = {
assetId: `${index}`,
hosting: HostingMode.Basic,
basic: full,
}
assetItems.add(fullAsset);
index += 1;
return { image: { thumb: `${index-2}`, full: `${index-1}` }};
} else if (video) {
const { thumb, hd, lq } = video;
const thumbAsset = {
assetId: `${index}`,
hosting: HostingMode.Basic,
basic: thumb,
}
assetItems.add(thumbAsset);
index += 1;
const hdAsset = {
assetId: `${index}`,
hosting: HostingMode.Basic,
basic: hd,
}
assetItems.add(hdAsset);
index += 1;
const lqAsset = {
assetId: `${index}`,
hosting: HostingMode.Basic,
basic: lq,
}
assetItems.add(lqAsset);
index += 1;
return { video: { thumb: `${index-3}`, hd: `${index-2}`, lq: `${index-1}` }};
} else if (audio) {
const { label, full } = audio;
const fullAsset = {
assetId: `${index}`,
hosting: HostingMode.Basic,
basic: full,
}
assetItems.add(fullAsset);
index += 1;
return { audio: { label, full: `${index-1}` }};
} else {
const { label, extension, data } = binary;
const dataAsset = {
assetId: `${index}`,
hosting: HostingMode.Basic,
basic: data,
}
assetItems.add(dataAsset);
index += 1;
return { audio: { label, extension, data: `${index-1}` }};
}
}
})
return { data: { text, textColor, textSize, assets: dataAssets }, assets: Array.from(assetItems.values()) };
}

View File

@ -19,6 +19,7 @@ import { clearChannelCard } from './net/clearChannelCard';
import { getChannelNotifications } from './net/getChannelNotifications';
import { setChannelNotifications } from './net/setChannelNotifications';
import { addFlag } from './net/addFlag';
import { getLegacyData } from './legacy';
const CLOSE_POLL_MS = 100;
const RETRY_POLL_MS = 2000;
@ -556,6 +557,7 @@ export class StreamModule {
const { summary, detail, channelKey } = item;
const channelData = detail.sealed ? item.unsealedDetail : detail.data || '{}';
const topicData = summary.sealed ? item.unsealedSummary : summary.data || '{}';
const parsed = this.parse(topicData);
return {
channelId,
@ -564,7 +566,7 @@ export class StreamModule {
guid: summary.guid,
sealed: summary.sealed,
dataType: summary.dataType,
data: this.parse(topicData),
data: getLegacyData(parsed).data,
created: summary.created,
updated: summary.updated,
status: summary.status,