diff --git a/backend/src/schema/resolvers/messages.ts b/backend/src/schema/resolvers/messages.ts index b7e7a7a73..c1381045f 100644 --- a/backend/src/schema/resolvers/messages.ts +++ b/backend/src/schema/resolvers/messages.ts @@ -25,8 +25,8 @@ export default { chatMessageAdded: { subscribe: withFilter( () => pubsub.asyncIterator(CHAT_MESSAGE_ADDED), - (payload, variables) => { - return payload.userId === variables.userId + (payload, variables, context) => { + return payload.userId === context.user?.id }, ), }, diff --git a/backend/src/schema/resolvers/notifications.ts b/backend/src/schema/resolvers/notifications.ts index e427de227..6a3e232cc 100644 --- a/backend/src/schema/resolvers/notifications.ts +++ b/backend/src/schema/resolvers/notifications.ts @@ -7,8 +7,8 @@ export default { notificationAdded: { subscribe: withFilter( () => pubsub.asyncIterator(NOTIFICATION_ADDED), - (payload, variables) => { - return payload.notificationAdded.to.id === variables.userId + (payload, variables, context) => { + return payload.notificationAdded.to.id === context.user?.id }, ), }, diff --git a/backend/src/schema/resolvers/rooms.ts b/backend/src/schema/resolvers/rooms.ts index 5e931a446..5382c5ee7 100644 --- a/backend/src/schema/resolvers/rooms.ts +++ b/backend/src/schema/resolvers/rooms.ts @@ -20,8 +20,8 @@ export default { roomCountUpdated: { subscribe: withFilter( () => pubsub.asyncIterator(ROOM_COUNT_UPDATED), - (payload, variables) => { - return payload.userId === variables.userId + (payload, variables, context) => { + return payload.userId === context.user?.id }, ), }, diff --git a/backend/src/schema/types/type/Message.gql b/backend/src/schema/types/type/Message.gql index 71d175e1c..16e458151 100644 --- a/backend/src/schema/types/type/Message.gql +++ b/backend/src/schema/types/type/Message.gql @@ -46,5 +46,5 @@ type Query { } type Subscription { - chatMessageAdded(userId: ID!): Message + chatMessageAdded: Message } diff --git a/backend/src/schema/types/type/NOTIFIED.gql b/backend/src/schema/types/type/NOTIFIED.gql index 62a1f3696..1f825decc 100644 --- a/backend/src/schema/types/type/NOTIFIED.gql +++ b/backend/src/schema/types/type/NOTIFIED.gql @@ -38,5 +38,5 @@ type Mutation { } type Subscription { - notificationAdded(userId: ID!): NOTIFIED + notificationAdded: NOTIFIED } diff --git a/backend/src/schema/types/type/Room.gql b/backend/src/schema/types/type/Room.gql index 0cf5b22c8..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 { @@ -57,5 +58,5 @@ type Query { } type Subscription { - roomCountUpdated(userId: ID!): Int + roomCountUpdated: Int } diff --git a/webapp/assets/_new/styles/export.scss b/webapp/assets/_new/styles/export.scss index 5b866d6b7..e29c014e2 100644 --- a/webapp/assets/_new/styles/export.scss +++ b/webapp/assets/_new/styles/export.scss @@ -31,4 +31,7 @@ chatMessageTimestamp: $chat-message-timestamp; chatMessageCheckmarkSeen: $chat-message-checkmark-seen; chatMessageCheckmark: $chat-message-checkmark; + + chatRoomBackgroundCounterBadge: $chat-room-background-counter-badge; + chatRoomColorCounterBadge: $chat-room-color-counter-badge; } \ No newline at end of file diff --git a/webapp/assets/_new/styles/tokens.scss b/webapp/assets/_new/styles/tokens.scss index ef5086240..dd3a042d1 100644 --- a/webapp/assets/_new/styles/tokens.scss +++ b/webapp/assets/_new/styles/tokens.scss @@ -420,3 +420,5 @@ $chat-new-message-color: $color-secondary-active; $chat-message-timestamp: $text-color-soft; $chat-message-checkmark-seen: $text-color-secondary; $chat-message-checkmark: $text-color-soft; +$chat-room-color-counter-badge: $text-color-inverse; +$chat-room-background-counter-badge: $color-secondary; 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 63cf045e8..883067666 100644 --- a/webapp/components/Chat/Chat.vue +++ b/webapp/components/Chat/Chat.vue @@ -4,7 +4,7 @@ -
-
- -
+
+ + + + + + + +
+ + + +
+
+
@@ -89,11 +108,6 @@ export default { data() { return { menuActions: [ - // NOTE: if menuActions is empty, the related slot is not shown - { - name: 'dummyItem', - title: 'Just a dummy item', - }, /* { name: 'inviteUser', @@ -159,22 +173,7 @@ export default { }, mounted() { if (this.singleRoom) { - this.$apollo - .mutate({ - mutation: createRoom(), - variables: { - userId: this.roomId, - }, - }) - .then(({ data: { CreateRoom } }) => { - this.fetchRooms({ room: CreateRoom }) - }) - .catch((error) => { - this.$toast.error(error) - }) - .finally(() => { - // this.loading = false - }) + this.newRoom(this.roomId) } else { this.fetchRooms() } @@ -182,9 +181,6 @@ export default { // Subscriptions const observer = this.$apollo.subscribe({ query: chatMessageAdded(), - variables: { - userId: this.currentUser.id, - }, }) observer.subscribe({ @@ -197,10 +193,24 @@ export default { computed: { ...mapGetters({ currentUser: 'auth/user', + getStoreRoomId: 'chat/roomID', }), computedChatStyle() { return chatStyle.STYLE.light }, + computedRoomId() { + let roomId = null + + if (!this.singleRoom) { + roomId = this.roomId + + if (this.getStoreRoomId.roomId) { + roomId = this.getStoreRoomId.roomId + } + } + + return roomId + }, textMessages() { return { ROOMS_EMPTY: this.$t('chat.roomsEmpty'), @@ -221,10 +231,12 @@ export default { methods: { ...mapMutations({ 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 }, @@ -242,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) } }) @@ -262,6 +264,13 @@ export default { this.roomsLoaded = true } this.roomPage += 1 + + if (this.singleRoom && this.rooms.length > 0) { + this.commitRoomIdFromSingleRoom(this.rooms[0].roomId) + } else if (this.getStoreRoomId.roomId) { + // reset store room id + this.commitRoomIdFromSingleRoom(null) + } } catch (error) { this.rooms = [] this.$toast.error(error.message) @@ -366,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) @@ -380,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 + }) + }, }, } @@ -408,4 +473,8 @@ body { transform: translate(-50%, -50%); } } + +.ds-flex-item.single-chat-bubble { + margin-right: 1em; +} diff --git a/webapp/components/ChatNotificationMenu/ChatNotificationMenu.vue b/webapp/components/ChatNotificationMenu/ChatNotificationMenu.vue index ec3f9fbc7..dd36b965a 100644 --- a/webapp/components/ChatNotificationMenu/ChatNotificationMenu.vue +++ b/webapp/components/ChatNotificationMenu/ChatNotificationMenu.vue @@ -44,11 +44,6 @@ export default { }, subscribeToMore: { document: roomCountUpdated(), - variables() { - return { - userId: this.user.id, - } - }, updateQuery: (previousResult, { subscriptionData }) => { return { UnreadRooms: subscriptionData.data.roomCountUpdated } }, 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/ContentMenu/GroupContentMenu.vue b/webapp/components/ContentMenu/GroupContentMenu.vue index 7a7737320..1ca1b5b33 100644 --- a/webapp/components/ContentMenu/GroupContentMenu.vue +++ b/webapp/components/ContentMenu/GroupContentMenu.vue @@ -58,14 +58,14 @@ export default { routes.push({ label: this.$t('group.contentMenu.visitGroupPage'), icon: 'home', - name: 'group-id-slug', + path: `/groups/${this.group.id}`, params: { id: this.group.id, slug: this.group.slug }, }) } if (this.group.myRole === 'owner') { routes.push({ label: this.$t('admin.settings.name'), - path: `/group/edit/${this.group.id}`, + path: `/groups/edit/${this.group.id}`, icon: 'edit', }) } 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/Editor/Editor.vue b/webapp/components/Editor/Editor.vue index cf0fd710b..8bc0a04d3 100644 --- a/webapp/components/Editor/Editor.vue +++ b/webapp/components/Editor/Editor.vue @@ -28,10 +28,10 @@ import { replace, build } from 'xregexp/xregexp-all.js' import * as key from '../../constants/keycodes' import { HASHTAG, MENTION } from '../../constants/editor' -import defaultExtensions from './defaultExtensions.js' -import EventHandler from './plugins/eventHandler.js' -import Hashtag from './nodes/Hashtag.js' -import Mention from './nodes/Mention.js' +import defaultExtensions from './defaultExtensions' +import EventHandler from './plugins/eventHandler' +import Hashtag from './nodes/Hashtag' +import Mention from './nodes/Mention' import MenuBar from './MenuBar' import ContextMenu from './ContextMenu' import SuggestionList from './SuggestionList' 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') }}

- - - +
+ +