Skip to content

Commit 03d80af

Browse files
Oleksandr1414IgorKhomenkoku9nov
authored
Release 0.26.0 (#138)
* SK-217 Implemented group chat images (#117) * SK-189 added `avatar_object` field for user object * SK-189 implemented the logic of creating links for downloading user avatars * SK-189 renamed downloadFile to getFileDownloadUrl * SK-217 added `image_object` for Conversation fields * SK-217 added `image_url` field to the system event * SK-217 added sending update request to other users * SK-217 cleanup * SK-217 minor fix * SK-217 added image_object for conversationCreate * SK-217 add log * SK-217 remove log * SK-217 add log * SK-217 remove log * SK-194 updated `typing` object (#121) * Sk-194 updated typing object * SK-194 updated API.md * SK-234 removed file name from uuid in file `object_id` (#122) * updated CHANGELOG.md (0.24.0 -> 0.25.0) * Updated tests for status typing (removed tests for deleted fields) * FM-27 added device_token for push subscription (#136) * Release 0.25.0 (#123) * SK-217 Implemented group chat images (#117) * SK-189 added `avatar_object` field for user object * SK-189 implemented the logic of creating links for downloading user avatars * SK-189 renamed downloadFile to getFileDownloadUrl * SK-217 added `image_object` for Conversation fields * SK-217 added `image_url` field to the system event * SK-217 added sending update request to other users * SK-217 cleanup * SK-217 minor fix * SK-217 added image_object for conversationCreate * SK-217 add log * SK-217 remove log * SK-217 add log * SK-217 remove log * SK-194 updated `typing` object (#121) * Sk-194 updated typing object * SK-194 updated API.md * SK-234 removed file name from uuid in file `object_id` (#122) * updated CHANGELOG.md (0.24.0 -> 0.25.0) * Release 0.25.0 (#124) * SK-217 Implemented group chat images (#117) * SK-189 added `avatar_object` field for user object * SK-189 implemented the logic of creating links for downloading user avatars * SK-189 renamed downloadFile to getFileDownloadUrl * SK-217 added `image_object` for Conversation fields * SK-217 added `image_url` field to the system event * SK-217 added sending update request to other users * SK-217 cleanup * SK-217 minor fix * SK-217 added image_object for conversationCreate * SK-217 add log * SK-217 remove log * SK-217 add log * SK-217 remove log * SK-194 updated `typing` object (#121) * Sk-194 updated typing object * SK-194 updated API.md * SK-234 removed file name from uuid in file `object_id` (#122) * updated CHANGELOG.md (0.24.0 -> 0.25.0) * Updated tests for status typing (removed tests for deleted fields) * Update API.md * Update README.md * Update README.md * Update README.md * Update README.md * updated package.json * Update README.md * Сhange development flow (#132) * FM-27 added `device_token` for push subscription * FM-27 minor cleanup * FM-27 removed `rsmq-promise`, updated bull queue methods * FM-27 renamed minor comments --------- Co-authored-by: IgorKhomenko <[email protected]> Co-authored-by: Igor Khomenko <[email protected]> Co-authored-by: ku9nov <[email protected]> * updated CHANGELOG.md * renamed env file --------- Co-authored-by: IgorKhomenko <[email protected]> Co-authored-by: Igor Khomenko <[email protected]> Co-authored-by: ku9nov <[email protected]>
1 parent d41da05 commit 03d80af

File tree

15 files changed

+76
-176
lines changed

15 files changed

+76
-176
lines changed

.env.example

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ HOSTNAME=NodeName
5151

5252
PUSH_QUEUE_DRIVER=sama_native
5353

54-
SAMA_NATIVE_PUSH_QUEUE_NAME=notification
54+
SAMA_NATIVE_PUSH_QUEUE_NAME=push_notifications
55+
5556

56-
RSM_CHAT_ALERT_QUEUE_NAME=TEST1
57-
RSM_PUSH_QUEUE_NAME=TEST2

APIs/JSON/controllers/push_notifications.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class PushNotificationsController extends BaseJSONController {
1616
async push_subscription_create(ws, data) {
1717
const {
1818
id: requestId,
19-
push_subscription_create: { platform, web_endpoint, web_key_auth, web_key_p256dh, device_udid },
19+
push_subscription_create: { web_endpoint, web_key_auth, web_key_p256dh, device_token, device_udid },
2020
} = data
2121

2222
const sessionService = ServiceLocatorContainer.use("SessionService")
@@ -26,7 +26,7 @@ class PushNotificationsController extends BaseJSONController {
2626
(
2727
await PushSubscription.findOneAndUpdate(
2828
{ device_udid, user_id: userId },
29-
{ $set: { web_endpoint, web_key_auth, web_key_p256dh } }
29+
{ $set: { web_endpoint, web_key_auth, web_key_p256dh, device_token } }
3030
)
3131
)?.value
3232
)

APIs/JSON/validations/push_notifications_schema_validation.js

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,30 @@ export const pushNotificationsSchemaValidation = {
1111
cause: ERROR_STATUES.INCORRECT_PLATFROM_TYPE,
1212
})
1313
),
14-
web_endpoint: Joi.string()
15-
.required()
16-
.error(
17-
new Error(ERROR_STATUES.INCORRECT_TOKEN.message, {
18-
cause: ERROR_STATUES.INCORRECT_TOKEN,
19-
})
20-
),
21-
web_key_auth: Joi.string()
22-
.required()
23-
.error(
24-
new Error(ERROR_STATUES.INCORRECT_TOKEN.message, {
25-
cause: ERROR_STATUES.INCORRECT_KEYS,
26-
})
27-
),
28-
web_key_p256dh: Joi.string()
29-
.required()
30-
.error(
31-
new Error(ERROR_STATUES.INCORRECT_TOKEN.message, {
32-
cause: ERROR_STATUES.INCORRECT_KEYS,
33-
})
34-
),
14+
web_endpoint: Joi.string().error(
15+
new Error(ERROR_STATUES.INCORRECT_TOKEN.message, {
16+
cause: ERROR_STATUES.INCORRECT_TOKEN,
17+
})
18+
),
19+
web_key_auth: Joi.string().error(
20+
new Error(ERROR_STATUES.INCORRECT_TOKEN.message, {
21+
cause: ERROR_STATUES.INCORRECT_KEYS,
22+
})
23+
),
24+
web_key_p256dh: Joi.string().error(
25+
new Error(ERROR_STATUES.INCORRECT_TOKEN.message, {
26+
cause: ERROR_STATUES.INCORRECT_KEYS,
27+
})
28+
),
3529
device_udid: Joi.string()
3630
.required()
3731
.error(
3832
new Error(ERROR_STATUES.INCORRECT_DEVICE_ID.message, {
3933
cause: ERROR_STATUES.INCORRECT_DEVICE_ID,
4034
})
4135
),
42-
}).required(),
36+
device_token: Joi.string(),
37+
}).or("web_endpoint", "device_token"),
4338
push_subscription_list: Joi.object({
4439
user_id: Joi.alternatives()
4540
.try(Joi.object(), Joi.string(), Joi.number())

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# Changelog
22

3+
## 0.26.0
4+
5+
### Features
6+
7+
- Implemented a new docker flow for the project build
8+
- Added `device_token` field for `push_sbuscription_create` request
9+
10+
### Updated
11+
12+
- Сhanged development flow
13+
- Updated environment variables
14+
- Updated tests for status typing
15+
316
## 0.25.0
417

518
### Features

app/lib/push_queue/base.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@ export default class BasePushQueue {
1515
return pushEvents
1616
}
1717

18+
async getSubscriptionsByPlatform(platform, user_id) {
19+
return await pushNotificationsRepository.getSubscriptionsByPlatform(platform, user_id)
20+
}
21+
1822
async createPush(pushQueueMessage) {
1923
if (pushQueueMessage instanceof CreateChatAlertEventOptions) {
20-
await this.createChatAlert(pushQueueMessage)
24+
return await this.createChatAlert(pushQueueMessage)
2125
} else if (pushQueueMessage instanceof CreatePushEventOptions) {
22-
await this.createPushEvents(pushQueueMessage)
26+
return await this.createPushEvents(pushQueueMessage)
2327
}
2428

2529
throw new Error("Unknown push message type")

app/lib/push_queue/rsm_queue.js

Lines changed: 0 additions & 56 deletions
This file was deleted.

app/lib/push_queue/sama_native_queue.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,32 @@ export default class SamaNativePushQueue extends BasePushQueue {
1919

2020
const pushEvents = await this.buildPushEvents(createPushEventOptions)
2121

22-
await this.addToQueue(pushEvents)
22+
await this.#addToQueue(pushEvents)
2323
}
2424

2525
async createPushEvents(createPushEventOptions) {
2626
const pushEvents = await this.buildPushEvents(createPushEventOptions)
2727

28-
await this.addToQueue(pushEvents)
28+
await this.#addToQueue(pushEvents)
2929

3030
return pushEvents
3131
}
3232

33-
async addToQueue(pushEvents) {
34-
const pushEventIds = pushEvents.map((pushEvent) => pushEvent.params._id.toString())
33+
async #addToQueue(pushEvents) {
34+
for (const pushEvent of pushEvents) {
35+
let devices = []
36+
const platform = pushEvent.params.platform
3537

36-
for (const pushEventId of pushEventIds) {
37-
await this.queue.add({ push_event_id: pushEventId })
38-
}
38+
for (const uid of pushEvent.params.user_ids) {
39+
const userDevices = await this.getSubscriptionsByPlatform(platform, uid)
40+
if (!userDevices.length) continue
41+
devices = devices.concat(userDevices)
42+
}
43+
44+
if (!Object.keys(devices).length) continue
3945

40-
return pushEventIds
46+
const data = { devices, message: pushEvent.params.message, platform }
47+
await this.queue.add(data)
48+
}
4149
}
4250
}

app/models/push_subscription.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export default class PushSubscription extends BaseModel {
1919
"web_key_auth",
2020
"web_key_p256dh",
2121
"device_udid",
22+
"device_token",
2223
]
2324
}
2425
}

