-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* user token start * tests * refactor auth * caching * api * fix test * comment * expiry * batching * remove user token implementation * Revert "remove user token implementation" This reverts commit 1e1dd78. * refact auth * remove file * fix * refact client auth function * refact function * refact * fix * remove file * end turn route * responses * return message also * use cache for collectors * hintRespondingTo * incomingId * bump messaging client * turn id * collect flag * fix ui * backend validate user token is correct * schema * socket auth * update testing ui * bring changes * remove user token api * remove user token api * revert * remove correct user token api * bring changes * extract constant * verifyToken * fix tests * users.get * socket prevent lost requests * conversations socket * some refact and changes * refact schema validation * refact user rights check * remove nonsense * socket refact * move socket code at of api start * socket root class * remove private * refact schema * fix * fix * dont server client * remove ui from changes * custom timeout * bring changes * fix * tests start * fix * more tests * tests * pr comments * fix
- Loading branch information
1 parent
b16535d
commit 4c1141e
Showing
27 changed files
with
693 additions
and
366 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,38 @@ | ||
import Joi from 'joi' | ||
|
||
export const CreateConvoSchema = Joi.object({ | ||
userId: Joi.string().guid().required() | ||
}) | ||
|
||
export const GetConvoSchema = Joi.object({ | ||
id: Joi.string().guid().required() | ||
}) | ||
|
||
export const ListConvosSchema = Joi.object({ | ||
userId: Joi.string().guid().required(), | ||
limit: Joi.number().required() | ||
}) | ||
|
||
export const RecentConvoSchema = Joi.object({ | ||
userId: Joi.string().guid().required() | ||
}) | ||
|
||
export const UseConvoSocketSchema = Joi.object({ | ||
conversationId: Joi.string().guid().optional() | ||
}) | ||
const Api = { | ||
Create: Joi.object({ | ||
userId: Joi.string().guid().required() | ||
}), | ||
|
||
Get: Joi.object({ | ||
id: Joi.string().guid().required() | ||
}), | ||
|
||
List: Joi.object({ | ||
userId: Joi.string().guid().required(), | ||
limit: Joi.number().required() | ||
}), | ||
|
||
Recent: Joi.object({ | ||
userId: Joi.string().guid().required() | ||
}) | ||
} | ||
|
||
const Socket = { | ||
Create: Joi.object({}), | ||
|
||
Get: Joi.object({ | ||
id: Joi.string().guid().required() | ||
}), | ||
|
||
List: Joi.object({ | ||
limit: Joi.number().required() | ||
}), | ||
|
||
Delete: Joi.object({ | ||
id: Joi.string().guid().required() | ||
}) | ||
} | ||
|
||
export const Schema = { Api, Socket } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { SocketManager, SocketRequest } from '../socket/manager' | ||
import { UserService } from '../users/service' | ||
import { Schema } from './schema' | ||
import { ConversationService } from './service' | ||
|
||
export class ConversationSocket { | ||
constructor(private sockets: SocketManager, private users: UserService, private conversations: ConversationService) {} | ||
|
||
setup() { | ||
this.sockets.handle('conversations.create', Schema.Socket.Create, this.create.bind(this)) | ||
this.sockets.handle('conversations.get', Schema.Socket.Get, this.get.bind(this)) | ||
this.sockets.handle('conversations.list', Schema.Socket.List, this.list.bind(this)) | ||
this.sockets.handle('conversations.delete', Schema.Socket.Delete, this.delete.bind(this)) | ||
} | ||
|
||
async create(socket: SocketRequest) { | ||
const user = await this.users.get(socket.userId) | ||
const conversation = await this.conversations.create(user!.clientId, user!.id) | ||
|
||
socket.reply(conversation) | ||
} | ||
|
||
async get(socket: SocketRequest) { | ||
const { id } = socket.data | ||
const conversation = await this.conversations.get(id) | ||
|
||
if (!conversation || conversation.userId !== socket.userId) { | ||
return socket.reply(undefined) | ||
} | ||
|
||
socket.reply(conversation) | ||
} | ||
|
||
async list(socket: SocketRequest) { | ||
const { limit } = socket.data | ||
|
||
const user = await this.users.get(socket.userId) | ||
const conversations = await this.conversations.listByUserId(user!.clientId, socket.userId, +limit) | ||
|
||
socket.reply(conversations) | ||
} | ||
|
||
async delete(socket: SocketRequest) { | ||
const { id } = socket.data | ||
const conversation = await this.conversations.get(id) | ||
|
||
if (!conversation) { | ||
return socket.reply(false) | ||
} else if (conversation.userId !== socket.userId) { | ||
return socket.forbid('Conversation does not belong to user') | ||
} | ||
|
||
await this.conversations.delete(id) | ||
socket.reply(true) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.