@corva/chat-core 0.1.19 → 0.1.20
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/index.js +15 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4773,9 +4773,23 @@ function createAttachmentsAPI(autumnUrl, getToken, platform) {
|
|
|
4773
4773
|
}
|
|
4774
4774
|
|
|
4775
4775
|
// src/api/modules/directMessages.ts
|
|
4776
|
+
var isMissingSendPermission = (error) => {
|
|
4777
|
+
if (!(error instanceof HttpError) || error.status !== 403) return false;
|
|
4778
|
+
const body = error.body;
|
|
4779
|
+
return body?.type === "MissingPermission" && body.permission === "SendMessage";
|
|
4780
|
+
};
|
|
4776
4781
|
function createDirectMessagesAPI(http, getUserFn, getMessagesFn) {
|
|
4777
4782
|
async function getOrCreateDMFromUser(userId) {
|
|
4778
|
-
|
|
4783
|
+
const openDm = () => http.request(`/users/${userId}/dm`);
|
|
4784
|
+
try {
|
|
4785
|
+
return await openDm();
|
|
4786
|
+
} catch (error) {
|
|
4787
|
+
if (!isMissingSendPermission(error)) throw error;
|
|
4788
|
+
await getChatHost().corvaApi.post("/v2/integration/revolt_chat_friendships", {
|
|
4789
|
+
revolt_user_id: userId
|
|
4790
|
+
});
|
|
4791
|
+
return openDm();
|
|
4792
|
+
}
|
|
4779
4793
|
}
|
|
4780
4794
|
async function getDMRecipient(dmChannelId, currentUserId, cachedChannel) {
|
|
4781
4795
|
try {
|