Update api.js
This commit is contained in:
1 parent
d3741cb3ea
commit
028bca44ed
1 file changed
+62
-1
@@ -203,4 +203,65 @@ const API = {
|
|||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({ action })
|
body: JSON.stringify({ action })
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) { /* 静默失败 */ }
|
||||||
|
},
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// 论坛设置
|
||||||
|
// ============================================================
|
||||||
|
async getSettings() {
|
||||||
|
const data = await apiFetch('/settings');
|
||||||
|
if (data.error) throw new Error(data.error);
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
|
||||||
|
async updateSettings(forum_name) {
|
||||||
|
const data = await apiFetch('/settings', {
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify({ forum_name })
|
||||||
|
});
|
||||||
|
if (data.error) throw new Error(data.error);
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// 私信
|
||||||
|
// ============================================================
|
||||||
|
async getConversations() {
|
||||||
|
const data = await apiFetch('/conversations');
|
||||||
|
if (data.error) throw new Error(data.error);
|
||||||
|
return data || [];
|
||||||
|
},
|
||||||
|
|
||||||
|
async getOrCreateConversation(other_user_id) {
|
||||||
|
const data = await apiFetch('/conversations', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({ other_user_id })
|
||||||
|
});
|
||||||
|
if (data.error) throw new Error(data.error);
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
|
||||||
|
async getMessages(conversationId) {
|
||||||
|
const data = await apiFetch('/conversations/' + conversationId + '/messages');
|
||||||
|
if (data.error) throw new Error(data.error);
|
||||||
|
return data || [];
|
||||||
|
},
|
||||||
|
|
||||||
|
async sendMessage(conversationId, content) {
|
||||||
|
const data = await apiFetch('/conversations/' + conversationId + '/messages', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({ content })
|
||||||
|
});
|
||||||
|
if (data.error) throw new Error(data.error);
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
|
||||||
|
async markMessageRead(messageId) {
|
||||||
|
const data = await apiFetch('/messages/' + messageId + '/read', {
|
||||||
|
method: 'PUT'
|
||||||
|
});
|
||||||
|
if (data.error) throw new Error(data.error);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in new issue
Block a user