Skip to content

London | 26-SDC-July | Raihan Sharif | Sprint 2 | Chat-app - #124

Open
RaihanSharif wants to merge 50 commits into
CodeYourFuture:mainfrom
RaihanSharif:main
Open

RaihanSharif wants to merge 50 commits into
CodeYourFuture:mainfrom
RaihanSharif:main

Conversation

@RaihanSharif

Copy link
Copy Markdown

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Task code

CYF-1162

Changelist

Created a live updating chat app that allows client to use either long polling or short polling.

  • Users can add new message

  • User is notified whenever a new message is created by another user

  • User can like or dislike a message

  • User is notified when a message is liked/disliked

backend: https://z4k2yzxetkpevkwf6zy9ea37.trainees.hosting.cyf.academy/messages
frontend: https://qhdyqohwxffxraktvwh1e0ys.trainees.hosting.cyf.academy/

@RaihanSharif RaihanSharif added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Sep 22, 2026
Only return list of messages, or a single message.

Clean up js doc
Messages can now be fetched or created using REST API.

Client can then fetch subsequent messages using event streaming.
create new message handling function.
@RaihanSharif

RaihanSharif commented Sep 29, 2026 •

Copy link
Copy Markdown
Author

Updated long/short polling implementation to use event-driven architecture. This prevents race conditions where some reactions may not be sent to a client if they arrive in the gap between processing one request and sending another. Resulting in reactions on one client being behind another, until they refresh.

@RaihanSharif

Copy link
Copy Markdown
Author

Update: I have now created the two separate apps, one polling and one Websocket. Both try to reuse as much code as possible, both in the frontend and backend.

Backend:

  • pollingApp.js
  • websocketApp.js
  • All other files are common between the two, such as the model, helper functions etc.

Frontend:

  • pollingScript.js
  • websocketScript.js
  • common.js -- contains the common files between the two.

Application uses HTTP post to create new messages and reactions and event streaming through either long polling or websocket to read new events.

Has some functionality to avoid race conditions by using even cursor per client.

@LonMcGregor LonMcGregor added the Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. label Oct 7, 2026
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown

The files changed in this PR don't match what is expected for this task.

Please check that you committed the right files for the task, and that there are no accidentally committed files from other sprints.

Please review the 'files changed' tab at the top of the page.

Here is an example of a file that has been changed on this branch but shouldn't be: .vscode/settings.json

If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed).

If this PR needs reviewed, please add the 'Needs Review' label to this PR after you have resolved the issues listed above.

@github-actions github-actions Bot removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 7, 2026

@LonMcGregor LonMcGregor left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work building this app, you've organised the files neatly and used classes where appropriate. I can also see places where you've given consideration to how you could extend with new functionality later.

I have spotted a few areas where you could improve, or where you could answer my questions to check your understanding of the code.

Comment thread .vscode/settings.json
@@ -0,0 +1,3 @@
{
"githubPullRequests.ignoredPullRequestBranches": ["main"]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these are just settings for your own machine, you shouldn't commit them to a PR. Is that the case here?

const msg_body = document.getElementById("message-input").value;

try {
await chatRequest(`${BACKEND_URL}/messages`, {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are using the socket based app, does sendMessage have any way of using the socket, or does it end up making extra requests?

@@ -0,0 +1,17 @@
export class Message {
static #nextId = 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain what the static keyword here means?

}

/**
* Adds an event to the event stream. {sequnce, type, timestamp, data}.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good use of documentation comments

/**
* Sends new events for each waiting request, if there are any events to send.
*/
notifyWaiters() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the difference between a "waiter" and a "subscriber"?

@LonMcGregor LonMcGregor added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels Oct 7, 2026
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown

The files changed in this PR don't match what is expected for this task.

Please check that you committed the right files for the task, and that there are no accidentally committed files from other sprints.

Please review the 'files changed' tab at the top of the page.

Here is an example of a file that has been changed on this branch but shouldn't be: .vscode/settings.json

If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed).

If this PR needs reviewed, please add the 'Needs Review' label to this PR after you have resolved the issues listed above.

1 similar comment
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown

The files changed in this PR don't match what is expected for this task.

Please check that you committed the right files for the task, and that there are no accidentally committed files from other sprints.

Please review the 'files changed' tab at the top of the page.

Here is an example of a file that has been changed on this branch but shouldn't be: .vscode/settings.json

If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed).

If this PR needs reviewed, please add the 'Needs Review' label to this PR after you have resolved the issues listed above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Reviewed Volunteer to add when completing a review with trainee action still to take.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants