Merge branch 'master' into chat-last-messages

This commit is contained in:
Ulf Gebhardt 2023-07-18 15:22:56 +02:00
commit f9dad608c7
Signed by: ulfgebhardt
GPG Key ID: DA6B843E748679C9
19 changed files with 997 additions and 918 deletions

View File

@ -1,4 +1,5 @@
backend: &backend backend: &backend
- '.github/workflows/test-backend.yml'
- 'backend/**/*' - 'backend/**/*'
- 'neo4j/**/*' - 'neo4j/**/*'
@ -6,4 +7,5 @@ docker: &docker
- 'docker-compose.*' - 'docker-compose.*'
webapp: &webapp webapp: &webapp
- '.github/workflows/test-webapp.yml'
- 'webapp/**/*' - 'webapp/**/*'

View File

@ -10,10 +10,11 @@ jobs:
outputs: outputs:
backend: ${{ steps.changes.outputs.backend }} backend: ${{ steps.changes.outputs.backend }}
docker: ${{ steps.changes.outputs.docker }} docker: ${{ steps.changes.outputs.docker }}
pr-number: ${{ steps.pr.outputs.number }}
steps: steps:
- uses: actions/checkout@v3.3.0 - uses: actions/checkout@v3.3.0
- name: Check for frontend file changes - name: Check for backend file changes
uses: dorny/paths-filter@v2.11.1 uses: dorny/paths-filter@v2.11.1
id: changes id: changes
with: with:
@ -21,6 +22,10 @@ jobs:
filters: .github/file-filters.yml filters: .github/file-filters.yml
list-files: shell list-files: shell
- name: Get pr number
id: pr
uses: 8BitJonny/gh-get-current-pr@2.2.0
build_test_neo4j: build_test_neo4j:
name: Docker Build Test - Neo4J name: Docker Build Test - Neo4J
if: needs.files-changed.outputs.backend == 'true' || needs.files-changed.outputs.docker == 'true' if: needs.files-changed.outputs.backend == 'true' || needs.files-changed.outputs.docker == 'true'
@ -35,11 +40,12 @@ jobs:
docker build --target community -t "ocelotsocialnetwork/neo4j-community:test" neo4j/ docker build --target community -t "ocelotsocialnetwork/neo4j-community:test" neo4j/
docker save "ocelotsocialnetwork/neo4j-community:test" > /tmp/neo4j.tar docker save "ocelotsocialnetwork/neo4j-community:test" > /tmp/neo4j.tar
- name: Upload Artifact - name: Cache docker images
uses: actions/upload-artifact@v3 id: cache-neo4j
uses: actions/cache/save@v3.3.1
with: with:
name: docker-neo4j-image
path: /tmp/neo4j.tar path: /tmp/neo4j.tar
key: backend-neo4j-cache-pr${{ needs.files-changed.outputs.pr-number }}
build_test_backend: build_test_backend:
name: Docker Build Test - Backend name: Docker Build Test - Backend
@ -55,11 +61,12 @@ jobs:
docker build --target test -t "ocelotsocialnetwork/backend:test" backend/ docker build --target test -t "ocelotsocialnetwork/backend:test" backend/
docker save "ocelotsocialnetwork/backend:test" > /tmp/backend.tar docker save "ocelotsocialnetwork/backend:test" > /tmp/backend.tar
- name: Upload Artifact - name: Cache docker images
uses: actions/upload-artifact@v3 id: cache-backend
uses: actions/cache/save@v3.3.1
with: with:
name: docker-backend-test
path: /tmp/backend.tar path: /tmp/backend.tar
key: backend-cache-pr${{ needs.files-changed.outputs.pr-number }}
lint_backend: lint_backend:
name: Lint Backend name: Lint Backend
@ -84,28 +91,29 @@ jobs:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v3 uses: actions/checkout@v3
- name: Download Docker Image (Neo4J) - name: Restore Neo4J cache
uses: actions/download-artifact@v3 uses: actions/cache/restore@v3.3.1
with: with:
name: docker-neo4j-image path: /tmp/neo4j.tar
path: /tmp key: backend-neo4j-cache-pr${{ needs.files-changed.outputs.pr-number }}
fail-on-cache-miss: true
- name: Load Docker Image - name: Restore Backend cache
run: docker load < /tmp/neo4j.tar uses: actions/cache/restore@v3.3.1
- name: Download Docker Image (Backend)
uses: actions/download-artifact@v3
with: with:
name: docker-backend-test path: /tmp/backend.tar
path: /tmp key: backend-cache-pr${{ needs.files-changed.outputs.pr-number }}
fail-on-cache-miss: true
- name: Load Docker Image - name: Load Docker Images
run: docker load < /tmp/backend.tar run: |
docker load < /tmp/neo4j.tar
docker load < /tmp/backend.tar
- name: backend | copy env files webapp - name: backend | copy env files
run: cp webapp/.env.template webapp/.env run: |
- name: backend | copy env files backend cp webapp/.env.template webapp/.env
run: cp backend/.env.template backend/.env cp backend/.env.template backend/.env
- name: backend | docker-compose - name: backend | docker-compose
run: docker-compose -f docker-compose.yml -f docker-compose.test.yml up --detach --no-deps neo4j backend run: docker-compose -f docker-compose.yml -f docker-compose.test.yml up --detach --no-deps neo4j backend
@ -118,3 +126,20 @@ jobs:
- name: backend | Unit test incl. coverage check - name: backend | Unit test incl. coverage check
run: docker-compose exec -T backend yarn test run: docker-compose exec -T backend yarn test
cleanup:
name: Cleanup
if: always()
needs: [files-changed, unit_test_backend]
runs-on: ubuntu-latest
steps:
- name: Delete cache
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh extension install actions/gh-actions-cache
set +e
KEY="backend-neo4j-cache-pr${{ needs.files-changed.outputs.pr-number }}"
gh actions-cache delete $KEY -R Ocelot-Social-Community/Ocelot-Social --confirm
KEY="backend-cache-pr${{ needs.files-changed.outputs.pr-number }}"
gh actions-cache delete $KEY -R Ocelot-Social-Community/Ocelot-Social --confirm

View File

@ -113,5 +113,6 @@ jobs:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: | run: |
gh extension install actions/gh-actions-cache gh extension install actions/gh-actions-cache
set +e
KEY="e2e-preparation-cache-pr${{ needs.docker_preparation.outputs.pr-number }}" KEY="e2e-preparation-cache-pr${{ needs.docker_preparation.outputs.pr-number }}"
gh actions-cache delete $KEY -R Ocelot-Social-Community/Ocelot-Social --confirm gh actions-cache delete $KEY -R Ocelot-Social-Community/Ocelot-Social --confirm

