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
- '.github/workflows/test-backend.yml'
- 'backend/**/*'
- 'neo4j/**/*'
@ -6,4 +7,5 @@ docker: &docker
- 'docker-compose.*'
webapp: &webapp
- '.github/workflows/test-webapp.yml'
- 'webapp/**/*'

View File

@ -10,10 +10,11 @@ jobs:
outputs:
backend: ${{ steps.changes.outputs.backend }}
docker: ${{ steps.changes.outputs.docker }}
pr-number: ${{ steps.pr.outputs.number }}
steps:
- 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
id: changes
with:
@ -21,6 +22,10 @@ jobs:
filters: .github/file-filters.yml
list-files: shell
- name: Get pr number
id: pr
uses: 8BitJonny/gh-get-current-pr@2.2.0
build_test_neo4j:
name: Docker Build Test - Neo4J
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 save "ocelotsocialnetwork/neo4j-community:test" > /tmp/neo4j.tar
- name: Upload Artifact
uses: actions/upload-artifact@v3
- name: Cache docker images
id: cache-neo4j
uses: actions/cache/save@v3.3.1
with:
name: docker-neo4j-image
path: /tmp/neo4j.tar
key: backend-neo4j-cache-pr${{ needs.files-changed.outputs.pr-number }}
build_test_backend:
name: Docker Build Test - Backend
@ -55,11 +61,12 @@ jobs:
docker build --target test -t "ocelotsocialnetwork/backend:test" backend/
docker save "ocelotsocialnetwork/backend:test" > /tmp/backend.tar
- name: Upload Artifact
uses: actions/upload-artifact@v3
- name: Cache docker images
id: cache-backend
uses: actions/cache/save@v3.3.1
with:
name: docker-backend-test
path: /tmp/backend.tar
key: backend-cache-pr${{ needs.files-changed.outputs.pr-number }}
lint_backend:
name: Lint Backend
@ -84,28 +91,29 @@ jobs:
- name: Checkout code
uses: actions/checkout@v3
- name: Download Docker Image (Neo4J)
uses: actions/download-artifact@v3
- name: Restore Neo4J cache
uses: actions/cache/restore@v3.3.1
with:
name: docker-neo4j-image
path: /tmp
path: /tmp/neo4j.tar
key: backend-neo4j-cache-pr${{ needs.files-changed.outputs.pr-number }}
fail-on-cache-miss: true
- name: Load Docker Image
run: docker load < /tmp/neo4j.tar
- name: Download Docker Image (Backend)
uses: actions/download-artifact@v3
- name: Restore Backend cache
uses: actions/cache/restore@v3.3.1
with:
name: docker-backend-test
path: /tmp
path: /tmp/backend.tar
key: backend-cache-pr${{ needs.files-changed.outputs.pr-number }}
fail-on-cache-miss: true
- name: Load Docker Image
run: docker load < /tmp/backend.tar
- name: Load Docker Images
run: |
docker load < /tmp/neo4j.tar
docker load < /tmp/backend.tar
- name: backend | copy env files webapp
run: cp webapp/.env.template webapp/.env
- name: backend | copy env files backend
run: cp backend/.env.template backend/.env
- name: backend | copy env files
run: |
cp webapp/.env.template webapp/.env
cp backend/.env.template backend/.env
- name: backend | docker-compose
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
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 }}
run: |
gh extension install actions/gh-actions-cache
set +e
KEY="e2e-preparation-cache-pr${{ needs.docker_preparation.outputs.pr-number }}"
gh actions-cache delete $KEY -R Ocelot-Social-Community/Ocelot-Social --confirm

View File

