Skip to content

Commit

Permalink
feat(share): web
Browse files Browse the repository at this point in the history
  • Loading branch information
mym0404 committed May 4, 2024
1 parent ae4bd5c commit 34e6ed3
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/navi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,6 @@
},
"gitHead": "57203ed1725b209e814da7cfbb71b36f52d24210",
"dependencies": {
"@mj-studio/js-util": "1.1.2"
"@mj-studio/js-util": "1.1.3"
}
}
5 changes: 4 additions & 1 deletion packages/share/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,8 @@
"javaPackageName": "net.mjstudio.rnkakao.share"
}
},
"gitHead": "57203ed1725b209e814da7cfbb71b36f52d24210"
"gitHead": "57203ed1725b209e814da7cfbb71b36f52d24210",
"dependencies": {
"@mj-studio/js-util": "1.1.3"
}
}
92 changes: 91 additions & 1 deletion packages/share/src/index.web.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { filterNonNullishKeys, snakeCaseObject } from '@mj-studio/js-util';
import { kRunWebAPI } from '@react-native-kakao/core';

import type { KakaoShareAPI } from './index';
Expand All @@ -10,7 +11,63 @@ declare const Kakao: {
API: { request: (args: any) => Promise<any> };
};

// @ts-ignore
function createShareDefault({
serverCallbackArgs,
template,
objectType,
}: {
objectType: string;
template: any;
serverCallbackArgs?: Record<string, string>;
}) {
return kRunWebAPI(() =>
Kakao.Share.sendDefault({
objectType,
...template,
serverCallbackArgs,
}),
);
}

function createSendDefaultMe({ template, objectType }: { objectType: string; template: any }) {
return kRunWebAPI(() =>
Kakao.API.request({
url: '/v2/api/talk/memo/default/send',
data: {
template_object: snakeCaseObject({
objectType,
...template,
}),
},
}),
);
}

function createSendDefaultFriends({
objectType,
template,
receiverUuids,
}: {
template: any;
objectType: any;
receiverUuids: string[];
}) {
return kRunWebAPI(() =>
Kakao.API.request({
url: '/v1/api/talk/friends/message/default/send',
data: {
template_object: snakeCaseObject(
filterNonNullishKeys({
objectType,
...template,
}),
),
receiver_uuids: receiverUuids,
},
}),
);
}

const KakaoShare: KakaoShareAPI = {
shareCustomTemplate: ({ templateArgs, templateId, serverCallbackArgs }) =>
kRunWebAPI(() =>
Expand Down Expand Up @@ -38,6 +95,39 @@ const KakaoShare: KakaoShareAPI = {
},
}),
),
shareFeedTemplate: ({ template, serverCallbackArgs }) =>
createShareDefault({ template, serverCallbackArgs, objectType: 'feed' }),
sendFeedTemplateToMe: ({ template }) => createSendDefaultMe({ template, objectType: 'feed' }),
sendFeedTemplateToFriends: ({ template, receiverUuids }) =>
createSendDefaultFriends({ template, receiverUuids, objectType: 'feed' }),
shareListTemplate: ({ template, serverCallbackArgs }) =>
createShareDefault({ template, serverCallbackArgs, objectType: 'list' }),
sendListTemplateToMe: ({ template }) => createSendDefaultMe({ template, objectType: 'list' }),
sendListTemplateToFriends: ({ template, receiverUuids }) =>
createSendDefaultFriends({ template, receiverUuids, objectType: 'list' }),
shareLocationTemplate: ({ template, serverCallbackArgs }) =>
createShareDefault({ template, serverCallbackArgs, objectType: 'location' }),
sendLocationTemplateToMe: ({ template }) =>
createSendDefaultMe({ template, objectType: 'location' }),
sendLocationTemplateToFriends: ({ template, receiverUuids }) =>
createSendDefaultFriends({ template, receiverUuids, objectType: 'location' }),
shareCommerceTemplate: ({ template, serverCallbackArgs }) =>
createShareDefault({ template, serverCallbackArgs, objectType: 'commerce' }),
sendCommerceTemplateToMe: ({ template }) =>
createSendDefaultMe({ template, objectType: 'commerce' }),
sendCommerceTemplateToFriends: ({ template, receiverUuids }) =>
createSendDefaultFriends({ template, receiverUuids, objectType: 'commerce' }),
shareTextTemplate: ({ template, serverCallbackArgs }) =>
createShareDefault({ template, serverCallbackArgs, objectType: 'text' }),
sendTextTemplateToMe: ({ template }) => createSendDefaultMe({ template, objectType: 'text' }),
sendTextTemplateToFriends: ({ template, receiverUuids }) =>
createSendDefaultFriends({ template, receiverUuids, objectType: 'text' }),
shareCalendarTemplate: ({ template, serverCallbackArgs }) =>
createShareDefault({ template, serverCallbackArgs, objectType: 'calendar' }),
sendCalendarTemplateToMe: ({ template }) =>
createSendDefaultMe({ template, objectType: 'calendar' }),
sendCalendarTemplateToFriends: ({ template, receiverUuids }) =>
createSendDefaultFriends({ template, receiverUuids, objectType: 'calendar' }),
};
export const {
sendCalendarTemplateToFriends,
Expand Down
2 changes: 1 addition & 1 deletion packages/social/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,6 @@
},
"gitHead": "57203ed1725b209e814da7cfbb71b36f52d24210",
"dependencies": {
"@mj-studio/js-util": "1.1.2"
"@mj-studio/js-util": "1.1.3"
}
}
2 changes: 1 addition & 1 deletion packages/user/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,6 @@
},
"gitHead": "57203ed1725b209e814da7cfbb71b36f52d24210",
"dependencies": {
"@mj-studio/js-util": "1.1.2"
"@mj-studio/js-util": "1.1.3"
}
}
15 changes: 8 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3972,10 +3972,10 @@ __metadata:
languageName: node
linkType: hard

