@streamlayer/feature-gamification 0.36.0 → 0.37.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/background.js CHANGED
@@ -75,12 +75,10 @@ export class GamificationBackground {
75
75
  });
76
76
  this.feedSubscription = queries.feedSubscription(this.slStreamId, instance.transport);
77
77
  this.feedSubscription.addListener('feed-subscription-active-question', (response) => {
78
- window.requestAnimationFrame(() => {
79
- const $activeQuestionId = this.activeQuestionId.getStore();
80
- if ($activeQuestionId) {
81
- $activeQuestionId.mutate(response.data?.attributes);
82
- }
83
- });
78
+ const $activeQuestionId = this.activeQuestionId.getStore();
79
+ if ($activeQuestionId) {
80
+ $activeQuestionId.mutate(response.data?.attributes);
81
+ }
84
82
  });
85
83
  // refresh moderation if question empty, it`s mean that moderation was changed
86
84
  this.feedSubscription.addListener('moderation update', (response) => {
package/lib/deepLink.d.ts CHANGED
@@ -5,7 +5,7 @@ type DeepLinkData = {
5
5
  loading?: boolean;
6
6
  error?: string;
7
7
  };
8
- export declare const deepLink: (transport: Transport, $eventId: ReadableAtom<string | undefined>, $userId: ReadableAtom<string | undefined>) => {
8
+ export declare const deepLink: (transport: Transport, $eventId: ReadableAtom<string | undefined>, $externalEventId: ReadableAtom<string | undefined>, $userId: ReadableAtom<string | undefined>) => {
9
9
  $store: import("nanostores").MapStore<DeepLinkData>;
10
10
  fetch: typeof fetch;
11
11
  };
package/lib/deepLink.js CHANGED
@@ -1,27 +1,37 @@
1
1
  import { createMapStore } from '@streamlayer/sdk-web-interfaces';
2
- import { DEEP_LINK_USER_ID, DEEP_LINK_EVENT_ID } from '@streamlayer/sdk-web-core';
2
+ import { DEEP_LINK_USER_ID, DEEP_LINK_EVENT_ID, DEEP_LINK_EXTERNAL_EVENT_ID, } from '@streamlayer/sdk-web-core';
3
3
  import { onMount } from 'nanostores';
4
4
  import { $deepLink, generateShortLink } from './queries/deepLink';
5
- export const deepLink = (transport, $eventId, $userId) => {
5
+ const createUrlParams = (prevParams, data) => {
6
+ const url = new URLSearchParams(prevParams);
7
+ for (const [key, value] of Object.entries(data)) {
8
+ url.append(key, value);
9
+ }
10
+ return url.toString();
11
+ };
12
+ export const deepLink = (transport, $eventId, $externalEventId, $userId) => {
6
13
  const $store = createMapStore({});
7
14
  onMount($store, () => {
8
- const $branchLink = $deepLink(transport, [$eventId]);
15
+ const $branchLink = $deepLink(transport, [$eventId, $externalEventId]);
9
16
  const cancel = $branchLink.subscribe(async ({ data, error, loading }) => {
10
17
  const mobileDeepLink = error ? 'https://masters.com' : data?.url;
11
- const userId = $userId.get();
12
- const eventId = $eventId.get();
13
- if (!loading && mobileDeepLink && userId && eventId) {
18
+ const userId = $userId.get() || '';
19
+ const eventId = $eventId.get() || '';
20
+ const externalEventId = $externalEventId.get() || '';
21
+ const urlParamsData = {
22
+ [DEEP_LINK_USER_ID]: userId,
23
+ [DEEP_LINK_EVENT_ID]: eventId,
24
+ [DEEP_LINK_EXTERNAL_EVENT_ID]: externalEventId,
25
+ };
26
+ if (!loading && mobileDeepLink) {
14
27
  $store.setKey('loading', true);
15
28
  let search = window.location.search;
16
29
  let hash = window.location.hash;
17
30
  if ((search && hash) || hash) {
18
- const params = new URLSearchParams(search);
19
- userId && params.append(DEEP_LINK_USER_ID, userId);
20
- eventId && params.append(DEEP_LINK_EVENT_ID, eventId);
21
- search = `?${params.toString()}`;
31
+ search = `?${createUrlParams(search, urlParamsData)}`;
22
32
  }
23
33
  else {
24
- hash = `#${`${DEEP_LINK_EVENT_ID}=${eventId}&${DEEP_LINK_USER_ID}=${userId}`}`;
34
+ hash = `#${createUrlParams('', urlParamsData)}`;
25
35
  }
26
36
  const desktopLink = window.location.origin + window.location.pathname + search + hash;
27
37
  const shortLink = await generateShortLink(transport, { web: desktopLink, mobile: mobileDeepLink });
@@ -63,7 +63,7 @@ export class Gamification extends AbstractFeature {
63
63
  this.closeFeature = () => instance.sdk.closeFeature(true);
64
64
  this.openFeature = () => instance.sdk.openFeature(FeatureType.GAMES);
65
65
  this.openedQuestion = this.background.openedQuestion;
66
- this.deepLink = deepLink(this.transport, this.background.slStreamId, this.background.userId);
66
+ this.deepLink = deepLink(this.transport, this.background.slStreamId, instance.stores.providerStreamId.getStore(), this.background.userId);
67
67
  this.leaderboardList = leaderboard(this.transport, this.background.slStreamId, this.background.userId, this.friends);
68
68
  this.status.subscribe((status) => {
69
69
  if (status === FeatureStatus.Ready) {
@@ -230,6 +230,7 @@ export class Gamification extends AbstractFeature {
230
230
  const instantView = {
231
231
  heading: question.data.question.notification.title,
232
232
  body: question.data.question.notification.body,
233
+ imageMode: question.data.question.notification.imageMode,
233
234
  image: optionsValue?.image,
234
235
  video: {
235
236
  id: optionsValue?.video?.id || '',
@@ -261,6 +262,7 @@ export class Gamification extends AbstractFeature {
261
262
  image: question.data.question.notification?.image,
262
263
  account: optionsValue?.tweetMeta?.account || '',
263
264
  accountVerified: !!optionsValue?.tweetMeta?.accountVerified,
265
+ tweet: optionsValue?.tweetMeta?.tweet,
264
266
  };
265
267
  this.notifications.add({
266
268
  type: NotificationType.QUESTION,
@@ -2,7 +2,8 @@ import type { Transport } from '@streamlayer/sdk-web-api';
2
2
  import { ReadableAtom } from 'nanostores';
3
3
  import { DeepLink } from '@streamlayer/sl-eslib/sdkSettings/client/client_pb';
4
4
  type EventId = ReadableAtom<string | undefined>;
5
- export declare const $deepLink: (transport: Transport, params: [EventId]) => import("@nanostores/query").FetcherStore<DeepLink | undefined, any>;
5
+ type ExternalEventId = ReadableAtom<string | undefined>;
6
+ export declare const $deepLink: (transport: Transport, params: [EventId, ExternalEventId]) => import("@nanostores/query").FetcherStore<DeepLink | undefined, any>;
6
7
  export declare const generateShortLink: (transport: Transport, { web, mobile }: {
7
8
  web: string;
8
9
  mobile: string;
@@ -6,11 +6,13 @@ export const $deepLink = (transport, params) => {
6
6
  params,
7
7
  });
8
8
  return transport.nanoquery.createFetcherStore(queryKey, {
9
- fetcher: async (_, __, eventId) => {
9
+ fetcher: async (_, __, eventId, externalEventId) => {
10
10
  if (!eventId) {
11
11
  return {};
12
12
  }
13
- const res = await client.generateDeepLink({ data: { eventId: eventId } });
13
+ const res = await client.generateDeepLink({
14
+ data: { gamification: true, externalEventId: externalEventId, eventId: eventId },
15
+ });
14
16
  return res.data?.attributes;
15
17
  },
16
18
  });
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "@streamlayer/feature-gamification",
3
- "version": "0.36.0",
3
+ "version": "0.37.0",
4
4
  "peerDependencies": {
5
5
  "@bufbuild/protobuf": "^1.6.0",
6
6
  "@fastify/deepmerge": "*",
7
- "@streamlayer/sl-eslib": "^5.66.0",
7
+ "@streamlayer/sl-eslib": "^5.67.0",
8
8
  "nanostores": "^0.9.5",
9
- "@streamlayer/sdk-web-api": "^0.21.0",
10
- "@streamlayer/sdk-web-core": "^0.19.0",
11
- "@streamlayer/sdk-web-interfaces": "^0.20.2",
12
- "@streamlayer/sdk-web-logger": "^0.5.13",
13
- "@streamlayer/sdk-web-notifications": "^0.13.8",
14
- "@streamlayer/sdk-web-storage": "^0.4.0",
15
- "@streamlayer/sdk-web-types": "^0.22.0"
9
+ "@streamlayer/sdk-web-api": "^0.21.1",
10
+ "@streamlayer/sdk-web-core": "^0.20.0",
11
+ "@streamlayer/sdk-web-interfaces": "^0.20.3",
12
+ "@streamlayer/sdk-web-logger": "^0.5.14",
13
+ "@streamlayer/sdk-web-notifications": "^0.13.9",
14
+ "@streamlayer/sdk-web-storage": "^0.4.1",
15
+ "@streamlayer/sdk-web-types": "^0.22.1"
16
16
  },
17
17
  "devDependencies": {
18
18
  "tslib": "^2.6.2"