app/repositories/push_notifications_repository.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class PushNotificationsRepository extends BaseRepository {
1010
this.PushSubscriptionModel = PushSubscriptionModel
1111
}
1212

13-
async usersPlatforms(users_ids) {
13+
async #usersPlatforms(users_ids) {
1414
let notificationChannelIds = new Set()
1515

1616
for (const user_id of users_ids) {
@@ -26,8 +26,17 @@ class PushNotificationsRepository extends BaseRepository {
2626
return [...notificationChannelIds]
2727
}
2828

29+
async getSubscriptionsByPlatform(platform, user_id) {
30+
return await this.PushSubscriptionModel.findAll({ platform, user_id }, [
31+
"web_endpoint",
32+
"web_key_auth",
33+
"web_key_p256dh",
34+
"device_token",
35+
])
36+
}
37+
2938
async createPushEvents(userId, userIds, payload, options) {
30-
const platforms = await this.usersPlatforms(userIds)
39+
const platforms = await this.#usersPlatforms(userIds)
3140

3241
const base64Payload = Buffer.from(JSON.stringify(payload)).toString("base64")
3342

docs/API.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,12 +1010,15 @@ If users are offline, they will receive a message once became online.
10101010
web_endpoint: 'enpoint',
10111011
web_key_auth: 'auth',
10121012
web_key_p256dh: 'p256dh',
1013+
device_token: "..."
10131014
device_udid: "deviceId"
10141015
},
10151016
id: "1",
10161017
},
10171018
};
10181019
1020+
The [`web_endpoint`, `web_key_auth`, `web_key_p256dh`] and `device_token` fields are interchangeable for different devices
1021+
10191022
{
10201023
response: {
10211024
id: "1",

index.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import Minio from "./app/lib/storage/minio.js"
1919
import S3 from "./app/lib/storage/s3.js"
2020
import Spaces from "./app/lib/storage/spaces.js"
2121

22-
import RSMPushQueue from "./app/lib/push_queue/rsm_queue.js"
2322
import SamaNativePushQueue from "./app/lib/push_queue/sama_native_queue.js"
2423

2524
import { connectToDBPromise, getDb } from "./app/lib/db.js"
@@ -43,12 +42,6 @@ switch (process.env.STORAGE_DRIVER) {
4342
}
4443

4544
switch (process.env.PUSH_QUEUE_DRIVER) {
46-
case "rsmq":
47-
RuntimeDefinedContext.PUSH_QUEUE_DRIVER = new RSMPushQueue(RedisClient.client, {
48-
chatAlertQueueName: process.env.RSM_CHAT_ALERT_QUEUE_NAME,
49-
pushQueueName: process.env.RSM_PUSH_QUEUE_NAME,
50-
})
51-
break
5245
case "sama_native":
5346
default:
5447
RuntimeDefinedContext.PUSH_QUEUE_DRIVER = new SamaNativePushQueue(

0 commit comments

Comments
 (0)