Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SK-258 added encrypted_message_type for Message object #134

Merged
merged 4 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions APIs/JSON/validations/messages_schema_validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const messagesSchemaValidation = {
})
),
deleted_for: Joi.array().items(Joi.alternatives().try(Joi.object(), Joi.string(), Joi.number()).required()),
encrypted_message_type: Joi.number().allow(1, 0),
})
.or("body", "attachments"),
edit: Joi.object({
Expand Down
1 change: 1 addition & 0 deletions app/DTO/Response/message/create/public_fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class MessagePublicFields {
this.body = messageModel.body
this.attachments = messageModel.attachments
this.x = messageModel.x
this.encrypted_message_type = messageModel.encrypted_message_type

this.created_at = messageModel.created_at

Expand Down
1 change: 1 addition & 0 deletions app/new_models/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default class Message extends BaseModel {
"body",
"x",
"attachments",
"encrypted_message_type",

"created_at",

Expand Down
2 changes: 1 addition & 1 deletion app/providers/operations/encryption/register/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class EncryptionRegisterOperation {
async perform(ws, registerDeviceParams) {
const userId = this.sessionService.getSessionUserId(ws)
const deviceId = this.sessionService.getDeviceId(ws, userId)
const existingDevice = await this.encryptionService.encryptionRepo.findByDeviceId(deviceId, userId)
const existingDevice = await this.encryptionService.encryptionRepo.findByDeviceId(deviceId)

if (existingDevice) {
await this.encryptionService.update(existingDevice, registerDeviceParams)
Expand Down
8 changes: 4 additions & 4 deletions app/providers/repositories/encryption/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import BaseRepository from "../base.js"

class EncryptionRepository extends BaseRepository {
async findByDeviceId(device_id, user_id) {
const device = await this.findOne({ device_id, user_id })
async findByDeviceId(device_id) {
const device = await this.findOne({ device_id })

return device
}
Expand Down Expand Up @@ -44,7 +44,7 @@ class EncryptionRepository extends BaseRepository {
_id: 1,
identity_key: 1,
signed_key: 1,
one_time_pre_keys: 1,
one_time_pre_key: 1,
devices: 1,
}
const aggregatedResult = await this.aggregate([{ $match }, { $group }, { $sort }, { $project }])
Expand All @@ -56,7 +56,7 @@ class EncryptionRepository extends BaseRepository {
(result[obj._id] = obj.devices.map((device) => ({
identity_key: device.identity_key,
signed_key: device.signed_key,
one_time_pre_keys: Object.values(device.one_time_pre_keys)[0],
one_time_pre_key: Object.values(device.one_time_pre_keys)[0],
})))
)

Expand Down