Skip to content

Commit

Permalink
Merge branch 'release/1.0.55'
Browse files Browse the repository at this point in the history
  • Loading branch information
Averylamp committed Jul 19, 2019
2 parents d419353 + be29176 commit 3d394bf
Show file tree
Hide file tree
Showing 21 changed files with 431 additions and 144 deletions.
2 changes: 1 addition & 1 deletion admin-panel
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"geolib": "^2.0.24",
"graphql": "^14.1.1",
"graphql-tag": "^2.10.1",
"grpc": "^1.22.2",
"lodash": "^4.17.11",
"mongo-dot-notation": "^1.2.0",
"mongoose": "^5.4.13",
Expand Down
2 changes: 1 addition & 1 deletion release
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.54
1.0.55
66 changes: 54 additions & 12 deletions src/FirebaseManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export const createMatchChat = ({

// does not throw
export const sendMessage = async ({
chatID, messageType, content, sender_id,
chatID, messageType, content, sender_id, contentType,
}) => {
try {
const db = getFirebaseDb();
Expand All @@ -151,7 +151,7 @@ export const sendMessage = async ({
const messageSetObj = {
documentID: newMessageRef.id,
type: messageType,
contentType: 'TEXT',
contentType: contentType || 'TEXT',
content,
timestamp: now,
};
Expand Down Expand Up @@ -221,19 +221,61 @@ export const notifyEndorsementChatAcceptedRequest = async ({
});
};

export const sendMatchmakerRequestMessage = async ({ chatID, sentBy, requestText }) => sendMessage({
export const sendMatchmakerRequestMessage = async ({
chatID,
messageType: 'MATCHMAKER_REQUEST',
content: requestText,
sender_id: sentBy._id.toString(),
});
sentBy,
requestText,
likedPhoto,
likedPrompt,
}) => {
const contentObj = {};
let contentType = 'TEXT';
if (requestText) {
contentObj.message = requestText;
}
if (likedPhoto) {
contentObj.likedPhoto = likedPhoto;
contentType = 'PHOTO_LIKE';
} else if (likedPrompt) {
contentObj.likedPrompt = likedPrompt;
contentType = 'PROMPT_LIKE';
}
sendMessage({
chatID,
messageType: 'MATCHMAKER_REQUEST',
content: contentType === 'TEXT' ? (requestText || '') : JSON.stringify(contentObj),
contentType,
sender_id: sentBy._id.toString(),
});
};

export const sendPersonalRequestMessage = async ({ chatID, sentBy, requestText }) => sendMessage({
export const sendPersonalRequestMessage = async ({
chatID,
messageType: 'PERSONAL_REQUEST',
content: requestText,
sender_id: sentBy._id.toString(),
});
sentBy,
requestText,
likedPhoto,
likedPrompt,
}) => {
const contentObj = {};
let contentType = 'TEXT';
if (requestText) {
contentObj.message = requestText;
}
if (likedPhoto) {
contentObj.likedPhoto = likedPhoto;
contentType = 'PHOTO_LIKE';
} else if (likedPrompt) {
contentObj.likedPrompt = likedPrompt;
contentType = 'PROMPT_LIKE';
}
sendMessage({
chatID,
messageType: 'PERSONAL_REQUEST',
content: contentType === 'TEXT' ? (requestText || '') : JSON.stringify(contentObj),
contentType,
sender_id: sentBy._id.toString(),
});
};

export const sendPushNotification = async ({ deviceToken, title, body }) => {
try {
Expand Down
13 changes: 13 additions & 0 deletions src/models/DetachedProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ extend type Mutation{
# ID is optional, for testing only
approveNewDetachedProfile(approveDetachedProfileInput: ApproveDetachedProfileInput!): UserMutationResponse!
# rejects the detached profile
rejectDetachedProfile(rejectDetachedProfileInput: RejectDetachedProfileInput!): DetachedProfileMutationResponse!
# creator can edit the detached profile
editDetachedProfile(editDetachedProfileInput: EditDetachedProfileInput!): DetachedProfileMutationResponse!
Expand Down Expand Up @@ -86,6 +89,15 @@ input ApproveDetachedProfileInput {
}
`;

const rejectDetachedProfileInput = `
input RejectDetachedProfileInput {
# id of the user rejecting
user_id: ID!
# id of the detached profile
detachedProfile_id: ID!
}
`;

const editDetachedProfileInput = `
input EditDetachedProfileInput {
# id of the profile being edited
Expand Down Expand Up @@ -163,6 +175,7 @@ export const typeDef = queryRoutes
+ mutationRoutes
+ createDetachedProfileInput
+ approveDetachedProfileInput
+ rejectDetachedProfileInput
+ editDetachedProfileInput
+ detachedProfileType
+ detachedProfileMutationResponse;
Expand Down
15 changes: 14 additions & 1 deletion src/models/MatchModel.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { ImageContainerSchema } from './ImageSchemas';
import { QuestionUserResponseSchema } from './ContentModels';

const mongoose = require('mongoose');

const { Schema } = mongoose;
Expand Down Expand Up @@ -38,8 +41,10 @@ input CreateMatchRequestInput {
# Discovered user receiving the request
receivedByUser_id: ID!
# Optional text that goes along with the chat request
# Optional text that goes along with the like
requestText: String
likedPhoto: CreateImageContainer
likedPrompt: QuestionUserResponseInput
}
`;

Expand Down Expand Up @@ -70,6 +75,10 @@ type Match{
receivedByUser_id: ID!
receivedByUser: User
isMatchmakerMade: Boolean!
requestText: String
likedPhoto: ImageContainer
likedPrompt: QuestionUserResponse
sentForUserStatus: RequestResponse!
sentForUserStatusLastUpdated: String!
Expand Down Expand Up @@ -121,6 +130,10 @@ const MatchSchema = new Schema({
receivedByUser_id: { type: Schema.Types.ObjectId, required: true, index: true },
isMatchmakerMade: { type: Boolean, required: true },

requestText: { type: String, required: false },
likedPhoto: { type: ImageContainerSchema, required: false },
likedPrompt: { type: QuestionUserResponseSchema, required: false },

sentForUserStatus: {
type: String,
required: true,
Expand Down
13 changes: 13 additions & 0 deletions src/models/UserActionModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ enum UserActionType {
SKIP_CARD
SEND_FR
ACCEPT_FR
REJECT_FR
EDIT_DP
UNKNOWN
JOIN_EVENT
Expand All @@ -82,6 +83,7 @@ const ActionTypes = {
SKIP_CARD: 'SKIP_CARD',
SEND_FR: 'SEND_FR',
ACCEPT_FR: 'ACCEPT_FR',
REJECT_FR: 'REJECT_FR',
EDIT_DP: 'EDIT_DP',
JOIN_EVENT: 'JOIN_EVENT',
UNKNOWN: 'UNKNOWN',
Expand Down Expand Up @@ -329,6 +331,17 @@ export const recordEditDP = ({ creator, detachedProfile }) => {
recordAction({ user_id: creator._id, action });
};

export const recordRejectFR = ({ rejectDetachedProfileInput, detachedProfile }) => {
const action = {
actor_id: rejectDetachedProfileInput.user_id,
user_ids: [rejectDetachedProfileInput.user_id, detachedProfile.creatorUser_id],
description: `$0 rejected profile from $1 with ${detachedProfile.questionResponses.length} promtps`,
actionType: ActionTypes.REJECT_FR,
};
recordAction({ user_id: rejectDetachedProfileInput.user_id, action });
recordAction({ user_id: detachedProfile.creatorUser_id, action });
};

export const recordJoinEvent = ({ user, event }) => {
const action = {
actor_id: user._id,
Expand Down
17 changes: 0 additions & 17 deletions src/models/UserModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { MatchingDemographicsSchema, MatchingPreferencesSchema } from './Matchin
import { ImageContainerSchema } from './ImageSchemas';
import { EdgeSummarySchema } from './MatchModel';
import { EndorsementEdgeSchema } from './EndorsementModels';
import { USERS_ALREADY_MATCHED_ERROR } from '../resolvers/ResolverErrorStrings';
import {
BioSchema,
BoastSchema, DontSchema, DoSchema, InterestSchema,
Expand Down Expand Up @@ -541,14 +540,6 @@ export const createUserObject = (userInput, skipTimestamps) => {
};

export const receiveRequest = (me, otherUser, match_id, isFromFriend) => {
const alreadyExists = me.edgeSummaries.find(
edgeSummary => (edgeSummary.otherUser_id.toString() === otherUser._id.toString()),
);
if (alreadyExists !== undefined) {
return Promise.reject(
new Error(USERS_ALREADY_MATCHED_ERROR),
);
}
me.edgeSummaries.push({
otherUser_id: otherUser._id,
match_id,
Expand All @@ -563,14 +554,6 @@ export const receiveRequest = (me, otherUser, match_id, isFromFriend) => {
};

export const sendRequest = (me, otherUser, match_id) => {
const alreadyExists = me.edgeSummaries.find(
edgeSummary => (edgeSummary.otherUser_id.toString() === otherUser._id.toString()),
);
if (alreadyExists !== undefined) {
return Promise.reject(
new Error(USERS_ALREADY_MATCHED_ERROR),
);
}
me.personalMatchesSentCount += 1;
me.edgeSummaries.push({
otherUser_id: otherUser._id,
Expand Down
27 changes: 24 additions & 3 deletions src/resolvers/DetachedProfileResolvers/DetachedProfileResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
CREATE_DETACHED_PROFILE_ERROR,
DELETE_DETACHED_PROFILE_ERROR,
EDIT_DETACHED_PROFILE_ERROR,
GET_USER_ERROR,
GET_USER_ERROR, REJECT_PROFILE_ERROR,
VIEW_DETACHED_PROFILE_ERROR,
WRONG_CREATOR_ERROR,
} from '../ResolverErrorStrings';
Expand All @@ -16,6 +16,7 @@ import { getAndValidateUsersAndDetachedProfileObjects } from './DetachedProfileR
import { editDetachedProfileResolver } from './EditDetachedProfile';
import { generateSentryErrorForResolver } from '../../SentryHelper';
import { datadogStats } from '../../DatadogHelper';
import { rejectDetachedProfileResolver } from './RejectDetachedProfile';

const debug = require('debug')('dev:DetachedProfileResolvers');
const errorLog = require('debug')('error:DetachedProfileResolvers');
Expand Down Expand Up @@ -99,7 +100,7 @@ export const resolvers = {
errorLog(`error occurred editing detached profile: ${e}`);
generateSentryErrorForResolver({
resolverType: 'mutation',
routeName: 'editDetachedProfileInput',
routeName: 'editDetachedProfile',
args: { editDetachedProfileInput },
errorMsg: e,
errorName: EDIT_DETACHED_PROFILE_ERROR,
Expand All @@ -119,7 +120,7 @@ export const resolvers = {
errorLog(`error occurred approving detached profile: ${e}`);
generateSentryErrorForResolver({
resolverType: 'mutation',
routeName: 'approveDetachedProfileInput',
routeName: 'approveDetachedProfile',
args: { approveDetachedProfileInput },
errorMsg: e,
errorName: APPROVE_PROFILE_ERROR,
Expand All @@ -130,6 +131,26 @@ export const resolvers = {
};
}
},
rejectDetachedProfile: async (_source, { rejectDetachedProfileInput }) => {
functionCallConsole('Reject Profile Called');
datadogStats.increment('server.stats.detached_profile_rejected');
try {
return rejectDetachedProfileResolver({ rejectDetachedProfileInput });
} catch (e) {
errorLog(`error occurred rejecting detached profile :${e}`);
generateSentryErrorForResolver({
resolverType: 'mutation',
routeName: 'rejectDetachedProfile',
args: { rejectDetachedProfileInput },
errorMsg: e,
errorName: REJECT_PROFILE_ERROR,
});
return {
success: false,
message: REJECT_PROFILE_ERROR,
};
}
},
// TODO
deleteDetachedProfile: async (_source, { creator_id, detachedProfile_id }) => {
functionCallConsole('deleteDetachedProfile called');
Expand Down
49 changes: 49 additions & 0 deletions src/resolvers/DetachedProfileResolvers/RejectDetachedProfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { User } from '../../models/UserModel';
import {
GET_DETACHED_PROFILE_ERROR,
GET_USER_ERROR, WRONG_USER_ERROR,
} from '../ResolverErrorStrings';
import { DetachedProfile } from '../../models/DetachedProfile';
import { recordRejectFR } from '../../models/UserActionModel';

export const rejectDetachedProfileResolver = async ({ rejectDetachedProfileInput }) => {
const user = await User.findById(rejectDetachedProfileInput.user_id)
.exec()
.catch(err => err);
let detachedProfile = await DetachedProfile
.findById(rejectDetachedProfileInput.detachedProfile_id)
.exec()
.catch(err => err);
if (!user || user instanceof Error) {
return {
success: false,
message: GET_USER_ERROR,
};
}
if (!detachedProfile || detachedProfile instanceof Error) {
return {
success: false,
message: GET_DETACHED_PROFILE_ERROR,
};
}
if (detachedProfile.status === 'accepted') {
// no-op if detached profile has already been approved
return {
success: true,
detachedProfile,
};
}
if (user.phoneNumber !== detachedProfile.phoneNumber) {
return {
success: false,
message: WRONG_USER_ERROR,
};
}
detachedProfile.status = 'declined';
detachedProfile = await detachedProfile.save();
recordRejectFR({ rejectDetachedProfileInput, detachedProfile });
return {
success: true,
detachedProfile,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ export const addCardsToCache = async ({ user, discoveryQueue, nCardsToAdd }) =>
let cardsToPush = [];
for (const ignoreSkipList of [false, true]) {
for (const includeLocation of [true, false]) {
for (const widerAge of [0, 3, 5, 10]) {
for (const widerAge of [0, 2]) {
for (const seededOnly of [true, false]) {
let seededOnlyFinal = seededOnly;
if (discoveryQueue.decidedDiscoveryItems
Expand Down
Loading

0 comments on commit 3d394bf

Please sign in to comment.