diff --git a/backend/src/schema/types/type/Room.gql b/backend/src/schema/types/type/Room.gql
index 0cf5b22c8..d758808bb 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 @@
+
+
+
+ {{ $t('chat.addRoomHeadline') }}
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/webapp/components/Chat/Chat.vue b/webapp/components/Chat/Chat.vue
index c2c7c412c..c18c12a58 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()
}
@@ -250,9 +236,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 },
@@ -270,17 +257,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)
}
})
@@ -401,6 +378,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)
@@ -415,6 +396,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/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') }}
-
-
-
-
-
-
-
+
+
+