@jsb188/app 1.0.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/constants/billing.ts +146 -0
- package/constants/emoji.ts +8945 -0
- package/constants/user.ts +36 -0
- package/constants/ws.ts +47 -0
- package/i18n/app.ts +107 -0
- package/i18n/auth.ts +40 -0
- package/i18n/billing.ts +95 -0
- package/i18n/datetime.ts +22 -0
- package/i18n/error.ts +131 -0
- package/i18n/form.ts +72 -0
- package/i18n/index.ts +6 -0
- package/i18n/user.ts +95 -0
- package/main.ts +21 -0
- package/package.json +37 -0
- package/types/app.d.ts +53 -0
- package/types/datetime.d.ts +10 -0
- package/types/form.d.ts +53 -0
- package/types/user.d.ts +52 -0
- package/types.d.ts +23 -0
- package/utils/billing.ts +134 -0
- package/utils/datetime.ts +356 -0
- package/utils/emoji.ts +151 -0
- package/utils/logic.ts +90 -0
- package/utils/number.ts +115 -0
- package/utils/object.ts +367 -0
- package/utils/string.ts +211 -0
- package/utils/url_client.ts +138 -0
- package/utils/user.ts +273 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
|
|
2
|
+
type LinkType = 'USER' | 'KAJI' | 'DATASET' | 'VOICE' | 'FEED' | 'ROOM' | 'THREAD' | 'OTHER';
|
|
3
|
+
|
|
4
|
+
// links to consider for User cards
|
|
5
|
+
// instagram
|
|
6
|
+
// tiktok
|
|
7
|
+
// youtube
|
|
8
|
+
// pinterest
|
|
9
|
+
// twitch
|
|
10
|
+
// linkedin
|
|
11
|
+
// facebook
|
|
12
|
+
// twiitter (x)
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Uploaded assets
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export function makeUploadsUrl(
|
|
19
|
+
urlPath?: string | null,
|
|
20
|
+
size?: string,
|
|
21
|
+
animateGifs?: boolean,
|
|
22
|
+
): string {
|
|
23
|
+
if (!urlPath) {
|
|
24
|
+
return '';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
let uriPrefix;
|
|
28
|
+
if (
|
|
29
|
+
urlPath.substring(urlPath.lastIndexOf('.')).toLowerCase() === '.gif' &&
|
|
30
|
+
animateGifs
|
|
31
|
+
) {
|
|
32
|
+
uriPrefix = 'original/';
|
|
33
|
+
} else {
|
|
34
|
+
switch (size) {
|
|
35
|
+
case 'original':
|
|
36
|
+
uriPrefix = 'original/';
|
|
37
|
+
break;
|
|
38
|
+
case 'large':
|
|
39
|
+
case 'medium':
|
|
40
|
+
uriPrefix = 'medium/';
|
|
41
|
+
break;
|
|
42
|
+
case 'small':
|
|
43
|
+
case 'tiny':
|
|
44
|
+
uriPrefix = 'small/';
|
|
45
|
+
break;
|
|
46
|
+
default:
|
|
47
|
+
uriPrefix = 'small/';
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return 'https://static.chiefhappiness.co/' + uriPrefix + urlPath;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Make chat URL
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
export function makeChatUrl(
|
|
58
|
+
firstChatId?: string | null,
|
|
59
|
+
secondChatId?: string | null,
|
|
60
|
+
nextFirstChatId?: string | null,
|
|
61
|
+
nextSecondChatId?: string | null,
|
|
62
|
+
) {
|
|
63
|
+
const path = 'chat';
|
|
64
|
+
|
|
65
|
+
if (
|
|
66
|
+
nextFirstChatId &&
|
|
67
|
+
nextFirstChatId === secondChatId
|
|
68
|
+
) {
|
|
69
|
+
return `/${path}/${firstChatId}/${secondChatId}`;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const first = nextFirstChatId || firstChatId || 'none';
|
|
73
|
+
const second = nextSecondChatId || secondChatId;
|
|
74
|
+
|
|
75
|
+
if (first === second) {
|
|
76
|
+
return `/${path}/${first}`;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return `/${path}/${first}${second ? `/${second}` : ''}`;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Get default text for URL type
|
|
84
|
+
*/
|
|
85
|
+
|
|
86
|
+
export function getUrlType(type: LinkType) {
|
|
87
|
+
switch (type) {
|
|
88
|
+
case 'USER':
|
|
89
|
+
return 'User';
|
|
90
|
+
case 'KAJI':
|
|
91
|
+
return 'AI';
|
|
92
|
+
case 'DATASET':
|
|
93
|
+
return 'Dataset';
|
|
94
|
+
case 'VOICE':
|
|
95
|
+
return 'Voice';
|
|
96
|
+
case 'FEED':
|
|
97
|
+
return 'Feed post';
|
|
98
|
+
case 'ROOM':
|
|
99
|
+
return 'Room';
|
|
100
|
+
case 'THREAD':
|
|
101
|
+
return 'Forum thread';
|
|
102
|
+
default:
|
|
103
|
+
return 'Link';
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Convert location search string to object
|
|
109
|
+
*/
|
|
110
|
+
|
|
111
|
+
export function locationSearchToObject(searchParams?: string) {
|
|
112
|
+
if (!searchParams) {
|
|
113
|
+
return {};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const search = searchParams.substring(1);
|
|
117
|
+
const searchParamsArray = search.split('&');
|
|
118
|
+
const searchParamsObject: Record<string, string> = {};
|
|
119
|
+
|
|
120
|
+
searchParamsArray.forEach((param) => {
|
|
121
|
+
const [key, value] = param.split('=');
|
|
122
|
+
searchParamsObject[key] = value;
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
return searchParamsObject;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Check if current page is a chat page
|
|
130
|
+
*/
|
|
131
|
+
|
|
132
|
+
export function isChatPage() {
|
|
133
|
+
const pathname = globalThis?.location?.pathname?.toLowerCase();
|
|
134
|
+
if (pathname) {
|
|
135
|
+
return /^\/(?:chat|dm)\//i.test(pathname);
|
|
136
|
+
}
|
|
137
|
+
return false;
|
|
138
|
+
}
|
package/utils/user.ts
ADDED
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import i18n from '../i18n/';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Types
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
type LightModeValue = 'LIGHT' | 'DARK' | 'SYSTEM';
|
|
8
|
+
type FriendStatusEnum = 'BLOCKED' | 'DECLINED' | 'PENDING' | 'ACCEPTED';
|
|
9
|
+
|
|
10
|
+
interface FriendFragment {
|
|
11
|
+
myStatus: FriendStatusEnum;
|
|
12
|
+
otherStatus: FriendStatusEnum;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface FriendOptionsObj {
|
|
16
|
+
friendButtonText: string;
|
|
17
|
+
friendButtonIconName: string;
|
|
18
|
+
friendStatusText: string;
|
|
19
|
+
messageAllowed: boolean;
|
|
20
|
+
options: {
|
|
21
|
+
value: string;
|
|
22
|
+
iconName: string;
|
|
23
|
+
text: string;
|
|
24
|
+
}[];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
type PlusGroupEnum = 'NORMAL' | 'PERKS' | 'PLUS' | 'PRO';
|
|
28
|
+
|
|
29
|
+
interface UserSubOutput {
|
|
30
|
+
name: string | null;
|
|
31
|
+
group: PlusGroupEnum;
|
|
32
|
+
cancelled: boolean;
|
|
33
|
+
expired: boolean;
|
|
34
|
+
expireAt: Date | null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Get light mode value
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
export function getLightMode(mode: string, mobileApp: boolean): LightModeValue {
|
|
42
|
+
if (!mode) {
|
|
43
|
+
return 'LIGHT';
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const index = mobileApp ? 1 : 0;
|
|
47
|
+
const value = Number(mode.charAt(index));
|
|
48
|
+
|
|
49
|
+
return (['LIGHT', 'SYSTEM', 'DARK'][value] || 'LIGHT') as LightModeValue;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Update light mode value
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
export function updateLightMode(mode_: string | undefined, newValue: LightModeValue, mobileApp: boolean): string {
|
|
57
|
+
const mode = mode_ || '00';
|
|
58
|
+
const index = mobileApp ? 1 : 0;
|
|
59
|
+
|
|
60
|
+
let value = ['LIGHT', 'SYSTEM', 'DARK'].indexOf(newValue);
|
|
61
|
+
if (value === -1) {
|
|
62
|
+
value = 0;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return mode.substring(0, index) + value + mode.substring(index + 1);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Resolve user's online status for chat
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
export function resolveOnlineStatus(user: object, viewerUserId: number) {
|
|
73
|
+
// console.log('..... RESOLVE ONLINE STATUS .....', user.id, viewerUserId, user.onlineStatus);
|
|
74
|
+
if (
|
|
75
|
+
// This check won't be valid if user is switching logins;
|
|
76
|
+
// So for those cases, use [user.self = true],
|
|
77
|
+
// to validate that this is a self online status
|
|
78
|
+
viewerUserId == user.id ||
|
|
79
|
+
user.self
|
|
80
|
+
) {
|
|
81
|
+
return user.onlineStatus;
|
|
82
|
+
} else if (!user.lastLoginAt) {
|
|
83
|
+
return 'APPEAR_OFFLINE';
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const now = Date.now();
|
|
87
|
+
const wasOnline = (now - user.lastLoginAt) < 420000; // 7 minutes
|
|
88
|
+
|
|
89
|
+
if (wasOnline) {
|
|
90
|
+
return user.onlineStatus;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return 'APPEAR_OFFLINE';
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Get friend status between 2 users
|
|
98
|
+
*/
|
|
99
|
+
|
|
100
|
+
export function getFriendOptions(friend?: FriendFragment | null): FriendOptionsObj {
|
|
101
|
+
const { myStatus, otherStatus } = friend || {};
|
|
102
|
+
if (myStatus === 'BLOCKED') {
|
|
103
|
+
// Blocked by user
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
friendButtonText: i18n.t('user.blocked'),
|
|
107
|
+
friendStatusText: i18n.t('user.blocked_by_me'),
|
|
108
|
+
friendButtonIconName: 'user-x',
|
|
109
|
+
messageAllowed: false,
|
|
110
|
+
options: [{
|
|
111
|
+
value: 'DECLINED',
|
|
112
|
+
iconName: 'user',
|
|
113
|
+
text: i18n.t('user.unblock'),
|
|
114
|
+
}],
|
|
115
|
+
};
|
|
116
|
+
} else if (otherStatus === 'BLOCKED') {
|
|
117
|
+
// Blocked by "other" user
|
|
118
|
+
|
|
119
|
+
return {
|
|
120
|
+
friendButtonText: i18n.t('user.blocked'),
|
|
121
|
+
friendStatusText: i18n.t('user.blocked_by_other'),
|
|
122
|
+
friendButtonIconName: 'user-x',
|
|
123
|
+
messageAllowed: false,
|
|
124
|
+
options: [],
|
|
125
|
+
};
|
|
126
|
+
} else if (myStatus === 'ACCEPTED' && otherStatus === 'ACCEPTED') {
|
|
127
|
+
// Friends
|
|
128
|
+
|
|
129
|
+
return {
|
|
130
|
+
friendButtonText: i18n.t('user.friends'),
|
|
131
|
+
friendStatusText: i18n.t('user.friends_msg'),
|
|
132
|
+
friendButtonIconName: 'user-check',
|
|
133
|
+
messageAllowed: true,
|
|
134
|
+
options: [{
|
|
135
|
+
value: 'DECLINED',
|
|
136
|
+
iconName: 'user-cancel',
|
|
137
|
+
text: i18n.t('user.remove_friend'),
|
|
138
|
+
}, {
|
|
139
|
+
value: 'BLOCKED',
|
|
140
|
+
iconName: 'user-x',
|
|
141
|
+
text: i18n.t('user.block'),
|
|
142
|
+
}],
|
|
143
|
+
};
|
|
144
|
+
} else if (myStatus === 'PENDING') {
|
|
145
|
+
// Pending request from other user
|
|
146
|
+
|
|
147
|
+
return {
|
|
148
|
+
friendButtonText: i18n.t('user.friend_request'),
|
|
149
|
+
friendStatusText: i18n.t('user.add_friend_msg'),
|
|
150
|
+
friendButtonIconName: 'user-plus',
|
|
151
|
+
messageAllowed: false,
|
|
152
|
+
options: [{
|
|
153
|
+
value: 'ACCEPTED',
|
|
154
|
+
iconName: 'user-check',
|
|
155
|
+
text: i18n.t('user.accept_friend'),
|
|
156
|
+
}, {
|
|
157
|
+
value: 'DECLINED',
|
|
158
|
+
iconName: 'user-cancel',
|
|
159
|
+
text: i18n.t('user.ignore_friend'),
|
|
160
|
+
}, {
|
|
161
|
+
value: 'BLOCKED',
|
|
162
|
+
iconName: 'user-x',
|
|
163
|
+
text: i18n.t('user.block'),
|
|
164
|
+
}],
|
|
165
|
+
};
|
|
166
|
+
} else if (otherStatus === 'PENDING') {
|
|
167
|
+
// Sent a friend request; now waiting
|
|
168
|
+
|
|
169
|
+
return {
|
|
170
|
+
friendButtonText: i18n.t('user.friend_requested'),
|
|
171
|
+
friendStatusText: i18n.t('user.sent_friend_msg'),
|
|
172
|
+
friendButtonIconName: 'mail',
|
|
173
|
+
messageAllowed: false,
|
|
174
|
+
options: [{
|
|
175
|
+
value: 'DECLINED',
|
|
176
|
+
iconName: 'user-cancel',
|
|
177
|
+
text: i18n.t('user.cancel_friend'),
|
|
178
|
+
}],
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// No actions taken, user can/should send request
|
|
183
|
+
return {
|
|
184
|
+
friendButtonText: i18n.t('user.add_friend'),
|
|
185
|
+
friendStatusText: i18n.t('user.add_friend_msg'),
|
|
186
|
+
friendButtonIconName: 'user-plus',
|
|
187
|
+
messageAllowed: false,
|
|
188
|
+
options: [{
|
|
189
|
+
value: 'PENDING',
|
|
190
|
+
iconName: 'mail',
|
|
191
|
+
text: i18n.t('user.send_friend'),
|
|
192
|
+
}, {
|
|
193
|
+
value: 'BLOCKED',
|
|
194
|
+
iconName: 'user-x',
|
|
195
|
+
text: i18n.t('user.block'),
|
|
196
|
+
}],
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Get user subscription type
|
|
202
|
+
*/
|
|
203
|
+
|
|
204
|
+
export const getPlusStatus = (plus: any) => {
|
|
205
|
+
if (!plus || plus.expireAt <= Date.now()) {
|
|
206
|
+
return 'NORMAL';
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
switch (plus.type) {
|
|
210
|
+
case 'kajiwoto_plus':
|
|
211
|
+
case 'kajiwoto_plus_yearly':
|
|
212
|
+
case 'big_planet_plus':
|
|
213
|
+
case 'big_planet_plus_yearly':
|
|
214
|
+
return 'PLUS';
|
|
215
|
+
case 'kajiwoto_pro':
|
|
216
|
+
case 'kajiwoto_pro_yearly':
|
|
217
|
+
case 'big_planet_pro':
|
|
218
|
+
case 'big_planet_pro_yearly':
|
|
219
|
+
return 'PRO';
|
|
220
|
+
case 'perks':
|
|
221
|
+
return 'PERKS';
|
|
222
|
+
default:
|
|
223
|
+
return 'NORMAL';
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Get user's subscription & status
|
|
229
|
+
*/
|
|
230
|
+
|
|
231
|
+
export const getUserSubscription = (plus: any): UserSubOutput => {
|
|
232
|
+
if (!plus) {
|
|
233
|
+
return {
|
|
234
|
+
name: null,
|
|
235
|
+
group: 'NORMAL',
|
|
236
|
+
cancelled: false,
|
|
237
|
+
expired: false,
|
|
238
|
+
expireAt: null,
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const expired = (new Date(plus.expireAt)).getTime() < Date.now();
|
|
243
|
+
|
|
244
|
+
let group: PlusGroupEnum = 'NORMAL';
|
|
245
|
+
if (!expired) {
|
|
246
|
+
switch (plus.type) {
|
|
247
|
+
case 'kajiwoto_plus':
|
|
248
|
+
case 'kajiwoto_plus_yearly':
|
|
249
|
+
case 'big_planet_plus':
|
|
250
|
+
case 'big_planet_plus_yearly':
|
|
251
|
+
group = 'PLUS';
|
|
252
|
+
break;
|
|
253
|
+
case 'kajiwoto_pro':
|
|
254
|
+
case 'kajiwoto_pro_yearly':
|
|
255
|
+
case 'big_planet_pro':
|
|
256
|
+
case 'big_planet_pro_yearly':
|
|
257
|
+
group = 'PRO';
|
|
258
|
+
break;
|
|
259
|
+
case 'perks':
|
|
260
|
+
group = 'PERKS';
|
|
261
|
+
break;
|
|
262
|
+
default:
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
return {
|
|
267
|
+
name: plus.type,
|
|
268
|
+
group,
|
|
269
|
+
cancelled: !!plus.cancelled,
|
|
270
|
+
expired,
|
|
271
|
+
expireAt: plus.expireAt,
|
|
272
|
+
};
|
|
273
|
+
};
|