-
Notifications
You must be signed in to change notification settings - Fork 218
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
added feature of terminating when the link is deleted issue number #352 issue has been solved #375
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
MONGO_URI=mongodb+srv://<username>:<password>@cluster0-zbsik.mongodb.net | ||
MONGO_DB_NAME='' | ||
CHAT_LINK_DOMAIN='' | ||
MONGO_URI=mongodb://localhost:27017 | ||
MONGO_DB_NAME=mydatabase | ||
CHAT_LINK_DOMAIN='http://localhost:3000' | ||
IMAGE_BB_API_KEY='' | ||
IMGUR_API_KEY'' | ||
IMGUR_API_KEY='' |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,17 @@ import { | |
findOneFromDB as _findOneFromDB, insertInDb as _insertInDb, updateOneFromDb as _updateOneFromDb | ||
} from './inMemDB'; | ||
|
||
const uri = process.env.MONGO_URI; | ||
const dbName = process.env.MONGO_DB_NAME; | ||
// added local db address if you didnt create a .env file | ||
const uri = process.env.MONGO_URI || 'mongodb://localhost:27017'; | ||
const dbName = process.env.MONGO_DB_NAME || 'realtimechatting'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove the arbitrary defaults. Let it be set explicitly in .env |
||
|
||
console.log('uri', uri); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unnecessary |
||
console.log('dbName', dbName); | ||
|
||
const client = uri ? new MongoClient(uri) : null; | ||
|
||
console.log('client', client); | ||
|
||
let db: Db = null; | ||
let inMem = uri ? false : true; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,26 @@ | ||
.deleteButton { | ||
height: 30px; | ||
display: flex; | ||
width: 80px; | ||
font-family: inherit; | ||
font-size: 14px; | ||
align-items: center; | ||
justify-content: center; | ||
cursor: pointer; | ||
background: #e91e63; | ||
color: #fff; | ||
transition: 180ms; | ||
height: 30px; | ||
display: flex; | ||
width: 80px; | ||
font-family: inherit; | ||
font-size: 14px; | ||
align-items: center; | ||
justify-content: center; | ||
cursor: pointer; | ||
background: #e91e63; | ||
color: #fff; | ||
transition: 180ms; | ||
} | ||
|
||
.lightModeDelete { | ||
background: #3cb043; | ||
color: #fff; | ||
background: #3cb043; | ||
color: #fff; | ||
} | ||
|
||
.lightModeDelete:hover { | ||
background: #028a0f !important; | ||
background: #028a0f !important; | ||
} | ||
|
||
.deleteButton:hover { | ||
background: #ab0b42; | ||
} | ||
background: #ab0b42; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
import React, { useCallback, useContext, useEffect, useRef, useState } from 'react'; | ||
|
||
|
||
import React, { useCallback, useContext, useEffect, useRef, useState } from 'react'; | ||
import { useHistory, useParams } from 'react-router-dom'; | ||
|
||
import { | ||
|
@@ -258,6 +260,69 @@ const Chat = () => { | |
timestamp | ||
}; | ||
}); | ||
|
||
// added a useeffect to check whather the | ||
useEffect(() => { | ||
const validateLink = async () => { | ||
try { | ||
// FOR PRODUCTION MODE URL SHOULD BE https://chat-e2ee-2.azurewebsites.net/api/chat-link/status/${channelID} | ||
// FOR RUNING LOCALLY URL SHOULD BE http://localhost:3001/api/chat-link/status/${channelID} | ||
const URL = `http://localhost:3001/api/chat-link/status/${channelID}` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. urls should not be hard-coded. Also UI layer does not need to know anything about the server. That's why we have the service. |
||
const response = await fetch(URL); | ||
if (response.status !== 200) { | ||
// If the link is invalid, start a 2-second countdown before redirecting | ||
setLinkActive(false); | ||
const timer = setTimeout(() => { | ||
history.push("/"); // Redirect after 2 seconds | ||
}, 2000); | ||
|
||
return () => clearTimeout(timer); // Cleanup the timer if component unmounts | ||
} else { | ||
// Link is still valid | ||
setLinkActive(true); | ||
} | ||
} catch (error) { | ||
console.error("Error validating chat link:", error); | ||
setLinkActive(false); | ||
const timer = setTimeout(() => { | ||
history.push("/"); // Redirect after 2 seconds on error | ||
}, 2000); // redireting aftrer 2 second and u can as much u want | ||
|
||
return () => clearTimeout(timer); // Cleanup the timer if component unmounts | ||
} | ||
}; | ||
|
||
// Function to throttle link validation checks | ||
const throttledValidateLink = throttle(validateLink, 1000); // Throttle the function to run every 5 seconds | ||
|
||
// Validate the link immediately on component mount | ||
validateLink(); | ||
|
||
// Periodically revalidate the link every 5 seconds | ||
const intervalId = setInterval(() => { | ||
throttledValidateLink(); | ||
}, 1000); // Check every 1 seconds (adjust this interval as needed) | ||
|
||
return () => { | ||
clearInterval(intervalId); // Cleanup the interval on component unmount | ||
}; | ||
}, [channelID, history]); | ||
|
||
|
||
// Helper function to throttle a function call | ||
function throttle<T extends (...args: any[]) => void>(func: T, limit: number): (...args: Parameters<T>) => void { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can be moved to ./utils. |
||
let inThrottle: boolean; | ||
return function (this: any, ...args: Parameters<T>) { | ||
if (!inThrottle) { | ||
func.apply(this, args); | ||
inThrottle = true; | ||
setTimeout(() => { | ||
inThrottle = false; | ||
}, limit); | ||
} | ||
}; | ||
} | ||
|
||
if (linkActive) { | ||
return ( | ||
<> | ||
|
@@ -307,11 +372,23 @@ const Chat = () => { | |
return ( | ||
<div className={styles.messageContainer}> | ||
<div className={`${styles.messageBlock} ${!darkMode && styles.lightModeContainer}`}> | ||
<p>This link is no longer active</p> | ||
<div style={{ | ||
display: 'flex', | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
height: '100vh', | ||
textAlign: 'center', | ||
}}> | ||
<div> | ||
<p>This link has expired or been deleted!</p> | ||
<p>Redirecting to home page in seconds...</p> | ||
</div> | ||
</div> | ||
|
||
</div> | ||
</div> | ||
); | ||
} | ||
}; | ||
|
||
export default Chat; | ||
export default Chat; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this fallback.