Skip to content

Commit 37ce0cb

Browse files
authored
Make experiments generic (#284)
* Make experiments generic * Show experiments * Extra sections html * Restore sections * a * mm * Show unavailability * b * file * Label changes * Types for in suggestion calls * ab * Reuse for backing calls
1 parent 3571d07 commit 37ce0cb

23 files changed

+352
-157
lines changed

src/Client/Experiments/Update.purs

+11-12
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,21 @@ update model =
2424
pure Nothing
2525
]
2626
JoinExperiment code →
27-
model
28-
{ section = HideSections
29-
, current = Just code
30-
} /\ dispatchEvent (Just code)
27+
F.noMessages model
28+
-- { current = Just code
29+
-- } /\ dispatchEvent (Just code)
3130
ToggleSection section → F.noMessages $ model { section = section }
32-
ConfirmImpersonation profileF.noMessages model { impersonation = profile }
31+
ConfirmExperiment experimentF.noMessages model { confirming = experiment }
3332
RedirectKarma → model /\
3433
[ do
3534
liftEffect <<< FS.send imId <<< SpecialRequest $ ToggleModal ShowKarmaPrivileges
3635
pure Nothing
3736
]
3837
UpdatePrivileges { privileges } → F.noMessages model { user { privileges = privileges } }
39-
where
40-
dispatchEvent payload =
41-
[ liftEffect do
42-
--refactor: if experiments depends on im on webpack this can be safe
43-
FSUC.broadcast setChatExperiment payload
44-
pure Nothing
45-
]
38+
-- where
39+
-- dispatchEvent payload =
40+
-- [ liftEffect do
41+
-- --refactor: if experiments depends on im on webpack this can be safe
42+
-- FSUC.broadcast setChatExperiment payload
43+
-- pure Nothing
44+
-- ]

src/Client/Im/Main.purs

+1
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ update st model =
172172
SpecialRequest (BlockUser id) → CIS.blockUser webSocket id model
173173
DisplayMoreSuggestions suggestions → CIS.displayMoreSuggestions suggestions model
174174
ToggleSuggestionsFromOnlineCIS.toggleSuggestionsFromOnline model
175+
SetBugging mc → CIS.setBugging mc model
175176
--user menu
176177
ToggleInitialScreen toggle → CIU.toggleInitialScreen toggle model
177178
Logout after → CIU.logout after model

src/Client/Im/Suggestion.purs

+31-13
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,36 @@ import Data.Either (Either(..))
1414
import Data.Enum as DE
1515
import Data.Maybe (Maybe(..))
1616
import Data.Maybe as DM
17-
import Data.Tuple (Tuple)
18-
import Data.Tuple as DT
17+
1918
import Data.Tuple.Nested ((/\))
2019
import Debug (spy)
2120
import Effect.Class (liftEffect)
21+
import Effect.Random as ER
2222
import Flame as F
2323
import Shared.Options.Page (suggestionsPerPage)
2424
import Web.Socket.WebSocket (WebSocket)
2525

2626
nextSuggestion ImModel MoreMessages
27-
nextSuggestion model@{ suggestions, suggesting } =
28-
let
29-
next = DM.maybe 0 (_ + 1) suggesting
30-
in
31-
if next >= DA.length suggestions then
32-
fetchMoreSuggestions model
27+
nextSuggestion model =
28+
if next >= DA.length model.suggestions then
29+
fetchMoreSuggestions model
30+
else
31+
model
32+
{ freeToFetchSuggestions = true
33+
, suggesting = Just next
34+
, chatting = Nothing
35+
} /\ [ bugUser ]
36+
where
37+
next = DM.maybe 0 (_ + 1) model.suggesting
38+
bugUser = do
39+
chance ← liftEffect $ ER.randomInt 0 100
40+
{- if chance <= 2 then
41+
pure <<< Just $ SetBugging Experimenting
42+
else -}
43+
if chance <= 10 then
44+
pure <<< Just $ SetBugging Backing
3345
else
34-
F.noMessages $ model
35-
{ freeToFetchSuggestions = true
36-
, suggesting = Just next
37-
, chatting = Nothing
38-
}
46+
pure Nothing
3947

