From 410ae72b9eb082e4fbe662e0285a83d04a5bd2bb Mon Sep 17 00:00:00 2001 From: Mary Kate Date: Wed, 9 Sep 2020 17:20:10 -0500 Subject: [PATCH] basic view chat routing and component structure --- src/api/chat.js | 32 ++++ src/components/ChatMessage/index.vue | 163 ++++++++++++++++++ src/lang/en.js | 6 + src/router/index.js | 28 ++++ src/store/index.js | 2 + src/store/modules/chat.js | 39 +++++ src/views/chats/index.vue | 167 ++++++++++++++++++ src/views/chats/show.vue | 242 +++++++++++++++++++++++++++ src/views/users/show.vue | 26 +-- 9 files changed, 693 insertions(+), 12 deletions(-) create mode 100644 src/api/chat.js create mode 100644 src/components/ChatMessage/index.vue create mode 100644 src/store/modules/chat.js create mode 100644 src/views/chats/index.vue create mode 100644 src/views/chats/show.vue diff --git a/src/api/chat.js b/src/api/chat.js new file mode 100644 index 00000000..7a3bd66c --- /dev/null +++ b/src/api/chat.js @@ -0,0 +1,32 @@ +import request from '@/utils/request' +import { getToken } from '@/utils/auth' +import { baseName } from './utils' + +export async function deleteChatMessage(id, message_id, authHost, token) { + return await request({ + baseURL: baseName(authHost), + url: `/api/pleroma/admin/chats/{id}/messages/${message_id}`, + method: 'delete', + headers: authHeaders(token) + }) +} + +export async function fetchChat(id, authHost, token) { + return await request({ + baseURL: baseName(authHost), + url: `/api/pleroma/admin/chats/${id}`, + method: 'get', + headers: authHeaders(token) + }) +} + +export async function fetchChatMessages(id, authHost, token) { + return await request({ + baseURL: baseName(authHost), + url: `/api/pleroma/admin/chats/${id}/messages`, + method: 'get', + headers: authHeaders(token) + }) +} + +const authHeaders = (token) => token ? { 'Authorization': `Bearer ${getToken()}` } : {} diff --git a/src/components/ChatMessage/index.vue b/src/components/ChatMessage/index.vue new file mode 100644 index 00000000..b23325aa --- /dev/null +++ b/src/components/ChatMessage/index.vue @@ -0,0 +1,163 @@ + + + + + diff --git a/src/lang/en.js b/src/lang/en.js index a3d6ce02..76f8b879 100644 --- a/src/lang/en.js +++ b/src/lang/en.js @@ -67,6 +67,7 @@ export default { reports: 'Reports', invites: 'Invites', statuses: 'Statuses', + chats: 'Chats', settings: 'Settings', moderationLog: 'Moderation Log', mediaProxyCache: 'MediaProxy Cache', @@ -299,6 +300,11 @@ export default { unlisted: 'Unlisted', openStatusInInstance: 'Open status in instance' }, + chats: { + chats: 'Chats', + loadMore: 'Load more', + chatHistory: 'Chat History' + }, userProfile: { tags: 'Tags', moderator: 'Moderator', diff --git a/src/router/index.js b/src/router/index.js index 60be0f88..ca765efc 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -35,6 +35,21 @@ const statuses = { ] } +const chatsDisabled = disabledFeatures.includes('chats') +const chats = { + path: '/chats', + component: Layout, + children: [ + { + path: 'index', + component: () => import('@/views/chats/index'), + name: 'Chats', + meta: { title: 'chats', icon: 'form', noCache: true } + } + ], + hidden: true +} + const reportsDisabled = disabledFeatures.includes('reports') const reports = { path: '/reports', @@ -169,6 +184,7 @@ export const asyncRouterMap = [ ] }, ...(statusesDisabled ? [] : [statuses]), + ...(chatsDisabled ? [] : [chats]), ...(reportsDisabled ? [] : [reports]), ...(invitesDisabled ? [] : [invites]), ...(emojiPacksDisabled ? [] : [emojiPacks]), @@ -211,5 +227,17 @@ export const asyncRouterMap = [ ], hidden: true }, + { + path: '/chats/:id', + component: Layout, + children: [ + { + path: '', + name: 'ChatsShow', + component: () => import('@/views/chats/show') + } + ], + hidden: true + }, { path: '*', redirect: '/404', hidden: true } ] diff --git a/src/store/index.js b/src/store/index.js index bd4a6e5b..6e9d3b7e 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -13,6 +13,7 @@ import relays from './modules/relays' import reports from './modules/reports' import settings from './modules/settings' import status from './modules/status' +import chat from './modules/chat' import tagsView from './modules/tagsView' import user from './modules/user' import userProfile from './modules/userProfile' @@ -34,6 +35,7 @@ const store = new Vuex.Store({ reports, settings, status, + chat, tagsView, user, userProfile, diff --git a/src/store/modules/chat.js b/src/store/modules/chat.js new file mode 100644 index 00000000..0cee17d1 --- /dev/null +++ b/src/store/modules/chat.js @@ -0,0 +1,39 @@ +import { fetchChat, fetchChatMessages } from '@/api/chat' + +const chat = { + state: { + fetchedChat: {}, + fetchedChatMessages: {}, + loading: false, + chatAuthor: {} + }, + mutations: { + SET_LOADING: (state, status) => { + state.loading = status + }, + SET_CHAT: (state, chat) => { + state.fetchedChat = chat + }, + SET_CHAT_MESSAGES: (state, chatMessages) => { + state.fetchedChatMessages = chatMessages + } + }, + actions: { + async FetchChat({ commit, dispatch, getters, state }, id) { + commit('SET_LOADING', true) + const chat = await fetchChat(id, getters.authHost, getters.token) + + commit('SET_CHAT', chat.data) + commit('SET_LOADING', false) + }, + async FetchChatMessages({ commit, dispatch, getters, state }, id) { + commit('SET_LOADING', true) + const chat = await fetchChatMessages(id, getters.authHost, getters.token) + + commit('SET_CHAT_MESSAGES', chat.data) + commit('SET_LOADING', false) + } + } +} + +export default chat diff --git a/src/views/chats/index.vue b/src/views/chats/index.vue new file mode 100644 index 00000000..ec64212d --- /dev/null +++ b/src/views/chats/index.vue @@ -0,0 +1,167 @@ + + + + + diff --git a/src/views/chats/show.vue b/src/views/chats/show.vue new file mode 100644 index 00000000..be99d0f4 --- /dev/null +++ b/src/views/chats/show.vue @@ -0,0 +1,242 @@ + + + + + diff --git a/src/views/users/show.vue b/src/views/users/show.vue index 5813405b..1a57582b 100644 --- a/src/views/users/show.vue +++ b/src/views/users/show.vue @@ -120,19 +120,21 @@ -
- - - -
+
+ {{ chat.last_message.content }} +
+