"@mj-studio/js-util@npm:1.1.2":
version: 1.1.2
resolution: "@mj-studio/js-util@npm:1.1.2"
checksum: 10/9193d2822cb8efb14ed73d11ec9e3050d677b037ae3200c1fc762db1555f493bcbc41410dc037fcb9664e039fa0704772bd37bd7547f8d6ad66d0224c2406bfc
"@mj-studio/js-util@npm:1.1.3":
version: 1.1.3
resolution: "@mj-studio/js-util@npm:1.1.3"
checksum: 10/c93e52f33c65a7d58bdb7bfd8f5be72403e12489638946d939a1d64a1e3f05a40f92d8f9d763e7fc038034e0f696f1f1c9e2715f82af732f4b95c3c1eff666cf
languageName: node
linkType: hard

Expand Down Expand Up @@ -4777,7 +4777,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@react-native-kakao/navi@workspace:packages/navi"
dependencies:
"@mj-studio/js-util": "npm:1.1.2"
"@mj-studio/js-util": "npm:1.1.3"
"@react-native-kakao/core": "npm:2.1.0"
"@types/invariant": "npm:^2"
"@types/jest": "npm:^29.5.5"
Expand All @@ -4799,6 +4799,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@react-native-kakao/share@workspace:packages/share"
dependencies:
"@mj-studio/js-util": "npm:1.1.3"
"@react-native-kakao/core": "npm:2.1.0"
"@types/jest": "npm:^29.5.5"
"@types/react": "npm:^18.2.44"
Expand All @@ -4819,7 +4820,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@react-native-kakao/social@workspace:packages/social"
dependencies:
"@mj-studio/js-util": "npm:1.1.2"
"@mj-studio/js-util": "npm:1.1.3"
"@react-native-kakao/core": "npm:2.1.0"
"@types/invariant": "npm:^2"
"@types/jest": "npm:^29.5.5"
Expand All @@ -4841,7 +4842,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@react-native-kakao/user@workspace:packages/user"
dependencies:
"@mj-studio/js-util": "npm:1.1.2"
"@mj-studio/js-util": "npm:1.1.3"
"@react-native-kakao/core": "npm:2.1.0"
"@types/invariant": "npm:^2"
"@types/jest": "npm:^29.5.5"
Expand Down

0 comments on commit 34e6ed3

Please sign in to comment.