diff --git a/frontend-next/src/app/user/page.js b/frontend-next/src/app/user/page.js index 52a7a25..eb84533 100644 --- a/frontend-next/src/app/user/page.js +++ b/frontend-next/src/app/user/page.js @@ -8,7 +8,6 @@ import { useAuthState } from "react-firebase-hooks/auth" // Refactored Component Imports - // Data Structure Imports import { ProfileRoom } from "../../components/app/profile/ProfileRoom"; import { ProfileEdit } from "../../components/app/profile/ProfileEdit"; @@ -20,6 +19,9 @@ import { Header } from "../../components/app/header"; // Friend Import import { addFriend } from "../../components/app/friends/friends"; +// Icons +import CircleIcon from '@mui/icons-material/Circle'; + /** * User Profile Page * @returns {Object} - User Profile Page @@ -125,11 +127,10 @@ function UserProfile() {
-
- {profileData.firstName} {profileData.lastName} +
+ {profileData.lastOnline == true && }{profileData.firstName} {profileData.lastName}
@{profileData.username}
{profileData.bio}
diff --git a/frontend-next/src/components/app/datatypes.js b/frontend-next/src/components/app/datatypes.js index 973d383..81ef5d1 100644 --- a/frontend-next/src/components/app/datatypes.js +++ b/frontend-next/src/components/app/datatypes.js @@ -9,6 +9,7 @@ import {remove, ref} from "firebase/database" // Icons import PersonIcon from '@mui/icons-material/Person'; import DeleteOutlineIcon from '@mui/icons-material/DeleteOutline'; +import CircleIcon from '@mui/icons-material/Circle'; // Colors for Messages const userColors = [ @@ -42,19 +43,27 @@ let dateOptions = { * @returns {String} - Formatted Message (IN HTML) */ function RMF(message) { + var IMG_END = [".jpg", ".jpeg", ".png", ".gif", ".webp"] var URLREGEX = /[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/g; var URLmatch = message.match(URLREGEX); + var newMessage = URLmatch ? [] : message if (URLmatch) { for (var i = 0; i < URLmatch.length; i++) { - var link = ( - {message.split(URLmatch[i])[0]} - {URLmatch[i]} - {message.split(URLmatch[i])[1]} - ) - message = link + if (IMG_END.includes(URLmatch[i].slice(-4)) || IMG_END.includes(URLmatch[i].slice(-5))) { + // Its a photo + newMessage.push(()) + } else { + console.log(message) + newMessage.push(( + {URLmatch.length == 1 && message.split(URLmatch[i])[0]} + {URLmatch[i]} + {(i == URLmatch.length || URLmatch.length == 1) && message.split(URLmatch[i])[1]} + )) + } + } } - return message + return newMessage } /** * Grabs Window Size @@ -101,15 +110,15 @@ const generateColor = (user_str) => { * @props {JSON} chatObj - Chat Object * @returns {Object} - Chat Message Component */ -export function Chat({ chatObj, user, path }) { - +export function Chat({ chatObj }) { function deleteMessage() { remove(ref(database, `/rooms/${path}/chats/${chatObj.timestamp}-${chatObj.user}`)) } - - var message = RMF(chatObj.body) - if (message) - message = filter.clean(message) + + if (chatObj.body) { + var message = filter.clean(chatObj.body) + message = RMF(message) + } return (
@@ -163,7 +172,7 @@ export function Member({ memberObj }) { return (
- {memberObj.username} + {memberObj.lastOnline == true && }{memberObj.username}
); diff --git a/frontend-next/src/components/app/friends/dm.js b/frontend-next/src/components/app/friends/dm.js index 6e2e92d..44071c1 100644 --- a/frontend-next/src/components/app/friends/dm.js +++ b/frontend-next/src/components/app/friends/dm.js @@ -44,10 +44,12 @@ export function DM({user,friendObj}) {
{openDM(user,friendObj.uid)}}> -
-
-
{friendObj.firstName} {friendObj.lastName}
-
@{friendObj.username}
+
+
+
+
{friendObj.lastOnline == true && }{friendObj.firstName} {friendObj.lastName}
+
@{friendObj.username}
+
diff --git a/frontend-next/src/components/app/friends/friends.js b/frontend-next/src/components/app/friends/friends.js index 467a2ff..1d1f774 100644 --- a/frontend-next/src/components/app/friends/friends.js +++ b/frontend-next/src/components/app/friends/friends.js @@ -12,6 +12,7 @@ import { openDM } from './dm'; // Icons import CheckIcon from '@mui/icons-material/Check'; import CloseIcon from '@mui/icons-material/Close'; +import CircleIcon from '@mui/icons-material/Circle'; /** * Send a friend request to a user @@ -39,10 +40,12 @@ export function Friend({user,friendObj}) {
-
-
-
{friendObj.firstName} {friendObj.lastName}
-
@{friendObj.username}
+
+
+
+
{friendObj.lastOnline == true && }{friendObj.firstName} {friendObj.lastName}
+
@{friendObj.username}
+
diff --git a/frontend-next/src/components/app/header.js b/frontend-next/src/components/app/header.js index aa860c8..467f89d 100644 --- a/frontend-next/src/components/app/header.js +++ b/frontend-next/src/components/app/header.js @@ -3,7 +3,7 @@ import Link from "next/link" // Firebase Imports import { database } from "../../../firebase-config"; -import { ref, set, remove } from "firebase/database"; +import { ref, set, remove, onDisconnect, serverTimestamp } from "firebase/database"; // Component Imports import { NotificationPanel } from "./notifications/notifications"; @@ -88,6 +88,17 @@ export function Header({mainTab,chatRoomObj,user,sidebarControl}) { } } + + // Sets User Online / Offline + // Stored in header for easy code maintenance and retains user online/offline throughout app + // Makes user online + if (user.invisibleStatus == false) { + set(ref(database, `/users/${user.uid}/lastOnline`), true) + } + + // Makes user offline (with last time online) + onDisconnect(ref(database, `/users/${user.uid}/lastOnline`)).set(serverTimestamp()) + return (
diff --git a/frontend-next/src/components/app/page/chat.js b/frontend-next/src/components/app/page/chat.js index 1374ea2..bf666c2 100644 --- a/frontend-next/src/components/app/page/chat.js +++ b/frontend-next/src/components/app/page/chat.js @@ -50,23 +50,25 @@ export function ChatRoom({ roomObj, user }) { * @returns {void} */ function sendMessage(data) { - reset(); - var payload = { - body: data.message, - user: user.username, - uid: user.uid, - isSystem: false, - timestamp: new Date().getTime(), - }; - set( - ref( - database, - `/rooms/${ - roomObj.path + "/" + roomObj.name + "-" + roomObj.timestamp - }/chats/${new Date().getTime()}-${user.username}` - ), - payload - ); + if (data.message) { + reset(); + var payload = { + body: data.message, + user: user.username, + uid: user.uid, + isSystem: false, + timestamp: new Date().getTime(), + }; + set( + ref( + database, + `/rooms/${ + roomObj.path + "/" + roomObj.name + "-" + roomObj.timestamp + }/chats/${new Date().getTime()}-${user.username}` + ), + payload + ); + } } if (!chats) return
No Chats
; diff --git a/frontend-next/src/components/app/profile/ProfilePanel.js b/frontend-next/src/components/app/profile/ProfilePanel.js index 0b3dcb3..387025d 100644 --- a/frontend-next/src/components/app/profile/ProfilePanel.js +++ b/frontend-next/src/components/app/profile/ProfilePanel.js @@ -3,8 +3,9 @@ import { Popover } from "@headlessui/react"; import Link from "next/link" // Firebase Imports -import { auth } from "../../../../firebase-config"; +import { auth, database } from "../../../../firebase-config"; import { signOut } from "firebase/auth"; +import {update, ref, serverTimestamp} from "firebase/database"; /** * Logs out from Firebase Authentication @@ -43,6 +44,18 @@ export function ProfilePanel({user}) { > View Profile +
{ + // Toggle Invisible Status + update(ref(database, `/users/${user.uid}`), { + invisibleStatus: user.invisibleStatus? !user.invisibleStatus: true, + lastOnline: user.invisibleStatus? true: serverTimestamp() + } + ); + }} + > + {user.invisibleStatus ? "Go Online" : "Go Invisible"} +