4048
previousSuggestion ImModel MoreMessages
4149
previousSuggestion model@{ suggesting } =
@@ -137,3 +145,13 @@ toggleSuggestionsFromOnline model = fetchMoreSuggestions model
137145
{ suggestionsFrom = if model.suggestionsFrom == OnlineOnly then ThisWeek else OnlineOnly
138146
, suggestionsPage = 0
139147
}
148+
149+
setBugging MeroChatCall ImModel NoMessages
150+
setBugging mc model = F.noMessages $ model
151+
{ bugging = Just mc
152+
--offset index to account for non profile suggestion
153+
, suggesting = case model.suggesting of
154+
Just s | s > 0 -> Just $ s - 1
155+
Just s -> Just s
156+
Nothing -> Nothing
157+
}

src/Client/Im/WebSocket/Events.purs

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import Shared.Experiments.Types as SET
4141
import Shared.Im.Types (ClientMessagePayload, Contact, FullWebSocketPayloadClient(..), HistoryMessage, ImMessage(..), MessageStatus(..), RetryableRequest(..), TimeoutIdWrapper(..), WebSocketPayloadClient(..), WebSocketPayloadServer(..), ImModel, EditedMessagePayload)
4242
import Shared.Json as SJ
4343
import Shared.Options.MountPoint (experimentsId, imId, profileId)
44+
import Shared.Privilege (Privilege)
4445
import Shared.Profile.Types as SPT
4546
import Shared.ResponseError (DatabaseError(..))
4647
import Shared.Unsafe ((!@))
@@ -264,7 +265,7 @@ receiveTyping received model = CIC.updateTyping received.id true model /\
264265
]
265266

266267
-- | User privileges are requested on socket (re)connection
267-
receivePrivileges _ ImModel NoMessages
268+
receivePrivileges { karma Int, privileges Array Privilege } ImModel NoMessages
268269
receivePrivileges received model =
269270
model
270271
{ user

src/Client/css/experiments.css

+12
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@
2525
margin: 10px 0;
2626
}
2727

