@streamlayer/feature-gamification
Advanced tools
Comparing version 1.3.3 to 1.4.0
@@ -1,4 +0,3 @@ | ||
import { createMapStore } from '@streamlayer/sdk-web-interfaces'; | ||
import { createMapStore, StreamLayerContext } from '@streamlayer/sdk-web-interfaces'; | ||
import { PromotionOptions } from '@streamlayer/sdk-web-types'; | ||
import { type Transport } from '@streamlayer/sdk-web-api'; | ||
import { type GamificationBackground } from '../background'; | ||
@@ -33,3 +32,3 @@ import { getPromotionDetail } from '../queries'; | ||
*/ | ||
export declare const advertisement: ($slStreamId: GamificationBackground["slStreamId"], $feedSubscription: GamificationBackground["feedSubscription"], transport: Transport) => { | ||
export declare const advertisement: ($slStreamId: GamificationBackground["slStreamId"], $feedSubscription: GamificationBackground["feedSubscription"], instance: StreamLayerContext) => { | ||
hide: (notificationId: string) => void; | ||
@@ -36,0 +35,0 @@ show: (advertisementId: string, data?: Awaited<ReturnType<typeof getPromotionDetail>>) => void; |
@@ -20,3 +20,4 @@ import { ApiStore, createMapStore, eventBus } from '@streamlayer/sdk-web-interfaces'; | ||
*/ | ||
export const advertisement = ($slStreamId, $feedSubscription, transport) => { | ||
export const advertisement = ($slStreamId, $feedSubscription, instance) => { | ||
const transport = instance.transport; | ||
const logger = createLogger('advertisement_queue'); | ||
@@ -69,2 +70,6 @@ const queue = new AdvertisementsQueue({ concurrency: 1, animationDelay: 1000 }); | ||
markAsViewed(notificationId); | ||
instance.sdk.onAdvertisementActivate({ | ||
stage: 'deactivate', | ||
id: notificationId, | ||
}); | ||
}; | ||
@@ -94,2 +99,45 @@ const getActiveAdvertisement = (persistent) => { | ||
}; | ||
$advertisementList.subscribe((list) => { | ||
if (list.data) { | ||
const last = list.data[list.data.length - 1]; | ||
if (last) { | ||
instance.sdk.onAdvertisementActivate({ | ||
stage: 'activate', | ||
id: last.id, | ||
isShowed: !!storage.isShowed(last.id), | ||
}); | ||
} | ||
} | ||
}); | ||
$feedSubscription.addListener('promotion cb', (response) => { | ||
const feedItem = response.data?.attributes?.feedItem?.attributes?.attributes?.case === 'promotion' | ||
? response.data.attributes.feedItem.attributes | ||
: undefined; | ||
const promotionItem = response.data?.attributes?.question?.options?.options.case === 'promotion' | ||
? response.data.attributes.question.options.options.value | ||
: undefined; | ||
if (feedItem === undefined || promotionItem === undefined) { | ||
logger.debug('not promotion'); | ||
return; | ||
} | ||
if (feedItem.status === QuestionStatus.RESOLVED) { | ||
instance.sdk.onAdvertisementActivate({ | ||
stage: 'deactivate', | ||
id: feedItem.id, | ||
}); | ||
logger.debug({ feedItem }, 'resolved: %o'); | ||
return; | ||
} | ||
if (feedItem.status === QuestionStatus.ACTIVE) { | ||
logger.debug({ feedItem }, 'active: %o'); | ||
instance.sdk.onAdvertisementActivate({ | ||
stage: 'activate', | ||
id: feedItem.id, | ||
isShowed: !!storage.isShowed(feedItem.id), | ||
}); | ||
return; | ||
} | ||
logger.debug({ feedItem }, 'skip: %o'); | ||
return; | ||
}); | ||
onMount(queue.advertisementList, () => { | ||
@@ -96,0 +144,0 @@ $advertisementList.subscribe((list) => { |
@@ -123,3 +123,3 @@ import { ApiStore, SingleStore, createSingleStore } from '@streamlayer/sdk-web-interfaces'; | ||
}); | ||
this.advertisement = advertisement(this.slStreamId, this.feedSubscription, instance.transport); | ||
this.advertisement = advertisement(this.slStreamId, this.feedSubscription, instance); | ||
} | ||
@@ -126,0 +126,0 @@ /** |
@@ -69,2 +69,3 @@ import { AbstractFeature, ApiStore, FeatureSource, type FeatureProps, type StreamLayerContext } from '@streamlayer/sdk-web-interfaces'; | ||
}) => void | (() => void); | ||
getFeedItem: (id: string) => Promise<import("@streamlayer/sl-eslib/interactive/feed/interactive.feed_pb").FeedItem | undefined>; | ||
isOpenedQuestion: (questionId: string) => string | undefined; | ||
@@ -71,0 +72,0 @@ closeQuestion: (questionId?: string) => void; |
@@ -400,2 +400,5 @@ /* eslint-disable @typescript-eslint/ban-ts-comment */ | ||
}; | ||
getFeedItem = (id) => { | ||
return queries.getFeedItem(id, this.transport); | ||
}; | ||
isOpenedQuestion = (questionId) => { | ||
@@ -402,0 +405,0 @@ return this.notifications.isViewed(questionId); |
@@ -7,2 +7,3 @@ import type { Transport } from '@streamlayer/sdk-web-api'; | ||
export declare const $activeQuestion: (slStreamId: ReadableAtom<string | undefined>, transport: Transport) => import("@nanostores/query").FetcherStore<import("@streamlayer/sl-eslib/interactive/feed/interactive.feed_pb").FeedQuestion | undefined, any>; | ||
export declare const getFeedItem: (questionId: string, transport: Transport) => Promise<import("@streamlayer/sl-eslib/interactive/feed/interactive.feed_pb").FeedItem | undefined>; | ||
export declare const feedSubscription: ($slStreamId: ReadableAtom<string | undefined>, transport: Transport) => import("packages/sdk-web-api/lib/grpc/subscription").ServerStreamSubscription<import("@bufbuild/protobuf").ServiceType, import("@bufbuild/protobuf").Message<import("@bufbuild/protobuf").AnyMessage>, import("@bufbuild/protobuf").Message<import("@bufbuild/protobuf").AnyMessage>, never, never> | import("packages/sdk-web-api/lib/grpc/subscription").ServerStreamSubscription<{ | ||
@@ -107,2 +108,8 @@ readonly typeName: "streamlayer.interactive.feed.Feed"; | ||
}; | ||
readonly item: { | ||
readonly name: "Item"; | ||
readonly I: typeof import("@streamlayer/sl-eslib/interactive/feed/interactive.feed_pb").FeedItemRequest; | ||
readonly O: typeof import("@streamlayer/sl-eslib/interactive/feed/interactive.feed_pb").FeedItemResponse; | ||
readonly kind: import("@bufbuild/protobuf").MethodKind.Unary; | ||
}; | ||
readonly feedSubscription: { | ||
@@ -218,2 +225,8 @@ readonly name: "FeedSubscription"; | ||
}; | ||
readonly item: { | ||
readonly name: "Item"; | ||
readonly I: typeof import("@streamlayer/sl-eslib/interactive/feed/interactive.feed_pb").FeedItemRequest; | ||
readonly O: typeof import("@streamlayer/sl-eslib/interactive/feed/interactive.feed_pb").FeedItemResponse; | ||
readonly kind: import("@bufbuild/protobuf").MethodKind.Unary; | ||
}; | ||
readonly feedSubscription: { | ||
@@ -326,2 +339,8 @@ readonly name: "FeedSubscription"; | ||
}; | ||
readonly item: { | ||
readonly name: "Item"; | ||
readonly I: typeof import("@streamlayer/sl-eslib/interactive/feed/interactive.feed_pb").FeedItemRequest; | ||
readonly O: typeof import("@streamlayer/sl-eslib/interactive/feed/interactive.feed_pb").FeedItemResponse; | ||
readonly kind: import("@bufbuild/protobuf").MethodKind.Unary; | ||
}; | ||
readonly feedSubscription: { | ||
@@ -328,0 +347,0 @@ readonly name: "FeedSubscription"; |
@@ -23,2 +23,9 @@ import { QuestionStatus, QuestionType } from '@streamlayer/sdk-web-types'; | ||
}; | ||
export const getFeedItem = async (questionId, transport) => { | ||
const { client } = transport.createPromiseClient(Feed, { method: 'item', params: [questionId] }); | ||
const res = await client.item({ | ||
id: questionId, | ||
}); | ||
return res.data; | ||
}; | ||
export const feedSubscription = ($slStreamId, transport) => { | ||
@@ -25,0 +32,0 @@ const { client } = transport.createStreamClient(Feed); |
{ | ||
"name": "@streamlayer/feature-gamification", | ||
"version": "1.3.3", | ||
"version": "1.4.0", | ||
"peerDependencies": { | ||
"@bufbuild/protobuf": "^1.10.0", | ||
"@fastify/deepmerge": "^2.0.0", | ||
"@streamlayer/sl-eslib": "^5.117.0", | ||
"@streamlayer/sl-eslib": "^5.122.0", | ||
"nanostores": "^0.10.3", | ||
"@streamlayer/sdk-web-api": "^1.2.3", | ||
"@streamlayer/sdk-web-core": "^1.1.3", | ||
"@streamlayer/sdk-web-logger": "^1.0.8", | ||
"@streamlayer/sdk-web-interfaces": "^1.1.3", | ||
"@streamlayer/sdk-web-notifications": "^1.1.3", | ||
"@streamlayer/sdk-web-storage": "^1.0.8", | ||
"@streamlayer/sdk-web-types": "^1.2.3" | ||
"@streamlayer/sdk-web-api": "^1.3.0", | ||
"@streamlayer/sdk-web-core": "^1.2.0", | ||
"@streamlayer/sdk-web-interfaces": "^1.1.4", | ||
"@streamlayer/sdk-web-logger": "^1.0.9", | ||
"@streamlayer/sdk-web-notifications": "^1.1.4", | ||
"@streamlayer/sdk-web-storage": "^1.0.9", | ||
"@streamlayer/sdk-web-types": "^1.3.0" | ||
}, | ||
@@ -17,0 +17,0 @@ "devDependencies": { |
127697
2560