Skip to content

Commit 1fd1d75

Browse files
committed
Send audio messages
1 parent 955b762 commit 1fd1d75

File tree

10 files changed

+56
-18
lines changed

10 files changed

+56
-18
lines changed

src/Client/Im/Chat.purs

+13-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Shared.Im.Types
66

77
import Client.Common.Dom as CCD
88
import Client.Common.File as CCF
9-
import Client.Im.Flame (MoreMessages, NextMessage, NoMessages)
9+
import Client.Im.Flame (NextMessage, NoMessages, MoreMessages)
1010
import Client.Im.Flame as CIF
1111
import Client.Im.Scroll as CIS
1212
import Client.Im.WebSocket as CIW
@@ -419,6 +419,18 @@ checkTyping text now webSocket model@{ lastTyping: DateTimeWrapper lt, contacts,
419419
minimumLength = 7
420420
enoughTime dt = let (Milliseconds milliseconds) = DT.diff now dt in milliseconds >= 800.0
421421

422+
beforeAudioMessage :: ImModel -> MoreMessages
423+
beforeAudioMessage model = model /\ [pure Nothing]
424+
425+
audioMessage :: Touch -> ImModel -> MoreMessages
426+
audioMessage touch model =
427+
if touch.startX - touch.endX >= threshold && touch.startY - touch.endY < threshold then
428+
model /\ [pure Nothing]
429+
else
430+
model /\ [pure Nothing]
431+
where
432+
threshold = 40
433+
422434
--this messy ass event can be from double click, context menu or swipe
423435
quoteMessage String Either Touch (Maybe Event) ImModel NextMessage
424436
quoteMessage contents event model@{ chatting, smallScreen } =

src/Client/Im/Main.purs

+2
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ update st model =
138138
Apply markup → CIC.applyMarkup markup model
139139
SetEmoji event → CIC.setEmoji event model
140140
ToggleMessageEnterCIC.toggleMessageEnter model
141+
BeforeAudioMessage -> CIC.beforeAudioMessage model
142+
AudioMessage touch -> CIC.audioMessage touch model
141143
FocusCurrentSuggestionCIC.focusCurrentSuggestion model
142144
FocusInput elementId → focusInput elementId model
143145
QuoteMessage message et → CIC.quoteMessage message et model

src/Client/Im/Touch.purs

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ import Web.Event.Internal.Types (Event)
1313
foreign import touchStart EffectFn1 Event Unit
1414
foreign import touchEnd EffectFn1 Event (Array Int)
1515

16-
onTouchStart message. NodeData message
17-
onTouchStart = HA.createRawEvent "touchstart" handler
16+
onTouchStart message. Maybe message -> NodeData message
17+
onTouchStart message = HA.createRawEvent "touchstart" handler
1818
where
1919
handler event = do
2020
EU.runEffectFn1 touchStart event
21-
pure Nothing
21+
pure message
2222

2323
onTouchEnd message. (Touch message) NodeData message
2424
onTouchEnd message = HA.createRawEvent "touchend" handler

src/Client/css/im.css

+15-3
Original file line numberDiff line numberDiff line change
@@ -2105,6 +2105,18 @@ select {
21052105
margin-bottom: 20px;
21062106
}
21072107

2108+
.audio-button {
2109+
display: none;
2110+
}
2111+
2112+
.chat-input:placeholder-shown + .chat-right-buttons .send-button-div {
2113+
display: none;
2114+
}
2115+
2116+
.chat-input:not(:placeholder-shown) + .chat-right-buttons .attachment-button {
2117+
display: none;
2118+
}
2119+
21082120
/* dry this shite */
21092121

21102122
@media (max-width:1279px) {
@@ -2113,9 +2125,9 @@ select {
21132125
overflow-x: hidden
21142126
}
21152127

2116-
/* .contact-name-badge .badge-text {
2117-
display: none
2118-
} */
2128+
.audio-button {
2129+
display: block;
2130+
}
21192131

21202132
.sign-up-call {
21212133
display: flex;

src/Server/Guard.purs

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ checkLoggedUser { configuration: { tokenSecret }, pool } request = do
3838
maybeUserId ← SE.poolEffect pool <<< ST.userIdFromToken tokenSecret <<< DMB.fromMaybe "" $ DM.lookup cookieName cookies
3939
case maybeUserId of
4040
Just userId → pure $ Right userId
41-
_ → if isPost then
41+
_ →
42+
if isPost then
4243
pure <<< Left $ PSR.unauthorized Empty
4344
else
4445
redirectLogin

src/Server/KarmaPrivileges/Database.purs

+1-9
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,8 @@ fetchInBetween10 ∷ Int → ServerEffect (Array LeaderboardUser)
3030
fetchInBetween10 position = avatarPath <$> SD.unsafeQuery "select u.name, u.avatar, position, current_karma karma from karma_leaderboard k join users u on k.ranker = u.id where position between greatest(1, @position - 5) and @position + 5 order by position" { position }
3131

3232
fetchPrivileges Int ServerEffect (Array PrivilegeUser)
33-
fetchPrivileges loggedUserId = SD.unsafeQuery "SELECT name, description, quantity, current_karma >= quantity AS got FROM privileges LEFT JOIN karma_leaderboard ON ranker = @loggedUserId WHERE feature = ANY(@privileges) ORDER BY quantity desc"
33+
fetchPrivileges loggedUserId = SD.unsafeQuery "SELECT name, description, quantity, current_karma >= quantity AS got FROM privileges LEFT JOIN karma_leaderboard ON ranker = @loggedUserId ORDER BY quantity desc"
3434
{ loggedUserId
35-
, privileges:
36-
[ ReceiveChats
37-
, StartChats
38-
, StartChatExperiments
39-
, MoreTags
40-
, SendLinks
41-
, SendImages
42-
]
4335
}
4436

4537
fetchStats Int ServerEffect _

src/Server/sql/index.sql

+1
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,7 @@ insert into privileges (feature, name, description, quantity) values
884884
(201, 'Impersonation', 'Start Impersonation chat experiment', 1000),
885885
(300, 'More tags', 'Increased number of max profile tags', 250),
886886
(400, 'Send links', 'Send markdown links', 1000),
887+
(401, 'Send audio', 'Send voice messages', 2000),
887888
(500, 'Send images', 'Send pictures in chats', 3000);
888889

889890
insert into badges (kind, description) values

src/Shared/Im/Types.purs

+2
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ data ImMessage
295295
| SetMessageContent (Maybe Int) String
296296
| Apply Markup
297297
| SetEmoji Event
298+
| BeforeAudioMessage
299+
| AudioMessage Touch
298300
| InsertLink
299301
| CheckTyping String
300302
| NoTyping Int

src/Shared/Im/View/ChatInput.purs

+11
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Shared.Availability
55
import Shared.Im.Types
66

77
import Client.Common.Privilege as CCP
8+
import Client.Im.Swipe as CIT
89
import Control.Alt ((<|>))
910
import Data.Array ((!!), (:))
1011
import Data.Array as DA
@@ -132,6 +133,7 @@ chatBarInput
132133
]
133134
, HE.div (HA.class' "chat-right-buttons")
134135
[ imageButton
136+
, audioButton
135137
, sendButton messageEnter model
136138
]
137139
]
@@ -247,6 +249,15 @@ imageButton = HE.svg [ HA.onClick $ ToggleChatModal ShowSelectedImage, HA.class'
247249
[ HE.path' [ HA.class' "strokeless", HA.d "M10.91,4v8.78a2.44,2.44,0,0,1-.72,1.65A3.31,3.31,0,0,1,8,15.25H7.67a2.67,2.67,0,0,1-2.58-2.48L5.26,2.9V2.82l0-.2h0a2,2,0,0,1,.19-.7v0a1.82,1.82,0,0,1,1.6-1A1.69,1.69,0,0,1,7.73,1,2.14,2.14,0,0,1,9.16,2.81h0v7.81c0,.75-.36,1.26-1.13,1.26A1.12,1.12,0,0,1,6.9,10.63V4H6.11v6.61a1.93,1.93,0,0,0,2,2,1.83,1.83,0,0,0,1.82-2l0-7.81c0-.06,0-.12,0-.18s0-.11,0-.17,0,0,0-.05a2.59,2.59,0,0,0-.32-1s0,0,0,0A3.19,3.19,0,0,0,7.77.09h0A2.41,2.41,0,0,0,7.09,0a2.56,2.56,0,0,0-1,.21H6A2.74,2.74,0,0,0,4.76,1.39h0a3,3,0,0,0-.37,1.43v10A3.41,3.41,0,0,0,7.67,16H8A4,4,0,0,0,10.69,15a3.22,3.22,0,0,0,.93-2.18V4Z" ]
248250
]
249251

252+
audioButton Html ImMessage
253+
audioButton = HE.svg [ CIT.onTouchStart $ Just BeforeAudioMessage, CIT.onTouchEnd AudioMessage, HA.class' "attachment-button audio-button", HA.viewBox "0 0 512 512" ]
254+
[
255+
HE.g_
256+
[ HE.path' [HA.class' "strokeless", HA.d "m439.5,236c0-11.3-9.1-20.4-20.4-20.4s-20.4,9.1-20.4,20.4c0,70-64,126.9-142.7,126.9-78.7,0-142.7-56.9-142.7-126.9 0-11.3-9.1-20.4-20.4-20.4s-20.4,9.1-20.4,20.4c0,86.2 71.5,157.4 163.1,166.7v57.5h-23.6c-11.3,0-20.4,9.1-20.4,20.4 0,11.3 9.1,20.4 20.4,20.4h88c11.3,0 20.4-9.1 20.4-20.4 0-11.3-9.1-20.4-20.4-20.4h-23.6v-57.5c91.6-9.3 163.1-80.5 163.1-166.7z" ]
257+
, HE.path' [ HA.class' "strokeless", HA.d "m256,323.5c51,0 92.3-41.3 92.3-92.3v-127.9c0-51-41.3-92.3-92.3-92.3s-92.3,41.3-92.3,92.3v127.9c0,51 41.3,92.3 92.3,92.3zm-52.3-220.2c0-28.8 23.5-52.3 52.3-52.3s52.3,23.5 52.3,52.3v127.9c0,28.8-23.5,52.3-52.3,52.3s-52.3-23.5-52.3-52.3v-127.9z" ]
258+
]
259+
]
260+
250261
sendButton Boolean ImModel Html ImMessage
251262
sendButton messageEnter model =
252263
HE.div

src/Shared/Privilege.purs

+6-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ data Privilege
2525
| ImpersonationChatExperiment
2626
| MoreTags
2727
| SendLinks
28+
| SendAudios
2829
| SendImages
2930

3031
hasPrivilege r. Privilege { privileges Array Privilege | r } Boolean
@@ -56,6 +57,7 @@ instance BoundedEnum Privilege where
5657
ImpersonationChatExperiment201
5758
MoreTags300
5859
SendLinks400
60+
SendAudios401
5961
SendImages500
6062

6163
toEnum = case _ of
@@ -65,6 +67,7 @@ instance BoundedEnum Privilege where
6567
201Just ImpersonationChatExperiment
6668
300Just MoreTags
6769
400Just SendLinks
70+
401Just SendAudios
6871
500Just SendImages
6972
_ → Nothing
7073

@@ -76,6 +79,7 @@ instance Enum Privilege where
7679
ImpersonationChatExperimentNothing
7780
MoreTagsJust SendLinks
7881
SendLinksJust SendImages
82+
SendAudiosJust SendImages
7983
SendImagesNothing
8084

8185
pred = case _ of
@@ -85,7 +89,8 @@ instance Enum Privilege where
8589
ImpersonationChatExperimentJust StartChatExperiments
8690
MoreTagsJust StartChatExperiments
8791
SendLinksJust MoreTags
88-
SendImagesJust SendLinks
92+
SendAudiosJust SendLinks
93+
SendImagesJust SendAudios
8994

9095
instance Show Privilege where
9196
show = DSG.genericShow

0 commit comments

Comments
 (0)