@ -9,6 +9,7 @@ jobs:
runs-on: ubuntu-latest
outputs:
docker: ${{ steps.changes.outputs.docker }}
pr-number: ${{ steps.pr.outputs.number }}
webapp: ${{ steps.changes.outputs.webapp }}
steps:
- uses: actions/checkout@v3.3.0
@ -21,6 +22,10 @@ jobs:
filters: .github/file-filters.yml
list-files: shell
- name: Get pr number
id: pr
uses: 8BitJonny/gh-get-current-pr@2.2.0
prepare:
name: Prepare
if: needs.files-changed.outputs.webapp == 'true'
@ -44,16 +49,16 @@ jobs:
- name: Checkout code
uses: actions/checkout@v3
- name: webapp | Build 'test' image
- name: Webapp | Build 'test' image
run: |
docker build --target test -t "ocelotsocialnetwork/webapp:test" webapp/
docker save "ocelotsocialnetwork/webapp:test" > /tmp/webapp.tar
- name: Upload Artifact
uses: actions/upload-artifact@v3
- name: Cache docker image
uses: actions/cache/save@v3.3.1
with:
name: docker-webapp-test
path: /tmp/webapp.tar
key: webapp-cache-pr${{ needs.files-changed.outputs.pr-number }}
lint_webapp:
name: Lint Webapp
@ -78,20 +83,19 @@ jobs:
- name: Checkout code
uses: actions/checkout@v3
- name: Download Docker Image (Webapp)
uses: actions/download-artifact@v3
- name: Restore webapp cache
uses: actions/cache/restore@v3.3.1
with:
name: docker-webapp-test
path: /tmp
path: /tmp/webapp.tar
key: webapp-cache-pr${{ needs.files-changed.outputs.pr-number }}
- name: Load Docker Image
run: docker load < /tmp/webapp.tar
- name: backend | copy env files webapp
run: cp webapp/.env.template webapp/.env
- name: backend | copy env files backend
run: cp backend/.env.template backend/.env
- name: Copy env files
run: |
cp webapp/.env.template webapp/.env
cp backend/.env.template backend/.env
- name: backend | docker-compose
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
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')
// categories
await Promise.all(
categories.map(({ icon, name }, index) => {
return Factory.build('category', {
id: `cat${index + 1}`,
slug: name,
name,
icon,
let i = 0
for (const category of categories) {
await Factory.build('category', {
id: `cat${i++}`,
slug: category.name,
naem: category.name,
icon: category.icon,
})
}),
)
}
// tags
const environment = await Factory.build('tag', {
id: 'Environment',
})
@ -295,8 +295,7 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
// groups
authenticatedUser = await peterLustig.toJson()
await Promise.all([
mutate({
await mutate({
mutation: createGroupMutation(),
variables: {
id: 'g0',
@ -308,53 +307,49 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
categoryIds: ['cat6', 'cat12', 'cat16'],
locationName: 'Hamburg, Germany',
},
}),
])
await Promise.all([
mutate({
})
await mutate({
mutation: joinGroupMutation(),
variables: {
groupId: 'g0',
userId: 'u2',
},
}),
mutate({
})
await mutate({
mutation: joinGroupMutation(),
variables: {
groupId: 'g0',
userId: 'u4',
},
}),
mutate({
})
await mutate({
mutation: joinGroupMutation(),
variables: {
groupId: 'g0',
userId: 'u6',
},
}),
])
await Promise.all([
mutate({
})
await mutate({
mutation: changeGroupMemberRoleMutation(),
variables: {
groupId: 'g0',
userId: 'u2',
roleInGroup: 'usual',
},
}),
mutate({
})
await mutate({
mutation: changeGroupMemberRoleMutation(),
variables: {
groupId: 'g0',
userId: 'u4',
roleInGroup: 'admin',
},
}),
])
})
// post into group
await Promise.all([
mutate({
await mutate({
mutation: createPostMutation(),
variables: {
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?',
categoryIds: ['cat6'],
},
}),
])
})
authenticatedUser = await bobDerBaumeister.toJson()
await Promise.all([
mutate({
await mutate({
mutation: createPostMutation(),
variables: {
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.',
categoryIds: ['cat12', 'cat16'],
},
}),
])
})
authenticatedUser = await jennyRostock.toJson()
await Promise.all([
mutate({
await mutate({
mutation: createGroupMutation(),
variables: {
id: 'g1',
@ -393,74 +385,69 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
categoryIds: ['cat8', 'cat14'],
locationName: 'France',
},
}),
])
await Promise.all([
mutate({
})
await mutate({
mutation: joinGroupMutation(),
variables: {
groupId: 'g1',
userId: 'u1',
},
}),
mutate({
})
await mutate({
mutation: joinGroupMutation(),
variables: {
groupId: 'g1',
userId: 'u2',
},
}),
mutate({
})
await mutate({
mutation: joinGroupMutation(),
variables: {
groupId: 'g1',
userId: 'u5',
},
}),
mutate({
})
await mutate({
mutation: joinGroupMutation(),
variables: {
groupId: 'g1',
userId: 'u6',
},
}),
mutate({
})
await mutate({
mutation: joinGroupMutation(),
variables: {
groupId: 'g1',
userId: 'u7',
},
}),
])
await Promise.all([
mutate({
})
await mutate({
mutation: changeGroupMemberRoleMutation(),
variables: {
groupId: 'g1',
userId: 'u1',
roleInGroup: 'usual',
},
}),
mutate({
})
await mutate({
mutation: changeGroupMemberRoleMutation(),
variables: {
groupId: 'g1',
userId: 'u5',
roleInGroup: 'admin',
},
}),
mutate({
})
await mutate({
mutation: changeGroupMemberRoleMutation(),
variables: {
groupId: 'g1',
userId: 'u6',
roleInGroup: 'owner',
},
}),
])
})
// post into group
await Promise.all([
mutate({
await mutate({
mutation: createPostMutation(),
variables: {
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?',
categoryIds: ['cat8'],
},
}),
])
})
authenticatedUser = await peterLustig.toJson()
await Promise.all([
mutate({
await mutate({
mutation: createPostMutation(),
variables: {
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.',
categoryIds: ['cat14'],
},
}),
])
})
authenticatedUser = await bobDerBaumeister.toJson()
await Promise.all([
mutate({
await mutate({
mutation: createGroupMutation(),
variables: {
id: 'g2',
@ -498,83 +481,78 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
actionRadius: 'interplanetary',
categoryIds: ['cat4', 'cat5', 'cat17'],
},
}),
])
await Promise.all([
mutate({
})
await mutate({
mutation: joinGroupMutation(),
variables: {
groupId: 'g2',
userId: 'u3',
},
}),
mutate({
})
await mutate({
mutation: joinGroupMutation(),
variables: {
groupId: 'g2',
userId: 'u4',
},
}),
mutate({
})
await mutate({
mutation: joinGroupMutation(),
variables: {
groupId: 'g2',
userId: 'u5',
},
}),
mutate({
})
await mutate({
mutation: joinGroupMutation(),
variables: {
groupId: 'g2',
userId: 'u6',
},
}),
mutate({
})
await mutate({
mutation: joinGroupMutation(),
variables: {
groupId: 'g2',
userId: 'u7',
},
}),
])
await Promise.all([
mutate({
})
await mutate({
mutation: changeGroupMemberRoleMutation(),
variables: {
groupId: 'g2',
userId: 'u3',
roleInGroup: 'usual',
},
}),
mutate({
})
await mutate({
mutation: changeGroupMemberRoleMutation(),
variables: {
groupId: 'g2',
userId: 'u4',
roleInGroup: 'pending',
},
}),
mutate({
})
await mutate({
mutation: changeGroupMemberRoleMutation(),
variables: {
groupId: 'g2',
userId: 'u5',
roleInGroup: 'admin',
},
}),
mutate({
})
await mutate({
mutation: changeGroupMemberRoleMutation(),
variables: {
groupId: 'g2',
userId: 'u6',
roleInGroup: 'usual',
},
}),
])
})
authenticatedUser = await louie.toJson()
await Promise.all([
mutate({
await mutate({
mutation: createPostMutation(),
variables: {
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.',
categoryIds: ['cat4'],
},
}),
])
})
// Create Events (by peter lustig)
authenticatedUser = await peterLustig.toJson()
const now = new Date()
await Promise.all([
mutate({
await mutate({
mutation: createPostMutation(),
variables: {
id: 'e0',
@ -600,17 +576,13 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
categoryIds: ['cat4'],
postType: 'Event',
eventInput: {
eventStart: new Date(
now.getFullYear(),
now.getMonth(),
now.getDate() + 7,
).toISOString(),
eventStart: new Date(now.getFullYear(), now.getMonth(), now.getDate() + 7).toISOString(),
eventVenue: 'Ellis Kinderzimmer',
eventLocationName: 'Deutschland',
},
},
}),
mutate({
})
await mutate({
mutation: createPostMutation(),
variables: {
id: 'e1',
@ -619,17 +591,13 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
categoryIds: ['cat5'],
postType: 'Event',
eventInput: {
eventStart: new Date(
now.getFullYear(),
now.getMonth(),
now.getDate() + 1,
).toISOString(),
eventStart: new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1).toISOString(),
eventVenue: 'Schlossgarten',
eventLocationName: 'Stuttgart',
},
},
}),
mutate({
})
await mutate({
mutation: createPostMutation(),
variables: {
id: 'e2',
@ -638,18 +606,13 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
categoryIds: ['cat5'],
postType: 'Event',
eventInput: {
eventStart: new Date(
now.getFullYear(),
now.getMonth(),
now.getDate() + 1,
).toISOString(),
eventStart: new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1).toISOString(),
eventEnd: new Date(now.getFullYear(), now.getMonth(), now.getDate() + 4).toISOString(),
eventVenue: 'Ferienlager',
eventLocationName: 'Bahra, Sachsen',
},
},
}),
])
})
let passedEvent = await neode.find('Post', 'e1')
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 =
'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([
mutate({
await mutate({
mutation: createPostMutation(),
variables: {
id: 'p2',
@ -845,8 +807,8 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
content: hashtag1,
categoryIds: ['cat2'],
},
}),
mutate({
})
await mutate({
mutation: createPostMutation(),
variables: {
id: 'p7',
@ -854,8 +816,8 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
content: `${mention1} ${faker.lorem.paragraph()}`,
categoryIds: ['cat7'],
},
}),
mutate({
})
await mutate({
mutation: createPostMutation(),
variables: {
id: 'p8',
@ -864,8 +826,8 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
content: hashtagAndMention1,
categoryIds: ['cat8'],
},
}),
mutate({
})
await mutate({
mutation: createPostMutation(),
variables: {
id: 'p12',
@ -873,11 +835,13 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
content: `${mention2} ${faker.lorem.paragraph()}`,
categoryIds: ['cat12'],
},
}),
])
const [p2, p7, p8, p12] = await Promise.all(
['p2', 'p7', 'p8', 'p12'].map((id) => neode.find('Post', id)),
)
})
const p2 = await neode.find('Post', 'p2')
const p7 = await neode.find('Post', 'p7')
const p8 = await neode.find('Post', 'p8')
const p12 = await neode.find('Post', 'p12')
authenticatedUser = null
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.'
const mentionInComment2 =
'Did <a class="mention" data-mention-id="u1" href="/profile/u1">@peter-lustig</a> tell you?'
await Promise.all([
mutate({
await mutate({
mutation: createCommentMutation,
variables: {
id: 'c4',
postId: 'p2',
content: mentionInComment1,
},
}),
mutate({
})
await mutate({
mutation: createCommentMutation,
variables: {
id: 'c4-1',
postId: 'p2',
content: mentionInComment2,
},
}),
mutate({
})
await mutate({
mutation: createCommentMutation,
variables: {
postId: 'p14',
content: faker.lorem.paragraph(),
},
}), // should send a notification
])
}) // should send a notification
authenticatedUser = null
const comments: any[] = []
@ -1193,24 +1156,22 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
closed: true,
})
const additionalUsers = await Promise.all(
[...Array(30).keys()].map(() => Factory.build('user')),
)
await Promise.all(
additionalUsers.map(async (user) => {
const additionalUsers: any[] = []
for (let i = 0; i < 30; i++) {
const user = await Factory.build('user')
await jennyRostock.relateTo(user, 'following')
await user.relateTo(jennyRostock, 'following')
}),
)
additionalUsers.push(user)
}
await Promise.all(
[...Array(30).keys()].map((index) => Factory.build('user', { name: `Jenny${index}` })),
)
// Jenny users
for (let i = 0; i < 30; i++) {
await Factory.build('user', { name: `Jenny${i}` })
}
await Promise.all(
[...Array(30).keys()].map(() =>
Factory.build(
// Jenny posts
for (let i = 0; i < 30; i++) {
await Factory.build(
'post',
{ content: `Jenny ${faker.lorem.sentence()}` },
{
@ -1220,68 +1181,48 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
url: faker.image.unsplash.objects(),
}),
},
),
),
)
}
await Promise.all(
[...Array(30).keys()].map(() =>
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(
// comments on p2 jenny
for (let i = 0; i < 6; i++) {
await Factory.build(
'comment',
{},
{
author: jennyRostock,
postId: 'p2',
},
),
),
)
}
await Promise.all(
[...Array(4).keys()].map(() =>
Factory.build(
// comments on p15 jenny
for (let i = 0; i < 4; i++) {
await Factory.build(
'comment',
{},
{
author: jennyRostock,
postId: 'p15',
},
),
),
)
}
await Promise.all(
[...Array(2).keys()].map(() =>
Factory.build(
// comments on p4 jenny
for (let i = 0; i < 2; i++) {
await Factory.build(
'comment',
{},
{
author: jennyRostock,
postId: 'p4',
},
),
),
)
}
await Promise.all(
[...Array(21).keys()].map(() =>
Factory.build(
// Posts Peter Lustig
for (let i = 0; i < 21; i++) {
await Factory.build(
'post',
{},
{
@ -1291,52 +1232,48 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
url: faker.image.unsplash.buildings(),
}),
},
),
),
)
}
await Promise.all(
[...Array(3).keys()].map(() =>
Factory.build(
// comments p4 peter
for (let i = 0; i < 3; i++) {
await Factory.build(
'comment',
{},
{
author: peterLustig,
postId: 'p4',
},
),
),
)
}
await Promise.all(
[...Array(3).keys()].map(() =>
Factory.build(
// comments p14 peter
for (let i = 0; i < 3; i++) {
await Factory.build(
'comment',
{},
{
author: peterLustig,
postId: 'p14',
},
),
),
)
}
await Promise.all(
[...Array(6).keys()].map(() =>
Factory.build(
// comments p0 peter
for (let i = 0; i < 3; i++) {
await Factory.build(
'comment',
{},
{
author: peterLustig,
postId: 'p0',
},
),
),
)
}
await Promise.all(
[...Array(11).keys()].map(() =>
Factory.build(
// Posts dewey
for (let i = 0; i < 11; i++) {
await Factory.build(
'post',
{},
{
@ -1346,52 +1283,48 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
url: faker.image.unsplash.food(),
}),
},
),
),
)
}
await Promise.all(
[...Array(7).keys()].map(() =>
Factory.build(
// Comments p2 dewey
for (let i = 0; i < 7; i++) {
await Factory.build(
'comment',
{},
{
author: dewey,
postId: 'p2',
},
),
),
)
}
await Promise.all(
[...Array(5).keys()].map(() =>
Factory.build(
// Comments p6 dewey
for (let i = 0; i < 5; i++) {
await Factory.build(
'comment',
{},
{
author: dewey,
postId: 'p6',
},
),
),
)
}
await Promise.all(
[...Array(2).keys()].map(() =>
Factory.build(
// Comments p9 dewey
for (let i = 0; i < 2; i++) {
await Factory.build(
'comment',
{},
{
author: dewey,
postId: 'p9',
},
),
),
)
}
await Promise.all(
[...Array(16).keys()].map(() =>
Factory.build(
// Posts louie
for (let i = 0; i < 16; i++) {
await Factory.build(
'post',
{},
{
@ -1401,52 +1334,48 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
url: faker.image.unsplash.technology(),
}),
},
),
),
)
}
await Promise.all(
[...Array(4).keys()].map(() =>
Factory.build(
// Comments p1 louie
for (let i = 0; i < 4; i++) {
await Factory.build(
'comment',
{},
{
postId: 'p1',
author: louie,
},
),
),
)
}
await Promise.all(
[...Array(8).keys()].map(() =>
Factory.build(
// Comments p10 louie
for (let i = 0; i < 8; i++) {
await Factory.build(
'comment',
{},
{
author: louie,
postId: 'p10',
},
),
),
)
}
await Promise.all(
[...Array(5).keys()].map(() =>
Factory.build(
// Comments p13 louie
for (let i = 0; i < 5; i++) {
await Factory.build(
'comment',
{},
{
author: louie,
postId: 'p13',
},
),
),
)
}
await Promise.all(
[...Array(45).keys()].map(() =>
Factory.build(
// Posts Bob der Baumeister
for (let i = 0; i < 45; i++) {
await Factory.build(
'post',
{},
{
@ -1456,52 +1385,48 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
url: faker.image.unsplash.people(),
}),
},
),
),
)
}
await Promise.all(
[...Array(2).keys()].map(() =>
Factory.build(
// Comments p2 bob
for (let i = 0; i < 2; i++) {
await Factory.build(
'comment',
{},
{
author: bobDerBaumeister,
postId: 'p2',
},
),
),
)
}
await Promise.all(
[...Array(3).keys()].map(() =>
Factory.build(
// Comments p12 bob
for (let i = 0; i < 3; i++) {
await Factory.build(
'comment',
{},
{
author: bobDerBaumeister,
postId: 'p12',
},
),
),
)
}
await Promise.all(
[...Array(7).keys()].map(() =>
Factory.build(
// Comments p13 bob
for (let i = 0; i < 7; i++) {
await Factory.build(
'comment',
{},
{
author: bobDerBaumeister,
postId: 'p13',
},
),
),
)
}
await Promise.all(
[...Array(8).keys()].map(() =>
Factory.build(
// Posts huey
for (let i = 0; i < 8; i++) {
await Factory.build(
'post',
{},
{
@ -1511,48 +1436,44 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
url: faker.image.unsplash.nature(),
}),
},
),
),
)
}
await Promise.all(
[...Array(6).keys()].map(() =>
Factory.build(
// Comments p0 huey
for (let i = 0; i < 6; i++) {
await Factory.build(
'comment',
{},
{
author: huey,
postId: 'p0',
},
),
),
)
}
await Promise.all(
[...Array(8).keys()].map(() =>
Factory.build(
// Comments p13 huey
for (let i = 0; i < 8; i++) {
await Factory.build(
'comment',
{},
{
author: huey,
postId: 'p13',
},
),
),
)
}
await Promise.all(
[...Array(8).keys()].map(() =>
Factory.build(
// Comments p15 huey
for (let i = 0; i < 8; i++) {
await Factory.build(
'comment',
{},
{
author: huey,
postId: 'p15',
},
),
),
)
}
await Factory.build('donations')

View File

@ -26,7 +26,7 @@ export const createRoomMutation = () => {
export const roomQuery = () => {
return gql`
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
roomId
roomName

View File

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

View File

@ -117,7 +117,7 @@ describe('Message', () => {
})
describe('user chats in room', () => {
it('returns the message and publishes subscription', async () => {
it('returns the message and publishes subscriptions', async () => {
await expect(
mutate({
mutation: createMessageMutation(),
@ -146,6 +146,20 @@ describe('Message', () => {
roomCountUpdated: '1',
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', () => {

View File

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

View File

@ -423,58 +423,111 @@ describe('Room', () => {
})
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,
data: {
Room: [
{
Room: expect.arrayContaining([
expect.objectContaining({
id: expect.any(String),
roomId: expect.any(String),
roomName: 'Third Chatting User',
lastMessageAt: null,
unreadCount: 0,
lastMessage: null,
users: expect.arrayContaining([
{
expect.objectContaining({
_id: 'chatting-user',
id: 'chatting-user',
name: 'Chatting User',
avatar: {
url: expect.any(String),
},
},
{
}),
expect.objectContaining({
_id: 'third-chatting-user',
id: 'third-chatting-user',
name: 'Third Chatting User',
avatar: {
url: expect.any(String),
},
},
}),
]),
},
{
}),
expect.objectContaining({
id: expect.any(String),
roomId: expect.any(String),
roomName: 'Second Chatting User',
lastMessageAt: null,
unreadCount: 0,
lastMessage: null,
users: expect.arrayContaining([
{
expect.objectContaining({
_id: 'chatting-user',
id: 'chatting-user',
name: 'Chatting User',
avatar: {
url: expect.any(String),
},
},
{
}),
expect.objectContaining({
_id: 'second-chatting-user',
id: 'second-chatting-user',
name: 'Second Chatting User',
avatar: {
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),
roomId: expect.any(String),
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', () => {
let result: any = null
beforeAll(async () => {
authenticatedUser = await chattingUser.toJson()
result = await query({ query: roomQuery() })
})
describe('as chatter of room', () => {
it('returns the room', async () => {
expect(
@ -556,34 +578,19 @@ describe('Room', () => {
{
id: expect.any(String),
roomId: expect.any(String),
roomName: 'Third Chatting User',
users: expect.arrayContaining([
{
_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),
},
},
]),
roomName: result.data.Room[0].roomName,
users: expect.any(Array),
},
],
},
})
})
describe('as not chatter of room', () => {
beforeAll(async () => {
authenticatedUser = await notChattingUser.toJson()
})
it('returns no room', async () => {
authenticatedUser = await notChattingUser.toJson()
expect(

View File

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

View File

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

View File

@ -14,7 +14,7 @@ import bodyParser from 'body-parser'
import { graphqlUploadExpress } from 'graphql-upload'
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'
const { REDIS_DOMAIN, REDIS_PORT, REDIS_PASSWORD } = CONFIG
let prodPubsub, devPubsub

View File

@ -61,7 +61,12 @@
<script>
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 { mapGetters, mapMutations } from 'vuex'
@ -169,6 +174,21 @@ export default {
} else {
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: {
...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) {
// check for usersTag and change userid to username
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 = () => {
return gql`
mutation ($messageIds: [String!]) {

View File

@ -11,7 +11,7 @@ export const createRoom = () => gql`
export const roomQuery = () => gql`
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
roomId
roomName

View File

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

View File

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

View File

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