@streamplace/components 0.7.29 → 0.7.32
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/dist/components/chat/mod-view.js +28 -7
- package/dist/livestream-store/chat.js +6 -6
- package/node-compile-cache/v22.15.0-x64-efe9a9df-0/37be0eec +0 -0
- package/package.json +2 -2
- package/src/components/chat/mod-view.tsx +35 -8
- package/src/livestream-store/chat.tsx +6 -6
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -25,6 +25,7 @@ exports.ModView = (0, react_1.forwardRef)(() => {
|
|
|
25
25
|
const setReportModalOpen = (0, player_store_1.usePlayerStore)((x) => x.setReportModalOpen);
|
|
26
26
|
const setReportSubject = (0, player_store_1.usePlayerStore)((x) => x.setReportSubject);
|
|
27
27
|
const setModMessage = (0, player_store_1.usePlayerStore)((x) => x.setModMessage);
|
|
28
|
+
const deleteChatMessage = (0, livestream_store_1.useDeleteChatMessage)();
|
|
28
29
|
// get the channel did
|
|
29
30
|
const channelId = (0, player_store_1.usePlayerStore)((state) => state.src);
|
|
30
31
|
// get the logged in user's identity
|
|
@@ -77,23 +78,43 @@ exports.ModView = (0, react_1.forwardRef)(() => {
|
|
|
77
78
|
? "Blocking..."
|
|
78
79
|
: `Block user @${message.author.handle} from this channel` })) })] })), (0, jsx_runtime_1.jsxs)(ui_1.DropdownMenuGroup, { title: `User actions`, children: [(0, jsx_runtime_1.jsx)(ui_1.DropdownMenuItem, { onPress: () => {
|
|
79
80
|
react_native_1.Linking.openURL(`https://${BSKY_FRONTEND_DOMAIN}/profile/${message.author.handle}`);
|
|
80
|
-
}, children: (0, jsx_runtime_1.jsxs)(ui_1.Text, { color: "primary", children: ["View user on ", BSKY_FRONTEND_DOMAIN] }) }), message.author.did === agent?.did && ((0, jsx_runtime_1.jsx)(DeleteButton, { message: message })), message.author.did !== agent?.did && ((0, jsx_runtime_1.jsx)(ReportButton, { message: message, setReportModalOpen: setReportModalOpen, setReportSubject: setReportSubject }))] })] })) })] }));
|
|
81
|
+
}, children: (0, jsx_runtime_1.jsxs)(ui_1.Text, { color: "primary", children: ["View user on ", BSKY_FRONTEND_DOMAIN] }) }), message.author.did === agent?.did && ((0, jsx_runtime_1.jsx)(DeleteButton, { message: message, deleteChatMessage: deleteChatMessage })), message.author.did !== agent?.did && ((0, jsx_runtime_1.jsx)(ReportButton, { message: message, setReportModalOpen: setReportModalOpen, setReportSubject: setReportSubject }))] })] })) })] }));
|
|
81
82
|
});
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
var DeleteState;
|
|
84
|
+
(function (DeleteState) {
|
|
85
|
+
DeleteState[DeleteState["None"] = 0] = "None";
|
|
86
|
+
DeleteState[DeleteState["Confirmed"] = 1] = "Confirmed";
|
|
87
|
+
DeleteState[DeleteState["Deleting"] = 2] = "Deleting";
|
|
88
|
+
})(DeleteState || (DeleteState = {}));
|
|
89
|
+
function DeleteButton({ message, deleteChatMessage, }) {
|
|
90
|
+
const [confirming, setConfirming] = (0, react_1.useState)(DeleteState.None);
|
|
85
91
|
const { onOpenChange } = (0, dropdown_menu_1.useRootContext)();
|
|
92
|
+
const toast = (0, ui_1.useToast)();
|
|
86
93
|
return ((0, jsx_runtime_1.jsx)(ui_1.DropdownMenuItem, { onPress: () => {
|
|
87
94
|
if (!message)
|
|
88
95
|
return;
|
|
89
96
|
if (!confirming) {
|
|
90
|
-
setConfirming(
|
|
97
|
+
setConfirming(DeleteState.Confirmed);
|
|
91
98
|
return;
|
|
92
99
|
}
|
|
93
|
-
|
|
100
|
+
if (confirming === DeleteState.Confirmed) {
|
|
101
|
+
setConfirming(DeleteState.Deleting);
|
|
102
|
+
}
|
|
103
|
+
deleteChatMessage(message.uri)
|
|
104
|
+
.then(() => {
|
|
105
|
+
// wait ~a second before resetting state to allow deletion to take effect
|
|
106
|
+
setTimeout(() => setConfirming(DeleteState.None), 1000);
|
|
94
107
|
onOpenChange?.(false);
|
|
108
|
+
})
|
|
109
|
+
.catch((e) => {
|
|
110
|
+
toast.show("Couldn't delete the message", e);
|
|
111
|
+
setConfirming(DeleteState.None);
|
|
95
112
|
});
|
|
96
|
-
}, children: (0, jsx_runtime_1.jsx)(ui_1.Text, { color: "destructive", children: confirming
|
|
113
|
+
}, children: (0, jsx_runtime_1.jsx)(ui_1.Text, { color: "destructive", children: confirming === DeleteState.Confirmed
|
|
114
|
+
? "Are you sure? Click again to confirm."
|
|
115
|
+
: confirming === DeleteState.Deleting
|
|
116
|
+
? "Deleting..."
|
|
117
|
+
: "Delete message" }) }));
|
|
97
118
|
}
|
|
98
119
|
function ReportButton({ message, setReportModalOpen, setReportSubject, }) {
|
|
99
120
|
const { onOpenChange } = (0, dropdown_menu_1.useRootContext)();
|
|
@@ -102,14 +102,14 @@ const useCreateChatMessage = () => {
|
|
|
102
102
|
exports.useCreateChatMessage = useCreateChatMessage;
|
|
103
103
|
const useDeleteChatMessage = () => {
|
|
104
104
|
const pdsAgent = (0, xrpc_1.usePDSAgent)();
|
|
105
|
-
if (!pdsAgent) {
|
|
106
|
-
throw new Error("No PDS agent found");
|
|
107
|
-
}
|
|
108
105
|
const userDID = (0, streamplace_store_1.useDID)();
|
|
109
|
-
if (!userDID) {
|
|
110
|
-
throw new Error("No user DID found");
|
|
111
|
-
}
|
|
112
106
|
return async (uri) => {
|
|
107
|
+
if (!pdsAgent) {
|
|
108
|
+
throw new Error("No PDS agent found");
|
|
109
|
+
}
|
|
110
|
+
if (!userDID) {
|
|
111
|
+
throw new Error("No user DID found");
|
|
112
|
+
}
|
|
113
113
|
const rkey = uri.split("/").pop();
|
|
114
114
|
if (!rkey) {
|
|
115
115
|
throw new Error("No rkey found");
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamplace/components",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.32",
|
|
4
4
|
"description": "Streamplace React (Native) Components",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "src/index.tsx",
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"start": "tsc --watch --preserveWatchOutput",
|
|
55
55
|
"prepare": "tsc"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "8c9f6186d1e718bcc4dfe84fe8c681680dddcf0e"
|
|
58
58
|
}
|
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
layout,
|
|
22
22
|
ResponsiveDropdownMenuContent,
|
|
23
23
|
Text,
|
|
24
|
+
useToast,
|
|
24
25
|
View,
|
|
25
26
|
} from "../ui";
|
|
26
27
|
|
|
@@ -49,6 +50,7 @@ export const ModView = forwardRef<ModViewRef, ModViewProps>(() => {
|
|
|
49
50
|
const setReportModalOpen = usePlayerStore((x) => x.setReportModalOpen);
|
|
50
51
|
const setReportSubject = usePlayerStore((x) => x.setReportSubject);
|
|
51
52
|
const setModMessage = usePlayerStore((x) => x.setModMessage);
|
|
53
|
+
const deleteChatMessage = useDeleteChatMessage();
|
|
52
54
|
|
|
53
55
|
// get the channel did
|
|
54
56
|
const channelId = usePlayerStore((state) => state.src);
|
|
@@ -174,7 +176,10 @@ export const ModView = forwardRef<ModViewRef, ModViewProps>(() => {
|
|
|
174
176
|
<Text color="primary">View user on {BSKY_FRONTEND_DOMAIN}</Text>
|
|
175
177
|
</DropdownMenuItem>
|
|
176
178
|
{message.author.did === agent?.did && (
|
|
177
|
-
<DeleteButton
|
|
179
|
+
<DeleteButton
|
|
180
|
+
message={message}
|
|
181
|
+
deleteChatMessage={deleteChatMessage}
|
|
182
|
+
/>
|
|
178
183
|
)}
|
|
179
184
|
{message.author.did !== agent?.did && (
|
|
180
185
|
<ReportButton
|
|
@@ -191,29 +196,51 @@ export const ModView = forwardRef<ModViewRef, ModViewProps>(() => {
|
|
|
191
196
|
);
|
|
192
197
|
});
|
|
193
198
|
|
|
199
|
+
enum DeleteState {
|
|
200
|
+
None,
|
|
201
|
+
Confirmed,
|
|
202
|
+
Deleting,
|
|
203
|
+
}
|
|
204
|
+
|
|
194
205
|
export function DeleteButton({
|
|
195
206
|
message,
|
|
207
|
+
deleteChatMessage,
|
|
196
208
|
}: {
|
|
197
209
|
message: ChatMessageViewHydrated;
|
|
210
|
+
deleteChatMessage: (uri: string) => Promise<any>;
|
|
198
211
|
}) {
|
|
199
|
-
const
|
|
200
|
-
const [confirming, setConfirming] = useState(false);
|
|
212
|
+
const [confirming, setConfirming] = useState<DeleteState>(DeleteState.None);
|
|
201
213
|
const { onOpenChange } = useRootContext();
|
|
214
|
+
const toast = useToast();
|
|
202
215
|
return (
|
|
203
216
|
<DropdownMenuItem
|
|
204
217
|
onPress={() => {
|
|
205
218
|
if (!message) return;
|
|
206
219
|
if (!confirming) {
|
|
207
|
-
setConfirming(
|
|
220
|
+
setConfirming(DeleteState.Confirmed);
|
|
208
221
|
return;
|
|
209
222
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
}
|
|
223
|
+
if (confirming === DeleteState.Confirmed) {
|
|
224
|
+
setConfirming(DeleteState.Deleting);
|
|
225
|
+
}
|
|
226
|
+
deleteChatMessage(message.uri)
|
|
227
|
+
.then(() => {
|
|
228
|
+
// wait ~a second before resetting state to allow deletion to take effect
|
|
229
|
+
setTimeout(() => setConfirming(DeleteState.None), 1000);
|
|
230
|
+
onOpenChange?.(false);
|
|
231
|
+
})
|
|
232
|
+
.catch((e) => {
|
|
233
|
+
toast.show("Couldn't delete the message", e);
|
|
234
|
+
setConfirming(DeleteState.None);
|
|
235
|
+
});
|
|
213
236
|
}}
|
|
214
237
|
>
|
|
215
238
|
<Text color="destructive">
|
|
216
|
-
{confirming
|
|
239
|
+
{confirming === DeleteState.Confirmed
|
|
240
|
+
? "Are you sure? Click again to confirm."
|
|
241
|
+
: confirming === DeleteState.Deleting
|
|
242
|
+
? "Deleting..."
|
|
243
|
+
: "Delete message"}
|
|
217
244
|
</Text>
|
|
218
245
|
</DropdownMenuItem>
|
|
219
246
|
);
|
|
@@ -135,14 +135,14 @@ export const useCreateChatMessage = () => {
|
|
|
135
135
|
|
|
136
136
|
export const useDeleteChatMessage = () => {
|
|
137
137
|
const pdsAgent = usePDSAgent();
|
|
138
|
-
if (!pdsAgent) {
|
|
139
|
-
throw new Error("No PDS agent found");
|
|
140
|
-
}
|
|
141
138
|
const userDID = useDID();
|
|
142
|
-
if (!userDID) {
|
|
143
|
-
throw new Error("No user DID found");
|
|
144
|
-
}
|
|
145
139
|
return async (uri: string) => {
|
|
140
|
+
if (!pdsAgent) {
|
|
141
|
+
throw new Error("No PDS agent found");
|
|
142
|
+
}
|
|
143
|
+
if (!userDID) {
|
|
144
|
+
throw new Error("No user DID found");
|
|
145
|
+
}
|
|
146
146
|
const rkey = uri.split("/").pop();
|
|
147
147
|
if (!rkey) {
|
|
148
148
|
throw new Error("No rkey found");
|