28+
.word-chain {
29+
margin: 10px 25px;
30+
}
31+
32+
.word-chain .green-button {
33+
font-weight: bold;
34+
}
35+
36+
.chat-experiments .modal-part {
37+
margin-bottom: 40px;
38+
}
39+
2840
.impersonation-header {
2941
border-bottom: 1px solid #373737;
3042
padding: 0px 5px;

src/Client/css/im.css

+58-2
Original file line numberDiff line numberDiff line change
@@ -1212,6 +1212,22 @@ input:not(type=button):focus {
12121212
justify-content: center;
12131213
}
12141214

1215+
.donate-options {
1216+
display: flex;
1217+
padding-top: 40px;
1218+
justify-content: center;
1219+
}
1220+
1221+
.donate-options i {
1222+
padding-right: 6px;
1223+
padding-left: 15px;
1224+
vertical-align: super;
1225+
}
1226+
1227+
.donate-options form {
1228+
display: inline;
1229+
}
1230+
12151231
.chat-right-buttons {
12161232
position: absolute;
12171233
top: 2px;
@@ -1223,6 +1239,16 @@ input:not(type=button):focus {
12231239
background: #2d2d2d;
12241240
}
12251241

1242+
.backing-suggestion-call {
1243+
text-align: center;
1244+
padding-top: 20px;
1245+
}
1246+
1247+
.backing-suggestion-call-enjoyer {
1248+
color: #db5a5d
1249+
}
1250+
1251+
12261252
.chatting-contact {
12271253
background: #373737;
12281254
}
@@ -1427,13 +1453,26 @@ select {
14271453
padding-left: 15px;
14281454
}
14291455

1430-
1431-
14321456
.close-avatar path {
14331457
stroke: inherit;
14341458
}
14351459

14361460

1461+
.backing-suggestion-call .svg-patreon {
1462+
vertical-align: middle;
1463+
width: 15px;
1464+
height: 15px;
1465+
1466+
}
1467+
1468+
.backing-suggestion-call .patreon-button {
1469+
border-radius: 10px;
1470+
border-radius: 15px;
1471+
padding: 5px 10px;
1472+
1473+
}
1474+
1475+
14371476
.avatar-profile {
14381477
cursor: pointer;
14391478
}
@@ -2351,6 +2390,21 @@ select {
23512390
margin-right: 25px;
23522391
}
23532392

2393+
.donate-options {
2394+
flex-direction: column;
2395+
}
2396+
2397+
.donate-options i{
2398+
padding: 0;
2399+
padding-top: 15px;
2400+
padding-bottom: 5px;
2401+
}
2402+
2403+
.donate-options .patreon-button {
2404+
width: fit-content;
2405+
align-self: center;
2406+
}
2407+
23542408
.suggestions-button {
23552409
display: block;
23562410
cursor: pointer;
@@ -2364,12 +2418,14 @@ select {
23642418

23652419
#profile-edition-form,
23662420
.suggestion.new,
2421+
.backing-suggestion-call,
23672422
.suggestion.old {
23682423
padding: 10px 15px;
23692424
}
23702425

23712426
.suggestion-cards,
23722427
.cards,
2428+
.backing-suggestion-call,
23732429
.card,
23742430
.card-center {
23752431
max-width: 100%;

src/Server/Database/Experiments.purs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import Droplet.Language
55
import Data.Date (Date)
66
import Data.DateTime (DateTime)
77
import Data.Maybe (Maybe)
8-
import Shared.Experiments.Types (ExperimentData)
8+
import Shared.Experiments.Types (Experiment)
99
import Data.Tuple.Nested (type (/\))
1010
import Type.Proxy (Proxy(..))
1111

1212
type Experiments =
1313
( idColumn Int (PrimaryKey /\ Identity)
14-
, codeExperimentData
14+
, codeExperiment
1515
, nameString
1616
, descriptionString
1717
, addedColumn DateTime Default

src/Server/Experiments/Template.purs

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import Flame as F
88
import Shared.Experiments.View as SEV
99

1010
template _ Effect String
11-
template { experiments, user } = F.preMount (QuerySelector ".chat-experiments")
11+
template payload = F.preMount (QuerySelector ".chat-experiments")
1212
{ view: SEV.view
1313
, init:
14-
{ experiments
15-
, section: HideSections
16-
, impersonation: Nothing
14+
{ experiments: payload.experiments
1715
, current: Nothing
18-
, user
16+
, confirming: Nothing
17+
, user: payload.user
18+
, section: HideSections
1919
}
2020
}

src/Server/Im/Template.purs

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ template payload = do
5858
, link: Nothing
5959
, linkText: Nothing
6060
, selectedImage: Nothing
61+
, bugging: Nothing
6162
, fullContactProfileVisible: false
6263
, freeToFetchContactList: true
6364
, erroredFields: []

src/Server/Template.purs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ defaultParameters =
3838
--work around purs-backend-es bug
3939
externalDefaultParameters a. Parameters a
4040
externalDefaultParameters =
41-
{ title: "MeroChat - Friendly Random Chat"
41+
{ title: "MeroChat - Text only, no video or group chats, and friendly only random chat!"
4242
, favicon: SP.resourcePath (Left Favicon) Ico
4343
, javascript: []
4444
, bundled: false

src/Server/sql/index.sql

+24-1
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,28 @@ language plpgsql;
343343

344344
create trigger recent_edit_boom after insert on complete_profiles for each row execute function temporarily_place_at_top();
345345

346+
create or replace function unread_for
347+
(dt timestamptz) returns int as
348+
$$
349+
declare minutes int = (extract(epoch from (utc_now() - dt)) / 60);
350+
begin
351+
if (minutes <= 10) then
352+
return 0;
353+
end if;
354+
if (minutes > 60 and minutes <= 70) then
355+
return 1;
356+
end if;
357+
if (minutes > 60 * 24 and minutes <= 60 * 24 + 10) then
358+
return 2;
359+
end if;
360+
if (minutes > 60 * 24 * 30 and minutes <= 60 * 24 * 30 + 10) then
361+
return 3;
362+
end if;
363+
return 1000;
364+
end;
365+
$$
366+
language plpgsql;
367+
346368
create or replace function insert_history
347369
(sender_id int, recipient_id int) returns void as
348370
$$
@@ -701,7 +723,8 @@ values
701723
('Zimbabwe');
702724

703725
insert into experiments (code, name, description) values
704-
(0, 'Impersonation', 'Temporarily change your profile to a character, famous person or historical figure so you can chat as if it was the same person typing it');
726+
(0, 'Impersonation', 'Temporarily change your profile to a character, famous person or historical figure so you can chat as if it was the same person typing it'),
727+
(10, 'Word chain', 'Play Word Chain with other users');
705728

706729
insert into stock_text (contents, text_type) values
707730
('I stayed up all night wondering where the sun went, then it dawned on me', 0),

0 commit comments

Comments
 (0)