-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
6,227 additions
and
1,209 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import firebase from "firebase-admin"; | ||
|
||
export const ensureUserAuthorized = async (token: any): Promise<[uid: string | undefined, error: string | undefined]> => { | ||
if (!token) { | ||
return [undefined, "User not authenticated!"]; | ||
} | ||
|
||
var uid: string; | ||
try { | ||
const decodedToken = await firebase.auth().verifyIdToken(token); | ||
uid = decodedToken.uid; | ||
return [uid, undefined]; | ||
} catch { | ||
return [undefined, "User id token is invalid!"]; | ||
} | ||
} | ||
|
||
export const getUserProfile = async (uid: string): Promise<firebase.firestore.DocumentData | undefined> => { | ||
const userProfileSnapshot = await firebase.firestore().collection('users').doc(uid).get(); | ||
return userProfileSnapshot.data(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export { ping } from "./methods/ping"; | ||
export { updateLocation } from "./methods/update_location" | ||
export { message } from "./methods/message" | ||
export { nearby } from "./methods/nearby" | ||
export { sendMessage } from "./methods/send_message" | ||
export { getNearbyUsers } from "./methods/get_nearby_users" | ||
export { notifyUpdateProfile } from "./methods/notify_update_profile" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { getUserProfile } from "../firebase_methods"; | ||
import { getActiveUsersInView } from "../regions"; | ||
import { ConnectionContext } from "../socket_server"; | ||
|
||
export const notifyUpdateProfile = async (ctx: ConnectionContext, ack: any): Promise<void> => { | ||
console.log(`[WS] Received notification of user profile update <${ctx.socket.id}>.`); | ||
|
||
// pull updated user profile from Firebase | ||
const userProfile = await getUserProfile(ctx.user.uid); | ||
ctx.user.profile.displayName = userProfile.displayName; | ||
ctx.user.profile.profilePicture = userProfile.profilePicture; | ||
|
||
const messageToNearbyOthers = { | ||
uid: ctx.user.uid, | ||
profile: ctx.user.profile, | ||
}; | ||
|
||
// forward notification to all nearby users | ||
const usersInView = getActiveUsersInView(ctx.user.location); | ||
for(const userInView of usersInView) { | ||
if (userInView.uid === ctx.user.uid) continue; // Skip sender | ||
userInView.socket.emit('notifyUpdateProfile', messageToNearbyOthers); | ||
} | ||
|
||
if (ack) ack("success"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { Location } from "./types/location"; | ||
export { ActiveUser } from "./types/active_user" | ||
export { UserProfile } from "./types/user_profile" | ||
export { Message } from "./types/message" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import { IOSocket } from "../socket_server/socket_server"; | ||
import { Location } from "./location"; | ||
import { Location, UserProfile } from "../types"; | ||
|
||
export interface ActiveUser { | ||
socket: IOSocket | ||
|
||
uid: string, | ||
location: Location, | ||
} | ||
|
||
profile: UserProfile, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export interface UserProfile { | ||
displayName: string, | ||
profilePicture: number, | ||
} |