View File

@ -9,6 +9,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
outputs: outputs:
docker: ${{ steps.changes.outputs.docker }} docker: ${{ steps.changes.outputs.docker }}
pr-number: ${{ steps.pr.outputs.number }}
webapp: ${{ steps.changes.outputs.webapp }} webapp: ${{ steps.changes.outputs.webapp }}
steps: steps:
- uses: actions/checkout@v3.3.0 - uses: actions/checkout@v3.3.0
@ -21,6 +22,10 @@ jobs:
filters: .github/file-filters.yml filters: .github/file-filters.yml
list-files: shell list-files: shell
- name: Get pr number
id: pr
uses: 8BitJonny/gh-get-current-pr@2.2.0
prepare: prepare:
name: Prepare name: Prepare
if: needs.files-changed.outputs.webapp == 'true' if: needs.files-changed.outputs.webapp == 'true'
@ -44,16 +49,16 @@ jobs:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v3 uses: actions/checkout@v3
- name: webapp | Build 'test' image - name: Webapp | Build 'test' image
run: | run: |
docker build --target test -t "ocelotsocialnetwork/webapp:test" webapp/ docker build --target test -t "ocelotsocialnetwork/webapp:test" webapp/
docker save "ocelotsocialnetwork/webapp:test" > /tmp/webapp.tar docker save "ocelotsocialnetwork/webapp:test" > /tmp/webapp.tar
- name: Upload Artifact - name: Cache docker image
uses: actions/upload-artifact@v3 uses: actions/cache/save@v3.3.1
with: with:
name: docker-webapp-test
path: /tmp/webapp.tar path: /tmp/webapp.tar
key: webapp-cache-pr${{ needs.files-changed.outputs.pr-number }}
lint_webapp: lint_webapp:
name: Lint Webapp name: Lint Webapp
@ -78,20 +83,19 @@ jobs:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v3 uses: actions/checkout@v3
- name: Download Docker Image (Webapp) - name: Restore webapp cache
uses: actions/download-artifact@v3 uses: actions/cache/restore@v3.3.1
with: with:
name: docker-webapp-test path: /tmp/webapp.tar
path: /tmp key: webapp-cache-pr${{ needs.files-changed.outputs.pr-number }}
- name: Load Docker Image - name: Load Docker Image
run: docker load < /tmp/webapp.tar run: docker load < /tmp/webapp.tar
- name: backend | copy env files webapp - name: Copy env files
run: cp webapp/.env.template webapp/.env run: |
cp webapp/.env.template webapp/.env
- name: backend | copy env files backend cp backend/.env.template backend/.env
run: cp backend/.env.template backend/.env
- name: backend | docker-compose - name: backend | docker-compose
run: docker-compose -f docker-compose.yml -f docker-compose.test.yml up --detach --no-deps webapp run: docker-compose -f docker-compose.yml -f docker-compose.test.yml up --detach --no-deps webapp
@ -99,3 +103,18 @@ jobs:
- name: webapp | Unit tests incl. coverage check - name: webapp | Unit tests incl. coverage check
run: docker-compose exec -T webapp yarn test run: docker-compose exec -T webapp yarn test
cleanup:
name: Cleanup
if: always()
needs: [files-changed, unit_test_webapp]
runs-on: ubuntu-latest
steps:
- name: Delete cache
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh extension install actions/gh-actions-cache
set +e
KEY="webapp-cache-pr${{ needs.files-changed.outputs.pr-number }}"
gh actions-cache delete $KEY -R Ocelot-Social-Community/Ocelot-Social --confirm

View File

@ -269,17 +269,17 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
await dagobert.relateTo(louie, 'blocked') await dagobert.relateTo(louie, 'blocked')
// categories // categories
await Promise.all( let i = 0
categories.map(({ icon, name }, index) => { for (const category of categories) {
return Factory.build('category', { await Factory.build('category', {
id: `cat${index + 1}`, id: `cat${i++}`,
slug: name, slug: category.name,
name, naem: category.name,
icon, icon: category.icon,
}) })
}), }
)
// tags
const environment = await Factory.build('tag', { const environment = await Factory.build('tag', {
id: 'Environment', id: 'Environment',
}) })
@ -295,8 +295,7 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
// groups // groups
authenticatedUser = await peterLustig.toJson() authenticatedUser = await peterLustig.toJson()
await Promise.all([ await mutate({
mutate({
mutation: createGroupMutation(), mutation: createGroupMutation(),
variables: { variables: {
id: 'g0', id: 'g0',
@ -308,53 +307,49 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
categoryIds: ['cat6', 'cat12', 'cat16'], categoryIds: ['cat6', 'cat12', 'cat16'],
locationName: 'Hamburg, Germany', locationName: 'Hamburg, Germany',
}, },
}), })
]) await mutate({
await Promise.all([
mutate({
mutation: joinGroupMutation(), mutation: joinGroupMutation(),
variables: { variables: {
groupId: 'g0', groupId: 'g0',
userId: 'u2', userId: 'u2',
}, },
}), })
mutate({ await mutate({
mutation: joinGroupMutation(), mutation: joinGroupMutation(),
variables: { variables: {
groupId: 'g0', groupId: 'g0',
userId: 'u4', userId: 'u4',
}, },
}), })
mutate({ await mutate({
mutation: joinGroupMutation(), mutation: joinGroupMutation(),
variables: { variables: {
groupId: 'g0', groupId: 'g0',
userId: 'u6', userId: 'u6',
}, },
}), })
])
await Promise.all([ await mutate({
mutate({
mutation: changeGroupMemberRoleMutation(), mutation: changeGroupMemberRoleMutation(),
variables: { variables: {
groupId: 'g0', groupId: 'g0',
userId: 'u2', userId: 'u2',
roleInGroup: 'usual', roleInGroup: 'usual',
}, },
}), })
mutate({
await mutate({
mutation: changeGroupMemberRoleMutation(), mutation: changeGroupMemberRoleMutation(),
variables: { variables: {
groupId: 'g0', groupId: 'g0',
userId: 'u4', userId: 'u4',
roleInGroup: 'admin', roleInGroup: 'admin',
}, },
}), })
])
// post into group // post into group
await Promise.all([ await mutate({
mutate({
mutation: createPostMutation(), mutation: createPostMutation(),
variables: { variables: {
id: 'p0-g0', id: 'p0-g0',
@ -363,11 +358,10 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
content: 'A sack of rise dropped in Shanghai. Should we further investigate?', content: 'A sack of rise dropped in Shanghai. Should we further investigate?',
categoryIds: ['cat6'], categoryIds: ['cat6'],
}, },
}), })
])
authenticatedUser = await bobDerBaumeister.toJson() authenticatedUser = await bobDerBaumeister.toJson()
await Promise.all([ await mutate({
mutate({
mutation: createPostMutation(), mutation: createPostMutation(),
variables: { variables: {
id: 'p1-g0', id: 'p1-g0',
@ -376,12 +370,10 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
content: 'We have to further investigate about the stories of a man living on the moon.', content: 'We have to further investigate about the stories of a man living on the moon.',
categoryIds: ['cat12', 'cat16'], categoryIds: ['cat12', 'cat16'],
}, },
}), })
])
authenticatedUser = await jennyRostock.toJson() authenticatedUser = await jennyRostock.toJson()
await Promise.all([ await mutate({
mutate({
mutation: createGroupMutation(), mutation: createGroupMutation(),
variables: { variables: {
id: 'g1', id: 'g1',
@ -393,74 +385,69 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
categoryIds: ['cat8', 'cat14'], categoryIds: ['cat8', 'cat14'],
locationName: 'France', locationName: 'France',
}, },
}), })
]) await mutate({
await Promise.all([
mutate({
mutation: joinGroupMutation(), mutation: joinGroupMutation(),
variables: { variables: {
groupId: 'g1', groupId: 'g1',
userId: 'u1', userId: 'u1',
}, },
}), })
mutate({ await mutate({
mutation: joinGroupMutation(), mutation: joinGroupMutation(),
variables: { variables: {
groupId: 'g1', groupId: 'g1',
userId: 'u2', userId: 'u2',
}, },
}), })
mutate({ await mutate({
mutation: joinGroupMutation(), mutation: joinGroupMutation(),
variables: { variables: {
groupId: 'g1', groupId: 'g1',
userId: 'u5', userId: 'u5',
}, },
}), })
mutate({ await mutate({
mutation: joinGroupMutation(), mutation: joinGroupMutation(),
variables: { variables: {
groupId: 'g1', groupId: 'g1',
userId: 'u6', userId: 'u6',
}, },
}), })
mutate({ await mutate({
mutation: joinGroupMutation(), mutation: joinGroupMutation(),
variables: { variables: {
groupId: 'g1', groupId: 'g1',
userId: 'u7', userId: 'u7',
}, },
}), })
])
await Promise.all([ await mutate({
mutate({
mutation: changeGroupMemberRoleMutation(), mutation: changeGroupMemberRoleMutation(),
variables: { variables: {
groupId: 'g1', groupId: 'g1',
userId: 'u1', userId: 'u1',
roleInGroup: 'usual', roleInGroup: 'usual',
}, },
}), })
mutate({ await mutate({
mutation: changeGroupMemberRoleMutation(), mutation: changeGroupMemberRoleMutation(),
variables: { variables: {
groupId: 'g1', groupId: 'g1',
userId: 'u5', userId: 'u5',
roleInGroup: 'admin', roleInGroup: 'admin',
}, },
}), })
mutate({ await mutate({
mutation: changeGroupMemberRoleMutation(), mutation: changeGroupMemberRoleMutation(),
variables: { variables: {
groupId: 'g1', groupId: 'g1',
userId: 'u6', userId: 'u6',
roleInGroup: 'owner', roleInGroup: 'owner',
}, },
}), })
])
// post into group // post into group
await Promise.all([ await mutate({
mutate({
mutation: createPostMutation(), mutation: createPostMutation(),
variables: { variables: {
id: 'p0-g1', id: 'p0-g1',
@ -469,11 +456,9 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
content: 'I like the concept of this school. Can we use our software in this?', content: 'I like the concept of this school. Can we use our software in this?',
categoryIds: ['cat8'], categoryIds: ['cat8'],
}, },
}), })
])
authenticatedUser = await peterLustig.toJson() authenticatedUser = await peterLustig.toJson()
await Promise.all([ await mutate({
mutate({
mutation: createPostMutation(), mutation: createPostMutation(),
variables: { variables: {
id: 'p1-g1', id: 'p1-g1',
@ -482,12 +467,10 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
content: 'This idea is too inportant to have the scope only on France.', content: 'This idea is too inportant to have the scope only on France.',
categoryIds: ['cat14'], categoryIds: ['cat14'],
}, },
}), })
])
authenticatedUser = await bobDerBaumeister.toJson() authenticatedUser = await bobDerBaumeister.toJson()
await Promise.all([ await mutate({
mutate({
mutation: createGroupMutation(), mutation: createGroupMutation(),
variables: { variables: {
id: 'g2', id: 'g2',
@ -498,83 +481,78 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
actionRadius: 'interplanetary', actionRadius: 'interplanetary',
categoryIds: ['cat4', 'cat5', 'cat17'], categoryIds: ['cat4', 'cat5', 'cat17'],
}, },
}), })
]) await mutate({
await Promise.all([
mutate({
mutation: joinGroupMutation(), mutation: joinGroupMutation(),
variables: { variables: {
groupId: 'g2', groupId: 'g2',
userId: 'u3', userId: 'u3',
}, },
}), })
mutate({ await mutate({
mutation: joinGroupMutation(), mutation: joinGroupMutation(),
variables: { variables: {
groupId: 'g2', groupId: 'g2',
userId: 'u4', userId: 'u4',
}, },
}), })
mutate({ await mutate({
mutation: joinGroupMutation(), mutation: joinGroupMutation(),
variables: { variables: {
groupId: 'g2', groupId: 'g2',
userId: 'u5', userId: 'u5',
}, },
}), })
mutate({ await mutate({
mutation: joinGroupMutation(), mutation: joinGroupMutation(),
variables: { variables: {
groupId: 'g2', groupId: 'g2',
userId: 'u6', userId: 'u6',
}, },
}), })
mutate({ await mutate({
mutation: joinGroupMutation(), mutation: joinGroupMutation(),
variables: { variables: {
groupId: 'g2', groupId: 'g2',
userId: 'u7', userId: 'u7',
}, },
}), })
])
await Promise.all([ await mutate({
mutate({
mutation: changeGroupMemberRoleMutation(), mutation: changeGroupMemberRoleMutation(),
variables: { variables: {
groupId: 'g2', groupId: 'g2',
userId: 'u3', userId: 'u3',
roleInGroup: 'usual', roleInGroup: 'usual',
}, },
}), })
mutate({ await mutate({
mutation: changeGroupMemberRoleMutation(), mutation: changeGroupMemberRoleMutation(),
variables: { variables: {
groupId: 'g2', groupId: 'g2',
userId: 'u4', userId: 'u4',
roleInGroup: 'pending', roleInGroup: 'pending',
}, },
}), })
mutate({ await mutate({
mutation: changeGroupMemberRoleMutation(), mutation: changeGroupMemberRoleMutation(),
variables: { variables: {
groupId: 'g2', groupId: 'g2',
userId: 'u5', userId: 'u5',
roleInGroup: 'admin', roleInGroup: 'admin',
}, },
}), })
mutate({ await mutate({
mutation: changeGroupMemberRoleMutation(), mutation: changeGroupMemberRoleMutation(),
variables: { variables: {
groupId: 'g2', groupId: 'g2',
userId: 'u6', userId: 'u6',
roleInGroup: 'usual', roleInGroup: 'usual',
}, },
}), })
])
authenticatedUser = await louie.toJson() authenticatedUser = await louie.toJson()
await Promise.all([ await mutate({
mutate({
mutation: createPostMutation(), mutation: createPostMutation(),
variables: { variables: {
id: 'p0-g2', id: 'p0-g2',
@ -583,15 +561,13 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
content: 'I am new to Yoga and did not join this group so far.', content: 'I am new to Yoga and did not join this group so far.',
categoryIds: ['cat4'], categoryIds: ['cat4'],
}, },
}), })
])
// Create Events (by peter lustig) // Create Events (by peter lustig)
authenticatedUser = await peterLustig.toJson() authenticatedUser = await peterLustig.toJson()
const now = new Date() const now = new Date()
await Promise.all([ await mutate({
mutate({
mutation: createPostMutation(), mutation: createPostMutation(),
variables: { variables: {
id: 'e0', id: 'e0',
@ -600,17 +576,13 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
categoryIds: ['cat4'], categoryIds: ['cat4'],
postType: 'Event', postType: 'Event',
eventInput: { eventInput: {
eventStart: new Date( eventStart: new Date(now.getFullYear(), now.getMonth(), now.getDate() + 7).toISOString(),
now.getFullYear(),
now.getMonth(),
now.getDate() + 7,
).toISOString(),
eventVenue: 'Ellis Kinderzimmer', eventVenue: 'Ellis Kinderzimmer',
eventLocationName: 'Deutschland', eventLocationName: 'Deutschland',
}, },
}, },
}), })
mutate({ await mutate({
mutation: createPostMutation(), mutation: createPostMutation(),
variables: { variables: {
id: 'e1', id: 'e1',
@ -619,17 +591,13 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
categoryIds: ['cat5'], categoryIds: ['cat5'],
postType: 'Event', postType: 'Event',
eventInput: { eventInput: {
eventStart: new Date( eventStart: new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1).toISOString(),
now.getFullYear(),
now.getMonth(),
now.getDate() + 1,
).toISOString(),
eventVenue: 'Schlossgarten', eventVenue: 'Schlossgarten',
eventLocationName: 'Stuttgart', eventLocationName: 'Stuttgart',
}, },
}, },
}), })
mutate({ await mutate({
mutation: createPostMutation(), mutation: createPostMutation(),
variables: { variables: {
id: 'e2', id: 'e2',
@ -638,18 +606,13 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
categoryIds: ['cat5'], categoryIds: ['cat5'],
postType: 'Event', postType: 'Event',
eventInput: { eventInput: {
eventStart: new Date( eventStart: new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1).toISOString(),
now.getFullYear(),
now.getMonth(),
now.getDate() + 1,
).toISOString(),
eventEnd: new Date(now.getFullYear(), now.getMonth(), now.getDate() + 4).toISOString(), eventEnd: new Date(now.getFullYear(), now.getMonth(), now.getDate() + 4).toISOString(),
eventVenue: 'Ferienlager', eventVenue: 'Ferienlager',
eventLocationName: 'Bahra, Sachsen', eventLocationName: 'Bahra, Sachsen',
}, },
}, },
}), })
])
let passedEvent = await neode.find('Post', 'e1') let passedEvent = await neode.find('Post', 'e1')
await passedEvent.update({ eventStart: new Date(2010, 8, 30, 10).toISOString() }) await passedEvent.update({ eventStart: new Date(2010, 8, 30, 10).toISOString() })
@ -836,8 +799,7 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
const hashtagAndMention1 = const hashtagAndMention1 =
'The new physics of <a class="hashtag" data-hashtag-id="QuantenFlussTheorie" href="/?hashtag=QuantenFlussTheorie">#QuantenFlussTheorie</a> can explain <a class="hashtag" data-hashtag-id="QuantumGravity" href="/?hashtag=QuantumGravity">#QuantumGravity</a>! <a class="mention" data-mention-id="u1" href="/profile/u1">@peter-lustig</a> got that already. ;-)' 'The new physics of <a class="hashtag" data-hashtag-id="QuantenFlussTheorie" href="/?hashtag=QuantenFlussTheorie">#QuantenFlussTheorie</a> can explain <a class="hashtag" data-hashtag-id="QuantumGravity" href="/?hashtag=QuantumGravity">#QuantumGravity</a>! <a class="mention" data-mention-id="u1" href="/profile/u1">@peter-lustig</a> got that already. ;-)'
await Promise.all([ await mutate({
mutate({
mutation: createPostMutation(), mutation: createPostMutation(),
variables: { variables: {
id: 'p2', id: 'p2',
@ -845,8 +807,8 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
content: hashtag1, content: hashtag1,
categoryIds: ['cat2'], categoryIds: ['cat2'],
}, },
}), })
mutate({ await mutate({
mutation: createPostMutation(), mutation: createPostMutation(),
variables: { variables: {
id: 'p7', id: 'p7',
@ -854,8 +816,8 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
content: `${mention1} ${faker.lorem.paragraph()}`, content: `${mention1} ${faker.lorem.paragraph()}`,
categoryIds: ['cat7'], categoryIds: ['cat7'],
}, },
}), })
mutate({ await mutate({
mutation: createPostMutation(), mutation: createPostMutation(),
variables: { variables: {
id: 'p8', id: 'p8',
@ -864,8 +826,8 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
content: hashtagAndMention1, content: hashtagAndMention1,
categoryIds: ['cat8'], categoryIds: ['cat8'],
}, },
}), })
mutate({ await mutate({
mutation: createPostMutation(), mutation: createPostMutation(),
variables: { variables: {
id: 'p12', id: 'p12',
@ -873,11 +835,13 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
content: `${mention2} ${faker.lorem.paragraph()}`, content: `${mention2} ${faker.lorem.paragraph()}`,
categoryIds: ['cat12'], categoryIds: ['cat12'],
}, },
}), })
])
const [p2, p7, p8, p12] = await Promise.all( const p2 = await neode.find('Post', 'p2')
['p2', 'p7', 'p8', 'p12'].map((id) => neode.find('Post', id)), const p7 = await neode.find('Post', 'p7')
) const p8 = await neode.find('Post', 'p8')
const p12 = await neode.find('Post', 'p12')
authenticatedUser = null authenticatedUser = null
authenticatedUser = await dewey.toJson() authenticatedUser = await dewey.toJson()
@ -885,31 +849,30 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
'I heard <a class="mention" data-mention-id="u3" href="/profile/u3">@jenny-rostock</a> has practiced it for 3 years now.' 'I heard <a class="mention" data-mention-id="u3" href="/profile/u3">@jenny-rostock</a> has practiced it for 3 years now.'
const mentionInComment2 = const mentionInComment2 =
'Did <a class="mention" data-mention-id="u1" href="/profile/u1">@peter-lustig</a> tell you?' 'Did <a class="mention" data-mention-id="u1" href="/profile/u1">@peter-lustig</a> tell you?'
await Promise.all([ await mutate({
mutate({
mutation: createCommentMutation, mutation: createCommentMutation,
variables: { variables: {
id: 'c4', id: 'c4',
postId: 'p2', postId: 'p2',
content: mentionInComment1, content: mentionInComment1,
}, },
}), })
mutate({ await mutate({
mutation: createCommentMutation, mutation: createCommentMutation,
variables: { variables: {
id: 'c4-1', id: 'c4-1',
postId: 'p2', postId: 'p2',
content: mentionInComment2, content: mentionInComment2,
}, },
}), })
mutate({ await mutate({
mutation: createCommentMutation, mutation: createCommentMutation,
variables: { variables: {
postId: 'p14', postId: 'p14',
content: faker.lorem.paragraph(), content: faker.lorem.paragraph(),
}, },
}), // should send a notification }) // should send a notification
])
authenticatedUser = null authenticatedUser = null
const comments: any[] = [] const comments: any[] = []
@ -1193,24 +1156,22 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
closed: true, closed: true,
}) })
const additionalUsers = await Promise.all( const additionalUsers: any[] = []
[...Array(30).keys()].map(() => Factory.build('user')), for (let i = 0; i < 30; i++) {
) const user = await Factory.build('user')
await Promise.all(
additionalUsers.map(async (user) => {
await jennyRostock.relateTo(user, 'following') await jennyRostock.relateTo(user, 'following')
await user.relateTo(jennyRostock, 'following') await user.relateTo(jennyRostock, 'following')
}), additionalUsers.push(user)
) }
await Promise.all( // Jenny users
[...Array(30).keys()].map((index) => Factory.build('user', { name: `Jenny${index}` })), for (let i = 0; i < 30; i++) {
) await Factory.build('user', { name: `Jenny${i}` })
}
await Promise.all( // Jenny posts
[...Array(30).keys()].map(() => for (let i = 0; i < 30; i++) {
Factory.build( await Factory.build(
'post', 'post',
{ content: `Jenny ${faker.lorem.sentence()}` }, { content: `Jenny ${faker.lorem.sentence()}` },
{ {
@ -1220,68 +1181,48 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
url: faker.image.unsplash.objects(), url: faker.image.unsplash.objects(),
}), }),
}, },
),
),
) )
}
await Promise.all( // comments on p2 jenny
[...Array(30).keys()].map(() => for (let i = 0; i < 6; i++) {
Factory.build( await Factory.build(
'post',
{},
{
categoryIds: ['cat1'],
author: jennyRostock,
image: Factory.build('image', {
url: faker.image.unsplash.objects(),
}),
},
),
),
)
await Promise.all(
[...Array(6).keys()].map(() =>
Factory.build(
'comment', 'comment',
{}, {},
{ {
author: jennyRostock, author: jennyRostock,
postId: 'p2', postId: 'p2',
}, },
),
),
) )
}
await Promise.all( // comments on p15 jenny
[...Array(4).keys()].map(() => for (let i = 0; i < 4; i++) {
Factory.build( await Factory.build(
'comment', 'comment',
{}, {},
{ {
author: jennyRostock, author: jennyRostock,
postId: 'p15', postId: 'p15',
}, },
),
),
) )
}
await Promise.all( // comments on p4 jenny
[...Array(2).keys()].map(() => for (let i = 0; i < 2; i++) {
Factory.build( await Factory.build(
'comment', 'comment',
{}, {},
{ {
author: jennyRostock, author: jennyRostock,
postId: 'p4', postId: 'p4',
}, },
),
),
) )
}
await Promise.all( // Posts Peter Lustig
[...Array(21).keys()].map(() => for (let i = 0; i < 21; i++) {
Factory.build( await Factory.build(
'post', 'post',
{}, {},
{ {
@ -1291,52 +1232,48 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
url: faker.image.unsplash.buildings(), url: faker.image.unsplash.buildings(),
}), }),
}, },
),
),
) )
}
await Promise.all( // comments p4 peter
[...Array(3).keys()].map(() => for (let i = 0; i < 3; i++) {
Factory.build( await Factory.build(
'comment', 'comment',
{}, {},
{ {
author: peterLustig, author: peterLustig,
postId: 'p4', postId: 'p4',
}, },
),
),
) )
}
await Promise.all( // comments p14 peter
[...Array(3).keys()].map(() => for (let i = 0; i < 3; i++) {
Factory.build( await Factory.build(
'comment', 'comment',
{}, {},
{ {
author: peterLustig, author: peterLustig,
postId: 'p14', postId: 'p14',
}, },
),
),
) )
}
await Promise.all( // comments p0 peter
[...Array(6).keys()].map(() => for (let i = 0; i < 3; i++) {
Factory.build( await Factory.build(
'comment', 'comment',
{}, {},
{ {
author: peterLustig, author: peterLustig,
postId: 'p0', postId: 'p0',
}, },
),
),
) )
}
await Promise.all( // Posts dewey
[...Array(11).keys()].map(() => for (let i = 0; i < 11; i++) {
Factory.build( await Factory.build(
'post', 'post',
{}, {},
{ {
@ -1346,52 +1283,48 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
url: faker.image.unsplash.food(), url: faker.image.unsplash.food(),
}), }),
}, },
),
),
) )
}
await Promise.all( // Comments p2 dewey
[...Array(7).keys()].map(() => for (let i = 0; i < 7; i++) {
Factory.build( await Factory.build(
'comment', 'comment',
{}, {},
{ {
author: dewey, author: dewey,
postId: 'p2', postId: 'p2',
}, },
),
),
) )
}
await Promise.all( // Comments p6 dewey
[...Array(5).keys()].map(() => for (let i = 0; i < 5; i++) {
Factory.build( await Factory.build(
'comment', 'comment',
{}, {},
{ {
author: dewey, author: dewey,
postId: 'p6', postId: 'p6',
}, },
),
),
) )
}
await Promise.all( // Comments p9 dewey
[...Array(2).keys()].map(() => for (let i = 0; i < 2; i++) {
Factory.build( await Factory.build(
'comment', 'comment',
{}, {},
{ {
author: dewey, author: dewey,
postId: 'p9', postId: 'p9',
}, },
),
),
) )
}
await Promise.all( // Posts louie
[...Array(16).keys()].map(() => for (let i = 0; i < 16; i++) {
Factory.build( await Factory.build(
'post', 'post',
{}, {},
{ {
@ -1401,52 +1334,48 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
url: faker.image.unsplash.technology(), url: faker.image.unsplash.technology(),
}), }),
}, },
),
),
) )
}
await Promise.all( // Comments p1 louie
[...Array(4).keys()].map(() => for (let i = 0; i < 4; i++) {
Factory.build( await Factory.build(
'comment', 'comment',
{}, {},
{ {
postId: 'p1', postId: 'p1',
author: louie, author: louie,
}, },
),
),
) )
}
await Promise.all( // Comments p10 louie
[...Array(8).keys()].map(() => for (let i = 0; i < 8; i++) {
Factory.build( await Factory.build(
'comment', 'comment',
{}, {},
{ {
author: louie, author: louie,
postId: 'p10', postId: 'p10',
}, },
),
),
) )
}
await Promise.all( // Comments p13 louie
[...Array(5).keys()].map(() => for (let i = 0; i < 5; i++) {
Factory.build( await Factory.build(
'comment', 'comment',
{}, {},
{ {
author: louie, author: louie,
postId: 'p13', postId: 'p13',
}, },
),
),
) )
}
await Promise.all( // Posts Bob der Baumeister
[...Array(45).keys()].map(() => for (let i = 0; i < 45; i++) {
Factory.build( await Factory.build(
'post', 'post',
{}, {},
{ {
@ -1456,52 +1385,48 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
url: faker.image.unsplash.people(), url: faker.image.unsplash.people(),
}), }),
}, },
),
),
) )
}
await Promise.all( // Comments p2 bob
[...Array(2).keys()].map(() => for (let i = 0; i < 2; i++) {
Factory.build( await Factory.build(
'comment', 'comment',
{}, {},
{ {
author: bobDerBaumeister, author: bobDerBaumeister,
postId: 'p2', postId: 'p2',
}, },
),
),
) )
}
await Promise.all( // Comments p12 bob
[...Array(3).keys()].map(() => for (let i = 0; i < 3; i++) {
Factory.build( await Factory.build(
'comment', 'comment',
{}, {},
{ {
author: bobDerBaumeister, author: bobDerBaumeister,
postId: 'p12', postId: 'p12',
}, },
),
),
) )
}
await Promise.all( // Comments p13 bob
[...Array(7).keys()].map(() => for (let i = 0; i < 7; i++) {
Factory.build( await Factory.build(
'comment', 'comment',
{}, {},
{ {
author: bobDerBaumeister, author: bobDerBaumeister,
postId: 'p13', postId: 'p13',
}, },
),
),
) )
}
await Promise.all( // Posts huey
[...Array(8).keys()].map(() => for (let i = 0; i < 8; i++) {
Factory.build( await Factory.build(
'post', 'post',
{}, {},
{ {
@ -1511,48 +1436,44 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
url: faker.image.unsplash.nature(), url: faker.image.unsplash.nature(),
}), }),
}, },
),
),
) )
}
await Promise.all( // Comments p0 huey
[...Array(6).keys()].map(() => for (let i = 0; i < 6; i++) {
Factory.build( await Factory.build(
'comment', 'comment',
{}, {},
{ {
author: huey, author: huey,
postId: 'p0', postId: 'p0',
}, },
),
),
) )
}
await Promise.all( // Comments p13 huey
[...Array(8).keys()].map(() => for (let i = 0; i < 8; i++) {
Factory.build( await Factory.build(
'comment', 'comment',
{}, {},
{ {
author: huey, author: huey,
postId: 'p13', postId: 'p13',
}, },
),
),
) )
}
await Promise.all( // Comments p15 huey
[...Array(8).keys()].map(() => for (let i = 0; i < 8; i++) {
Factory.build( await Factory.build(
'comment', 'comment',
{}, {},
{ {
author: huey, author: huey,
postId: 'p15', postId: 'p15',
}, },
),
),
) )
}
await Factory.build('donations') await Factory.build('donations')

