diff --git a/backend/src/schema/types/type/Room.gql b/backend/src/schema/types/type/Room.gql index 221df8299..60d54192c 100644 --- a/backend/src/schema/types/type/Room.gql +++ b/backend/src/schema/types/type/Room.gql @@ -8,6 +8,7 @@ # TODO change this to last message date enum _RoomOrdering { lastMessageAt_desc + createdAt_desc } type Room { diff --git a/webapp/components/Chat/AddChatRoomByUserSearch.vue b/webapp/components/Chat/AddChatRoomByUserSearch.vue new file mode 100644 index 000000000..b48120603 --- /dev/null +++ b/webapp/components/Chat/AddChatRoomByUserSearch.vue @@ -0,0 +1,67 @@ + + + + + diff --git a/webapp/components/Chat/Chat.vue b/webapp/components/Chat/Chat.vue index a1e5adf01..883067666 100644 --- a/webapp/components/Chat/Chat.vue +++ b/webapp/components/Chat/Chat.vue @@ -19,12 +19,13 @@ show-audio="false" :styles="JSON.stringify(computedChatStyle)" :show-footer="true" - @send-message="sendMessage($event.detail[0])" - @fetch-messages="fetchMessages($event.detail[0])" - @fetch-more-rooms="fetchRooms" :responsive-breakpoint="responsiveBreakpoint" :single-room="singleRoom" show-reaction-emojis="false" + @send-message="sendMessage($event.detail[0])" + @fetch-messages="fetchMessages($event.detail[0])" + @fetch-more-rooms="fetchRooms" + @add-room="toggleUserSearch" @show-demo-options="showDemoOptions = $event" >
{ - this.fetchRooms({ room: CreateRoom }) - }) - .catch((error) => { - this.$toast.error(error) - }) - .finally(() => { - // this.loading = false - }) + this.newRoom(this.roomId) } else { this.fetchRooms() } @@ -247,9 +233,10 @@ export default { commitUnreadRoomCount: 'chat/UPDATE_ROOM_COUNT', commitRoomIdFromSingleRoom: 'chat/UPDATE_ROOM_ID', }), - async fetchRooms({ room, options = {} } = {}) { - this.roomsLoaded = options.refetch ? this.roomsLoaded : false - const offset = (options.refetch ? 0 : this.roomPage) * this.roomPageSize + + async fetchRooms({ room } = {}) { + this.roomsLoaded = false + const offset = this.roomPage * this.roomPageSize try { const { data: { Room }, @@ -267,17 +254,7 @@ export default { const rmsIds = [] ;[...Room, ...this.rooms].forEach((r) => { if (!rmsIds.find((v) => v === r.id)) { - rms.push({ - ...r, - index: r.lastMessage?.date, - lastMessage: { - ...r.lastMessage, - content: r.lastMessage?.content.trim().substring(0, 30), - }, - users: r.users.map((u) => { - return { ...u, username: u.name, avatar: u.avatar?.url } - }), - }) + rms.push(this.fixRoomObject(r)) rmsIds.push(r.id) } }) @@ -398,6 +375,10 @@ export default { const changedRoom = { ...this.rooms[roomIndex] } changedRoom.lastMessage = createdMessage changedRoom.lastMessage.content = changedRoom.lastMessage.content.trim().substring(0, 30) + // move current room to top (not 100% working) + // const rooms = [...this.rooms] + // rooms.splice(roomIndex,1) + // this.rooms = [changedRoom, ...rooms] this.rooms[roomIndex] = changedRoom } catch (error) { this.$toast.error(error.message) @@ -412,6 +393,58 @@ export default { if (!fullname) return return fullname.match(/\b\w/g).join('').substring(0, 3).toUpperCase() }, + + toggleUserSearch() { + this.$emit('toggle-user-search') + }, + + fixRoomObject(room) { + // This fixes the room object which arrives from the backend + const fixedRoom = { + ...room, + index: room.lastMessage ? room.lastMessage.date : room.createdAt, + lastMessage: room.lastMessage + ? { + ...room.lastMessage, + content: room.lastMessage?.content?.trim().substring(0, 30), + } + : null, + users: room.users.map((u) => { + return { ...u, username: u.name, avatar: u.avatar?.url } + }), + } + if (!fixedRoom.avatar) { + // as long as we cannot query avatar on CreateRoom + fixedRoom.avatar = fixedRoom.users.find((u) => u.id !== this.currentUser.id).avatar + } + return fixedRoom + }, + + newRoom(userId) { + this.$apollo + .mutate({ + mutation: createRoom(), + variables: { + userId, + }, + }) + .then(({ data: { CreateRoom } }) => { + const roomIndex = this.rooms.findIndex((r) => r.id === CreateRoom.roomId) + const room = this.fixRoomObject(CreateRoom) + + if (roomIndex === -1) { + this.rooms = [room, ...this.rooms] + } + this.fetchMessages({ room, options: { refetch: true } }) + this.$emit('show-chat', CreateRoom.id) + }) + .catch((error) => { + this.$toast.error(error.message) + }) + .finally(() => { + // this.loading = false + }) + }, }, } diff --git a/webapp/components/CommentForm/CommentForm.vue b/webapp/components/CommentForm/CommentForm.vue index 5f6a2420d..6d9b59de6 100644 --- a/webapp/components/CommentForm/CommentForm.vue +++ b/webapp/components/CommentForm/CommentForm.vue @@ -8,7 +8,6 @@ :disabled="disabled && !update" @click="handleCancel" data-test="cancel-button" - danger > {{ $t('actions.cancel') }} diff --git a/webapp/components/ContributionForm/ContributionForm.vue b/webapp/components/ContributionForm/ContributionForm.vue index 0067dab72..b595357f9 100644 --- a/webapp/components/ContributionForm/ContributionForm.vue +++ b/webapp/components/ContributionForm/ContributionForm.vue @@ -169,12 +169,7 @@ - + {{ $t('actions.cancel') }} diff --git a/webapp/components/Group/AddGroupMember.vue b/webapp/components/Group/AddGroupMember.vue index ff049ca4d..cc3e3b1e8 100644 --- a/webapp/components/Group/AddGroupMember.vue +++ b/webapp/components/Group/AddGroupMember.vue @@ -3,33 +3,7 @@

{{ $t('group.addUser') }}

- - - +
+ +