diff --git a/backend/src/schema/resolvers/rooms.spec.ts b/backend/src/schema/resolvers/rooms.spec.ts index d27c64e57..03c3d4456 100644 --- a/backend/src/schema/resolvers/rooms.spec.ts +++ b/backend/src/schema/resolvers/rooms.spec.ts @@ -92,6 +92,21 @@ describe('Room', () => { }) }) + describe('user id is self', () => { + it('throws error', async () => { + await expect( + mutate({ + mutation: createRoomMutation(), + variables: { + userId: 'chatting-user', + }, + }), + ).resolves.toMatchObject({ + errors: [{ message: 'Cannot create a room with self' }], + }) + }) + }) + describe('user id exists', () => { it('returns the id of the room', async () => { const result = await mutate({ diff --git a/backend/src/schema/resolvers/rooms.ts b/backend/src/schema/resolvers/rooms.ts index 02309e172..d5015a03b 100644 --- a/backend/src/schema/resolvers/rooms.ts +++ b/backend/src/schema/resolvers/rooms.ts @@ -32,6 +32,9 @@ export default { const { user: { id: currentUserId }, } = context + if (userId === currentUserId) { + throw new Error('Cannot create a room with self') + } const session = context.driver.session() const writeTxResultPromise = session.writeTransaction(async (transaction) => { const createRoomCypher = ` diff --git a/deployment/TODO-next-update.md b/deployment/TODO-next-update.md index 8630275b7..8e30d1f47 100644 --- a/deployment/TODO-next-update.md +++ b/deployment/TODO-next-update.md @@ -2,6 +2,10 @@ When you overtake this deploy and rebrand repo to your network you have to recognize the following changes and doings: +## Version >= 2.7.0 with 'ocelotDockerVersionTag' 2.7.0-470 + +- You have to rename all `.js` files to `.ts` in `branding/constants` + ## Version >= 2.4.0 with 'ocelotDockerVersionTag' 2.4.0-298 - You have to set `SHOW_CONTENT_FILTER_HEADER_MENU` and `SHOW_CONTENT_FILTER_MASONRY_GRID` in `branding/constants/filter.js` originally in main code file `webapp/constants/filter.js` to your preferred value. diff --git a/webapp/components/Chat/Chat.vue b/webapp/components/Chat/Chat.vue index 9cd3e391a..2b9514bf3 100644 --- a/webapp/components/Chat/Chat.vue +++ b/webapp/components/Chat/Chat.vue @@ -3,7 +3,7 @@ import { roomQuery, createRoom } from '~/graphql/Rooms' -import { messageQuery } from '~/graphql/Messages' +import { messageQuery, createMessageMutation } from '~/graphql/Messages' +import { mapGetters } from 'vuex' export default { name: 'Chat', @@ -43,7 +44,6 @@ export default { }, data() { return { - currentUserId: '1234', menuActions: [ /* { name: 'inviteUser', @@ -131,87 +131,51 @@ export default { }) } }, + computed: { + ...mapGetters({ + currentUser: 'auth/user', + }), + }, methods: { fetchMessages({ room, options = {} }) { - // console.log(room, options) this.messagesLoaded = false setTimeout(async () => { - if (options.reset) { - // console.log('reset messages') - this.messages = [] // this.addMessages(true) - } else { - try { - const { - data: { Message }, - } = await this.$apollo.query({ - query: messageQuery(), - variables: { - roomId: room.id, - }, - }) - // console.log('Messages', Message) - this.messages = Message - } catch (error) { - // console.log('Error', error) - this.messages = [] // this.addMessages(true) - this.$toast.error(error.message) - } + try { + const { + data: { Message }, + } = await this.$apollo.query({ + query: messageQuery(), + variables: { + roomId: room.id, + }, + fetchPolicy: 'no-cache', + }) + this.messages = Message + } catch (error) { + this.messages = [] + this.$toast.error(error.message) } this.messagesLoaded = true }) }, - /* addMessages(reset) { - const messages = [] - - for (let i = 0; i < 30; i++) { - messages.push({ - _id: reset ? i : this.messages.length + i, - content: `${reset ? '' : 'paginated'} message ${i + 1}`, - senderId: '4321', - username: 'John Doe', - date: '13 November', - timestamp: '10:20', - }) - } - messages.push({ - _id: '31', - content: `Hallo Welt`, - senderId: '1234', - username: 'John Doe', - date: '13 November', - timestamp: '10:20', - }) - - return messages - }, */ - - sendMessage(message) { - this.messages = [ - ...this.messages, - { - _id: this.messages.length, - content: message.content, - senderId: this.currentUserId, - timestamp: new Date().toString().substring(16, 21), - date: new Date().toDateString(), - }, - ] + refetchMessage(roomId) { + this.fetchMessages({ room: this.rooms.find((r) => r.roomId === roomId) }) }, - addNewMessage() { - setTimeout(() => { - this.messages = [ - ...this.messages, - { - _id: this.messages.length, - content: 'NEW MESSAGE', - senderId: '1234', - timestamp: new Date().toString().substring(16, 21), - date: new Date().toDateString(), + async sendMessage(message) { + try { + await this.$apollo.mutate({ + mutation: createMessageMutation(), + variables: { + roomId: message.roomId, + content: message.content, }, - ] - }, 2000) + }) + } catch (error) { + this.$toast.error(error.message) + } + this.refetchMessage(message.roomId) }, }, apollo: { @@ -220,7 +184,6 @@ export default { return roomQuery() }, update({ Room }) { - // console.log('Rooms', Room) if (!Room) { this.rooms = [] return @@ -240,14 +203,12 @@ export default { }).filter((r) => this.singleRoom ? r.users.filter((u) => u.id === this.singleRoomId).length > 0 : true, ) - - // console.log(this.rooms) }, error(error) { this.rooms = [] this.$toast.error(error.message) }, - fetchPolicy: 'cache-and-network', + fetchPolicy: 'no-cache', }, }, } diff --git a/webapp/graphql/Messages.js b/webapp/graphql/Messages.js index 099a7265e..41d647d4b 100644 --- a/webapp/graphql/Messages.js +++ b/webapp/graphql/Messages.js @@ -4,7 +4,9 @@ export const messageQuery = () => { return gql` query ($roomId: ID!) { Message(roomId: $roomId) { + _id id + senderId content author { id @@ -13,3 +15,14 @@ export const messageQuery = () => { } ` } + +export const createMessageMutation = () => { + return gql` + mutation ($roomId: ID!, $content: String!) { + CreateMessage(roomId: $roomId, content: $content) { + id + content + } + } + ` +} diff --git a/webapp/layouts/default.spec.js b/webapp/layouts/default.spec.js index 1b83491d7..cce8c2eca 100644 --- a/webapp/layouts/default.spec.js +++ b/webapp/layouts/default.spec.js @@ -37,7 +37,7 @@ describe('default.vue', () => { getters: { 'auth/isLoggedIn': () => true, 'chat/showChat': () => { - return { showChat: false, roomID: 'u0' } + return { showChat: false, roomID: null } }, }, }) diff --git a/webapp/layouts/default.vue b/webapp/layouts/default.vue index 8b6b80604..f14c4055f 100644 --- a/webapp/layouts/default.vue +++ b/webapp/layouts/default.vue @@ -16,7 +16,7 @@
RoomID: {{ $store.getters['chat/showChat'].roomID }} - + x @@ -41,6 +41,9 @@ export default { ChatModule, }, mixins: [seo, mobile()], + beforeCreate() { + this.$store.commit('chat/SET_OPEN_CHAT', { showChat: false, roomID: null }) + }, } diff --git a/webapp/store/chat.js b/webapp/store/chat.js index 2ee8a47ad..be4ddaec0 100644 --- a/webapp/store/chat.js +++ b/webapp/store/chat.js @@ -1,14 +1,14 @@ export const state = () => { return { showChat: false, - roomID: 'u0', + roomID: null, } } export const mutations = { SET_OPEN_CHAT(state, ctx) { state.showChat = ctx.showChat || false - state.roomID = ctx.roomID || 'u0' + state.roomID = ctx.roomID || null }, }