From be599d73ecf773527ab65791821c3ef080889090 Mon Sep 17 00:00:00 2001 From: Mohammed Abdoon Date: Thu, 25 Jun 2026 01:25:55 +0100 Subject: [PATCH 01/14] add files --- chat-app/.gitignore | 1 + chat-app/backEnd/package-lock.json | 913 +++++++++++++++++++++++++++++ chat-app/backEnd/package.json | 8 + chat-app/backEnd/server.js | 46 ++ chat-app/frontEnd/index.html | 32 + chat-app/frontEnd/script.js | 92 +++ chat-app/frontEnd/style.css | 91 +++ chat-app/package-lock.json | 47 ++ chat-app/package.json | 5 + chat-app/tempFile.file | 0 10 files changed, 1235 insertions(+) create mode 100644 chat-app/.gitignore create mode 100644 chat-app/backEnd/package-lock.json create mode 100644 chat-app/backEnd/package.json create mode 100644 chat-app/backEnd/server.js create mode 100644 chat-app/frontEnd/index.html create mode 100644 chat-app/frontEnd/script.js create mode 100644 chat-app/frontEnd/style.css create mode 100644 chat-app/package-lock.json create mode 100644 chat-app/package.json create mode 100644 chat-app/tempFile.file diff --git a/chat-app/.gitignore b/chat-app/.gitignore new file mode 100644 index 00000000..c2658d7d --- /dev/null +++ b/chat-app/.gitignore @@ -0,0 +1 @@ +node_modules/ diff --git a/chat-app/backEnd/package-lock.json b/chat-app/backEnd/package-lock.json new file mode 100644 index 00000000..a6b8f709 --- /dev/null +++ b/chat-app/backEnd/package-lock.json @@ -0,0 +1,913 @@ +{ + "name": "backEnd", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "dependencies": { + "cors": "^2.8.6", + "cros": "^1.1.0", + "express": "^5.2.1" + } + }, + "node_modules/accepts": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-2.0.0.tgz", + "integrity": "sha512-5cvg6CtKwfgdmVqY1WIiXKc3Q1bkRqGLi+2W/6ao+6Y7gu/RCwRuAhGEzh5B4KlszSuTLgZYuqFqo5bImjNKng==", + "license": "MIT", + "dependencies": { + "mime-types": "^3.0.0", + "negotiator": "^1.0.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/argparse": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", + "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", + "license": "Python-2.0" + }, + "node_modules/body-parser": { + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-2.2.2.tgz", + "integrity": "sha512-oP5VkATKlNwcgvxi0vM0p/D3n2C3EReYVX+DNYs5TjZFn/oQt2j+4sVJtSMr18pdRr8wjTcBl6LoV+FUwzPmNA==", + "license": "MIT", + "dependencies": { + "bytes": "^3.1.2", + "content-type": "^1.0.5", + "debug": "^4.4.3", + "http-errors": "^2.0.0", + "iconv-lite": "^0.7.0", + "on-finished": "^2.4.1", + "qs": "^6.14.1", + "raw-body": "^3.0.1", + "type-is": "^2.0.1" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/bytes": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", + "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/call-bind-apply-helpers": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz", + "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/call-bound": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.4.tgz", + "integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "get-intrinsic": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/commander": { + "version": "11.1.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-11.1.0.tgz", + "integrity": "sha512-yPVavfyCcRhmorC7rWlkHn15b4wDVgVmBA7kV4QVBsF7kv/9TKJAbAXVTxvTnwP8HHKjRCJDClKbciiYS7p0DQ==", + "license": "MIT", + "engines": { + "node": ">=16" + } + }, + "node_modules/content-disposition": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-1.1.0.tgz", + "integrity": "sha512-5jRCH9Z/+DRP7rkvY83B+yGIGX96OYdJmzngqnw2SBSxqCFPd0w2km3s5iawpGX8krnwSGmF0FW5Nhr0Hfai3g==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/content-type": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz", + "integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz", + "integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie-signature": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.2.2.tgz", + "integrity": "sha512-D76uU73ulSXrD1UXF4KE2TMxVVwhsnCgfAyTg9k8P6KGZjlXKrOLe4dJQKI3Bxi5wjesZoFXJWElNWBjPZMbhg==", + "license": "MIT", + "engines": { + "node": ">=6.6.0" + } + }, + "node_modules/cors": { + "version": "2.8.6", + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.6.tgz", + "integrity": "sha512-tJtZBBHA6vjIAaF6EnIaq6laBBP9aq/Y3ouVJjEfoHbRBcHBAHYcMh/w8LDrk2PvIMMq8gmopa5D4V8RmbrxGw==", + "license": "MIT", + "dependencies": { + "object-assign": "^4", + "vary": "^1" + }, + "engines": { + "node": ">= 0.10" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/cros": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/cros/-/cros-1.1.0.tgz", + "integrity": "sha512-agCKLNDjy3fCXBlpU4qRcUtpfK0Yh91R6EcJcrJe9rgWrNR6w1Jw8MHyNr0yWvyi3r00WK2yK6VXo4OmsmT12w==", + "license": "MIT", + "dependencies": { + "commander": "^11.1.0", + "js-yaml": "^4.1.0", + "ws": "^8.18.1" + }, + "bin": { + "cros": "bin/cli.js" + } + }, + "node_modules/debug": { + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", + "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", + "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/depd": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", + "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/dunder-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", + "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.1", + "es-errors": "^1.3.0", + "gopd": "^1.2.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/ee-first": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", + "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==", + "license": "MIT" + }, + "node_modules/encodeurl": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.0.tgz", + "integrity": "sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/es-define-property": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", + "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", + "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-object-atoms": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz", + "integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/escape-html": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", + "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==", + "license": "MIT" + }, + "node_modules/etag": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", + "integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/express": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/express/-/express-5.2.1.tgz", + "integrity": "sha512-hIS4idWWai69NezIdRt2xFVofaF4j+6INOpJlVOLDO8zXGpUVEVzIYk12UUi2JzjEzWL3IOAxcTubgz9Po0yXw==", + "license": "MIT", + "dependencies": { + "accepts": "^2.0.0", + "body-parser": "^2.2.1", + "content-disposition": "^1.0.0", + "content-type": "^1.0.5", + "cookie": "^0.7.1", + "cookie-signature": "^1.2.1", + "debug": "^4.4.0", + "depd": "^2.0.0", + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "etag": "^1.8.1", + "finalhandler": "^2.1.0", + "fresh": "^2.0.0", + "http-errors": "^2.0.0", + "merge-descriptors": "^2.0.0", + "mime-types": "^3.0.0", + "on-finished": "^2.4.1", + "once": "^1.4.0", + "parseurl": "^1.3.3", + "proxy-addr": "^2.0.7", + "qs": "^6.14.0", + "range-parser": "^1.2.1", + "router": "^2.2.0", + "send": "^1.1.0", + "serve-static": "^2.2.0", + "statuses": "^2.0.1", + "type-is": "^2.0.1", + "vary": "^1.1.2" + }, + "engines": { + "node": ">= 18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/finalhandler": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-2.1.1.tgz", + "integrity": "sha512-S8KoZgRZN+a5rNwqTxlZZePjT/4cnm0ROV70LedRHZ0p8u9fRID0hJUZQpkKLzro8LfmC8sx23bY6tVNxv8pQA==", + "license": "MIT", + "dependencies": { + "debug": "^4.4.0", + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "on-finished": "^2.4.1", + "parseurl": "^1.3.3", + "statuses": "^2.0.1" + }, + "engines": { + "node": ">= 18.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/forwarded": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", + "integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/fresh": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/fresh/-/fresh-2.0.0.tgz", + "integrity": "sha512-Rx/WycZ60HOaqLKAi6cHRKKI7zxWbJ31MhntmtwMoaTeF7XFH9hhBp8vITaMidfljRQ6eYWCKkaTK+ykVJHP2A==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/function-bind": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-intrinsic": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz", + "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "es-define-property": "^1.0.1", + "es-errors": "^1.3.0", + "es-object-atoms": "^1.1.1", + "function-bind": "^1.1.2", + "get-proto": "^1.0.1", + "gopd": "^1.2.0", + "has-symbols": "^1.1.0", + "hasown": "^2.0.2", + "math-intrinsics": "^1.1.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz", + "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==", + "license": "MIT", + "dependencies": { + "dunder-proto": "^1.0.1", + "es-object-atoms": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/gopd": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", + "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-symbols": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", + "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/hasown": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.3.tgz", + "integrity": "sha512-ej4AhfhfL2Q2zpMmLo7U1Uv9+PyhIZpgQLGT1F9miIGmiCJIoCgSmczFdrc97mWT4kVY72KA+WnnhJ5pghSvSg==", + "license": "MIT", + "dependencies": { + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/http-errors": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.1.tgz", + "integrity": "sha512-4FbRdAX+bSdmo4AUFuS0WNiPz8NgFt+r8ThgNWmlrjQjt1Q7ZR9+zTlce2859x4KSXrwIsaeTqDoKQmtP8pLmQ==", + "license": "MIT", + "dependencies": { + "depd": "~2.0.0", + "inherits": "~2.0.4", + "setprototypeof": "~1.2.0", + "statuses": "~2.0.2", + "toidentifier": "~1.0.1" + }, + "engines": { + "node": ">= 0.8" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/iconv-lite": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.7.2.tgz", + "integrity": "sha512-im9DjEDQ55s9fL4EYzOAv0yMqmMBSZp6G0VvFyTMPKWxiSBHUj9NW/qqLmXUwXrrM7AvqSlTCfvqRb0cM8yYqw==", + "license": "MIT", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3.0.0" + }, + "engines": { + "node": ">=0.10.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "license": "ISC" + }, + "node_modules/ipaddr.js": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", + "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==", + "license": "MIT", + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/is-promise": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-4.0.0.tgz", + "integrity": "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ==", + "license": "MIT" + }, + "node_modules/js-yaml": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.1.tgz", + "integrity": "sha512-qQKT4zQxXl8lLwBtHMWwaTcGfFOZviOJet3Oy/xmGk2gZH677CJM9EvtfdSkgWcATZhj/55JZ0rmy3myCT5lsA==", + "license": "MIT", + "dependencies": { + "argparse": "^2.0.1" + }, + "bin": { + "js-yaml": "bin/js-yaml.js" + } + }, + "node_modules/math-intrinsics": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", + "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/media-typer": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-1.1.0.tgz", + "integrity": "sha512-aisnrDP4GNe06UcKFnV5bfMNPBUw4jsLGaWwWfnH3v02GnBuXX2MCVn5RbrWo0j3pczUilYblq7fQ7Nw2t5XKw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/merge-descriptors": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-2.0.0.tgz", + "integrity": "sha512-Snk314V5ayFLhp3fkUREub6WtjBfPdCPY1Ln8/8munuLuiYhsABgBVWsozAG+MWMbVEvcdcpbi9R7ww22l9Q3g==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/mime-db": { + "version": "1.54.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.54.0.tgz", + "integrity": "sha512-aU5EJuIN2WDemCcAp2vFBfp/m4EAhWJnUNSSw0ixs7/kXbd6Pg64EmwJkNdFhB8aWt1sH2CTXrLxo/iAGV3oPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-3.0.2.tgz", + "integrity": "sha512-Lbgzdk0h4juoQ9fCKXW4by0UJqj+nOOrI9MJ1sSj4nI8aI2eo1qmvQEie4VD1glsS250n15LsWsYtCugiStS5A==", + "license": "MIT", + "dependencies": { + "mime-db": "^1.54.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "license": "MIT" + }, + "node_modules/negotiator": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-1.0.0.tgz", + "integrity": "sha512-8Ofs/AUQh8MaEcrlq5xOX0CQ9ypTF5dl78mjlMNfOK08fzpgTHQRQPBxcPlEtIw0yRpws+Zo/3r+5WRby7u3Gg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/object-inspect": { + "version": "1.13.4", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz", + "integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/on-finished": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz", + "integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==", + "license": "MIT", + "dependencies": { + "ee-first": "1.1.1" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", + "license": "ISC", + "dependencies": { + "wrappy": "1" + } + }, + "node_modules/parseurl": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", + "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/path-to-regexp": { + "version": "8.4.2", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-8.4.2.tgz", + "integrity": "sha512-qRcuIdP69NPm4qbACK+aDogI5CBDMi1jKe0ry5rSQJz8JVLsC7jV8XpiJjGRLLol3N+R5ihGYcrPLTno6pAdBA==", + "license": "MIT", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/proxy-addr": { + "version": "2.0.7", + "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", + "integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==", + "license": "MIT", + "dependencies": { + "forwarded": "0.2.0", + "ipaddr.js": "1.9.1" + }, + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/qs": { + "version": "6.15.1", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.15.1.tgz", + "integrity": "sha512-6YHEFRL9mfgcAvql/XhwTvf5jKcOiiupt2FiJxHkiX1z4j7WL8J/jRHYLluORvc1XxB5rV20KoeK00gVJamspg==", + "license": "BSD-3-Clause", + "dependencies": { + "side-channel": "^1.1.0" + }, + "engines": { + "node": ">=0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/range-parser": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", + "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/raw-body": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-3.0.2.tgz", + "integrity": "sha512-K5zQjDllxWkf7Z5xJdV0/B0WTNqx6vxG70zJE4N0kBs4LovmEYWJzQGxC9bS9RAKu3bgM40lrd5zoLJ12MQ5BA==", + "license": "MIT", + "dependencies": { + "bytes": "~3.1.2", + "http-errors": "~2.0.1", + "iconv-lite": "~0.7.0", + "unpipe": "~1.0.0" + }, + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/router": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/router/-/router-2.2.0.tgz", + "integrity": "sha512-nLTrUKm2UyiL7rlhapu/Zl45FwNgkZGaCpZbIHajDYgwlJCOzLSk+cIPAnsEqV955GjILJnKbdQC1nVPz+gAYQ==", + "license": "MIT", + "dependencies": { + "debug": "^4.4.0", + "depd": "^2.0.0", + "is-promise": "^4.0.0", + "parseurl": "^1.3.3", + "path-to-regexp": "^8.0.0" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", + "license": "MIT" + }, + "node_modules/send": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/send/-/send-1.2.1.tgz", + "integrity": "sha512-1gnZf7DFcoIcajTjTwjwuDjzuz4PPcY2StKPlsGAQ1+YH20IRVrBaXSWmdjowTJ6u8Rc01PoYOGHXfP1mYcZNQ==", + "license": "MIT", + "dependencies": { + "debug": "^4.4.3", + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "etag": "^1.8.1", + "fresh": "^2.0.0", + "http-errors": "^2.0.1", + "mime-types": "^3.0.2", + "ms": "^2.1.3", + "on-finished": "^2.4.1", + "range-parser": "^1.2.1", + "statuses": "^2.0.2" + }, + "engines": { + "node": ">= 18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/serve-static": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-2.2.1.tgz", + "integrity": "sha512-xRXBn0pPqQTVQiC8wyQrKs2MOlX24zQ0POGaj0kultvoOCstBQM5yvOhAVSUwOMjQtTvsPWoNCHfPGwaaQJhTw==", + "license": "MIT", + "dependencies": { + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "parseurl": "^1.3.3", + "send": "^1.2.0" + }, + "engines": { + "node": ">= 18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/setprototypeof": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", + "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==", + "license": "ISC" + }, + "node_modules/side-channel": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.0.tgz", + "integrity": "sha512-ZX99e6tRweoUXqR+VBrslhda51Nh5MTQwou5tnUDgbtyM0dBgmhEDtWGP/xbKn6hqfPRHujUNwz5fy/wbbhnpw==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "object-inspect": "^1.13.3", + "side-channel-list": "^1.0.0", + "side-channel-map": "^1.0.1", + "side-channel-weakmap": "^1.0.2" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-list": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/side-channel-list/-/side-channel-list-1.0.1.tgz", + "integrity": "sha512-mjn/0bi/oUURjc5Xl7IaWi/OJJJumuoJFQJfDDyO46+hBWsfaVM65TBHq2eoZBhzl9EchxOijpkbRC8SVBQU0w==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "object-inspect": "^1.13.4" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-map": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/side-channel-map/-/side-channel-map-1.0.1.tgz", + "integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==", + "license": "MIT", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-weakmap": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz", + "integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==", + "license": "MIT", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3", + "side-channel-map": "^1.0.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/statuses": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz", + "integrity": "sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/toidentifier": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", + "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==", + "license": "MIT", + "engines": { + "node": ">=0.6" + } + }, + "node_modules/type-is": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/type-is/-/type-is-2.0.1.tgz", + "integrity": "sha512-OZs6gsjF4vMp32qrCbiVSkrFmXtG/AZhY3t0iAMrMBiAZyV9oALtXO8hsrHbMXF9x6L3grlFuwW2oAz7cav+Gw==", + "license": "MIT", + "dependencies": { + "content-type": "^1.0.5", + "media-typer": "^1.1.0", + "mime-types": "^3.0.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/unpipe": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", + "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/vary": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", + "integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", + "license": "ISC" + }, + "node_modules/ws": { + "version": "8.20.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.20.0.tgz", + "integrity": "sha512-sAt8BhgNbzCtgGbt2OxmpuryO63ZoDk/sqaB/znQm94T4fCEsy/yV+7CdC1kJhOU9lboAEU7R3kquuycDoibVA==", + "license": "MIT", + "engines": { + "node": ">=10.0.0" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": ">=5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } + } + } + } +} diff --git a/chat-app/backEnd/package.json b/chat-app/backEnd/package.json new file mode 100644 index 00000000..f5df26a1 --- /dev/null +++ b/chat-app/backEnd/package.json @@ -0,0 +1,8 @@ +{ + "dependencies": { + "cors": "^2.8.6", + "cros": "^1.1.0", + "express": "^5.2.1" + }, + "type": "module" +} diff --git a/chat-app/backEnd/server.js b/chat-app/backEnd/server.js new file mode 100644 index 00000000..316c17ce --- /dev/null +++ b/chat-app/backEnd/server.js @@ -0,0 +1,46 @@ +import express from "express"; +import cors from "cors"; + +let messages = [ + { + message: "Hi! welcome to the app, you can send messages now.", + sender: "Mohammed Abdoon", + timestamp: 1, + }, +]; + +const app = express(); +const PORT = 3000; + +app.use( + cors({ + origin: [ + "http://localhost:5501", + "https://m-abdoon-chatapp-frontend.hosting.codeyourfuture.io", + ], + }), +); +app.use(express.json()); + +app.get("/getMessages", (req, res) => { + // since=timestamp + const since = parseInt(req.query.since) || 0; + const newMessages = messages.filter((msg) => msg.timestamp > since); + res.json(newMessages); +}); + +app.post("/sendMessage", (req, res) => { + const { message, sender } = req.body; + if (message && sender) { + messages.push({ message, sender, timestamp: Date.now() }); + + console.log("New message received:", { message, sender }); + res.status(200).json({ success: true }); + } else { + res.status(400).json({ success: false, error: "Invalid message data" }); + } +}); + +app.listen(PORT, () => { + console.log(`Server is running on port ${PORT}`); +}); diff --git a/chat-app/frontEnd/index.html b/chat-app/frontEnd/index.html new file mode 100644 index 00000000..a42876dd --- /dev/null +++ b/chat-app/frontEnd/index.html @@ -0,0 +1,32 @@ + + + + + + + Group Chat + + + + + + +
+ +
+ Group Chat +
+ +
+
+ +
+ + +
+ +
+ + + + \ No newline at end of file diff --git a/chat-app/frontEnd/script.js b/chat-app/frontEnd/script.js new file mode 100644 index 00000000..7842c610 --- /dev/null +++ b/chat-app/frontEnd/script.js @@ -0,0 +1,92 @@ +const appServerURL = "http://localhost:3000/"; +// const appServerURL = "https://m-abdoon-chatapp-backend.hosting.codeyourfuture.io/"; + +const currentUser = prompt("Enter your name:") || "Unknown"; + +let lastTimestamp = 0; + +async function setup() { + await renderMessages(); + + const messageText = document.getElementById("messageText"); + const submitMessage = document.getElementById("submitMessage"); + + submitMessage.addEventListener("click", async (e) => { + e.preventDefault(); + const message = messageText.value.trim(); + if (message) { + const success = await sendMessage(message); + if (success) { + messageText.value = ""; + } else { + alert("Failed to send message. Please try again."); + } + } + }); + + setInterval(pollNewMessages, 500); +} + +async function pollNewMessages() { + const newMessages = await fetchMessages(lastTimestamp); + if (newMessages.length > 0) { + appendMessages(newMessages); + } +} + +async function renderMessages() { + const messages = await fetchMessages(0); + messages.sort((a, b) => a.timestamp - b.timestamp); + appendMessages(messages); +} + +function appendMessages(messages) { + const messagesContainer = document.querySelector(".chat-messages"); + messages.sort((a, b) => a.timestamp - b.timestamp); + + messages.forEach((message) => { + const role = currentUser === message.sender ? "sent" : "received"; + + const div = document.createElement("div"); + div.className = `message ${role}`; + div.innerHTML = ` + ${message.sender} +

${message.message}

+ `; + messagesContainer.appendChild(div); + + if (message.timestamp > lastTimestamp) { + lastTimestamp = message.timestamp; + } + }); + + messagesContainer.scrollTop = messagesContainer.scrollHeight; +} + +async function fetchMessages(lastTimestamp = 0) { + try { + const response = await fetch( + `${appServerURL}getMessages?since=${lastTimestamp}`, + ); + const data = await response.json(); + return data; + } catch (error) { + return []; + } +} + +async function sendMessage(message) { + try { + const response = await fetch(`${appServerURL}sendMessage`, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ message, sender: currentUser }), + }); + const data = await response.json(); + return data.success; + } catch (error) { + return false; + } +} + +window.onload = setup; diff --git a/chat-app/frontEnd/style.css b/chat-app/frontEnd/style.css new file mode 100644 index 00000000..083ed9bd --- /dev/null +++ b/chat-app/frontEnd/style.css @@ -0,0 +1,91 @@ +body { + margin: 0; + font-family: Arial, sans-serif; + background-color: #2f2f2f; + display: flex; + justify-content: center; + align-items: center; + height: 100vh; +} + +.chat-container { + width: 400px; + height: 600px; + background-color: #1e1e1e; + border-radius: 10px; + display: flex; + flex-direction: column; + overflow: hidden; +} + +.chat-header { + background-color: #4dd0e1; + color: black; + padding: 15px; + font-size: 20px; + font-weight: bold; +} + +.chat-messages { + flex: 1; + padding: 15px; + overflow-y: auto; + display: flex; + flex-direction: column; + gap: 10px; +} + +.message { + padding: 10px 15px; + border-radius: 10px; + max-width: 70%; + display: flex; + flex-direction: column; +} + +.received { + background-color: #3b3b3b; + color: white; + align-self: flex-start; +} + +.sent { + background-color: #4dd0e1; + color: black; + align-self: flex-end; +} + +.sender-name { + font-size: 12px; + opacity: 0.7; + margin-bottom: 5px; + font-weight: bold; +} + +.message p { + margin: 0; +} + +.chat-input-area { + display: flex; + padding: 10px; + background-color: #2a2a2a; +} + +.chat-input-area input { + flex: 1; + padding: 10px; + border: none; + border-radius: 5px; + font-size: 16px; +} + +.chat-input-area button { + margin-left: 10px; + padding: 10px 15px; + border: none; + background-color: #4dd0e1; + color: black; + border-radius: 5px; + cursor: pointer; +} diff --git a/chat-app/package-lock.json b/chat-app/package-lock.json new file mode 100644 index 00000000..fa9a17bd --- /dev/null +++ b/chat-app/package-lock.json @@ -0,0 +1,47 @@ +{ + "name": "chat-app", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "dependencies": { + "cors": "^2.8.6" + } + }, + "node_modules/cors": { + "version": "2.8.6", + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.6.tgz", + "integrity": "sha512-tJtZBBHA6vjIAaF6EnIaq6laBBP9aq/Y3ouVJjEfoHbRBcHBAHYcMh/w8LDrk2PvIMMq8gmopa5D4V8RmbrxGw==", + "license": "MIT", + "dependencies": { + "object-assign": "^4", + "vary": "^1" + }, + "engines": { + "node": ">= 0.10" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/vary": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", + "integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + } + } +} diff --git a/chat-app/package.json b/chat-app/package.json new file mode 100644 index 00000000..c1217e12 --- /dev/null +++ b/chat-app/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "cors": "^2.8.6" + } +} diff --git a/chat-app/tempFile.file b/chat-app/tempFile.file new file mode 100644 index 00000000..e69de29b From 33879068bed3070248185e8fc9fc8b6dc8a4fd60 Mon Sep 17 00:00:00 2001 From: Mohammed Abdoon Date: Thu, 25 Jun 2026 01:54:50 +0100 Subject: [PATCH 02/14] set links & add likes&dislikes functionality --- chat-app/backEnd/server.js | 36 +++++++++++++++++++++-- chat-app/frontEnd/script.js | 58 +++++++++++++++++++++++++++---------- chat-app/frontEnd/style.css | 46 ++++++++++++++++++++++++++--- chat-app/tempFile.file | 0 4 files changed, 117 insertions(+), 23 deletions(-) delete mode 100644 chat-app/tempFile.file diff --git a/chat-app/backEnd/server.js b/chat-app/backEnd/server.js index 316c17ce..f7a97073 100644 --- a/chat-app/backEnd/server.js +++ b/chat-app/backEnd/server.js @@ -3,9 +3,12 @@ import cors from "cors"; let messages = [ { + id: 1, message: "Hi! welcome to the app, you can send messages now.", sender: "Mohammed Abdoon", timestamp: 1, + likes: 0, + dislikes: 0, }, ]; @@ -16,14 +19,14 @@ app.use( cors({ origin: [ "http://localhost:5501", - "https://m-abdoon-chatapp-frontend.hosting.codeyourfuture.io", + "http://127.0.0.1:5500", + "https://m-abdoon-chatapp.hosting.codeyourfuture.io", ], }), ); app.use(express.json()); app.get("/getMessages", (req, res) => { - // since=timestamp const since = parseInt(req.query.since) || 0; const newMessages = messages.filter((msg) => msg.timestamp > since); res.json(newMessages); @@ -32,7 +35,15 @@ app.get("/getMessages", (req, res) => { app.post("/sendMessage", (req, res) => { const { message, sender } = req.body; if (message && sender) { - messages.push({ message, sender, timestamp: Date.now() }); + const timestamp = Date.now(); + messages.push({ + id: timestamp, + message, + sender, + timestamp, + likes: 0, + dislikes: 0, + }); console.log("New message received:", { message, sender }); res.status(200).json({ success: true }); @@ -41,6 +52,25 @@ app.post("/sendMessage", (req, res) => { } }); +app.post("/reactMessage", (req, res) => { + const { id, reaction } = req.body; + const message = messages.find((msg) => msg.id === Number(id)); + + if (!message || !["like", "dislike"].includes(reaction)) { + return res + .status(400) + .json({ success: false, error: "Invalid reaction request" }); + } + + if (reaction === "like") { + message.likes += 1; + } else { + message.dislikes += 1; + } + + res.status(200).json({ success: true, message }); +}); + app.listen(PORT, () => { console.log(`Server is running on port ${PORT}`); }); diff --git a/chat-app/frontEnd/script.js b/chat-app/frontEnd/script.js index 7842c610..0588cf42 100644 --- a/chat-app/frontEnd/script.js +++ b/chat-app/frontEnd/script.js @@ -1,15 +1,15 @@ -const appServerURL = "http://localhost:3000/"; -// const appServerURL = "https://m-abdoon-chatapp-backend.hosting.codeyourfuture.io/"; +//const appServerURL = "http://localhost:3000/"; +const appServerURL = + "https://m-abdoon-chatapp-backend.hosting.codeyourfuture.io/"; const currentUser = prompt("Enter your name:") || "Unknown"; -let lastTimestamp = 0; - async function setup() { await renderMessages(); const messageText = document.getElementById("messageText"); const submitMessage = document.getElementById("submitMessage"); + const messagesContainer = document.querySelector(".chat-messages"); submitMessage.addEventListener("click", async (e) => { e.preventDefault(); @@ -18,31 +18,43 @@ async function setup() { const success = await sendMessage(message); if (success) { messageText.value = ""; + await renderMessages(); } else { alert("Failed to send message. Please try again."); } } }); - setInterval(pollNewMessages, 500); -} + messagesContainer.addEventListener("click", async (e) => { + const likeButton = e.target.closest(".like-button"); + const dislikeButton = e.target.closest(".dislike-button"); -async function pollNewMessages() { - const newMessages = await fetchMessages(lastTimestamp); - if (newMessages.length > 0) { - appendMessages(newMessages); - } + if (likeButton || dislikeButton) { + const button = likeButton || dislikeButton; + const messageId = button.dataset.id; + const reaction = likeButton ? "like" : "dislike"; + + const success = await reactToMessage(messageId, reaction); + if (success) { + await renderMessages(); + } + } + }); + + setInterval(renderMessages, 500); } async function renderMessages() { const messages = await fetchMessages(0); + const messagesContainer = document.querySelector(".chat-messages"); + messagesContainer.innerHTML = ""; + messages.sort((a, b) => a.timestamp - b.timestamp); appendMessages(messages); } function appendMessages(messages) { const messagesContainer = document.querySelector(".chat-messages"); - messages.sort((a, b) => a.timestamp - b.timestamp); messages.forEach((message) => { const role = currentUser === message.sender ? "sent" : "received"; @@ -52,12 +64,12 @@ function appendMessages(messages) { div.innerHTML = ` ${message.sender}

${message.message}

+
+ + +
`; messagesContainer.appendChild(div); - - if (message.timestamp > lastTimestamp) { - lastTimestamp = message.timestamp; - } }); messagesContainer.scrollTop = messagesContainer.scrollHeight; @@ -89,4 +101,18 @@ async function sendMessage(message) { } } +async function reactToMessage(id, reaction) { + try { + const response = await fetch(`${appServerURL}reactMessage`, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ id, reaction }), + }); + const data = await response.json(); + return data.success; + } catch (error) { + return false; + } +} + window.onload = setup; diff --git a/chat-app/frontEnd/style.css b/chat-app/frontEnd/style.css index 083ed9bd..b2fa4f8c 100644 --- a/chat-app/frontEnd/style.css +++ b/chat-app/frontEnd/style.css @@ -36,11 +36,12 @@ body { } .message { - padding: 10px 15px; - border-radius: 10px; + padding: 12px 14px; + border-radius: 14px; max-width: 70%; display: flex; flex-direction: column; + gap: 10px; } .received { @@ -57,13 +58,44 @@ body { .sender-name { font-size: 12px; - opacity: 0.7; - margin-bottom: 5px; + opacity: 0.75; + margin-bottom: 4px; font-weight: bold; } .message p { margin: 0; + line-height: 1.4; +} + +.reaction-row { + display: flex; + gap: 8px; +} + +.reaction-button { + border: none; + border-radius: 999px; + padding: 7px 12px; + font-size: 13px; + cursor: pointer; + transition: + transform 0.15s ease, + background-color 0.15s ease; +} + +.reaction-button:hover { + transform: translateY(-1px); +} + +.like-button { + background-color: rgba(255, 255, 255, 0.12); + color: #c8f0ff; +} + +.dislike-button { + background-color: rgba(255, 255, 255, 0.12); + color: #ffbaba; } .chat-input-area { @@ -78,6 +110,12 @@ body { border: none; border-radius: 5px; font-size: 16px; + background-color: #121212; + color: white; +} + +.chat-input-area input:focus { + outline: none; } .chat-input-area button { diff --git a/chat-app/tempFile.file b/chat-app/tempFile.file deleted file mode 100644 index e69de29b..00000000 From 422e630f4211fb7edf66863933b6cfa94cdb77d8 Mon Sep 17 00:00:00 2001 From: Mohammed Abdoon Date: Thu, 25 Jun 2026 02:05:32 +0100 Subject: [PATCH 03/14] fixed mispelled package name --- chat-app/backEnd/package-lock.json | 1 - 1 file changed, 1 deletion(-) diff --git a/chat-app/backEnd/package-lock.json b/chat-app/backEnd/package-lock.json index a6b8f709..c1ee6017 100644 --- a/chat-app/backEnd/package-lock.json +++ b/chat-app/backEnd/package-lock.json @@ -6,7 +6,6 @@ "": { "dependencies": { "cors": "^2.8.6", - "cros": "^1.1.0", "express": "^5.2.1" } }, From 8857b00c6a3391a38c74420c23992095a266472e Mon Sep 17 00:00:00 2001 From: Mohammed Abdoon Date: Tue, 30 Jun 2026 00:51:10 +0100 Subject: [PATCH 04/14] messages should be called according to the last message received --- chat-app/frontEnd/script.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/chat-app/frontEnd/script.js b/chat-app/frontEnd/script.js index 0588cf42..605f6c68 100644 --- a/chat-app/frontEnd/script.js +++ b/chat-app/frontEnd/script.js @@ -1,8 +1,9 @@ -//const appServerURL = "http://localhost:3000/"; -const appServerURL = - "https://m-abdoon-chatapp-backend.hosting.codeyourfuture.io/"; +const appServerURL = "http://localhost:3000/"; +// const appServerURL = +// "https://m-abdoon-chatapp-backend.hosting.codeyourfuture.io/"; const currentUser = prompt("Enter your name:") || "Unknown"; +let lastTimestamp = 0; async function setup() { await renderMessages(); @@ -45,10 +46,14 @@ async function setup() { } async function renderMessages() { - const messages = await fetchMessages(0); + const messages = await fetchMessages(lastTimestamp); const messagesContainer = document.querySelector(".chat-messages"); messagesContainer.innerHTML = ""; + if (messages.length > 0) { + lastTimestamp = Math.max(lastTimestamp, ...messages.map((m) => m.timestamp)); + } + messages.sort((a, b) => a.timestamp - b.timestamp); appendMessages(messages); } From 3f8d143035e96a5f6a8707690e9beaacd907a113 Mon Sep 17 00:00:00 2001 From: Mohammed Abdoon Date: Tue, 30 Jun 2026 00:55:47 +0100 Subject: [PATCH 05/14] console.log removed --- chat-app/backEnd/server.js | 1 - 1 file changed, 1 deletion(-) diff --git a/chat-app/backEnd/server.js b/chat-app/backEnd/server.js index f7a97073..2a93b790 100644 --- a/chat-app/backEnd/server.js +++ b/chat-app/backEnd/server.js @@ -45,7 +45,6 @@ app.post("/sendMessage", (req, res) => { dislikes: 0, }); - console.log("New message received:", { message, sender }); res.status(200).json({ success: true }); } else { res.status(400).json({ success: false, error: "Invalid message data" }); From 855deca32bc67aa2d0bb33ded207f8a20a76735c Mon Sep 17 00:00:00 2001 From: Mohammed Abdoon Date: Tue, 30 Jun 2026 01:34:42 +0100 Subject: [PATCH 06/14] fixed displaying last messages + used O(1) method instead of O(n) --- chat-app/backEnd/server.js | 2 +- chat-app/frontEnd/script.js | 29 +++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/chat-app/backEnd/server.js b/chat-app/backEnd/server.js index 2a93b790..2a9e6b5a 100644 --- a/chat-app/backEnd/server.js +++ b/chat-app/backEnd/server.js @@ -53,7 +53,7 @@ app.post("/sendMessage", (req, res) => { app.post("/reactMessage", (req, res) => { const { id, reaction } = req.body; - const message = messages.find((msg) => msg.id === Number(id)); + const message = messages.get(Number(id)); if (!message || !["like", "dislike"].includes(reaction)) { return res diff --git a/chat-app/frontEnd/script.js b/chat-app/frontEnd/script.js index 605f6c68..243920ee 100644 --- a/chat-app/frontEnd/script.js +++ b/chat-app/frontEnd/script.js @@ -4,6 +4,7 @@ const appServerURL = "http://localhost:3000/"; const currentUser = prompt("Enter your name:") || "Unknown"; let lastTimestamp = 0; +let displayedMessages = []; async function setup() { await renderMessages(); @@ -47,14 +48,16 @@ async function setup() { async function renderMessages() { const messages = await fetchMessages(lastTimestamp); - const messagesContainer = document.querySelector(".chat-messages"); - messagesContainer.innerHTML = ""; + if (messages.length === 0) { + return; + } if (messages.length > 0) { lastTimestamp = Math.max(lastTimestamp, ...messages.map((m) => m.timestamp)); } messages.sort((a, b) => a.timestamp - b.timestamp); + displayedMessages.push(...messages); appendMessages(messages); } @@ -114,10 +117,32 @@ async function reactToMessage(id, reaction) { body: JSON.stringify({ id, reaction }), }); const data = await response.json(); + + if (data.success && data.message) { + updateMessageReaction(data.message); + } + return data.success; } catch (error) { return false; } } +function updateMessageReaction(message) { + const existingMessage = displayedMessages.find((m) => m.id === message.id); + if (existingMessage) { + Object.assign(existingMessage, message); + } + + const likeButton = document.querySelector(`.like-button[data-id="${message.id}"]`); + const dislikeButton = document.querySelector(`.dislike-button[data-id="${message.id}"]`); + + if (likeButton) { + likeButton.textContent = `👍 ${message.likes || 0}`; + } + if (dislikeButton) { + dislikeButton.textContent = `👎 ${message.dislikes || 0}`; + } +} + window.onload = setup; From f4e4c9755a21b067598c6b18b59bbe21b0977a32 Mon Sep 17 00:00:00 2001 From: Mohammed Abdoon Date: Tue, 30 Jun 2026 01:42:04 +0100 Subject: [PATCH 07/14] fixed bug of html injection XSS --- chat-app/frontEnd/script.js | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/chat-app/frontEnd/script.js b/chat-app/frontEnd/script.js index 243920ee..df281e6a 100644 --- a/chat-app/frontEnd/script.js +++ b/chat-app/frontEnd/script.js @@ -69,14 +69,29 @@ function appendMessages(messages) { const div = document.createElement("div"); div.className = `message ${role}`; - div.innerHTML = ` - ${message.sender} -

${message.message}

-
- - -
- `; + + const senderName = document.createElement("span"); + senderName.className = "sender-name"; + senderName.textContent = message.sender; + + const text = document.createElement("p"); + text.textContent = message.message; + + const reactionRow = document.createElement("div"); + reactionRow.className = "reaction-row"; + + const likeButton = document.createElement("button"); + likeButton.className = "reaction-button like-button"; + likeButton.dataset.id = message.id; + likeButton.textContent = `👍 ${message.likes || 0}`; + + const dislikeButton = document.createElement("button"); + dislikeButton.className = "reaction-button dislike-button"; + dislikeButton.dataset.id = message.id; + dislikeButton.textContent = `👎 ${message.dislikes || 0}`; + + reactionRow.append(likeButton, dislikeButton); + div.append(senderName, text, reactionRow); messagesContainer.appendChild(div); }); From f08553550cbc41864726d61fd2848c8fc91dd9be Mon Sep 17 00:00:00 2001 From: Mohammed Abdoon Date: Tue, 30 Jun 2026 02:15:10 +0100 Subject: [PATCH 08/14] added reply-to-message feature --- chat-app/backEnd/server.js | 3 +- chat-app/frontEnd/index.html | 4 +++ chat-app/frontEnd/script.js | 68 ++++++++++++++++++++++++++++++++++-- chat-app/frontEnd/style.css | 54 ++++++++++++++++++++++++++++ 4 files changed, 125 insertions(+), 4 deletions(-) diff --git a/chat-app/backEnd/server.js b/chat-app/backEnd/server.js index 2a9e6b5a..5c30ea63 100644 --- a/chat-app/backEnd/server.js +++ b/chat-app/backEnd/server.js @@ -33,7 +33,7 @@ app.get("/getMessages", (req, res) => { }); app.post("/sendMessage", (req, res) => { - const { message, sender } = req.body; + const { message, sender, replyTo } = req.body; if (message && sender) { const timestamp = Date.now(); messages.push({ @@ -43,6 +43,7 @@ app.post("/sendMessage", (req, res) => { timestamp, likes: 0, dislikes: 0, + replyTo: replyTo || null, }); res.status(200).json({ success: true }); diff --git a/chat-app/frontEnd/index.html b/chat-app/frontEnd/index.html index a42876dd..bf5709f6 100644 --- a/chat-app/frontEnd/index.html +++ b/chat-app/frontEnd/index.html @@ -21,6 +21,10 @@
+
diff --git a/chat-app/frontEnd/script.js b/chat-app/frontEnd/script.js index df281e6a..0a1b7a59 100644 --- a/chat-app/frontEnd/script.js +++ b/chat-app/frontEnd/script.js @@ -5,6 +5,7 @@ const appServerURL = "http://localhost:3000/"; const currentUser = prompt("Enter your name:") || "Unknown"; let lastTimestamp = 0; let displayedMessages = []; +let replyToMessage = null; async function setup() { await renderMessages(); @@ -12,14 +13,16 @@ async function setup() { const messageText = document.getElementById("messageText"); const submitMessage = document.getElementById("submitMessage"); const messagesContainer = document.querySelector(".chat-messages"); + const cancelReplyButton = document.getElementById("cancelReplyButton"); submitMessage.addEventListener("click", async (e) => { e.preventDefault(); const message = messageText.value.trim(); if (message) { - const success = await sendMessage(message); + const success = await sendMessage(message, replyToMessage?.id); if (success) { messageText.value = ""; + clearReplyPreview(); await renderMessages(); } else { alert("Failed to send message. Please try again."); @@ -27,9 +30,20 @@ async function setup() { } }); + cancelReplyButton.addEventListener("click", () => { + clearReplyPreview(); + }); + messagesContainer.addEventListener("click", async (e) => { const likeButton = e.target.closest(".like-button"); const dislikeButton = e.target.closest(".dislike-button"); + const replyButton = e.target.closest(".reply-button"); + + if (replyButton) { + const messageId = replyButton.dataset.id; + handleReplyClick(messageId); + return; + } if (likeButton || dislikeButton) { const button = likeButton || dislikeButton; @@ -74,12 +88,27 @@ function appendMessages(messages) { senderName.className = "sender-name"; senderName.textContent = message.sender; + if (message.replyTo) { + const originalMessage = displayedMessages.find((m) => String(m.id) === String(message.replyTo)); + const replyPreview = document.createElement("div"); + replyPreview.className = "message-reply"; + replyPreview.textContent = originalMessage + ? `${originalMessage.sender}: ${originalMessage.message}` + : "Replied to a message"; + div.append(replyPreview); + } + const text = document.createElement("p"); text.textContent = message.message; const reactionRow = document.createElement("div"); reactionRow.className = "reaction-row"; + const replyButton = document.createElement("button"); + replyButton.className = "reply-button"; + replyButton.dataset.id = message.id; + replyButton.textContent = "Reply"; + const likeButton = document.createElement("button"); likeButton.className = "reaction-button like-button"; likeButton.dataset.id = message.id; @@ -90,7 +119,11 @@ function appendMessages(messages) { dislikeButton.dataset.id = message.id; dislikeButton.textContent = `👎 ${message.dislikes || 0}`; + if (role === "received") { + reactionRow.append(replyButton); + } reactionRow.append(likeButton, dislikeButton); + div.append(senderName, text, reactionRow); messagesContainer.appendChild(div); }); @@ -110,12 +143,12 @@ async function fetchMessages(lastTimestamp = 0) { } } -async function sendMessage(message) { +async function sendMessage(message, replyTo = null) { try { const response = await fetch(`${appServerURL}sendMessage`, { method: "POST", headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ message, sender: currentUser }), + body: JSON.stringify({ message, sender: currentUser, replyTo }), }); const data = await response.json(); return data.success; @@ -124,6 +157,35 @@ async function sendMessage(message) { } } +function handleReplyClick(messageId) { + const message = displayedMessages.find((m) => String(m.id) === String(messageId)); + if (!message) { + return; + } + + replyToMessage = message; + renderReplyPreview(); +} + +function renderReplyPreview() { + const replyPreview = document.getElementById("replyPreview"); + const replyPreviewText = document.getElementById("replyPreviewText"); + + if (!replyToMessage) { + replyPreview.classList.add("hidden"); + replyPreviewText.textContent = ""; + return; + } + + replyPreviewText.textContent = `${replyToMessage.sender}: ${replyToMessage.message}`; + replyPreview.classList.remove("hidden"); +} + +function clearReplyPreview() { + replyToMessage = null; + renderReplyPreview(); +} + async function reactToMessage(id, reaction) { try { const response = await fetch(`${appServerURL}reactMessage`, { diff --git a/chat-app/frontEnd/style.css b/chat-app/frontEnd/style.css index b2fa4f8c..8f6fb4c9 100644 --- a/chat-app/frontEnd/style.css +++ b/chat-app/frontEnd/style.css @@ -88,6 +88,59 @@ body { transform: translateY(-1px); } +.reply-button { + border: none; + border-radius: 999px; + padding: 7px 12px; + font-size: 13px; + cursor: pointer; + background-color: rgba(255, 255, 255, 0.08); + color: #fff; +} + +.message-reply { + border-left: 3px solid rgba(255, 255, 255, 0.35); + padding-left: 10px; + margin-bottom: 8px; + font-size: 13px; + opacity: 0.9; + max-height: 4.2em; + overflow: hidden; + white-space: nowrap; + text-overflow: ellipsis; +} + +.reply-preview { + display: flex; + align-items: center; + justify-content: space-between; + gap: 10px; + padding: 8px 10px; + border-radius: 8px; + background-color: rgba(255, 255, 255, 0.08); + color: #fff; + margin-bottom: 10px; +} + +.reply-preview.hidden { + display: none; +} + +.reply-preview-text { + flex: 1; + font-size: 14px; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + +#cancelReplyButton { + border: none; + background: transparent; + color: #ffbaba; + cursor: pointer; +} + .like-button { background-color: rgba(255, 255, 255, 0.12); color: #c8f0ff; @@ -100,6 +153,7 @@ body { .chat-input-area { display: flex; + flex-direction: column; padding: 10px; background-color: #2a2a2a; } From 74c847bb08b5d8f397f72b248b086ccce9cf6476 Mon Sep 17 00:00:00 2001 From: Mohammed Abdoon Date: Tue, 30 Jun 2026 03:09:10 +0100 Subject: [PATCH 09/14] added more uniqeness to the messages ids --- chat-app/backEnd/server.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/chat-app/backEnd/server.js b/chat-app/backEnd/server.js index 5c30ea63..05ef7ca9 100644 --- a/chat-app/backEnd/server.js +++ b/chat-app/backEnd/server.js @@ -1,5 +1,6 @@ import express from "express"; import cors from "cors"; +import { randomUUID } from "crypto"; let messages = [ { @@ -36,8 +37,9 @@ app.post("/sendMessage", (req, res) => { const { message, sender, replyTo } = req.body; if (message && sender) { const timestamp = Date.now(); + const id = messages.push({ - id: timestamp, + id: randomUUID(), message, sender, timestamp, From 29ba0f9041a605296725ea6b3f8e8356761bd86f Mon Sep 17 00:00:00 2001 From: Mohammed Abdoon Date: Tue, 30 Jun 2026 05:05:59 +0100 Subject: [PATCH 10/14] updated url --- chat-app/frontEnd/script.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/chat-app/frontEnd/script.js b/chat-app/frontEnd/script.js index 0a1b7a59..22f34761 100644 --- a/chat-app/frontEnd/script.js +++ b/chat-app/frontEnd/script.js @@ -1,6 +1,5 @@ -const appServerURL = "http://localhost:3000/"; -// const appServerURL = -// "https://m-abdoon-chatapp-backend.hosting.codeyourfuture.io/"; +//const appServerURL = "http://localhost:3000/"; +const appServerURL = "https://m-abdoon-chatapp-backend.hosting.codeyourfuture.io/"; const currentUser = prompt("Enter your name:") || "Unknown"; let lastTimestamp = 0; From b79f58f0b2420bb484f58c5c14e903932ef1d3df Mon Sep 17 00:00:00 2001 From: Mohammed Abdoon Date: Tue, 30 Jun 2026 05:51:09 +0100 Subject: [PATCH 11/14] fixed reacting issue --- chat-app/backEnd/server.js | 13 ++++++++----- chat-app/frontEnd/script.js | 4 ++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/chat-app/backEnd/server.js b/chat-app/backEnd/server.js index 05ef7ca9..9f2de4a9 100644 --- a/chat-app/backEnd/server.js +++ b/chat-app/backEnd/server.js @@ -2,7 +2,7 @@ import express from "express"; import cors from "cors"; import { randomUUID } from "crypto"; -let messages = [ +const messages = [ { id: 1, message: "Hi! welcome to the app, you can send messages now.", @@ -12,6 +12,7 @@ let messages = [ dislikes: 0, }, ]; +const messagesById = new Map(messages.map((msg) => [String(msg.id), msg])); const app = express(); const PORT = 3000; @@ -37,8 +38,7 @@ app.post("/sendMessage", (req, res) => { const { message, sender, replyTo } = req.body; if (message && sender) { const timestamp = Date.now(); - const id = - messages.push({ + const newMessage = { id: randomUUID(), message, sender, @@ -46,7 +46,10 @@ app.post("/sendMessage", (req, res) => { likes: 0, dislikes: 0, replyTo: replyTo || null, - }); + }; + + messages.push(newMessage); + messagesById.set(String(newMessage.id), newMessage); res.status(200).json({ success: true }); } else { @@ -56,7 +59,7 @@ app.post("/sendMessage", (req, res) => { app.post("/reactMessage", (req, res) => { const { id, reaction } = req.body; - const message = messages.get(Number(id)); + const message = messagesById.get(String(id)); if (!message || !["like", "dislike"].includes(reaction)) { return res diff --git a/chat-app/frontEnd/script.js b/chat-app/frontEnd/script.js index 22f34761..c6ea5d67 100644 --- a/chat-app/frontEnd/script.js +++ b/chat-app/frontEnd/script.js @@ -1,5 +1,5 @@ -//const appServerURL = "http://localhost:3000/"; -const appServerURL = "https://m-abdoon-chatapp-backend.hosting.codeyourfuture.io/"; +const appServerURL = "http://localhost:3000/"; +//const appServerURL = "https://m-abdoon-chatapp-backend.hosting.codeyourfuture.io/"; const currentUser = prompt("Enter your name:") || "Unknown"; let lastTimestamp = 0; From 66bd8aa23b7c18154f4a82838a69afcd8540a16b Mon Sep 17 00:00:00 2001 From: Mohammed Abdoon Date: Tue, 30 Jun 2026 05:53:49 +0100 Subject: [PATCH 12/14] updated link --- chat-app/frontEnd/script.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chat-app/frontEnd/script.js b/chat-app/frontEnd/script.js index c6ea5d67..22f34761 100644 --- a/chat-app/frontEnd/script.js +++ b/chat-app/frontEnd/script.js @@ -1,5 +1,5 @@ -const appServerURL = "http://localhost:3000/"; -//const appServerURL = "https://m-abdoon-chatapp-backend.hosting.codeyourfuture.io/"; +//const appServerURL = "http://localhost:3000/"; +const appServerURL = "https://m-abdoon-chatapp-backend.hosting.codeyourfuture.io/"; const currentUser = prompt("Enter your name:") || "Unknown"; let lastTimestamp = 0; From 567da16aca7701a3a01c51517b8f455807aa9477 Mon Sep 17 00:00:00 2001 From: Mohammed Abdoon Date: Wed, 1 Jul 2026 05:46:25 +0100 Subject: [PATCH 13/14] defined 500 ( milliseconds ) --- chat-app/frontEnd/script.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/chat-app/frontEnd/script.js b/chat-app/frontEnd/script.js index 22f34761..0bc14965 100644 --- a/chat-app/frontEnd/script.js +++ b/chat-app/frontEnd/script.js @@ -13,6 +13,7 @@ async function setup() { const submitMessage = document.getElementById("submitMessage"); const messagesContainer = document.querySelector(".chat-messages"); const cancelReplyButton = document.getElementById("cancelReplyButton"); + const messageRefreshInterval = 500; submitMessage.addEventListener("click", async (e) => { e.preventDefault(); @@ -56,7 +57,7 @@ async function setup() { } }); - setInterval(renderMessages, 500); + setInterval(renderMessages, messageRefreshInterval); } async function renderMessages() { From f72fed79ad3436766b9f0f1996d8c69e5903017e Mon Sep 17 00:00:00 2001 From: Mohammed Abdoon Date: Wed, 1 Jul 2026 16:05:29 +0100 Subject: [PATCH 14/14] modified renderReplyPreview() --- chat-app/frontEnd/script.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/chat-app/frontEnd/script.js b/chat-app/frontEnd/script.js index 0bc14965..981486b6 100644 --- a/chat-app/frontEnd/script.js +++ b/chat-app/frontEnd/script.js @@ -67,7 +67,8 @@ async function renderMessages() { } if (messages.length > 0) { - lastTimestamp = Math.max(lastTimestamp, ...messages.map((m) => m.timestamp)); + const lastMessage = messages[messages.length - 1]; + lastTimestamp = Math.max(lastTimestamp, lastMessage.timestamp); } messages.sort((a, b) => a.timestamp - b.timestamp); @@ -164,26 +165,26 @@ function handleReplyClick(messageId) { } replyToMessage = message; - renderReplyPreview(); + renderReplyPreview(message); } -function renderReplyPreview() { +function renderReplyPreview(msg) { const replyPreview = document.getElementById("replyPreview"); const replyPreviewText = document.getElementById("replyPreviewText"); - if (!replyToMessage) { + if (!msg) { replyPreview.classList.add("hidden"); replyPreviewText.textContent = ""; return; } - replyPreviewText.textContent = `${replyToMessage.sender}: ${replyToMessage.message}`; + replyPreviewText.textContent = `${msg.sender}: ${msg.message}`; replyPreview.classList.remove("hidden"); } function clearReplyPreview() { replyToMessage = null; - renderReplyPreview(); + renderReplyPreview(null); } async function reactToMessage(id, reaction) {