View File

@ -26,7 +26,7 @@ export const createRoomMutation = () => {
export const roomQuery = () => { export const roomQuery = () => {
return gql` return gql`
query Room($first: Int, $offset: Int, $id: ID) { query Room($first: Int, $offset: Int, $id: ID) {
Room(first: $first, offset: $offset, id: $id, orderBy: createdAt_desc) { Room(first: $first, offset: $offset, id: $id, orderBy: lastMessageAt_desc) {
id id
roomId roomId
roomName roomName

View File

@ -54,4 +54,7 @@ export default {
Mutation: { Mutation: {
CreateRoom: roomProperties, CreateRoom: roomProperties,
}, },
Subscription: {
chatMessageAdded: messageProperties,
},
} }

View File

@ -117,7 +117,7 @@ describe('Message', () => {
}) })
describe('user chats in room', () => { describe('user chats in room', () => {
it('returns the message and publishes subscription', async () => { it('returns the message and publishes subscriptions', async () => {
await expect( await expect(
mutate({ mutate({
mutation: createMessageMutation(), mutation: createMessageMutation(),
@ -146,6 +146,20 @@ describe('Message', () => {
roomCountUpdated: '1', roomCountUpdated: '1',
userId: 'other-chatting-user', userId: 'other-chatting-user',
}) })
expect(pubsubSpy).toBeCalledWith('CHAT_MESSAGE_ADDED', {
chatMessageAdded: expect.objectContaining({
id: expect.any(String),
content: 'Some nice message to other chatting user',
senderId: 'chatting-user',
username: 'Chatting User',
avatar: expect.any(String),
date: expect.any(String),
saved: true,
distributed: false,
seen: false,
}),
userId: 'other-chatting-user',
})
}) })
describe('room is updated as well', () => { describe('room is updated as well', () => {

View File

@ -1,7 +1,9 @@
import { neo4jgraphql } from 'neo4j-graphql-js' import { neo4jgraphql } from 'neo4j-graphql-js'
import Resolver from './helpers/Resolver' import Resolver from './helpers/Resolver'
import { getUnreadRoomsCount } from './rooms' import { getUnreadRoomsCount } from './rooms'
import { pubsub, ROOM_COUNT_UPDATED } from '../../server' import { pubsub, ROOM_COUNT_UPDATED, CHAT_MESSAGE_ADDED } from '../../server'
import { withFilter } from 'graphql-subscriptions'
const setMessagesAsDistributed = async (undistributedMessagesIds, session) => { const setMessagesAsDistributed = async (undistributedMessagesIds, session) => {
return session.writeTransaction(async (transaction) => { return session.writeTransaction(async (transaction) => {
@ -19,6 +21,16 @@ const setMessagesAsDistributed = async (undistributedMessagesIds, session) => {
} }
export default { export default {
Subscription: {
chatMessageAdded: {
subscribe: withFilter(
() => pubsub.asyncIterator(CHAT_MESSAGE_ADDED),
(payload, variables) => {
return payload.userId === variables.userId
},
),
},
},
Query: { Query: {
Message: async (object, params, context, resolveInfo) => { Message: async (object, params, context, resolveInfo) => {
const { roomId } = params const { roomId } = params
@ -102,10 +114,14 @@ export default {
const roomCountUpdated = await getUnreadRoomsCount(message.recipientId, session) const roomCountUpdated = await getUnreadRoomsCount(message.recipientId, session)
// send subscriptions // send subscriptions
await pubsub.publish(ROOM_COUNT_UPDATED, { void pubsub.publish(ROOM_COUNT_UPDATED, {
roomCountUpdated, roomCountUpdated,
userId: message.recipientId, userId: message.recipientId,
}) })
void pubsub.publish(CHAT_MESSAGE_ADDED, {
chatMessageAdded: message,
userId: message.recipientId,
})
} }
return message return message

View File

@ -423,58 +423,111 @@ describe('Room', () => {
}) })
it('returns the rooms paginated', async () => { it('returns the rooms paginated', async () => {
expect(await query({ query: roomQuery(), variables: { first: 3, offset: 0 } })).toMatchObject( await expect(
{ query({ query: roomQuery(), variables: { first: 3, offset: 0 } }),
).resolves.toMatchObject({
errors: undefined, errors: undefined,
data: { data: {
Room: [ Room: expect.arrayContaining([
{ expect.objectContaining({
id: expect.any(String), id: expect.any(String),
roomId: expect.any(String), roomId: expect.any(String),
roomName: 'Third Chatting User', roomName: 'Third Chatting User',
lastMessageAt: null,
unreadCount: 0,
lastMessage: null,
users: expect.arrayContaining([ users: expect.arrayContaining([
{ expect.objectContaining({
_id: 'chatting-user', _id: 'chatting-user',
id: 'chatting-user', id: 'chatting-user',
name: 'Chatting User', name: 'Chatting User',
avatar: { avatar: {
url: expect.any(String), url: expect.any(String),
}, },
}, }),
{ expect.objectContaining({
_id: 'third-chatting-user', _id: 'third-chatting-user',
id: 'third-chatting-user', id: 'third-chatting-user',
name: 'Third Chatting User', name: 'Third Chatting User',
avatar: { avatar: {
url: expect.any(String), url: expect.any(String),
}, },
}, }),
]), ]),
}, }),
{ expect.objectContaining({
id: expect.any(String), id: expect.any(String),
roomId: expect.any(String), roomId: expect.any(String),
roomName: 'Second Chatting User', roomName: 'Second Chatting User',
lastMessageAt: null,
unreadCount: 0,
lastMessage: null,
users: expect.arrayContaining([ users: expect.arrayContaining([
{ expect.objectContaining({
_id: 'chatting-user', _id: 'chatting-user',
id: 'chatting-user', id: 'chatting-user',
name: 'Chatting User', name: 'Chatting User',
avatar: { avatar: {
url: expect.any(String), url: expect.any(String),
}, },
}, }),
{ expect.objectContaining({
_id: 'second-chatting-user', _id: 'second-chatting-user',
id: 'second-chatting-user', id: 'second-chatting-user',
name: 'Second Chatting User', name: 'Second Chatting User',
avatar: { avatar: {
url: expect.any(String), url: expect.any(String),
}, },
}),
]),
}),
expect.objectContaining({
id: expect.any(String),
roomId: expect.any(String),
roomName: 'Other Chatting User',
lastMessageAt: expect.any(String),
unreadCount: 0,
lastMessage: {
_id: expect.any(String),
id: expect.any(String),
content: '2nd message to other chatting user',
senderId: 'chatting-user',
username: 'Chatting User',
avatar: expect.any(String),
date: expect.any(String),
saved: true,
distributed: false,
seen: false,
}, },
users: expect.arrayContaining([
expect.objectContaining({
_id: 'chatting-user',
id: 'chatting-user',
name: 'Chatting User',
avatar: {
url: expect.any(String),
},
}),
expect.objectContaining({
_id: 'other-chatting-user',
id: 'other-chatting-user',
name: 'Other Chatting User',
avatar: {
url: expect.any(String),
},
}),
]),
}),
]), ]),
}, },
{ })
await expect(
query({ query: roomQuery(), variables: { first: 3, offset: 3 } }),
).resolves.toMatchObject({
errors: undefined,
data: {
Room: [
expect.objectContaining({
id: expect.any(String), id: expect.any(String),
roomId: expect.any(String), roomId: expect.any(String),
roomName: 'Not Chatting User', roomName: 'Not Chatting User',
@ -496,52 +549,21 @@ describe('Room', () => {
}, },
}, },
]), ]),
}, }),
], ],
}, },
}, })
)
expect(await query({ query: roomQuery(), variables: { first: 3, offset: 3 } })).toMatchObject(
{
errors: undefined,
data: {
Room: [
{
id: expect.any(String),
roomId: expect.any(String),
roomName: 'Other Chatting User',
users: expect.arrayContaining([
{
_id: 'chatting-user',
id: 'chatting-user',
name: 'Chatting User',
avatar: {
url: expect.any(String),
},
},
{
_id: 'other-chatting-user',
id: 'other-chatting-user',
name: 'Other Chatting User',
avatar: {
url: expect.any(String),
},
},
]),
},
],
},
},
)
}) })
}) })
describe('query single room', () => { describe('query single room', () => {
let result: any = null let result: any = null
beforeAll(async () => { beforeAll(async () => {
authenticatedUser = await chattingUser.toJson() authenticatedUser = await chattingUser.toJson()
result = await query({ query: roomQuery() }) result = await query({ query: roomQuery() })
}) })
describe('as chatter of room', () => { describe('as chatter of room', () => {
it('returns the room', async () => { it('returns the room', async () => {
expect( expect(
@ -556,34 +578,19 @@ describe('Room', () => {
{ {
id: expect.any(String), id: expect.any(String),
roomId: expect.any(String), roomId: expect.any(String),
roomName: 'Third Chatting User', roomName: result.data.Room[0].roomName,
users: expect.arrayContaining([ users: expect.any(Array),
{
_id: 'chatting-user',
id: 'chatting-user',
name: 'Chatting User',
avatar: {
url: expect.any(String),
},
},
{
_id: 'third-chatting-user',
id: 'third-chatting-user',
name: 'Third Chatting User',
avatar: {
url: expect.any(String),
},
},
]),
}, },
], ],
}, },
}) })
}) })
describe('as not chatter of room', () => { describe('as not chatter of room', () => {
beforeAll(async () => { beforeAll(async () => {
authenticatedUser = await notChattingUser.toJson() authenticatedUser = await notChattingUser.toJson()
}) })
it('returns no room', async () => { it('returns no room', async () => {
authenticatedUser = await notChattingUser.toJson() authenticatedUser = await notChattingUser.toJson()
expect( expect(

View File

@ -44,3 +44,7 @@ type Query {
orderBy: [_MessageOrdering] orderBy: [_MessageOrdering]
): [Message] ): [Message]
} }
type Subscription {
chatMessageAdded(userId: ID!): Message
}

View File

@ -7,7 +7,7 @@
# TODO change this to last message date # TODO change this to last message date
enum _RoomOrdering { enum _RoomOrdering {
createdAt_desc lastMessageAt_desc
} }
type Room { type Room {

View File

@ -14,7 +14,7 @@ import bodyParser from 'body-parser'
import { graphqlUploadExpress } from 'graphql-upload' import { graphqlUploadExpress } from 'graphql-upload'
export const NOTIFICATION_ADDED = 'NOTIFICATION_ADDED' export const NOTIFICATION_ADDED = 'NOTIFICATION_ADDED'
// export const CHAT_MESSAGE_ADDED = 'CHAT_MESSAGE_ADDED' export const CHAT_MESSAGE_ADDED = 'CHAT_MESSAGE_ADDED'
export const ROOM_COUNT_UPDATED = 'ROOM_COUNT_UPDATED' export const ROOM_COUNT_UPDATED = 'ROOM_COUNT_UPDATED'
const { REDIS_DOMAIN, REDIS_PORT, REDIS_PASSWORD } = CONFIG const { REDIS_DOMAIN, REDIS_PORT, REDIS_PASSWORD } = CONFIG
let prodPubsub, devPubsub let prodPubsub, devPubsub

View File

@ -61,7 +61,12 @@
<script> <script>
import { roomQuery, createRoom, unreadRoomsQuery } from '~/graphql/Rooms' import { roomQuery, createRoom, unreadRoomsQuery } from '~/graphql/Rooms'
import { messageQuery, createMessageMutation, markMessagesAsSeen } from '~/graphql/Messages' import {
messageQuery,
createMessageMutation,
chatMessageAdded,
markMessagesAsSeen,
} from '~/graphql/Messages'
import chatStyle from '~/constants/chat.js' import chatStyle from '~/constants/chat.js'
import { mapGetters, mapMutations } from 'vuex' import { mapGetters, mapMutations } from 'vuex'
@ -169,6 +174,21 @@ export default {
} else { } else {
this.fetchRooms() this.fetchRooms()
} }
// Subscriptions
const observer = this.$apollo.subscribe({
query: chatMessageAdded(),
variables: {
userId: this.currentUser.id,
},
})
observer.subscribe({
next: this.chatMessageAdded,
error(error) {
this.$toast.error(error)
},
})
}, },
computed: { computed: {
...mapGetters({ ...mapGetters({
@ -297,6 +317,18 @@ export default {
} }
}, },
async chatMessageAdded({ data }) {
if (data.chatMessageAdded.room.id === this.selectedRoom?.id) {
this.fetchMessages({ room: this.selectedRoom, options: { refetch: true } })
} else {
// TODO this might be optimized selectively (first page vs rest)
this.rooms = []
this.roomPage = 0
this.roomsLoaded = false
this.fetchRooms()
}
},
async sendMessage(message) { async sendMessage(message) {
// check for usersTag and change userid to username // check for usersTag and change userid to username
message.usersTag.forEach((userTag) => { message.usersTag.forEach((userTag) => {

View File

@ -34,6 +34,32 @@ export const messageQuery = () => {
` `
} }
export const chatMessageAdded = () => {
return gql`
subscription chatMessageAdded($userId: ID!) {
chatMessageAdded(userId: $userId) {
_id
id
indexId
content
senderId
author {
id
}
username
avatar
date
room {
id
}
saved
distributed
seen
}
}
`
}
export const markMessagesAsSeen = () => { export const markMessagesAsSeen = () => {
return gql` return gql`
mutation ($messageIds: [String!]) { mutation ($messageIds: [String!]) {

View File

@ -11,7 +11,7 @@ export const createRoom = () => gql`
export const roomQuery = () => gql` export const roomQuery = () => gql`
query Room($first: Int, $offset: Int, $id: ID) { query Room($first: Int, $offset: Int, $id: ID) {
Room(first: $first, offset: $offset, id: $id, orderBy: createdAt_desc) { Room(first: $first, offset: $offset, id: $id, orderBy: lastMessageAt_desc) {
id id
roomId roomId
roomName roomName

View File

@ -86,6 +86,9 @@
"messageDeleted": "Diese Nachricht wuerde gelöscht", "messageDeleted": "Diese Nachricht wuerde gelöscht",
"messagesEmpty": "Keine Nachrichten", "messagesEmpty": "Keine Nachrichten",
"newMessages": "Neue Nachrichten", "newMessages": "Neue Nachrichten",
"page": {
"headline": "Chat"
},
"roomEmpty": "Keinen Raum selektiert", "roomEmpty": "Keinen Raum selektiert",
"roomsEmpty": "Keine Räume", "roomsEmpty": "Keine Räume",
"search": "Suche", "search": "Suche",

View File

@ -86,6 +86,9 @@
"messageDeleted": "This message was deleted", "messageDeleted": "This message was deleted",
"messagesEmpty": "No messages", "messagesEmpty": "No messages",
"newMessages": "New Messages", "newMessages": "New Messages",
"page": {
"headline": "Chat"
},
"roomEmpty": "No room selected", "roomEmpty": "No room selected",
"roomsEmpty": "No rooms", "roomsEmpty": "No rooms",
"search": "Search", "search": "Search",

View File

@ -1,5 +1,8 @@
<template> <template>
<div>
<ds-heading tag="h1">{{ $t('chat.page.headline') }}</ds-heading>
<chat /> <chat />
</div>
</template> </template>
<script> <script>