Messages - Makleido/ChatTestingApp GitHub Wiki
Responsible for being a service for messaging
Database
I've built a database of the default Users, Added a Messages table, which contains all messages after being stored there and they are all readed, and made a NewMessages table for incoming, unreaded messages, in case its easier to work with... Wanted to use cache, but something went wrong with it, and it was worse
API
Method |
Routes (api/auth/) |
Purpose |
GET |
chats |
Check if theres unreaded messages, and alert user |
GET |
users |
Get registrated users to chat with |
GET |
name |
Gives back your own name which is authenticated |
POST |
messages |
Gives back all the messages for the specificated sender-receiver |
POST |
send |
Send message to db |
POST |
delete |
Delete readed message from db (plans for changing only turning the specific message off, and will stay there, but wont be visible, also to 'delete' like this unreaded messages) |
PUT |
edit |
Edit readed message (plans for changing it to be able to change unreaded messages) |
Controller
Method |
Purpose |
__Construct |
authentication |
getAuth |
Get AuthController object |
getAuthUserName |
Get authenticated users name to work with easier |
getUsersToChat |
Returns a list of users |
sendMessage |
Sending/saving message in database |
editMessage |
Changes the message of a record both on readed and unreaded messages table (messages, new_messages) |
deleteMessage |
'delete' a message, it makes changes a state in db, and when the message is gone to frontend now it will show its deleted, also can do the same on readed and unreaded messages |
seenCheck |
If seen a new message send it to normal table |
messagesQuery |
A query for getting the readed messages, its for reducing the length of code, and make it readable, that its there only once |
messageCache |
Its for readed messages to put in cache, its for 60 seconds, mainly to save a bit of memory usage for server |
getMessages |
Returns all messages for the chat we wanted |
getUnreadedShow |
Returns users who sent us messages we didnt read yet |