From 6506a49cf080d804fd55bc206649c97853e51179 Mon Sep 17 00:00:00 2001 From: balzack Date: Tue, 24 Dec 2024 09:26:27 -0800 Subject: [PATCH] moving legacy message parse to common file --- app/sdk/src/contact.ts | 4 +- app/sdk/src/focus.ts | 103 +--------------------------------------- app/sdk/src/legacy.ts | 104 +++++++++++++++++++++++++++++++++++++++++ app/sdk/src/stream.ts | 4 +- 4 files changed, 112 insertions(+), 103 deletions(-) create mode 100644 app/sdk/src/legacy.ts diff --git a/app/sdk/src/contact.ts b/app/sdk/src/contact.ts index f700f8e2..462027bf 100644 --- a/app/sdk/src/contact.ts +++ b/app/sdk/src/contact.ts @@ -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, diff --git a/app/sdk/src/focus.ts b/app/sdk/src/focus.ts index a1334ecf..f2692bdf 100644 --- a/app/sdk/src/focus.ts +++ b/app/sdk/src/focus.ts @@ -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(); - 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 { diff --git a/app/sdk/src/legacy.ts b/app/sdk/src/legacy.ts new file mode 100644 index 00000000..9ea95b5a --- /dev/null +++ b/app/sdk/src/legacy.ts @@ -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(); + 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()) }; +} + diff --git a/app/sdk/src/stream.ts b/app/sdk/src/stream.ts index 81aaa4c9..597dcf91 100644 --- a/app/sdk/src/stream.ts +++ b/app/sdk/src/stream.ts @@ -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,