@messenger-box/platform-client 10.0.3-alpha.17 → 10.0.3-alpha.171
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/graphql/fragments/post-message.gql +36 -0
- package/lib/graphql/id-generation.js.map +1 -1
- package/lib/graphql/index.js.map +1 -1
- package/lib/graphql/mutations/channel-mutation.gql +5 -0
- package/lib/graphql/mutations/messages-mutation.gql +3 -0
- package/lib/graphql/policies/channel-policies.d.ts.map +1 -1
- package/lib/graphql/policies/channel-policies.js +150 -2
- package/lib/graphql/policies/channel-policies.js.map +1 -1
- package/lib/graphql/policies/messages-policies.d.ts.map +1 -1
- package/lib/graphql/policies/messages-policies.js +229 -37
- package/lib/graphql/policies/messages-policies.js.map +1 -1
- package/lib/graphql/policies/post-thread-policies.d.ts.map +1 -1
- package/lib/graphql/policies/post-thread-policies.js +136 -31
- package/lib/graphql/policies/post-thread-policies.js.map +1 -1
- package/lib/graphql/policies/posts-policies.js.map +1 -1
- package/lib/graphql/policies/teams-policies.d.ts.map +1 -1
- package/lib/graphql/policies/teams-policies.js +13 -1
- package/lib/graphql/policies/teams-policies.js.map +1 -1
- package/lib/graphql/policies/user-account-policies.js.map +1 -1
- package/lib/graphql/policies/user-policies.js.map +1 -1
- package/lib/graphql/queries/channels-by-user.gql +26 -0
- package/lib/graphql/queries/messages.gql +2 -2
- package/lib/graphql/queries/organization-query.gql +70 -35
- package/lib/graphql/queries/post-thread-message.gql +4 -0
- package/lib/graphql/queries/teams-query.gql +29 -29
- package/lib/graphql/queries/user-account.gql +1 -1
- package/lib/graphql/queries/users.gql +1 -1
- package/lib/graphql/schema/index.js.map +1 -1
- package/lib/graphql/subscription/fileUpdated.gql +11 -0
- package/lib/hooks/use-base-file-upload.hook.d.ts.map +1 -1
- package/lib/hooks/use-upload-file.hook.d.ts +1 -1
- package/lib/hooks/use-upload-file.hook.d.ts.map +1 -1
- package/lib/hooks/use-upload-file.hook.js +1 -1
- package/lib/hooks/use-upload-file.hook.js.map +1 -1
- package/lib/hooks/use-upload-file.hook.native.d.ts +1 -1
- package/lib/hooks/use-upload-file.hook.native.d.ts.map +1 -1
- package/lib/hooks/use-upload-file.hook.native.js +1 -1
- package/lib/hooks/use-upload-file.hook.native.js.map +1 -1
- package/lib/hooks/use-upload-files.hook.d.ts +1 -1
- package/lib/hooks/use-upload-files.hook.d.ts.map +1 -1
- package/lib/hooks/use-upload-files.hook.js +1 -1
- package/lib/hooks/use-upload-files.hook.js.map +1 -1
- package/lib/hooks/use-upload-files.hook.native.d.ts +1 -1
- package/lib/hooks/use-upload-files.hook.native.d.ts.map +1 -1
- package/lib/hooks/use-upload-files.hook.native.js +1 -1
- package/lib/hooks/use-upload-files.hook.native.js.map +1 -1
- package/lib/utils/index.d.ts.map +1 -1
- package/lib/utils/index.js.map +1 -1
- package/package.json +4 -4
- package/CHANGELOG.md +0 -141
- package/jest.config.js +0 -25
- package/rollup.config.mjs +0 -36
- package/src/graphql/fragments/configuration.gql +0 -12
- package/src/graphql/fragments/extended-user-account.gql +0 -10
- package/src/graphql/fragments/file-info.gql +0 -12
- package/src/graphql/fragments/messenger-user.gql +0 -15
- package/src/graphql/fragments/minimal-user.gql +0 -9
- package/src/graphql/fragments/post-message.gql +0 -116
- package/src/graphql/fragments/post-thread-message.gql +0 -77
- package/src/graphql/fragments/user.gql +0 -11
- package/src/graphql/id-generation.ts +0 -8
- package/src/graphql/index.ts +0 -24
- package/src/graphql/mutations/channel-mutation.gql +0 -72
- package/src/graphql/mutations/expo-notification-token.gql +0 -13
- package/src/graphql/mutations/message-threads-mutation.gql +0 -44
- package/src/graphql/mutations/messages-mutation.gql +0 -110
- package/src/graphql/mutations/messages-mutation.gql.bk +0 -66
- package/src/graphql/mutations/organization-mutation.gql.bk +0 -14
- package/src/graphql/mutations/teams-mutation.gql.bk +0 -8
- package/src/graphql/policies/channel-policies.ts +0 -7
- package/src/graphql/policies/index.ts +0 -7
- package/src/graphql/policies/messages-policies.ts +0 -109
- package/src/graphql/policies/post-thread-policies.ts +0 -59
- package/src/graphql/policies/posts-policies.ts +0 -110
- package/src/graphql/policies/teams-policies.ts +0 -7
- package/src/graphql/policies/user-account-policies.ts +0 -15
- package/src/graphql/policies/user-policies.ts +0 -32
- package/src/graphql/queries/channel.gql +0 -57
- package/src/graphql/queries/channels-by-user.gql +0 -60
- package/src/graphql/queries/check-for-new-messages.gql +0 -5
- package/src/graphql/queries/file-url.gql +0 -5
- package/src/graphql/queries/get-device-token.gql +0 -8
- package/src/graphql/queries/messages.gql +0 -28
- package/src/graphql/queries/organization-query.gql +0 -90
- package/src/graphql/queries/post-message.gql +0 -8
- package/src/graphql/queries/post-thread-message.gql +0 -20
- package/src/graphql/queries/support-service-channels.gql +0 -18
- package/src/graphql/queries/teams-query.gql +0 -32
- package/src/graphql/queries/user-account.gql +0 -5
- package/src/graphql/queries/users.gql +0 -48
- package/src/graphql/schema/index.ts +0 -6
- package/src/graphql/schema/messages.graphql +0 -5
- package/src/graphql/schema/post.graphql +0 -44
- package/src/graphql/schema/services.graphql +0 -6
- package/src/graphql/schema/user-account.graphql +0 -3
- package/src/graphql/subscription/chat-message-added.gql +0 -6
- package/src/graphql/subscription/public-post-added.gql +0 -5
- package/src/graphql/subscription/thread-chat-message-added.gql +0 -5
- package/src/graphql/subscription/thread-created-updated.gql +0 -12
- package/src/hooks/index.ts +0 -4
- package/src/hooks/use-base-file-upload.hook.ts +0 -148
- package/src/hooks/use-upload-file.hook.native.ts +0 -22
- package/src/hooks/use-upload-file.hook.ts +0 -22
- package/src/hooks/use-upload-files.hook.native.ts +0 -22
- package/src/hooks/use-upload-files.hook.ts +0 -22
- package/src/index.ts +0 -3
- package/src/inversify-containers/index.ts +0 -1
- package/src/inversify-containers/module.ts +0 -4
- package/src/packages/constants/constants.ts +0 -1831
- package/src/packages/types/channels.ts +0 -194
- package/src/packages/types/emojis.ts +0 -41
- package/src/packages/types/files.ts +0 -43
- package/src/packages/types/posts.ts +0 -155
- package/src/packages/types/reactions.ts +0 -8
- package/src/packages/types/teams.ts +0 -109
- package/src/packages/types/utilities.ts +0 -30
- package/src/services/index.ts +0 -0
- package/src/tests/mutation/__snapshots__/set-device-token.test.ts.snap +0 -18
- package/src/tests/mutation/set-device-token.test.ts +0 -85
- package/src/utils/constants.tsx +0 -1120
- package/src/utils/i18n.tsx +0 -15
- package/src/utils/index.ts +0 -34
- package/src/utils/post_list.ts +0 -54
- package/src/utils/post_utils.ts +0 -33
- package/src/utils/user_agent.tsx +0 -153
- package/src/utils/utils.tsx +0 -54
- package/tsconfig.json +0 -14
- package/webpack.config.js +0 -58
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
query GetChannelsByUser($role: String, $criteria: AnyObject, $limit: Int, $skip: Int, $sort: Sort) {
|
|
2
|
-
channelsByUser(role: $role, criteria: $criteria, limit: $limit, skip: $skip, sort: $sort) {
|
|
3
|
-
id
|
|
4
|
-
title
|
|
5
|
-
description
|
|
6
|
-
type
|
|
7
|
-
displayName
|
|
8
|
-
members {
|
|
9
|
-
id
|
|
10
|
-
user {
|
|
11
|
-
...MessengerUser
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
creator {
|
|
15
|
-
...MessengerUser
|
|
16
|
-
}
|
|
17
|
-
createdAt
|
|
18
|
-
updatedAt
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
query GetChannelsByUserWithServiceChannels($role: String, $criteria: AnyObject, $supportServiceCriteria: AnyObject, $limit: Int, $skip: Int, $sort: Sort,$supportServices:Boolean = true) {
|
|
25
|
-
supportServiceChannels(role: $role, criteria: $supportServiceCriteria, limit: $limit, skip: $skip, sort: $sort) @include(if: $supportServices) {
|
|
26
|
-
id
|
|
27
|
-
title
|
|
28
|
-
description
|
|
29
|
-
type
|
|
30
|
-
displayName
|
|
31
|
-
members {
|
|
32
|
-
id
|
|
33
|
-
user {
|
|
34
|
-
...MessengerUser
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
creator {
|
|
38
|
-
...MessengerUser
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
channelsByUser(role: $role, criteria: $criteria, limit: $limit, skip: $skip, sort: $sort) {
|
|
42
|
-
id
|
|
43
|
-
title
|
|
44
|
-
description
|
|
45
|
-
type
|
|
46
|
-
displayName
|
|
47
|
-
members {
|
|
48
|
-
id
|
|
49
|
-
user {
|
|
50
|
-
...MessengerUser
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
creator {
|
|
54
|
-
...MessengerUser
|
|
55
|
-
}
|
|
56
|
-
createdAt
|
|
57
|
-
updatedAt
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
query Messages($channelId: ID,$parentId: String, $limit: Int! = 10, $skip: Int! = 0, $sort: Sort) {
|
|
2
|
-
messages(channelId: $channelId,parentId:$parentId, limit: $limit, skip: $skip, sort: $sort) @connection(key: "messages", filter: ["channelId","skip"]){
|
|
3
|
-
messagesRefId @client
|
|
4
|
-
data{
|
|
5
|
-
...Post
|
|
6
|
-
}
|
|
7
|
-
totalCount
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
query PostThreadMessages($channelId: ID,$parentId: String, $limit: Int! = 10, $skip: Int! = 0, $sort: Sort) {
|
|
12
|
-
messages(channelId: $channelId,parentId:$parentId, limit: $limit, skip: $skip, sort: $sort) @connection(key: "threadposts", filter: ["channelId","parentId",,"skip"]) {
|
|
13
|
-
threadmessagesRefId @client
|
|
14
|
-
data{
|
|
15
|
-
...Post
|
|
16
|
-
}
|
|
17
|
-
totalCount
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
query PublicMessages($channelId: ID!) {
|
|
22
|
-
publicMessages(channelId: $channelId) {
|
|
23
|
-
totalCount
|
|
24
|
-
data {
|
|
25
|
-
...Post
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
query GetOrganizationDetail($where: OrgDetailWhere!) {
|
|
2
|
-
getOrganizationDetail(where: $where) {
|
|
3
|
-
createdAt
|
|
4
|
-
description
|
|
5
|
-
id
|
|
6
|
-
invitations {
|
|
7
|
-
active
|
|
8
|
-
acceptedAt
|
|
9
|
-
createdAt
|
|
10
|
-
email
|
|
11
|
-
fullName
|
|
12
|
-
id
|
|
13
|
-
invitedBy
|
|
14
|
-
teamId
|
|
15
|
-
updatedAt
|
|
16
|
-
tokenExpiration
|
|
17
|
-
role
|
|
18
|
-
inviteCount
|
|
19
|
-
}
|
|
20
|
-
name
|
|
21
|
-
orgMembers {
|
|
22
|
-
crossCheckEmail
|
|
23
|
-
inactive
|
|
24
|
-
orgName
|
|
25
|
-
user {
|
|
26
|
-
email
|
|
27
|
-
alias
|
|
28
|
-
emailVerified
|
|
29
|
-
id
|
|
30
|
-
username
|
|
31
|
-
}
|
|
32
|
-
roles
|
|
33
|
-
userId
|
|
34
|
-
}
|
|
35
|
-
orgUserCount
|
|
36
|
-
periodStart
|
|
37
|
-
periodStop
|
|
38
|
-
picture
|
|
39
|
-
status
|
|
40
|
-
title
|
|
41
|
-
updatedAt
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
query GetOrganizationMembersWithChannels($orgName: String,$role: String, $channelCriteria: AnyObject,$offset: Int, $limit: Int, $sort: Sort) {
|
|
49
|
-
getOrganizationMembers(offset: $offset, limit: $limit, orgName: $orgName) {
|
|
50
|
-
totalCount
|
|
51
|
-
data {
|
|
52
|
-
userId
|
|
53
|
-
roles
|
|
54
|
-
user {
|
|
55
|
-
id
|
|
56
|
-
givenName
|
|
57
|
-
familyName
|
|
58
|
-
picture
|
|
59
|
-
username
|
|
60
|
-
email
|
|
61
|
-
alias
|
|
62
|
-
}
|
|
63
|
-
teamNames
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
channelsByUser(role: $role, criteria: $channelCriteria, limit: $limit, skip: $offset, sort: $sort) {
|
|
67
|
-
id
|
|
68
|
-
title
|
|
69
|
-
description
|
|
70
|
-
orgName
|
|
71
|
-
type
|
|
72
|
-
displayName
|
|
73
|
-
members {
|
|
74
|
-
id
|
|
75
|
-
user {
|
|
76
|
-
...MessengerUser
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
creator {
|
|
80
|
-
...MessengerUser
|
|
81
|
-
}
|
|
82
|
-
createdAt
|
|
83
|
-
updatedAt
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
query GetOrganizationSharableLink($teamId: String) {
|
|
88
|
-
getOrganizationSharableLink(teamId: $teamId)
|
|
89
|
-
}
|
|
90
|
-
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
query ThreadMessages($channelId: ID, $postParentId: ID,$selectedFields: String, $role: String, $participantsIds: [String], $limit: Int, $skip: Int,$isServiceThreads: Boolean,$repliesLimit2: Int, $repliesSkip2: Int) {
|
|
2
|
-
threadMessages(channelId: $channelId, postParentId: $postParentId, selectedFields: $selectedFields, role: $role,participantsIds:$participantsIds, limit: $limit, skip: $skip,isServiceThreads: $isServiceThreads) {
|
|
3
|
-
totalCount
|
|
4
|
-
data {
|
|
5
|
-
...PostThreadWithoutReplies
|
|
6
|
-
replies(limit: $repliesLimit2, skip: $repliesSkip2) {
|
|
7
|
-
...PostWithoutReplies
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
query GetPostThread($postThreadId: ID, $channelId: ID, $postParentId: ID, $role: String, $participantsIds: [String], $selectedFields: String, $limit: Int, $skip: Int, $sort: Sort ,$isServiceThreads: Boolean) {
|
|
14
|
-
getPostThread(postThreadId: $postThreadId, channelId: $channelId, postParentId: $postParentId, role: $role, participantsIds: $participantsIds, selectedFields: $selectedFields,isServiceThreads: $isServiceThreads) {
|
|
15
|
-
...PostThreadWithoutReplies
|
|
16
|
-
replies(limit: $limit, skip: $skip, sort: $sort) {
|
|
17
|
-
...PostWithoutReplies
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
query SupportServiceChannels($role: String, $criteria: AnyObject, $limit: Int, $skip: Int, $sort: Sort) {
|
|
2
|
-
supportServiceChannels(role: $role, criteria: $criteria, limit: $limit, skip: $skip, sort: $sort) {
|
|
3
|
-
id
|
|
4
|
-
title
|
|
5
|
-
description
|
|
6
|
-
type
|
|
7
|
-
displayName
|
|
8
|
-
members {
|
|
9
|
-
id
|
|
10
|
-
user {
|
|
11
|
-
...MessengerUser
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
creator {
|
|
15
|
-
...MessengerUser
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
query GetOrganizationTeam($orgName: String!, $teamName: String!) {
|
|
4
|
-
getTeam(orgName: $orgName, teamName: $teamName) {
|
|
5
|
-
title
|
|
6
|
-
orgName
|
|
7
|
-
name
|
|
8
|
-
id
|
|
9
|
-
createdAt
|
|
10
|
-
updatedAt
|
|
11
|
-
_id
|
|
12
|
-
teamMembers:members {
|
|
13
|
-
id
|
|
14
|
-
name
|
|
15
|
-
email
|
|
16
|
-
username
|
|
17
|
-
userId
|
|
18
|
-
status
|
|
19
|
-
role
|
|
20
|
-
}
|
|
21
|
-
members {
|
|
22
|
-
id
|
|
23
|
-
name
|
|
24
|
-
email
|
|
25
|
-
username
|
|
26
|
-
userId
|
|
27
|
-
status
|
|
28
|
-
role
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
query GetAllUsers {
|
|
2
|
-
getUsers {
|
|
3
|
-
...MinimalUser
|
|
4
|
-
}
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
query GetUserById($userId: String!) {
|
|
8
|
-
getUserAccount(userId: $userId) {
|
|
9
|
-
...MinimalUser
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
query UsersToChat($auth0Id: String!) {
|
|
14
|
-
usersToChat(auth0Id: $auth0Id) {
|
|
15
|
-
...MinimalUser
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
query CurrentUser($auth0Id: String!) {
|
|
20
|
-
currentUser(auth0Id: $auth0Id) {
|
|
21
|
-
...MinimalUser
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
# query GetOrganizationMembers($offset: Int, $limit: Int, $orgName: String) {
|
|
28
|
-
# getOrganizationMembers(offset: $offset, limit: $limit, orgName: $orgName) {
|
|
29
|
-
# totalCount
|
|
30
|
-
# data {
|
|
31
|
-
# _id
|
|
32
|
-
# userId
|
|
33
|
-
# name
|
|
34
|
-
# email
|
|
35
|
-
# role
|
|
36
|
-
# user {
|
|
37
|
-
# id
|
|
38
|
-
# givenName
|
|
39
|
-
# familyName
|
|
40
|
-
# picture
|
|
41
|
-
# username
|
|
42
|
-
# email
|
|
43
|
-
# alias
|
|
44
|
-
# }
|
|
45
|
-
# teamNames
|
|
46
|
-
# }
|
|
47
|
-
# }
|
|
48
|
-
# }
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
extend type Post {
|
|
4
|
-
isPinned: Boolean @client
|
|
5
|
-
disableGroupHighlight: Boolean @client
|
|
6
|
-
fromBot: Boolean @client
|
|
7
|
-
|
|
8
|
-
""" Set to center the post """
|
|
9
|
-
center: Boolean @client
|
|
10
|
-
|
|
11
|
-
""" Set to render post compactly """
|
|
12
|
-
compactDisplay: Boolean @client
|
|
13
|
-
|
|
14
|
-
""" Set to render a preview of the parent post above this reply """
|
|
15
|
-
isFirstReply: Boolean @client
|
|
16
|
-
|
|
17
|
-
""" Set to highlight the background of the post """
|
|
18
|
-
shouldHighlight: Boolean @client
|
|
19
|
-
|
|
20
|
-
""" Set to render this post as if it was attached to the previous post """
|
|
21
|
-
consecutivePostByUser: Boolean @client
|
|
22
|
-
|
|
23
|
-
""" Set if the previous post is a comment """
|
|
24
|
-
previousPostIsComment: Boolean @client
|
|
25
|
-
|
|
26
|
-
togglePostMenu: Boolean @client
|
|
27
|
-
|
|
28
|
-
""" Set to render this comment as a mention """
|
|
29
|
-
isCommentMention: Boolean @client
|
|
30
|
-
|
|
31
|
-
""" If the post has replies """
|
|
32
|
-
hasReplies: Boolean @client
|
|
33
|
-
|
|
34
|
-
""" To check if the current post is last in the list """
|
|
35
|
-
isLastPost: Boolean @client
|
|
36
|
-
|
|
37
|
-
""" Whether or not the channel that contains this post is archived """
|
|
38
|
-
channelArchived: Boolean @client
|
|
39
|
-
|
|
40
|
-
""" Set to mark the post as flagged """
|
|
41
|
-
isFlagged: Boolean @client
|
|
42
|
-
|
|
43
|
-
isCollapsedThreadsEnabled: Boolean @client
|
|
44
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
subscription onThreadCreatedUpdated($channelId: String, $postParentId: String) {
|
|
2
|
-
threadCreatedUpdated(channelId: $channelId, postParentId: $postParentId) {
|
|
3
|
-
isCreated
|
|
4
|
-
isUpdated
|
|
5
|
-
lastMessage {
|
|
6
|
-
...PostWithoutReplies
|
|
7
|
-
}
|
|
8
|
-
data {
|
|
9
|
-
...PostThread
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
}
|
package/src/hooks/index.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export { useUploadFile } from './use-upload-file.hook';
|
|
2
|
-
export { useUploadFiles } from './use-upload-files.hook';
|
|
3
|
-
export { useUploadFile as useUploadFileNative } from './use-upload-file.hook.native';
|
|
4
|
-
export { useUploadFiles as useUploadFilesNative } from './use-upload-files.hook.native';
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import { ApolloError } from '@apollo/client';
|
|
2
|
-
import { ImageInfo } from 'expo-image-picker';
|
|
3
|
-
import { useCallback } from 'react';
|
|
4
|
-
import { ApolloClient, NetworkStatus } from '@apollo/client/core';
|
|
5
|
-
import { BaseMutationOptions } from '@apollo/client/react/types/types';
|
|
6
|
-
import { IFileInfo, IUploadedFileInput } from 'common';
|
|
7
|
-
|
|
8
|
-
export interface IStartUploadResponse<T = IFileInfo> {
|
|
9
|
-
data?: Omit<T, 'createdAt' | 'updatedAt'>;
|
|
10
|
-
urls?: string[];
|
|
11
|
-
error: ApolloError;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface CustomBlob extends Blob {
|
|
15
|
-
name: string;
|
|
16
|
-
width: number;
|
|
17
|
-
height: number;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface IStartUploadOptions<C, S> {
|
|
21
|
-
file: ImageInfo | ImageInfo[];
|
|
22
|
-
createUploadLink?: {
|
|
23
|
-
variables: C;
|
|
24
|
-
} & BaseMutationOptions<any, C>;
|
|
25
|
-
saveUploadedFile?: {
|
|
26
|
-
variables: S;
|
|
27
|
-
} & BaseMutationOptions<any, S>;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface IUseUploadFileResponse<C, S> {
|
|
31
|
-
startUpload: <T = IFileInfo>(options: IStartUploadOptions<C, S>) => Promise<IStartUploadResponse<T>>;
|
|
32
|
-
loading: boolean;
|
|
33
|
-
error: ApolloError;
|
|
34
|
-
networkStatus: NetworkStatus;
|
|
35
|
-
client: ApolloClient<any>;
|
|
36
|
-
called: boolean;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export interface IUseUploadFileOptions<C, S> {
|
|
40
|
-
createUploadLink: {
|
|
41
|
-
name: string;
|
|
42
|
-
mutation: any;
|
|
43
|
-
processVariables: (file: CustomBlob | CustomBlob[], variables?: C) => Record<string, unknown>;
|
|
44
|
-
};
|
|
45
|
-
saveUploadedFile: {
|
|
46
|
-
name: string;
|
|
47
|
-
mutation: any;
|
|
48
|
-
processVariables: (file: IUploadedFileInput | IUploadedFileInput[], variables?: S) => Record<string, unknown>;
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export const useBaseUploadFile = <C, S>(options: IUseUploadFileOptions<C, S>): IUseUploadFileResponse<C, S> => {
|
|
53
|
-
const { createUploadLink: createLink, saveUploadedFile } = options;
|
|
54
|
-
const [createUploadLink, { loading: linkLoading, error: linkError }] = createLink.mutation();
|
|
55
|
-
const [attachFile, { loading: fileStoring, error: fileSaveError, ...rest }] = saveUploadedFile.mutation();
|
|
56
|
-
|
|
57
|
-
const startUpload = useCallback(async (options: IStartUploadOptions<C, S>): Promise<IStartUploadResponse> => {
|
|
58
|
-
try {
|
|
59
|
-
const {
|
|
60
|
-
file,
|
|
61
|
-
createUploadLink: createUploadLinkOptions,
|
|
62
|
-
saveUploadedFile: saveUploadedFileOptions,
|
|
63
|
-
} = options;
|
|
64
|
-
|
|
65
|
-
const blobs = await Promise.all(
|
|
66
|
-
(Array.isArray(file) ? file : [file]).map(async ({ uri }) => {
|
|
67
|
-
const res = await fetch(uri);
|
|
68
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
69
|
-
const blob: any = await res.blob();
|
|
70
|
-
// eslint-disable-next-line no-underscore-dangle
|
|
71
|
-
const { name, size, type: mimeType, width, height } = blob._data;
|
|
72
|
-
blob.name = name;
|
|
73
|
-
blob.width = width;
|
|
74
|
-
blob.height = height;
|
|
75
|
-
blob.mimeType = mimeType;
|
|
76
|
-
blob.mimeType = size;
|
|
77
|
-
return blob;
|
|
78
|
-
}),
|
|
79
|
-
);
|
|
80
|
-
const { variables: createUploadLinkVariables, ...restCreateUploadLinkOptions } =
|
|
81
|
-
createUploadLinkOptions || {};
|
|
82
|
-
const { data: link, errors: linkErrors } = await createUploadLink({
|
|
83
|
-
variables: createLink.processVariables(
|
|
84
|
-
Array.isArray(file) ? blobs : blobs[0],
|
|
85
|
-
createUploadLinkVariables,
|
|
86
|
-
),
|
|
87
|
-
...restCreateUploadLinkOptions,
|
|
88
|
-
});
|
|
89
|
-
if (linkErrors) {
|
|
90
|
-
return { error: linkErrors[0] };
|
|
91
|
-
}
|
|
92
|
-
const uploadLinks: string[] = Array.isArray(link[createLink.name])
|
|
93
|
-
? link[createLink.name]
|
|
94
|
-
: [link[createLink.name]];
|
|
95
|
-
const urls = await Promise.all(
|
|
96
|
-
uploadLinks.map(async (link, index) => {
|
|
97
|
-
const response = await fetch(link, {
|
|
98
|
-
method: 'PUT',
|
|
99
|
-
body: blobs[index],
|
|
100
|
-
});
|
|
101
|
-
if (response.status !== 200) {
|
|
102
|
-
return undefined;
|
|
103
|
-
}
|
|
104
|
-
return link;
|
|
105
|
-
}),
|
|
106
|
-
);
|
|
107
|
-
const filesInfo: IUploadedFileInput[] = await Promise.all(
|
|
108
|
-
blobs.map(async (i, index) => {
|
|
109
|
-
// eslint-disable-next-line no-underscore-dangle
|
|
110
|
-
const { name, size, type: mimeType, width, height } = (i as any)._data;
|
|
111
|
-
const url = urls[index];
|
|
112
|
-
return {
|
|
113
|
-
name,
|
|
114
|
-
size,
|
|
115
|
-
mimeType,
|
|
116
|
-
url,
|
|
117
|
-
width,
|
|
118
|
-
height,
|
|
119
|
-
};
|
|
120
|
-
}),
|
|
121
|
-
);
|
|
122
|
-
const { variables: saveUploadedFileVariables, ...restSaveUploadedFileOptions } =
|
|
123
|
-
saveUploadedFileOptions || {};
|
|
124
|
-
const { data: attachedFile, errors: attachFileErrors } = await attachFile({
|
|
125
|
-
variables: saveUploadedFile.processVariables(
|
|
126
|
-
Array.isArray(file) ? filesInfo : filesInfo[0],
|
|
127
|
-
saveUploadedFileVariables,
|
|
128
|
-
),
|
|
129
|
-
...restSaveUploadedFileOptions,
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
return {
|
|
133
|
-
data: attachedFile[saveUploadedFile.name],
|
|
134
|
-
urls,
|
|
135
|
-
error: attachFileErrors ? attachFileErrors[0] : null,
|
|
136
|
-
};
|
|
137
|
-
} catch (e) {
|
|
138
|
-
console.error(e);
|
|
139
|
-
}
|
|
140
|
-
}, []);
|
|
141
|
-
|
|
142
|
-
return {
|
|
143
|
-
startUpload,
|
|
144
|
-
loading: linkLoading || fileStoring,
|
|
145
|
-
error: linkError || fileSaveError,
|
|
146
|
-
...rest,
|
|
147
|
-
};
|
|
148
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { useUploadFile as useBaseUploadFile } from '@container-stack/file-info-client/lib/hooks/use-file-upload.native.js';
|
|
2
|
-
import { useAttachUploadedFileToMessageMutation, useCreateMessageFileUploadLinkMutation } from 'common/graphql';
|
|
3
|
-
|
|
4
|
-
export const useUploadFile = (): ReturnType<typeof useBaseUploadFile> =>
|
|
5
|
-
useBaseUploadFile({
|
|
6
|
-
createUploadLink: {
|
|
7
|
-
name: 'createMessageFileUploadLink',
|
|
8
|
-
mutation: useCreateMessageFileUploadLinkMutation,
|
|
9
|
-
processVariables: (file, variables) => ({
|
|
10
|
-
filename: Array.isArray(file) ? file[0]?.name : file.name,
|
|
11
|
-
...(typeof variables === 'object' ? variables : {}),
|
|
12
|
-
}),
|
|
13
|
-
},
|
|
14
|
-
saveUploadedFile: {
|
|
15
|
-
name: 'attachUploadedFileToMessage',
|
|
16
|
-
mutation: useAttachUploadedFileToMessageMutation,
|
|
17
|
-
processVariables: (file, variables) => ({
|
|
18
|
-
file,
|
|
19
|
-
...(typeof variables === 'object' ? variables : {}),
|
|
20
|
-
}),
|
|
21
|
-
},
|
|
22
|
-
});
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { useUploadFile as useBaseUploadFile } from '@container-stack/file-info-client/lib/hooks/use-upload-file.js';
|
|
2
|
-
import { useAttachUploadedFileToMessageMutation, useCreateMessageFileUploadLinkMutation } from 'common/graphql';
|
|
3
|
-
|
|
4
|
-
export const useUploadFile = (): ReturnType<typeof useBaseUploadFile> =>
|
|
5
|
-
useBaseUploadFile({
|
|
6
|
-
createUploadLink: {
|
|
7
|
-
name: 'createMessageFileUploadLink',
|
|
8
|
-
mutation: useCreateMessageFileUploadLinkMutation,
|
|
9
|
-
processVariables: (file, variables) => ({
|
|
10
|
-
filename: Array.isArray(file) ? file[0]?.name : file.name,
|
|
11
|
-
...(typeof variables === 'object' ? variables : {}),
|
|
12
|
-
}),
|
|
13
|
-
},
|
|
14
|
-
saveUploadedFile: {
|
|
15
|
-
name: 'attachUploadedFileToMessage',
|
|
16
|
-
mutation: useAttachUploadedFileToMessageMutation,
|
|
17
|
-
processVariables: (file, variables) => ({
|
|
18
|
-
file,
|
|
19
|
-
...(typeof variables === 'object' ? variables : {}),
|
|
20
|
-
}),
|
|
21
|
-
},
|
|
22
|
-
});
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { useUploadFile } from '@container-stack/file-info-client/lib/hooks/use-file-upload.native.js';
|
|
2
|
-
import { useAttachUploadedFilesToMessageMutation, useCreateMessageFilesUploadLinkMutation } from 'common/graphql';
|
|
3
|
-
|
|
4
|
-
export const useUploadFiles = (): ReturnType<typeof useUploadFile> =>
|
|
5
|
-
useUploadFile({
|
|
6
|
-
createUploadLink: {
|
|
7
|
-
name: 'createMessageFilesUploadLink',
|
|
8
|
-
mutation: useCreateMessageFilesUploadLinkMutation,
|
|
9
|
-
processVariables: (files, variables) => ({
|
|
10
|
-
filenames: Array.isArray(files) ? files.map((file) => file.name) : [files.name],
|
|
11
|
-
...(typeof variables === 'object' ? variables : {}),
|
|
12
|
-
}),
|
|
13
|
-
},
|
|
14
|
-
saveUploadedFile: {
|
|
15
|
-
name: 'attachUploadedFilesToMessage',
|
|
16
|
-
mutation: useAttachUploadedFilesToMessageMutation,
|
|
17
|
-
processVariables: (files, variables) => ({
|
|
18
|
-
files,
|
|
19
|
-
...(typeof variables === 'object' ? variables : {}),
|
|
20
|
-
}),
|
|
21
|
-
},
|
|
22
|
-
});
|