Skip to content

Commit

Permalink
Greet new users
Browse files Browse the repository at this point in the history
  • Loading branch information
easafe committed Jun 9, 2024
1 parent b8cb939 commit 7dac0d7
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 20 deletions.
9 changes: 6 additions & 3 deletions src/Client/Im/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,18 @@ setPrivacySettings { readReceipts, typingStatus, profileVisibility, onlineStatus
} :> [ pure $ Just FetchMoreSuggestions ]

finishTutorial ImModel NextMessage
finishTutorial model@{ toggleModal } = model { user { completedTutorial = true } } :> [ finish ]
finishTutorial model@{ toggleModal } = model { user { completedTutorial = true } } :> [ finish, greet ]
where
sender = 4
finish = do
void <<< CCNT.silentResponse $ request.im.tutorial {}
case toggleModal of
Tutorial _ → pure <<< Just <<< SpecialRequest $ ToggleModal HideUserMenuModal
_ → pure Nothing
greet = do
void <<< CCNT.silentResponse $ request.im.greeting {}
contact ← CCNT.silentResponse $ request.im.contact { query: { id: sender, impersonation: false } }
pure <<< Just $ DisplayNewContacts contact

report Int WebSocket ImModel MoreMessages
report userId webSocket model@{ reportReason, reportComment } = case reportReason of
Expand Down Expand Up @@ -575,9 +580,7 @@ processIncomingMessage
{ id, userId, date, content, experimenting }
model@
{ user: { id: recipientId }
, suggestions
, contacts
, chatting
} = case findAndUpdateContactList of
Just contacts' →
Right $ model
Expand Down
17 changes: 8 additions & 9 deletions src/Server/3000.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ module Server.ThreeK
( generateName
, generateHeadline
, generateDescription
, generateConversationStarter
) where

import Droplet.Language
import Prelude
import Server.Database.StockText
import Shared.Options.Profile

import Data.Array as DA
Expand All @@ -15,12 +14,9 @@ import Data.String as DS
import Effect.Class (liftEffect)
import Effect.Random as ER
import Run as R
import Server.Database.Fields
import Server.Database as SD
import Server.ThreeK.Name as STN
import Server.Effect (ServerEffect)
import Shared.Unsafe as SU
import Type.Proxy (Proxy(..))
import Server.ThreeK.Database as STBD

-- | Names are generated according to the following patterns:
-- | <adjective> [, <adjective>] <noun>
Expand All @@ -36,11 +32,14 @@ generateName = R.liftEffect do

-- | Headlines are pulled from a database of "funny" one liners
generateHeadline ServerEffect String
generateHeadline = map (_.contents <<< SU.fromJust) <<< SD.single $ select _contents # from stock_text # wher (_text_type .=. Headline) # orderBy random # limit (Proxy Proxy 1)
generateHeadline = STBD.fetchHeadline 1

generateConversationStarter ServerEffect String
generateConversationStarter = STBD.fetchConversationStarter 1

-- | Descriptions are bullet point lists of quotes/about me/conversation starters
generateDescription ServerEffect String
generateDescription = do
n ← liftEffect $ ER.randomInt 1 6
quotes ← DR.reifyType n (\l → SD.query $ select _contents # from stock_text # wher (_text_type .=. Description) # orderBy random # limit l)
pure <<< DS.joinWith "\n" $ map (("- " <> _) <<< _.contents) quotes
quotes ← STBD.fetchDescription n
pure <<< DS.joinWith "\n" $ map (("- " <> _)) quotes
4 changes: 3 additions & 1 deletion src/Server/Database/StockText.purs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@ import Data.Tuple.Nested (type (/\))
import Foreign as F
import Type.Proxy (Proxy(..))

data TextType = Headline | Description
data TextType = Headline | Description | ConversationStarter

instance ToValue TextType where
toValue = case _ of
HeadlineF.unsafeToForeign 0
DescriptionF.unsafeToForeign 1
ConversationStarterF.unsafeToForeign 2

instance FromValue TextType where
fromValue value =
case CME.runExcept $ F.readInt value of
Right 0Right Headline
Right 1Right Description
Right 2Right ConversationStarter
n → Left $ "Invalid TextType " <> show n

type StockText =
Expand Down
1 change: 1 addition & 0 deletions src/Server/Handler.purs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ handlers reading =
, register: runJson reading SIH.register
, report: runJson reading SIH.report
, tutorial: runJson reading SIH.tutorial
, greeting: runJson reading SIH.greeting
}
, profile:
{ get: runJson reading SPH.profile
Expand Down
25 changes: 19 additions & 6 deletions src/Server/Im/Action.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,38 @@ module Server.Im.Action where

import Debug
import Prelude
import Shared.Im.Types
import Shared.Privilege

import Data.Array as DA
import Data.Array.NonEmpty as DAN
import Data.Either (Either(..))
import Data.Maybe (Maybe(..))
import Data.Maybe as DM
import Data.Set (Set(..))
import Data.Either (Either(..))
import Data.Nullable as DN
import Data.Set (Set)
import Data.Set as DST
import Data.String as DS
import Data.Tuple (Tuple(..))
import Data.Nullable as DN
import Droplet.Driver (Pool)
import Run.Except as RE
import Server.AccountValidation as SA
import Server.Effect (BaseEffect, Configuration, ServerEffect)
import Server.Email as SE
import Server.File as SF
import Environment (production)
import Server.Im.Database as SID
import Server.Im.Database.Flat (FlatContactHistoryMessage, fromFlatContact, fromFlatMessage)
import Server.Im.Database.Flat as SIF
import Server.Im.Types
import Server.Im.Types (Payload)
import Server.Sanitize as SS
import Server.ThreeK as ST
import Server.Wheel as SW
import Shared.Im.Types
import Shared.Markdown (Token(..))
import Shared.Markdown as SM
import Shared.Resource (Media(..), ResourceType(..))
import Shared.Resource as SP
import Shared.ResponseError (ResponseError(..))
import Shared.Markdown (Token(..))

im Int ServerEffect Payload
im loggedUserId = do
Expand Down Expand Up @@ -143,6 +145,17 @@ reportUser loggedUserId report@{ reason, userId } = do
finishTutorial Int ServerEffect Unit
finishTutorial loggedUserId = SID.updateTutorialCompleted loggedUserId

--makeshift action so new users have more attention
greet Int ServerEffect Unit
greet loggedUserId =
if production then do
starter ← ST.generateConversationStarter
void $ SID.insertMessage sender loggedUserId 1 starter
else
pure unit
where
sender = 4

registerUser Int String String ServerEffect Unit
registerUser loggedUserId rawEmail password = do
email ← SA.validateEmail rawEmail
Expand Down
5 changes: 5 additions & 0 deletions src/Server/Im/Handler.purs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ tutorial { guards: { loggedUserId } } = do
SIA.finishTutorial loggedUserId
pure ok

greeting { guards { loggedUserId Int } } ServerEffect Ok
greeting { guards: { loggedUserId } } = do
SIA.greet loggedUserId
pure ok

register { guards { loggedUserId Int }, body { email String, password String } } ServerEffect Ok
register { guards: { loggedUserId }, body: { email, password } } = do
SIA.registerUser loggedUserId email password
Expand Down
50 changes: 49 additions & 1 deletion src/Server/sql/index.sql
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,55 @@ insert into stock_text (contents, text_type) values
('Tell me the funniest joke you''ve ever heard', 1),
('What is something that''s really popular right now that will be ridiculous in five years?', 1),
('What''s your favorite movie that you could watch over and over again?', 1),
('What do you think the world will be like 50 years in the future?', 1);
('What do you think the world will be like 50 years in the future?', 1),
('What did you want to be when you were young? ', 2),
('If you found a genie, what three wishes would you ask for?', 2),
('If money weren''t an issue, what would you do?', 2),
('Do you consider yourself a lemon or a lime? Why?', 2),
('What would be your DJ name?', 2),
('What is your superpower?', 2),
('What is the most random fact you know?', 2),
('Would you rather spend a weekend in a tropical island or a snowy mountain?', 2),
('Would you rather always be two hours early or 20 minutes late?', 2),
('Would you rather be a water bear or a blue whale?', 2),
('What subject do you wish was taught in every school?', 2),
('If you could know the answer to any question, what would it be?', 2),
('What would you do if you knew you couldn''t fail?', 2),
('If you could be any fictional character, who would you be?', 2),
('If you had to invent a new ice cream, what would it be?', 2),
('What would be the title of your biography?', 2),
('What three items would you bring with you on a deserted island?', 2),
('If you could live in a different country for a year, which country would you choose?', 2),
('Does any song brings you back childhood memories?', 2),
('Which band would you join? And what would your role be?', 2),
('If you could name a band, what would it be called?', 2),
('How has your taste in music changed in the past 10 years?', 2),
('What is your go-to karaoke song?', 2),
('If you were a genre of music, what would it be?', 2),
('If you could add a word to the dictionary what would you add and what would it mean?', 2),
('If you could meet any person or character for dinner, who would you pick and why?', 2),
('What is your most used emoji?', 2),
('If you had 25 hours a day, how would you spend your extra time?', 2),
('If you had to eat one meal every day for the rest of your life what would it be?', 2),
('What''s the weirdest food you''ve ever eaten?', 2),
('What are your three favorite foods?', 2),
('What is something you are great at cooking?', 2),
('What is something you can''t cook?', 2),
('If you could make everyone forget one thing, what would it be?', 2),
('The zombie apocalypse is coming, who are 3 people you want on your team?', 2),
('Have you ever been told you look like someone famous, and who was it?', 2),
('If you were famous, what would you be famous for?', 2),
('What was your least favorite food as a child? Do you still hate it or do you love it now?', 2),
('If you were left on a deserted island with either your worst enemy or no one, which would you choose?', 2),
('If aliens landed on earth tomorrow and offered to take you home with them, would you go?', 2),
('What''s your favorite dinosaur?', 2),
('If you had a superpower but could only use it for mundane tasks, like washing the dishes or folding the laundry, what would it be?', 2),
('If you could bring any inanimate object to life as a pet, what would you choose?', 2),
('If you could create any holiday, with decorations and traditions, what would it be called?', 2),
('If you weren''t here, what would you be doing?', 2),
('What is your favorite holiday?', 2),
('What''s your biggest pet peeve?', 2),
('What is the thing that annoys you most in life?', 2);

insert into privileges (feature, name, description, quantity) values
(0, 'Receive chats', 'Access basic chat features, edit your profile and settings', 1),
Expand Down
4 changes: 4 additions & 0 deletions src/Shared/Spec.purs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ spec ∷
POST "/tutorial"
{ response Ok
}
, greeting
POST "/greeting"
{ response Ok
}
}
, profile
Routes "/profile"
Expand Down

0 comments on commit 7dac0d7

Please sign in to comment.