@myrjfa/state 2.2.0 → 2.3.1
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/LICENSE +201 -201
- package/README.md +20 -3
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -0
- package/dist/lib/actions/actions.d.ts +13 -13
- package/dist/lib/actions/actions.d.ts.map +1 -1
- package/dist/lib/actions/actions.js +5 -4
- package/dist/lib/actions/adminDashboard.d.ts +4 -0
- package/dist/lib/actions/adminDashboard.d.ts.map +1 -0
- package/dist/lib/actions/adminDashboard.js +29 -0
- package/dist/lib/actions/adventure.d.ts +104 -0
- package/dist/lib/actions/adventure.d.ts.map +1 -0
- package/dist/lib/actions/adventure.js +203 -0
- package/dist/lib/actions/application.d.ts +35 -0
- package/dist/lib/actions/application.d.ts.map +1 -0
- package/dist/lib/actions/application.js +573 -0
- package/dist/lib/actions/auth.d.ts +108 -3
- package/dist/lib/actions/auth.d.ts.map +1 -1
- package/dist/lib/actions/auth.js +38 -8
- package/dist/lib/actions/blog.d.ts +61 -0
- package/dist/lib/actions/blog.d.ts.map +1 -0
- package/dist/lib/actions/blog.js +762 -0
- package/dist/lib/actions/brand.d.ts +83 -0
- package/dist/lib/actions/brand.d.ts.map +1 -0
- package/dist/lib/actions/brand.js +28 -0
- package/dist/lib/actions/chat.d.ts +261 -24
- package/dist/lib/actions/chat.d.ts.map +1 -1
- package/dist/lib/actions/chat.js +525 -41
- package/dist/lib/actions/companion.d.ts +174 -0
- package/dist/lib/actions/companion.d.ts.map +1 -0
- package/dist/lib/actions/companion.js +276 -0
- package/dist/lib/actions/event.d.ts +178 -0
- package/dist/lib/actions/event.d.ts.map +1 -0
- package/dist/lib/actions/event.js +214 -0
- package/dist/lib/actions/fetcher.d.ts.map +1 -1
- package/dist/lib/actions/fetcher.js +18 -8
- package/dist/lib/actions/guide.d.ts +55 -0
- package/dist/lib/actions/guide.d.ts.map +1 -0
- package/dist/lib/actions/guide.js +128 -0
- package/dist/lib/actions/hostDashboard.d.ts +122 -0
- package/dist/lib/actions/hostDashboard.d.ts.map +1 -0
- package/dist/lib/actions/hostDashboard.js +329 -0
- package/dist/lib/actions/location.d.ts +141 -0
- package/dist/lib/actions/location.d.ts.map +1 -0
- package/dist/lib/actions/location.js +113 -0
- package/dist/lib/actions/notifications.d.ts +91 -0
- package/dist/lib/actions/notifications.d.ts.map +1 -0
- package/dist/lib/actions/notifications.js +83 -0
- package/dist/lib/actions/opportunity.d.ts +44 -0
- package/dist/lib/actions/opportunity.d.ts.map +1 -0
- package/dist/lib/actions/opportunity.js +318 -0
- package/dist/lib/actions/package.d.ts +85 -0
- package/dist/lib/actions/package.d.ts.map +1 -0
- package/dist/lib/actions/package.js +167 -0
- package/dist/lib/actions/place.d.ts +191 -0
- package/dist/lib/actions/place.d.ts.map +1 -0
- package/dist/lib/actions/place.js +57 -0
- package/dist/lib/actions/portfolio.d.ts +65 -0
- package/dist/lib/actions/portfolio.d.ts.map +1 -0
- package/dist/lib/actions/portfolio.js +62 -0
- package/dist/lib/actions/property.d.ts +17 -0
- package/dist/lib/actions/property.d.ts.map +1 -0
- package/dist/lib/actions/property.js +16 -0
- package/dist/lib/actions/rental.d.ts +87 -0
- package/dist/lib/actions/rental.d.ts.map +1 -0
- package/dist/lib/actions/rental.js +205 -0
- package/dist/lib/actions/review.d.ts +8 -0
- package/dist/lib/actions/review.d.ts.map +1 -0
- package/dist/lib/actions/review.js +102 -0
- package/dist/lib/actions/room.d.ts +39 -0
- package/dist/lib/actions/room.d.ts.map +1 -0
- package/dist/lib/actions/room.js +74 -0
- package/dist/lib/actions/serverActions.d.ts +1 -0
- package/dist/lib/actions/serverActions.d.ts.map +1 -1
- package/dist/lib/actions/serverActions.js +15 -0
- package/dist/lib/actions/socket.d.ts.map +1 -1
- package/dist/lib/actions/socket.js +5 -1
- package/dist/lib/actions/stay.d.ts +97 -0
- package/dist/lib/actions/stay.d.ts.map +1 -0
- package/dist/lib/actions/stay.js +138 -0
- package/dist/lib/actions/travelPackage.d.ts +104 -0
- package/dist/lib/actions/travelPackage.d.ts.map +1 -0
- package/dist/lib/actions/travelPackage.js +487 -0
- package/dist/lib/actions.d.ts +24 -24
- package/dist/lib/actions.d.ts.map +1 -1
- package/dist/lib/actions.js +14 -11
- package/dist/lib/adminDashboardActions.d.ts +15 -3
- package/dist/lib/adminDashboardActions.d.ts.map +1 -1
- package/dist/lib/adminDashboardActions.js +16 -7
- package/dist/lib/authSessionManager.d.ts.map +1 -1
- package/dist/lib/authSessionManager.js +4 -3
- package/dist/lib/authSessionPolicy.d.ts +10 -0
- package/dist/lib/authSessionPolicy.d.ts.map +1 -0
- package/dist/lib/authSessionPolicy.js +9 -0
- package/dist/lib/authorizationActions.d.ts +77 -0
- package/dist/lib/authorizationActions.d.ts.map +1 -0
- package/dist/lib/authorizationActions.js +61 -0
- package/dist/lib/context/ChatContext.d.ts +25 -6
- package/dist/lib/context/ChatContext.d.ts.map +1 -1
- package/dist/lib/context/ChatContext.js +356 -245
- package/dist/lib/data/adventureDummyData.d.ts +3 -0
- package/dist/lib/data/adventureDummyData.d.ts.map +1 -0
- package/dist/lib/data/adventureDummyData.js +138 -0
- package/dist/lib/data/adventureFormPage.d.ts +28 -0
- package/dist/lib/data/adventureFormPage.d.ts.map +1 -0
- package/dist/lib/data/adventureFormPage.js +58 -0
- package/dist/lib/data/companionDummyData.d.ts +99 -0
- package/dist/lib/data/companionDummyData.d.ts.map +1 -0
- package/dist/lib/data/companionDummyData.js +203 -0
- package/dist/lib/data/destinations.d.ts +14 -0
- package/dist/lib/data/destinations.d.ts.map +1 -0
- package/dist/lib/data/destinations.js +203 -0
- package/dist/lib/data/eventFormPage.d.ts +38 -0
- package/dist/lib/data/eventFormPage.d.ts.map +1 -0
- package/dist/lib/data/eventFormPage.js +56 -0
- package/dist/lib/data/eventsDummyData.d.ts +54 -0
- package/dist/lib/data/eventsDummyData.d.ts.map +1 -0
- package/dist/lib/data/eventsDummyData.js +586 -0
- package/dist/lib/data/guideDummyData.d.ts +3 -0
- package/dist/lib/data/guideDummyData.d.ts.map +1 -0
- package/dist/lib/data/guideDummyData.js +66 -0
- package/dist/lib/data/opportunityFormData.d.ts +13 -0
- package/dist/lib/data/opportunityFormData.d.ts.map +1 -0
- package/dist/lib/data/opportunityFormData.js +62 -0
- package/dist/lib/data/opportunityFormPage.d.ts +12 -0
- package/dist/lib/data/opportunityFormPage.d.ts.map +1 -0
- package/dist/lib/data/opportunityFormPage.js +33 -0
- package/dist/lib/data/packageDummyData.d.ts +3 -0
- package/dist/lib/data/packageDummyData.d.ts.map +1 -0
- package/dist/lib/data/packageDummyData.js +56 -0
- package/dist/lib/data/rentalDummyData.d.ts +3 -0
- package/dist/lib/data/rentalDummyData.d.ts.map +1 -0
- package/dist/lib/data/rentalDummyData.js +382 -0
- package/dist/lib/data/rentalFormPage.d.ts +11 -0
- package/dist/lib/data/rentalFormPage.d.ts.map +1 -0
- package/dist/lib/data/rentalFormPage.js +86 -0
- package/dist/lib/data/staysDummyData.d.ts +72 -0
- package/dist/lib/data/staysDummyData.d.ts.map +1 -0
- package/dist/lib/data/staysDummyData.js +694 -0
- package/dist/lib/data/storeDummyData.d.ts +33 -0
- package/dist/lib/data/storeDummyData.d.ts.map +1 -0
- package/dist/lib/data/storeDummyData.js +336 -0
- package/dist/lib/data/travelPackageFormData.d.ts +19 -0
- package/dist/lib/data/travelPackageFormData.d.ts.map +1 -0
- package/dist/lib/data/travelPackageFormData.js +51 -0
- package/dist/lib/data/travelPackageFormPage.d.ts +22 -0
- package/dist/lib/data/travelPackageFormPage.d.ts.map +1 -0
- package/dist/lib/data/travelPackageFormPage.js +40 -0
- package/dist/lib/data/vehicleData.d.ts +2 -0
- package/dist/lib/data/vehicleData.d.ts.map +1 -0
- package/dist/lib/data/vehicleData.js +187 -0
- package/dist/lib/data/vehicleModels.d.ts +2 -0
- package/dist/lib/data/vehicleModels.d.ts.map +1 -0
- package/dist/lib/data/vehicleModels.js +128 -0
- package/dist/lib/discountActions.d.ts +43 -0
- package/dist/lib/discountActions.d.ts.map +1 -0
- package/dist/lib/discountActions.js +69 -0
- package/dist/lib/hooks/usePersistentDraftState.d.ts +20 -0
- package/dist/lib/hooks/usePersistentDraftState.d.ts.map +1 -0
- package/dist/lib/hooks/usePersistentDraftState.js +47 -0
- package/dist/lib/loyaltyActions.d.ts +32 -0
- package/dist/lib/loyaltyActions.d.ts.map +1 -0
- package/dist/lib/loyaltyActions.js +92 -0
- package/dist/lib/models/adventure.d.ts +0 -2
- package/dist/lib/models/adventure.d.ts.map +1 -1
- package/dist/lib/models/authorization.d.ts +107 -0
- package/dist/lib/models/authorization.d.ts.map +1 -0
- package/dist/lib/models/authorization.js +263 -0
- package/dist/lib/models/blog.d.ts +2 -2
- package/dist/lib/models/booking.d.ts +7 -2
- package/dist/lib/models/booking.d.ts.map +1 -1
- package/dist/lib/models/chat.d.ts +418 -32
- package/dist/lib/models/chat.d.ts.map +1 -1
- package/dist/lib/models/chat.js +5 -1
- package/dist/lib/models/discount.d.ts +587 -136
- package/dist/lib/models/discount.d.ts.map +1 -1
- package/dist/lib/models/discount.js +118 -96
- package/dist/lib/models/forms.d.ts +384 -0
- package/dist/lib/models/forms.d.ts.map +1 -0
- package/dist/lib/models/forms.js +121 -0
- package/dist/lib/models/guide.d.ts +0 -2
- package/dist/lib/models/guide.d.ts.map +1 -1
- package/dist/lib/models/loyalty.d.ts +88 -0
- package/dist/lib/models/loyalty.d.ts.map +1 -0
- package/dist/lib/models/loyalty.js +1 -0
- package/dist/lib/models/notifications.d.ts +4 -4
- package/dist/lib/models/opportunities/freelance.d.ts +66 -20
- package/dist/lib/models/opportunities/freelance.d.ts.map +1 -1
- package/dist/lib/models/opportunities/internship.d.ts +66 -20
- package/dist/lib/models/opportunities/internship.d.ts.map +1 -1
- package/dist/lib/models/opportunities/job.d.ts +66 -20
- package/dist/lib/models/opportunities/job.d.ts.map +1 -1
- package/dist/lib/models/opportunities/opportunity.d.ts +66 -20
- package/dist/lib/models/opportunities/opportunity.d.ts.map +1 -1
- package/dist/lib/models/opportunities/opportunity.js +2 -0
- package/dist/lib/models/opportunities/volunteerJob.d.ts +66 -20
- package/dist/lib/models/opportunities/volunteerJob.d.ts.map +1 -1
- package/dist/lib/models/package.d.ts +81 -220
- package/dist/lib/models/package.d.ts.map +1 -1
- package/dist/lib/models/package.js +0 -2
- package/dist/lib/models/props.d.ts +1 -1
- package/dist/lib/models/props.d.ts.map +1 -1
- package/dist/lib/models/rental.d.ts +0 -2
- package/dist/lib/models/rental.d.ts.map +1 -1
- package/dist/lib/models/stay.d.ts +4 -4
- package/dist/lib/models/store.d.ts +71 -0
- package/dist/lib/models/store.d.ts.map +1 -0
- package/dist/lib/models/store.js +1 -0
- package/dist/lib/models/tile.d.ts +0 -2
- package/dist/lib/models/tile.d.ts.map +1 -1
- package/dist/lib/models/travelPackage.d.ts +206 -305
- package/dist/lib/models/travelPackage.d.ts.map +1 -1
- package/dist/lib/models/travelPackage.js +0 -2
- package/dist/lib/models/user.d.ts +28 -4
- package/dist/lib/models/user.d.ts.map +1 -1
- package/dist/lib/models/user.js +10 -1
- package/dist/lib/opportunityFormPage.d.ts +1 -0
- package/dist/lib/opportunityFormPage.d.ts.map +1 -1
- package/dist/lib/opportunityFormPage.js +1 -0
- package/dist/lib/pricingActions.d.ts +13 -0
- package/dist/lib/pricingActions.d.ts.map +1 -0
- package/dist/lib/pricingActions.js +16 -0
- package/dist/lib/rentalActions.js +0 -1
- package/dist/lib/rentalDummyData.d.ts.map +1 -1
- package/dist/lib/rentalDummyData.js +0 -35
- package/dist/lib/rentalFormPage.d.ts +0 -2
- package/dist/lib/rentalFormPage.d.ts.map +1 -1
- package/dist/lib/rentalFormPage.js +0 -3
- package/dist/lib/storeActions.d.ts +25 -0
- package/dist/lib/storeActions.d.ts.map +1 -0
- package/dist/lib/storeActions.js +46 -0
- package/dist/lib/storeDummyData.d.ts +2 -26
- package/dist/lib/storeDummyData.d.ts.map +1 -1
- package/dist/lib/userAtom.d.ts +71 -36
- package/dist/lib/userAtom.d.ts.map +1 -1
- package/dist/lib/userAtom.js +11 -17
- package/dist/lib/utils/entitySubmission.d.ts +21 -0
- package/dist/lib/utils/entitySubmission.d.ts.map +1 -0
- package/dist/lib/utils/entitySubmission.js +10 -0
- package/dist/lib/utils/imageUpload.d.ts +4 -0
- package/dist/lib/utils/imageUpload.d.ts.map +1 -0
- package/dist/lib/utils/imageUpload.js +36 -0
- package/dist/lib/utils/tileConverters.d.ts +8 -0
- package/dist/lib/utils/tileConverters.d.ts.map +1 -0
- package/dist/lib/utils/tileConverters.js +59 -0
- package/dist/lib/utils.d.ts.map +1 -1
- package/dist/lib/utils.js +1 -1
- package/package.json +4 -2
package/dist/lib/actions/chat.js
CHANGED
|
@@ -1,11 +1,153 @@
|
|
|
1
|
-
import { get, post, patch, del } from "./fetcher";
|
|
1
|
+
import { get, post, patch, put, del } from "./fetcher";
|
|
2
2
|
const BASE_PATH = "/chat";
|
|
3
|
+
const idString = (value) => String(value || "");
|
|
4
|
+
const normalizeActorRef = (actor) => ({
|
|
5
|
+
actorId: idString(actor?.actorId),
|
|
6
|
+
actorModel: actor?.actorModel,
|
|
7
|
+
});
|
|
8
|
+
export const normalizeChatMessage = (message) => ({
|
|
9
|
+
...message,
|
|
10
|
+
_id: idString(message?._id),
|
|
11
|
+
conversationId: idString(message?.conversationId),
|
|
12
|
+
senderId: idString(message?.senderId),
|
|
13
|
+
senderModel: message?.senderModel,
|
|
14
|
+
content: {
|
|
15
|
+
text: message?.content?.text || "",
|
|
16
|
+
media: message?.content?.media || [],
|
|
17
|
+
linkPreview: message?.content?.linkPreview || undefined,
|
|
18
|
+
referenceId: message?.content?.referenceId,
|
|
19
|
+
referenceType: message?.content?.referenceType,
|
|
20
|
+
card: message?.content?.card || undefined,
|
|
21
|
+
mentions: (message?.content?.mentions || []).map(normalizeActorRef),
|
|
22
|
+
},
|
|
23
|
+
reactions: (message?.reactions || []).map((reaction) => ({
|
|
24
|
+
...normalizeActorRef(reaction),
|
|
25
|
+
emoji: reaction.emoji,
|
|
26
|
+
createdAt: reaction.createdAt,
|
|
27
|
+
})),
|
|
28
|
+
readBy: (message?.readBy || []).map((receipt) => ({
|
|
29
|
+
...normalizeActorRef(receipt),
|
|
30
|
+
readAt: receipt.readAt,
|
|
31
|
+
})),
|
|
32
|
+
deliveredTo: (message?.deliveredTo || []).map((receipt) => ({
|
|
33
|
+
...normalizeActorRef(receipt),
|
|
34
|
+
deliveredAt: receipt.deliveredAt,
|
|
35
|
+
})),
|
|
36
|
+
});
|
|
37
|
+
export const normalizeConversation = (conversation) => ({
|
|
38
|
+
...conversation,
|
|
39
|
+
_id: idString(conversation?._id),
|
|
40
|
+
type: conversation?.type || "individual",
|
|
41
|
+
participants: (conversation?.participants || []).map((participant) => ({
|
|
42
|
+
...normalizeActorRef(participant),
|
|
43
|
+
accountType: participant.accountType,
|
|
44
|
+
username: participant.username || "",
|
|
45
|
+
displayName: participant.displayName || participant.username || "",
|
|
46
|
+
profilePic: participant.profilePic || "",
|
|
47
|
+
chatRole: participant.chatRole || "member",
|
|
48
|
+
joinedAt: participant.joinedAt || conversation?.createdAt,
|
|
49
|
+
lastReadAt: participant.lastReadAt || null,
|
|
50
|
+
unreadCount: Number(participant.unreadCount || 0),
|
|
51
|
+
restrictedUntil: participant.restrictedUntil || null,
|
|
52
|
+
})),
|
|
53
|
+
features: {
|
|
54
|
+
milestones: Boolean(conversation?.features?.milestones),
|
|
55
|
+
expenses: Boolean(conversation?.features?.expenses),
|
|
56
|
+
events: conversation?.features?.events !== false,
|
|
57
|
+
},
|
|
58
|
+
groupSettings: {
|
|
59
|
+
announcementsOnly: Boolean(conversation?.groupSettings?.announcementsOnly),
|
|
60
|
+
joinApprovalRequired: Boolean(conversation?.groupSettings?.joinApprovalRequired),
|
|
61
|
+
},
|
|
62
|
+
context: conversation?.context,
|
|
63
|
+
lastMessage: conversation?.lastMessage
|
|
64
|
+
? {
|
|
65
|
+
text: conversation.lastMessage.text || "",
|
|
66
|
+
senderId: idString(conversation.lastMessage.senderId),
|
|
67
|
+
senderModel: conversation.lastMessage.senderModel,
|
|
68
|
+
sentAt: conversation.lastMessage.sentAt,
|
|
69
|
+
}
|
|
70
|
+
: undefined,
|
|
71
|
+
preference: {
|
|
72
|
+
conversationId: idString(conversation?.preference?.conversationId || conversation?._id),
|
|
73
|
+
actorId: idString(conversation?.preference?.actorId),
|
|
74
|
+
actorModel: conversation?.preference?.actorModel,
|
|
75
|
+
pinnedAt: conversation?.preference?.pinnedAt || null,
|
|
76
|
+
favouritedAt: conversation?.preference?.favouritedAt || null,
|
|
77
|
+
archivedAt: conversation?.preference?.archivedAt || null,
|
|
78
|
+
mutedUntil: conversation?.preference?.mutedUntil || null,
|
|
79
|
+
notificationLevel: conversation?.preference?.notificationLevel || "all",
|
|
80
|
+
markedUnreadAt: conversation?.preference?.markedUnreadAt || null,
|
|
81
|
+
draftText: conversation?.preference?.draftText || "",
|
|
82
|
+
draftUpdatedAt: conversation?.preference?.draftUpdatedAt || null,
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
const normalizePreference = (preference) => ({
|
|
86
|
+
conversationId: idString(preference?.conversationId),
|
|
87
|
+
actorId: idString(preference?.actorId),
|
|
88
|
+
actorModel: preference?.actorModel,
|
|
89
|
+
pinnedAt: preference?.pinnedAt || null,
|
|
90
|
+
favouritedAt: preference?.favouritedAt || null,
|
|
91
|
+
archivedAt: preference?.archivedAt || null,
|
|
92
|
+
mutedUntil: preference?.mutedUntil || null,
|
|
93
|
+
notificationLevel: preference?.notificationLevel || "all",
|
|
94
|
+
markedUnreadAt: preference?.markedUnreadAt || null,
|
|
95
|
+
draftText: preference?.draftText || "",
|
|
96
|
+
draftUpdatedAt: preference?.draftUpdatedAt || null,
|
|
97
|
+
});
|
|
98
|
+
const normalizeActorLine = (line) => ({ ...line, ...normalizeActorRef(line) });
|
|
99
|
+
const normalizeBalanceLine = (line) => ({
|
|
100
|
+
...normalizeActorLine(line),
|
|
101
|
+
// Canonical backend balance rows use `balance`; shared UI retains the
|
|
102
|
+
// established `netBalance` field.
|
|
103
|
+
netBalance: Number(line?.netBalance ?? line?.balance ?? 0),
|
|
104
|
+
});
|
|
105
|
+
const normalizeExpense = (expense) => ({ ...expense, _id: idString(expense?._id), conversationId: idString(expense?.conversationId), createdBy: normalizeActorRef(expense?.createdBy), paidBy: (expense?.paidBy || []).map(normalizeActorLine), splits: (expense?.splits || []).map(normalizeActorLine) });
|
|
106
|
+
const normalizeMilestone = (milestone) => ({ ...milestone, _id: idString(milestone?._id), conversationId: idString(milestone?.conversationId), createdBy: normalizeActorRef(milestone?.createdBy), checks: (milestone?.checks || []).map(normalizeActorLine) });
|
|
107
|
+
const normalizePoll = (poll) => ({
|
|
108
|
+
...poll,
|
|
109
|
+
_id: idString(poll?._id),
|
|
110
|
+
conversationId: idString(poll?.conversationId),
|
|
111
|
+
createdBy: normalizeActorRef(poll?.createdBy),
|
|
112
|
+
votes: (poll?.votes || []).map(normalizeActorLine),
|
|
113
|
+
});
|
|
114
|
+
const normalizeEvent = (event) => ({
|
|
115
|
+
...event,
|
|
116
|
+
_id: idString(event?._id),
|
|
117
|
+
conversationId: idString(event?.conversationId),
|
|
118
|
+
createdBy: normalizeActorRef(event?.createdBy),
|
|
119
|
+
invitedActors: (event?.invitedActors || []).map(normalizeActorRef),
|
|
120
|
+
rsvps: (event?.rsvps || []).map(normalizeActorLine),
|
|
121
|
+
});
|
|
3
122
|
export const chatApi = {
|
|
123
|
+
searchParticipants: async (query) => {
|
|
124
|
+
const response = await get(`${BASE_PATH}/participants?q=${encodeURIComponent(query)}`);
|
|
125
|
+
return (response.data || []).map((participant) => ({
|
|
126
|
+
actorId: idString(participant.actorId),
|
|
127
|
+
actorModel: participant.actorModel,
|
|
128
|
+
username: participant.username || "",
|
|
129
|
+
displayName: participant.displayName || participant.username || "Trippeaze member",
|
|
130
|
+
profilePic: participant.profilePic || "",
|
|
131
|
+
}));
|
|
132
|
+
},
|
|
133
|
+
createGroup: async (data) => {
|
|
134
|
+
const response = await post(`${BASE_PATH}/groups`, data);
|
|
135
|
+
return response.data ? normalizeConversation(response.data) : null;
|
|
136
|
+
},
|
|
4
137
|
// Conversations
|
|
5
|
-
getConversations: async () => {
|
|
138
|
+
getConversations: async (params) => {
|
|
6
139
|
try {
|
|
7
|
-
const
|
|
8
|
-
|
|
140
|
+
const query = new URLSearchParams();
|
|
141
|
+
if (params?.filter)
|
|
142
|
+
query.set("filter", params.filter);
|
|
143
|
+
if (params?.q)
|
|
144
|
+
query.set("q", params.q);
|
|
145
|
+
if (params?.before)
|
|
146
|
+
query.set("before", params.before);
|
|
147
|
+
if (params?.limit)
|
|
148
|
+
query.set("limit", String(params.limit));
|
|
149
|
+
const response = await get(`${BASE_PATH}/conversations?${query.toString()}`);
|
|
150
|
+
return (response.data || []).map(normalizeConversation);
|
|
9
151
|
}
|
|
10
152
|
catch (error) {
|
|
11
153
|
console.error(error);
|
|
@@ -15,7 +157,7 @@ export const chatApi = {
|
|
|
15
157
|
getConversation: async (id) => {
|
|
16
158
|
try {
|
|
17
159
|
const response = await get(`${BASE_PATH}/conversations/${id}`);
|
|
18
|
-
return response.data;
|
|
160
|
+
return response.data ? normalizeConversation(response.data) : null;
|
|
19
161
|
}
|
|
20
162
|
catch (error) {
|
|
21
163
|
console.error(error);
|
|
@@ -25,7 +167,7 @@ export const chatApi = {
|
|
|
25
167
|
createConversation: async (data) => {
|
|
26
168
|
try {
|
|
27
169
|
const response = await post(`${BASE_PATH}/conversations`, data);
|
|
28
|
-
return response.data;
|
|
170
|
+
return response.data ? normalizeConversation(response.data) : null;
|
|
29
171
|
}
|
|
30
172
|
catch (error) {
|
|
31
173
|
console.error(error);
|
|
@@ -35,7 +177,7 @@ export const chatApi = {
|
|
|
35
177
|
updateConversation: async (id, data) => {
|
|
36
178
|
try {
|
|
37
179
|
const response = await patch(`${BASE_PATH}/conversations/${id}`, data);
|
|
38
|
-
return response.data;
|
|
180
|
+
return response.data ? normalizeConversation(response.data) : null;
|
|
39
181
|
}
|
|
40
182
|
catch (error) {
|
|
41
183
|
console.error(error);
|
|
@@ -52,30 +194,30 @@ export const chatApi = {
|
|
|
52
194
|
return null;
|
|
53
195
|
}
|
|
54
196
|
},
|
|
55
|
-
addParticipants: async (id,
|
|
197
|
+
addParticipants: async (id, participantIds) => {
|
|
56
198
|
try {
|
|
57
|
-
const response = await post(`${BASE_PATH}/conversations/${id}/participants`, {
|
|
58
|
-
return response;
|
|
199
|
+
const response = await post(`${BASE_PATH}/conversations/${id}/participants`, { participantIds });
|
|
200
|
+
return response.data ? normalizeConversation(response.data) : null;
|
|
59
201
|
}
|
|
60
202
|
catch (error) {
|
|
61
203
|
console.error(error);
|
|
62
|
-
return
|
|
204
|
+
return null;
|
|
63
205
|
}
|
|
64
206
|
},
|
|
65
|
-
removeParticipant: async (convId,
|
|
207
|
+
removeParticipant: async (convId, actorId, actorModel) => {
|
|
66
208
|
try {
|
|
67
|
-
const response = await del(`${BASE_PATH}/conversations/${convId}/participants/${
|
|
68
|
-
return response.data;
|
|
209
|
+
const response = await del(`${BASE_PATH}/conversations/${convId}/participants/${actorModel}/${actorId}`);
|
|
210
|
+
return response.data ? normalizeConversation(response.data) : null;
|
|
69
211
|
}
|
|
70
212
|
catch (error) {
|
|
71
213
|
console.error(error);
|
|
72
214
|
return null;
|
|
73
215
|
}
|
|
74
216
|
},
|
|
75
|
-
updateParticipant: async (convId,
|
|
217
|
+
updateParticipant: async (convId, actorId, actorModel, data) => {
|
|
76
218
|
try {
|
|
77
|
-
const response = await patch(`${BASE_PATH}/conversations/${convId}/participants/${
|
|
78
|
-
return response.data;
|
|
219
|
+
const response = await patch(`${BASE_PATH}/conversations/${convId}/participants/${actorModel}/${actorId}`, data);
|
|
220
|
+
return response.data ? normalizeConversation(response.data) : null;
|
|
79
221
|
}
|
|
80
222
|
catch (error) {
|
|
81
223
|
console.error(error);
|
|
@@ -90,8 +232,12 @@ export const chatApi = {
|
|
|
90
232
|
qs.set("limit", String(params.limit));
|
|
91
233
|
if (params?.before)
|
|
92
234
|
qs.set("before", params.before);
|
|
235
|
+
if (params?.around)
|
|
236
|
+
qs.set("around", params.around);
|
|
237
|
+
if (params?.radius)
|
|
238
|
+
qs.set("radius", String(params.radius));
|
|
93
239
|
const response = await get(`${BASE_PATH}/conversations/${convId}/messages?${qs.toString()}`);
|
|
94
|
-
return response.data;
|
|
240
|
+
return (response.data || []).map(normalizeChatMessage);
|
|
95
241
|
}
|
|
96
242
|
catch (error) {
|
|
97
243
|
console.error(error);
|
|
@@ -100,8 +246,11 @@ export const chatApi = {
|
|
|
100
246
|
},
|
|
101
247
|
getMessage: async (convId, id) => {
|
|
102
248
|
try {
|
|
103
|
-
const response = await get(`${BASE_PATH}/conversations/${convId}/messages
|
|
104
|
-
return
|
|
249
|
+
const response = await get(`${BASE_PATH}/conversations/${convId}/messages/${id}`);
|
|
250
|
+
return {
|
|
251
|
+
...response,
|
|
252
|
+
data: response.data ? normalizeChatMessage(response.data) : null,
|
|
253
|
+
};
|
|
105
254
|
}
|
|
106
255
|
catch (error) {
|
|
107
256
|
console.error(error);
|
|
@@ -111,7 +260,7 @@ export const chatApi = {
|
|
|
111
260
|
sendMessage: async (convId, data) => {
|
|
112
261
|
try {
|
|
113
262
|
const response = await post(`${BASE_PATH}/conversations/${convId}/messages`, data);
|
|
114
|
-
return response.data;
|
|
263
|
+
return response.data ? normalizeChatMessage(response.data) : null;
|
|
115
264
|
}
|
|
116
265
|
catch (error) {
|
|
117
266
|
console.error(error);
|
|
@@ -121,7 +270,7 @@ export const chatApi = {
|
|
|
121
270
|
editMessage: async (id, text) => {
|
|
122
271
|
try {
|
|
123
272
|
const response = await patch(`${BASE_PATH}/messages/${id}`, { text });
|
|
124
|
-
return response.data;
|
|
273
|
+
return response.data ? normalizeChatMessage(response.data) : null;
|
|
125
274
|
}
|
|
126
275
|
catch (error) {
|
|
127
276
|
console.error(error);
|
|
@@ -130,8 +279,8 @@ export const chatApi = {
|
|
|
130
279
|
},
|
|
131
280
|
addMessageReaction: async (id, emoji) => {
|
|
132
281
|
try {
|
|
133
|
-
const response = await patch(`${BASE_PATH}/messages/${id}/
|
|
134
|
-
return response.data;
|
|
282
|
+
const response = await patch(`${BASE_PATH}/messages/${id}/reaction`, { emoji });
|
|
283
|
+
return response.data ? normalizeChatMessage(response.data) : null;
|
|
135
284
|
}
|
|
136
285
|
catch (error) {
|
|
137
286
|
console.error(error);
|
|
@@ -141,7 +290,7 @@ export const chatApi = {
|
|
|
141
290
|
deleteMessage: async (id) => {
|
|
142
291
|
try {
|
|
143
292
|
const response = await del(`${BASE_PATH}/messages/${id}`);
|
|
144
|
-
return response.data;
|
|
293
|
+
return response.data ? normalizeChatMessage(response.data) : null;
|
|
145
294
|
}
|
|
146
295
|
catch (error) {
|
|
147
296
|
console.error(error);
|
|
@@ -150,8 +299,8 @@ export const chatApi = {
|
|
|
150
299
|
},
|
|
151
300
|
addReaction: async (id, emoji) => {
|
|
152
301
|
try {
|
|
153
|
-
const response = await
|
|
154
|
-
return response.data;
|
|
302
|
+
const response = await patch(`${BASE_PATH}/messages/${id}/reaction`, { emoji });
|
|
303
|
+
return response.data ? normalizeChatMessage(response.data) : null;
|
|
155
304
|
}
|
|
156
305
|
catch (error) {
|
|
157
306
|
console.error(error);
|
|
@@ -160,8 +309,8 @@ export const chatApi = {
|
|
|
160
309
|
},
|
|
161
310
|
removeReaction: async (id) => {
|
|
162
311
|
try {
|
|
163
|
-
const response = await
|
|
164
|
-
return response.data;
|
|
312
|
+
const response = await patch(`${BASE_PATH}/messages/${id}/reaction`, { emoji: "" });
|
|
313
|
+
return response.data ? normalizeChatMessage(response.data) : null;
|
|
165
314
|
}
|
|
166
315
|
catch (error) {
|
|
167
316
|
console.error(error);
|
|
@@ -170,7 +319,7 @@ export const chatApi = {
|
|
|
170
319
|
},
|
|
171
320
|
markRead: async (convId, messageIds) => {
|
|
172
321
|
try {
|
|
173
|
-
const response = await post(`${BASE_PATH}/conversations/${convId}/
|
|
322
|
+
const response = await post(`${BASE_PATH}/conversations/${convId}/read`, { messageIds });
|
|
174
323
|
return response.data;
|
|
175
324
|
}
|
|
176
325
|
catch (error) {
|
|
@@ -178,11 +327,244 @@ export const chatApi = {
|
|
|
178
327
|
return null;
|
|
179
328
|
}
|
|
180
329
|
},
|
|
181
|
-
|
|
330
|
+
blockParticipant: async (targetId, targetModel) => {
|
|
331
|
+
const response = await post(`${BASE_PATH}/blocks/${targetModel}/${targetId}`, {});
|
|
332
|
+
return response.data;
|
|
333
|
+
},
|
|
334
|
+
restrictParticipant: async (convId, actorId, actorModel, restrictedUntil) => {
|
|
335
|
+
const response = await patch(`${BASE_PATH}/conversations/${convId}/participants/${actorModel}/${actorId}/restriction`, { restrictedUntil });
|
|
336
|
+
return response.data ? normalizeConversation(response.data) : null;
|
|
337
|
+
},
|
|
338
|
+
getConversationPreference: async (id) => {
|
|
339
|
+
const response = await get(`${BASE_PATH}/conversations/${id}/preferences`);
|
|
340
|
+
return normalizePreference(response.data);
|
|
341
|
+
},
|
|
342
|
+
updateConversationPreference: async (id, data) => {
|
|
343
|
+
const response = await patch(`${BASE_PATH}/conversations/${id}/preferences`, data);
|
|
344
|
+
return normalizePreference(response.data);
|
|
345
|
+
},
|
|
346
|
+
markConversationUnread: async (id) => {
|
|
347
|
+
const response = await post(`${BASE_PATH}/conversations/${id}/mark-unread`, {});
|
|
348
|
+
return normalizePreference(response.data);
|
|
349
|
+
},
|
|
350
|
+
unblockParticipant: async (targetId, targetModel) => {
|
|
351
|
+
const response = await del(`${BASE_PATH}/blocks/${targetModel}/${targetId}`);
|
|
352
|
+
return response.data;
|
|
353
|
+
},
|
|
354
|
+
getBlockStatus: async (targetId, targetModel) => {
|
|
355
|
+
const response = await get(`${BASE_PATH}/blocks/${targetModel}/${targetId}`);
|
|
356
|
+
return response.data;
|
|
357
|
+
},
|
|
358
|
+
getEvents: async (convId) => {
|
|
359
|
+
const response = await get(`${BASE_PATH}/conversations/${convId}/events`);
|
|
360
|
+
return (response.data || []).map(normalizeEvent);
|
|
361
|
+
},
|
|
362
|
+
createEvent: async (convId, data) => {
|
|
363
|
+
const response = await post(`${BASE_PATH}/conversations/${convId}/events`, data);
|
|
364
|
+
return normalizeEvent(response.data);
|
|
365
|
+
},
|
|
366
|
+
updateEvent: async (eventId, data) => {
|
|
367
|
+
const response = await patch(`${BASE_PATH}/events/${eventId}`, data);
|
|
368
|
+
return normalizeEvent(response.data);
|
|
369
|
+
},
|
|
370
|
+
deleteEvent: async (eventId) => {
|
|
371
|
+
const response = await del(`${BASE_PATH}/events/${eventId}`);
|
|
372
|
+
return response.data;
|
|
373
|
+
},
|
|
374
|
+
rsvpEvent: async (eventId, status) => {
|
|
375
|
+
const response = await post(`${BASE_PATH}/events/${eventId}/rsvp`, { status });
|
|
376
|
+
return normalizeEvent(response.data);
|
|
377
|
+
},
|
|
378
|
+
getEventCalendarUrl: (eventId) => `${BASE_PATH}/events/${eventId}/calendar`,
|
|
379
|
+
createGroupInvite: async (convId, data) => {
|
|
380
|
+
const response = await post(`${BASE_PATH}/conversations/${convId}/invites`, data);
|
|
381
|
+
return response.data;
|
|
382
|
+
},
|
|
383
|
+
getGroupInvites: async (convId) => {
|
|
384
|
+
const response = await get(`${BASE_PATH}/conversations/${convId}/invites`);
|
|
385
|
+
return response.data || [];
|
|
386
|
+
},
|
|
387
|
+
revokeGroupInvite: async (inviteId) => {
|
|
388
|
+
const response = await del(`${BASE_PATH}/invites/${inviteId}`);
|
|
389
|
+
return response.data;
|
|
390
|
+
},
|
|
391
|
+
joinGroupWithToken: async (token) => {
|
|
392
|
+
const response = await post(`${BASE_PATH}/join/${encodeURIComponent(token)}`, {});
|
|
393
|
+
return response.data;
|
|
394
|
+
},
|
|
395
|
+
getGroupJoinRequests: async (convId) => {
|
|
396
|
+
const response = await get(`${BASE_PATH}/conversations/${convId}/join-requests`);
|
|
397
|
+
return response.data || [];
|
|
398
|
+
},
|
|
399
|
+
reviewGroupJoinRequest: async (requestId, status) => {
|
|
400
|
+
const response = await patch(`${BASE_PATH}/join-requests/${requestId}`, { status });
|
|
401
|
+
return response.data;
|
|
402
|
+
},
|
|
403
|
+
moderateMessage: async (messageId, reason) => {
|
|
404
|
+
const response = await post(`${BASE_PATH}/messages/${messageId}/moderate`, { reason });
|
|
405
|
+
return normalizeChatMessage(response.data);
|
|
406
|
+
},
|
|
407
|
+
reportContent: async (convId, data) => {
|
|
408
|
+
const response = await post(`${BASE_PATH}/conversations/${convId}/reports`, data);
|
|
409
|
+
return response.data;
|
|
410
|
+
},
|
|
411
|
+
getPaymentProfile: async () => {
|
|
412
|
+
const response = await get(`${BASE_PATH}/payment-profile`);
|
|
413
|
+
return response.data;
|
|
414
|
+
},
|
|
415
|
+
updatePaymentProfile: async (methods) => {
|
|
416
|
+
const response = await put(`${BASE_PATH}/payment-profile`, { methods });
|
|
417
|
+
return response.data;
|
|
418
|
+
},
|
|
419
|
+
getSharedPaymentDetails: async (convId, target) => {
|
|
420
|
+
const response = await get(`${BASE_PATH}/conversations/${convId}/payment-details/${target.actorModel}/${target.actorId}`);
|
|
421
|
+
return response.data;
|
|
422
|
+
},
|
|
423
|
+
sharePaymentDetails: async (convId) => {
|
|
424
|
+
const response = await post(`${BASE_PATH}/conversations/${convId}/share-payment-details`, {});
|
|
425
|
+
return response.data;
|
|
426
|
+
},
|
|
427
|
+
getPaymentDetailRequests: async (convId) => {
|
|
428
|
+
const response = await get(`${BASE_PATH}/conversations/${convId}/payment-detail-requests`);
|
|
429
|
+
return response.data || [];
|
|
430
|
+
},
|
|
431
|
+
requestPaymentDetails: async (convId, target) => {
|
|
432
|
+
const response = await post(`${BASE_PATH}/conversations/${convId}/payment-detail-requests`, { targetId: target.actorId, targetModel: target.actorModel });
|
|
433
|
+
return { ...response.data, message: normalizeChatMessage(response.data.message) };
|
|
434
|
+
},
|
|
435
|
+
respondToPaymentDetailRequest: async (requestId, accepted, methodIds = []) => {
|
|
436
|
+
const response = await post(`${BASE_PATH}/payment-detail-requests/${requestId}/respond`, { accepted, methodIds });
|
|
437
|
+
return { ...response.data, message: normalizeChatMessage(response.data.message) };
|
|
438
|
+
},
|
|
439
|
+
getPaymentIntents: async (convId) => {
|
|
440
|
+
const response = await get(`${BASE_PATH}/conversations/${convId}/payment-intents`);
|
|
441
|
+
return response.data || [];
|
|
442
|
+
},
|
|
443
|
+
createPaymentIntent: async (convId, data) => {
|
|
444
|
+
const response = await post(`${BASE_PATH}/conversations/${convId}/payment-intents`, data);
|
|
445
|
+
return response.data;
|
|
446
|
+
},
|
|
447
|
+
verifyPaymentIntent: async (paymentIntentId, data) => {
|
|
448
|
+
const response = await post(`${BASE_PATH}/payment-intents/${paymentIntentId}/verify`, data);
|
|
449
|
+
return response.data;
|
|
450
|
+
},
|
|
451
|
+
confirmPaymentIntent: async (paymentIntentId, disputed = false, reason) => {
|
|
452
|
+
const response = await post(`${BASE_PATH}/payment-intents/${paymentIntentId}/confirm`, { disputed, reason });
|
|
453
|
+
return response.data;
|
|
454
|
+
},
|
|
455
|
+
getChatBusinessProfile: async () => {
|
|
456
|
+
const response = await get(`${BASE_PATH}/business-profile`);
|
|
457
|
+
return response.data;
|
|
458
|
+
},
|
|
459
|
+
updateChatBusinessProfile: async (data) => {
|
|
460
|
+
const response = await put(`${BASE_PATH}/business-profile`, data);
|
|
461
|
+
return response.data;
|
|
462
|
+
},
|
|
463
|
+
getChatQuickReplies: async () => {
|
|
464
|
+
const response = await get(`${BASE_PATH}/quick-replies`);
|
|
465
|
+
return response.data;
|
|
466
|
+
},
|
|
467
|
+
saveChatQuickReply: async (data, quickReplyId) => {
|
|
468
|
+
const response = quickReplyId
|
|
469
|
+
? await patch(`${BASE_PATH}/quick-replies/${quickReplyId}`, data)
|
|
470
|
+
: await post(`${BASE_PATH}/quick-replies`, data);
|
|
471
|
+
return response.data;
|
|
472
|
+
},
|
|
473
|
+
deleteChatQuickReply: async (quickReplyId) => {
|
|
474
|
+
await del(`${BASE_PATH}/quick-replies/${quickReplyId}`);
|
|
475
|
+
},
|
|
476
|
+
getHostConversationState: async (conversationId) => {
|
|
477
|
+
const response = await get(`${BASE_PATH}/conversations/${conversationId}/host-state`);
|
|
478
|
+
return response.data;
|
|
479
|
+
},
|
|
480
|
+
updateHostConversationState: async (conversationId, data) => {
|
|
481
|
+
const response = await patch(`${BASE_PATH}/conversations/${conversationId}/host-state`, data);
|
|
482
|
+
return response.data;
|
|
483
|
+
},
|
|
484
|
+
getOwnedPublishedChatListings: async (query = "") => {
|
|
485
|
+
const response = await get(`${BASE_PATH}/owned-listings${query ? `?q=${encodeURIComponent(query)}` : ""}`);
|
|
486
|
+
return response.data;
|
|
487
|
+
},
|
|
488
|
+
sendOwnedListingCard: async (conversationId, listing) => {
|
|
489
|
+
const response = await post(`${BASE_PATH}/conversations/${conversationId}/messages/listing-card`, listing);
|
|
490
|
+
return normalizeChatMessage(response.data);
|
|
491
|
+
},
|
|
492
|
+
sendBookingCard: async (conversationId, bookingId) => {
|
|
493
|
+
const response = await post(`${BASE_PATH}/conversations/${conversationId}/messages/booking-card`, { bookingId });
|
|
494
|
+
return normalizeChatMessage(response.data);
|
|
495
|
+
},
|
|
496
|
+
sendQuoteCard: async (conversationId, data) => {
|
|
497
|
+
const response = await post(`${BASE_PATH}/conversations/${conversationId}/messages/quote-card`, data);
|
|
498
|
+
return normalizeChatMessage(response.data);
|
|
499
|
+
},
|
|
500
|
+
sendHostTripCard: async (conversationId, data) => {
|
|
501
|
+
const response = await post(`${BASE_PATH}/conversations/${conversationId}/messages/host-card`, data);
|
|
502
|
+
return normalizeChatMessage(response.data);
|
|
503
|
+
},
|
|
504
|
+
requestChatCopilotAssistance: async (conversationId, data) => {
|
|
505
|
+
const response = await post(`${BASE_PATH}/conversations/${conversationId}/ai/assist`, data);
|
|
506
|
+
return response.data;
|
|
507
|
+
},
|
|
508
|
+
requestChatAICommand: async (conversationId, command) => {
|
|
509
|
+
const response = await post(`${BASE_PATH}/conversations/${conversationId}/ai/command`, { command, idempotencyKey: crypto.randomUUID() });
|
|
510
|
+
return response.data;
|
|
511
|
+
},
|
|
512
|
+
decideChatAIProposal: async (proposalId, confirm) => {
|
|
513
|
+
const response = await post(`${BASE_PATH}/ai-proposals/${proposalId}/decision`, { confirm });
|
|
514
|
+
return response.data;
|
|
515
|
+
},
|
|
516
|
+
setBusinessCommunicationConsent: async (conversationId, channel, granted) => {
|
|
517
|
+
await put(`${BASE_PATH}/conversations/${conversationId}/communication-consent`, { channel, granted });
|
|
518
|
+
},
|
|
519
|
+
getCampaignDrafts: async () => {
|
|
520
|
+
const response = await get(`${BASE_PATH}/campaigns`);
|
|
521
|
+
return response.data;
|
|
522
|
+
},
|
|
523
|
+
getBusinessCommunicationConsents: async (conversationId) => {
|
|
524
|
+
const response = await get(`${BASE_PATH}/conversations/${conversationId}/communication-consent`);
|
|
525
|
+
return response.data || [];
|
|
526
|
+
},
|
|
527
|
+
createCampaignDraft: async (data) => {
|
|
528
|
+
const response = await post(`${BASE_PATH}/campaigns`, data);
|
|
529
|
+
return response.data;
|
|
530
|
+
},
|
|
531
|
+
updateCampaign: async (campaignId, data) => {
|
|
532
|
+
const response = await patch(`${BASE_PATH}/campaigns/${campaignId}`, data);
|
|
533
|
+
return response.data;
|
|
534
|
+
},
|
|
535
|
+
getChatHostKnowledgeSources: async () => {
|
|
536
|
+
const response = await get(`${BASE_PATH}/knowledge-sources`);
|
|
537
|
+
return response.data;
|
|
538
|
+
},
|
|
539
|
+
saveChatHostKnowledgeSource: async (data) => {
|
|
540
|
+
const response = data._id
|
|
541
|
+
? await patch(`${BASE_PATH}/knowledge-sources/${data._id}`, data)
|
|
542
|
+
: await post(`${BASE_PATH}/knowledge-sources`, data);
|
|
543
|
+
return response.data;
|
|
544
|
+
},
|
|
545
|
+
deleteChatHostKnowledgeSource: async (sourceId) => {
|
|
546
|
+
await del(`${BASE_PATH}/knowledge-sources/${sourceId}`);
|
|
547
|
+
},
|
|
548
|
+
getActiveLiveLocations: async (conversationId) => {
|
|
549
|
+
const response = await get(`${BASE_PATH}/conversations/${conversationId}/live-locations`);
|
|
550
|
+
return response.data;
|
|
551
|
+
},
|
|
552
|
+
startLiveLocation: async (conversationId, data) => {
|
|
553
|
+
const response = await post(`${BASE_PATH}/conversations/${conversationId}/live-locations`, data);
|
|
554
|
+
return response.data;
|
|
555
|
+
},
|
|
556
|
+
updateLiveLocation: async (liveLocationId, data) => {
|
|
557
|
+
const response = await patch(`${BASE_PATH}/live-locations/${liveLocationId}`, data);
|
|
558
|
+
return response.data;
|
|
559
|
+
},
|
|
560
|
+
revokeLiveLocation: async (liveLocationId) => {
|
|
561
|
+
await del(`${BASE_PATH}/live-locations/${liveLocationId}`);
|
|
562
|
+
},
|
|
563
|
+
// Deferred Phase 4 methods remain exported for the existing hidden UI.
|
|
182
564
|
getMilestones: async (convId) => {
|
|
183
565
|
try {
|
|
184
566
|
const response = await get(`${BASE_PATH}/conversations/${convId}/milestones`);
|
|
185
|
-
return response.data;
|
|
567
|
+
return (response.data || []).map(normalizeMilestone);
|
|
186
568
|
}
|
|
187
569
|
catch (error) {
|
|
188
570
|
console.error(error);
|
|
@@ -192,7 +574,7 @@ export const chatApi = {
|
|
|
192
574
|
createMilestone: async (convId, data) => {
|
|
193
575
|
try {
|
|
194
576
|
const response = await post(`${BASE_PATH}/conversations/${convId}/milestones`, data);
|
|
195
|
-
return response;
|
|
577
|
+
return { ...response, data: response.data ? normalizeMilestone(response.data) : null };
|
|
196
578
|
}
|
|
197
579
|
catch (error) {
|
|
198
580
|
console.error(error);
|
|
@@ -202,7 +584,7 @@ export const chatApi = {
|
|
|
202
584
|
toggleMilestone: async (id, note) => {
|
|
203
585
|
try {
|
|
204
586
|
const response = await patch(`${BASE_PATH}/milestones/${id}/toggle`, { note });
|
|
205
|
-
return response;
|
|
587
|
+
return { ...response, data: response.data ? normalizeMilestone(response.data) : null };
|
|
206
588
|
}
|
|
207
589
|
catch (error) {
|
|
208
590
|
console.error(error);
|
|
@@ -212,7 +594,7 @@ export const chatApi = {
|
|
|
212
594
|
updateMilestone: async (id, data) => {
|
|
213
595
|
try {
|
|
214
596
|
const response = await patch(`${BASE_PATH}/milestones/${id}`, data);
|
|
215
|
-
return response;
|
|
597
|
+
return { ...response, data: response.data ? normalizeMilestone(response.data) : null };
|
|
216
598
|
}
|
|
217
599
|
catch (error) {
|
|
218
600
|
console.error(error);
|
|
@@ -233,7 +615,7 @@ export const chatApi = {
|
|
|
233
615
|
getExpenses: async (convId) => {
|
|
234
616
|
try {
|
|
235
617
|
const response = await get(`${BASE_PATH}/conversations/${convId}/expenses`);
|
|
236
|
-
return response.data;
|
|
618
|
+
return (response.data || []).map(normalizeExpense);
|
|
237
619
|
}
|
|
238
620
|
catch (error) {
|
|
239
621
|
console.error(error);
|
|
@@ -260,9 +642,9 @@ export const chatApi = {
|
|
|
260
642
|
return { error: error, data: null };
|
|
261
643
|
}
|
|
262
644
|
},
|
|
263
|
-
settleSplit: async (id,
|
|
645
|
+
settleSplit: async (id, targetActorId, amount, targetActorModel) => {
|
|
264
646
|
try {
|
|
265
|
-
const response = await post(`${BASE_PATH}/conversations/${id}/settleExpense`, {
|
|
647
|
+
const response = await post(`${BASE_PATH}/conversations/${id}/settleExpense`, { targetActorId, targetActorModel, amount });
|
|
266
648
|
return response;
|
|
267
649
|
}
|
|
268
650
|
catch (error) {
|
|
@@ -283,7 +665,15 @@ export const chatApi = {
|
|
|
283
665
|
getBalances: async (convId) => {
|
|
284
666
|
try {
|
|
285
667
|
const response = await get(`${BASE_PATH}/conversations/${convId}/balances`);
|
|
286
|
-
return response.data
|
|
668
|
+
return response.data ? {
|
|
669
|
+
...response.data,
|
|
670
|
+
balances: (response.data.balances || []).map(normalizeBalanceLine),
|
|
671
|
+
settlements: (response.data.settlements || []).map((settlement) => ({
|
|
672
|
+
...settlement,
|
|
673
|
+
from: normalizeActorRef(settlement.from),
|
|
674
|
+
to: normalizeActorRef(settlement.to),
|
|
675
|
+
})),
|
|
676
|
+
} : null;
|
|
287
677
|
}
|
|
288
678
|
catch (error) {
|
|
289
679
|
console.error(error);
|
|
@@ -310,6 +700,14 @@ export const chatApi = {
|
|
|
310
700
|
return { error: error, data: null };
|
|
311
701
|
}
|
|
312
702
|
},
|
|
703
|
+
transcribeVoice: async (file, language) => {
|
|
704
|
+
const formData = new FormData();
|
|
705
|
+
formData.append("file", file);
|
|
706
|
+
if (language)
|
|
707
|
+
formData.append("language", language);
|
|
708
|
+
const response = await post(`${BASE_PATH}/transcribe-voice`, formData);
|
|
709
|
+
return response.data;
|
|
710
|
+
},
|
|
313
711
|
getExpenseAnalytics: async (convId) => {
|
|
314
712
|
try {
|
|
315
713
|
const response = await get(`${BASE_PATH}/conversations/${convId}/expense-analytics`);
|
|
@@ -334,7 +732,7 @@ export const chatApi = {
|
|
|
334
732
|
getPollById: async (pollId) => {
|
|
335
733
|
try {
|
|
336
734
|
const response = await get(`${BASE_PATH}/polls/${pollId}`);
|
|
337
|
-
return response.data;
|
|
735
|
+
return response.data ? normalizePoll(response.data) : null;
|
|
338
736
|
}
|
|
339
737
|
catch (error) {
|
|
340
738
|
console.error(error);
|
|
@@ -351,10 +749,96 @@ export const chatApi = {
|
|
|
351
749
|
return { error: error, data: null };
|
|
352
750
|
}
|
|
353
751
|
},
|
|
752
|
+
updatePoll: async (pollId, data) => {
|
|
753
|
+
try {
|
|
754
|
+
const response = await patch(`${BASE_PATH}/polls/${pollId}`, data);
|
|
755
|
+
return { ...response, data: response.data ? normalizePoll(response.data) : null };
|
|
756
|
+
}
|
|
757
|
+
catch (error) {
|
|
758
|
+
console.error(error);
|
|
759
|
+
return { error, data: null };
|
|
760
|
+
}
|
|
761
|
+
},
|
|
762
|
+
searchConversationMessages: async (convId, params) => {
|
|
763
|
+
const qs = new URLSearchParams();
|
|
764
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
765
|
+
if (value !== undefined && value !== "")
|
|
766
|
+
qs.set(key, String(value));
|
|
767
|
+
});
|
|
768
|
+
const response = await get(`${BASE_PATH}/conversations/${convId}/search?${qs.toString()}`);
|
|
769
|
+
return {
|
|
770
|
+
results: (response.data?.results || []).map((result) => ({
|
|
771
|
+
message: normalizeChatMessage(result.message),
|
|
772
|
+
context: result.context || {},
|
|
773
|
+
})),
|
|
774
|
+
nextCursor: response.data?.nextCursor || null,
|
|
775
|
+
};
|
|
776
|
+
},
|
|
777
|
+
getSharedContent: async (convId, section, before) => {
|
|
778
|
+
const qs = new URLSearchParams({ section });
|
|
779
|
+
if (before)
|
|
780
|
+
qs.set("before", before);
|
|
781
|
+
const response = await get(`${BASE_PATH}/conversations/${convId}/shared-content?${qs.toString()}`);
|
|
782
|
+
const messageSections = new Set(["media", "documents", "links", "locations", "polls", "listings", "bookings"]);
|
|
783
|
+
return {
|
|
784
|
+
...response.data,
|
|
785
|
+
items: messageSections.has(section)
|
|
786
|
+
? (response.data?.items || []).map(normalizeChatMessage)
|
|
787
|
+
: response.data?.items || [],
|
|
788
|
+
};
|
|
789
|
+
},
|
|
790
|
+
getConversationStorage: async (convId) => {
|
|
791
|
+
const response = await get(`${BASE_PATH}/conversations/${convId}/storage`);
|
|
792
|
+
return response.data;
|
|
793
|
+
},
|
|
794
|
+
starMessage: async (messageId) => {
|
|
795
|
+
const response = await put(`${BASE_PATH}/messages/${messageId}/star`, {});
|
|
796
|
+
return response.data;
|
|
797
|
+
},
|
|
798
|
+
unstarMessage: async (messageId) => {
|
|
799
|
+
const response = await del(`${BASE_PATH}/messages/${messageId}/star`);
|
|
800
|
+
return response.data;
|
|
801
|
+
},
|
|
802
|
+
deleteMessageForMe: async (messageId) => {
|
|
803
|
+
const response = await post(`${BASE_PATH}/messages/${messageId}/delete-for-me`, {});
|
|
804
|
+
return response.data;
|
|
805
|
+
},
|
|
806
|
+
forwardMessage: async (messageId, targetConversationIds) => {
|
|
807
|
+
const response = await post(`${BASE_PATH}/messages/${messageId}/forward`, { targetConversationIds });
|
|
808
|
+
return (response.data || []).map((item) => ({
|
|
809
|
+
conversationId: idString(item.conversationId),
|
|
810
|
+
message: normalizeChatMessage(item.message),
|
|
811
|
+
}));
|
|
812
|
+
},
|
|
813
|
+
getStarredMessages: async (convId) => {
|
|
814
|
+
const response = await get(`${BASE_PATH}/conversations/${convId}/starred`);
|
|
815
|
+
return (response.data || []).map((star) => ({
|
|
816
|
+
...star,
|
|
817
|
+
conversationId: idString(star.conversationId),
|
|
818
|
+
messageId: normalizeChatMessage(star.messageId),
|
|
819
|
+
}));
|
|
820
|
+
},
|
|
821
|
+
pinMessage: async (messageId, expiresAt) => {
|
|
822
|
+
const response = await post(`${BASE_PATH}/messages/${messageId}/pin`, { expiresAt });
|
|
823
|
+
return response.data;
|
|
824
|
+
},
|
|
825
|
+
unpinMessage: async (messageId) => {
|
|
826
|
+
const response = await del(`${BASE_PATH}/messages/${messageId}/pin`);
|
|
827
|
+
return response.data;
|
|
828
|
+
},
|
|
829
|
+
getPinnedMessages: async (convId) => {
|
|
830
|
+
const response = await get(`${BASE_PATH}/conversations/${convId}/pins`);
|
|
831
|
+
return (response.data || []).map((pin) => ({
|
|
832
|
+
...pin,
|
|
833
|
+
conversationId: idString(pin.conversationId),
|
|
834
|
+
pinnedBy: normalizeActorRef(pin.pinnedBy),
|
|
835
|
+
messageId: normalizeChatMessage(pin.messageId),
|
|
836
|
+
}));
|
|
837
|
+
},
|
|
354
838
|
votePoll: async (pollId, optionIndex) => {
|
|
355
839
|
try {
|
|
356
840
|
const response = await patch(`${BASE_PATH}/polls/${pollId}/vote`, { optionIndex });
|
|
357
|
-
return response;
|
|
841
|
+
return { ...response, data: response.data ? normalizePoll(response.data) : null };
|
|
358
842
|
}
|
|
359
843
|
catch (error) {
|
|
360
844
|
console.error(error);
|