diff --git a/src/Client/Im/Chat.purs b/src/Client/Im/Chat.purs index dcb8e615..d3bf3b5c 100644 --- a/src/Client/Im/Chat.purs +++ b/src/Client/Im/Chat.purs @@ -109,10 +109,10 @@ beforeSendMessage content model = case content of where --the user messaged could be in the contacts and suggestions -- in either case, check if the chat history has not already been fetched - shouldFetchHistory /\ updatedModel = case model.chatting, model.suggesting of - Nothing, (Just index) → + shouldFetchHistory /\ updatedModel = case model.chatting of + Nothing → let - user = model.suggestions !@ index + user = model.suggestions !@ model.suggesting maybeIndex = DA.findIndex ((_ == user.id) <<< _.id <<< _.user) model.contacts updatedContacts | DM.isJust maybeIndex = model.contacts @@ -122,11 +122,11 @@ beforeSendMessage content model = case content of Tuple (updatedContacts !@ SU.fromJust updatedChatting).shouldFetchChatHistory model { chatting = updatedChatting , contacts = updatedContacts - , suggestions = SU.fromJust $ DA.deleteAt index model.suggestions + , suggestions = SU.fromJust $ DA.deleteAt model.suggesting model.suggestions } - _, _ → Tuple false model + _ → Tuple false model - nextEffects ct = [ fetchHistory, nextSendMessage ct ] + nextEffects ct = [ nextSendMessage ct, fetchHistory ] fetchHistory = pure <<< Just <<< SpecialRequest $ FetchHistory shouldFetchHistory nextSendMessage ct = do @@ -529,9 +529,9 @@ editMessage message id model = where setIt = EC.liftEffect do input ← chatInput model.chatting - CCD.setValue input (spy "msg" message) + CCD.setValue (spy "inp" input) message -deleteMessage ∷ Int → WebSocket -> ImModel → NoMessages +deleteMessage ∷ Int → WebSocket → ImModel → NoMessages deleteMessage id webSocket model = model { toggleContextMenu = HideContextMenu @@ -540,6 +540,6 @@ deleteMessage id webSocket model = chatting = SU.fromJust model.chatting deleteIt = do - EC.liftEffect <<< CIW.sendPayload webSocket $ DeletedMessage { id, userId : (model.contacts !@ chatting).user.id } + EC.liftEffect <<< CIW.sendPayload webSocket $ DeletedMessage { id, userId: (model.contacts !@ chatting).user.id } pure Nothing diff --git a/src/Client/Im/History.purs b/src/Client/Im/History.purs index 6af0f24f..cc93f856 100644 --- a/src/Client/Im/History.purs +++ b/src/Client/Im/History.purs @@ -20,15 +20,13 @@ import Shared.Unsafe as SU import Web.DOM.Element as WDE checkFetchHistory ∷ ImModel → MoreMessages -checkFetchHistory model@{ freeToFetchChatHistory } - | freeToFetchChatHistory = model /\ [ Just <<< SpecialRequest <<< FetchHistory <$> getScrollTop ] +checkFetchHistory model = + model /\ if model.freeToFetchChatHistory then [ Just <<< SpecialRequest <<< FetchHistory <$> getScrollTop ] else [] - where - getScrollTop = liftEffect do - element ← CCD.unsafeGetElementById MessageHistory - (_ < 1.0) <$> WDE.scrollTop element - - | otherwise = F.noMessages model + where + getScrollTop = liftEffect do + element ← CCD.unsafeGetElementById MessageHistory + (_ < 1.0) <$> WDE.scrollTop element --to avoid issues with older missed unread messages just get the whole chat history on first load fetchHistory ∷ Boolean → ImModel → MoreMessages diff --git a/src/Client/Im/Suggestion.purs b/src/Client/Im/Suggestion.purs index 9b1e88cd..bc53935d 100644 --- a/src/Client/Im/Suggestion.purs +++ b/src/Client/Im/Suggestion.purs @@ -27,12 +27,12 @@ nextSuggestion model = else model { freeToFetchSuggestions = true - , suggesting = Just next + , suggesting = next , chatting = Nothing , bugging = Nothing } /\ [ bugUser model ] where - next = DM.maybe 0 (_ + 1) model.suggesting + next = model.suggesting + 1 -- | Display previous suggestion card previousSuggestion ∷ ImModel → MoreMessages @@ -42,12 +42,12 @@ previousSuggestion model = else model { freeToFetchSuggestions = true - , suggesting = Just previous + , suggesting = previous , chatting = Nothing , bugging = Nothing } /\ [ bugUser model ] where - previous = DM.maybe 0 (_ - 1) model.suggesting + previous = model.suggesting - 1 -- | When moving suggestion cards, diplay a special card n% of the time bugUser ∷ ImModel → Aff (Maybe ImMessage) @@ -97,7 +97,7 @@ displayMoreSuggestions suggestions model = } where suggestionsSize = DA.length suggestions - suggesting = Just $ if suggestionsSize <= 1 then 0 else 1 + suggesting = if suggestionsSize <= 1 then 0 else 1 lowQualityUsersBin = 5 lowQualityUsersIn = DA.length <<< DA.filter ((_ >= lowQualityUsersBin) <<< _.bin) @@ -131,8 +131,5 @@ setBugging ∷ MeroChatCall → ImModel → NoMessages setBugging mc model = F.noMessages model { bugging = Just mc --offset index to account for non profile suggestion - , suggesting = case model.suggesting of - Just s | s > 0 → Just $ s - 1 - Just s → Just s - Nothing → Nothing + , suggesting = if model.suggesting > 0 then model.suggesting - 1 else model.suggesting } diff --git a/src/Client/Im/WebSocket/Events.purs b/src/Client/Im/WebSocket/Events.purs index b2ef260b..2e9d9067 100644 --- a/src/Client/Im/WebSocket/Events.purs +++ b/src/Client/Im/WebSocket/Events.purs @@ -358,7 +358,7 @@ unsuggest userId model = model i ← unsuggestedIndex DA.deleteAt i model.suggestions updatedSuggesting - | unsuggestedIndex /= Nothing && unsuggestedIndex < model.suggesting = (max 0 <<< (_ - 1)) <$> model.suggesting + | unsuggestedIndex /= Nothing && unsuggestedIndex < Just model.suggesting = max 0 (model.suggesting - 1) | otherwise = model.suggesting -- | Updated contacts if user is already there diff --git a/src/Server/Im/Database.purs b/src/Server/Im/Database.purs index 7642d23c..18e7ccf4 100644 --- a/src/Server/Im/Database.purs +++ b/src/Server/Im/Database.purs @@ -278,11 +278,11 @@ canEditMessage loggedUserId messageId = # from messages # wher (_id .=. messageId .&&. _sender .=. loggedUserId) -deleteMessage ∷ ∀ r. Int → Int → Int -> BaseEffect { pool ∷ Pool | r } Unit +deleteMessage ∷ ∀ r. Int → Int → Int → BaseEffect { pool ∷ Pool | r } Unit deleteMessage loggedUserId userId messageId = SD.execute $ - delete - # from messages - # wher (_id .=. messageId .&&. _sender .=. loggedUserId .&&. _recipient .=. userId) + delete + # from messages + # wher (_id .=. messageId .&&. _sender .=. loggedUserId .&&. _recipient .=. userId) insertMessage ∷ ∀ r. Int → Int → String → BaseEffect { pool ∷ Pool | r } Int insertMessage loggedUserId recipient content = SD.withTransaction $ \connection → do diff --git a/src/Server/Im/Template.purs b/src/Server/Im/Template.purs index 2001f2ce..60e894aa 100644 --- a/src/Server/Im/Template.purs +++ b/src/Server/Im/Template.purs @@ -23,9 +23,6 @@ import Shared.Resource as SP template ∷ Payload → Effect String template payload = do - let - unreadChats = SIU.countUnreadChats payload.user.id payload.contacts - suggestionsCount = DA.length payload.suggestions lt ← EN.nowDateTime F.preMount (QuerySelector $ show SE.Im) { view: \model → ST.templateWith $ defaultParameters @@ -41,7 +38,7 @@ template payload = do , temporaryId: 0 , typingIds: [] , modalsLoaded: [] - , suggesting: if suggestionsCount == 0 then Nothing else if suggestionsCount == 1 then Just 0 else Just 1 + , suggesting: if suggestionsCount == 1 then 0 else 1 , freeToFetchChatHistory: true , suggestionsPage: 1 , errorMessage: "" @@ -80,6 +77,9 @@ template payload = do } } where + unreadChats = SIU.countUnreadChats payload.user.id payload.contacts + suggestionsCount = DA.length payload.suggestions + javascript = [ HE.script' [ HA.type' "text/javascript", HA.src $ SP.bundlePath Emoji Js ] , HE.script' [ HA.type' "text/javascript", HA.src $ SP.bundlePath Im Js ] diff --git a/src/Shared/Avatar.purs b/src/Shared/Avatar.purs index 7a7f4cfb..8f1328e0 100644 --- a/src/Shared/Avatar.purs +++ b/src/Shared/Avatar.purs @@ -41,14 +41,14 @@ avatarPath index = SP.resourcePath (Left name) Png avatarForSender ∷ Maybe String → String avatarForSender = DM.fromMaybe defaultAvatar -avatarForRecipient ∷ Maybe Int → Maybe String → String -avatarForRecipient index = DM.fromMaybe (avatarPath <<< avatarIndex $ SU.fromJust index) +avatarForRecipient ∷ Int → Maybe String → String +avatarForRecipient index = DM.fromMaybe <<< avatarPath $ avatarIndex index avatarIndex ∷ Int → Int avatarIndex index = mod index differentAvatarImages + 1 -avatarColorClass ∷ Maybe Int → String -avatarColorClass index = className <> show (mod (SU.fromJust index) totalColorClasses + 1) +avatarColorClass ∷ Int → String +avatarColorClass index = className <> show (mod index totalColorClasses + 1) where className = " avatar-color-" totalColorClasses = 4 diff --git a/src/Shared/Experiments/Doppelganger.purs b/src/Shared/Experiments/Doppelganger.purs index 4f8b744d..4f6b061d 100644 --- a/src/Shared/Experiments/Doppelganger.purs +++ b/src/Shared/Experiments/Doppelganger.purs @@ -10,5 +10,5 @@ import Shared.Experiments.Types (ChatExperimentMessage, ChatExperimentModel) view ∷ ChatExperimentModel → Html ChatExperimentMessage view model = HE.div (HA.class' "word-chain duller") [ --HE.button (HA.class' "green-button") "Play!" - HE.text "Currently unavailable" + HE.text "Currently unavailable" ] \ No newline at end of file diff --git a/src/Shared/Experiments/Impersonation.purs b/src/Shared/Experiments/Impersonation.purs index c3912049..14eaee42 100644 --- a/src/Shared/Experiments/Impersonation.purs +++ b/src/Shared/Experiments/Impersonation.purs @@ -92,7 +92,7 @@ view model = HE.div (HA.class' "impersonation") profiles s = HE.div (HA.class' { hidden: model.section /= s }) <<< DA.mapWithIndex toProfile toProfile index p = HE.div [ HA.class' "contact", HA.onClick <<< ConfirmExperiment <<< Just <<< Impersonation $ Just p ] [ HE.div (HA.class' "avatar-contact-list-div") - [ HE.img [ HA.title $ SU.fromJust p.avatar, HA.class' $ "avatar-contact-list" <> SA.avatarColorClass (Just index), HA.src $ SU.fromJust p.avatar ] + [ HE.img [ HA.title $ SU.fromJust p.avatar, HA.class' $ "avatar-contact-list" <> SA.avatarColorClass index, HA.src $ SU.fromJust p.avatar ] ] , HE.div [ HA.class' "contact-profile", HA.title $ "Start Impersonation as " <> p.name ] [ HE.span (HA.class' "contact-name") p.name diff --git a/src/Shared/Experiments/Types.purs b/src/Shared/Experiments/Types.purs index 1a579d57..79a2ed4b 100644 --- a/src/Shared/Experiments/Types.purs +++ b/src/Shared/Experiments/Types.purs @@ -68,22 +68,22 @@ instance BoundedEnum Experiment where fromEnum = case _ of Impersonation _ → 0 WordChain → 10 - Doppelganger -> 20 + Doppelganger → 20 toEnum = case _ of 0 → Just (Impersonation Nothing) 10 → Just WordChain - 20 -> Just Doppelganger + 20 → Just Doppelganger _ → Nothing instance Enum Experiment where succ = case _ of Impersonation _ → Just WordChain WordChain → Just Doppelganger - Doppelganger -> Nothing + Doppelganger → Nothing pred = case _ of Impersonation _ → Nothing WordChain → Just (Impersonation Nothing) - Doppelganger -> Just WordChain + Doppelganger → Just WordChain derive instance Generic Experiment _ diff --git a/src/Shared/Experiments/View.purs b/src/Shared/Experiments/View.purs index e76f95f9..3d99f411 100644 --- a/src/Shared/Experiments/View.purs +++ b/src/Shared/Experiments/View.purs @@ -30,4 +30,4 @@ extra ∷ ChatExperimentModel → Experiment → Html ChatExperimentMessage extra model = case _ of Impersonation ip → SEI.view model WordChain → SEW.view model - Doppelganger -> SED.view model \ No newline at end of file + Doppelganger → SED.view model \ No newline at end of file diff --git a/src/Shared/Im/Modals.purs b/src/Shared/Im/Modals.purs index 9ad71898..4aa74e56 100644 --- a/src/Shared/Im/Modals.purs +++ b/src/Shared/Im/Modals.purs @@ -54,14 +54,12 @@ modals model@{ erroredFields, toggleModal, chatting } = where tutorialSteps = toggleModal == Tutorial ChatSuggestions && DM.isNothing chatting || toggleModal == Tutorial Chatting -showAvatar ∷ ImModel → Maybe Int → Html ImMessage +showAvatar ∷ ImModel → Int → Html ImMessage showAvatar model index = HE.lazy Nothing largeAvatar who where who = case model.chatting of Just c → map _.user (model.contacts !! c) - Nothing → case model.suggesting of - Just s → model.suggestions !! s - Nothing → Nothing + Nothing → model.suggestions !! model.suggesting largeAvatar p = HE.div (HA.class' "confirmation large") case p of Nothing → HE.createEmptyElement "div" diff --git a/src/Shared/Im/Types.purs b/src/Shared/Im/Types.purs index f0a134f1..3c2da188 100644 --- a/src/Shared/Im/Types.purs +++ b/src/Shared/Im/Types.purs @@ -146,7 +146,7 @@ type Im = --the current logged in user , user ∷ ImUser --indexes - , suggesting ∷ Maybe Int + , suggesting ∷ Int , chatting ∷ Maybe Int , smallScreen ∷ Boolean , editing ∷ Maybe Int @@ -202,7 +202,7 @@ data ShowUserMenuModal | ShowSettings | ShowKarmaPrivileges | ShowHelp - | ShowAvatar (Maybe Int) + | ShowAvatar Int | ShowBacker | ShowFeedback | ShowReport Int diff --git a/src/Shared/Im/View/ChatInput.purs b/src/Shared/Im/View/ChatInput.purs index 8feeb2d1..50b08b00 100644 --- a/src/Shared/Im/View/ChatInput.purs +++ b/src/Shared/Im/View/ChatInput.purs @@ -105,10 +105,8 @@ chatBarInput model@ { chatting , contacts - , suggesting , isWebSocketConnected , messageEnter - , suggestions , toggleChatModal } = HE.fragment [ emojiModal model @@ -118,7 +116,7 @@ chatBarInput ] , HE.div' [ HA.id $ show ChatInputPreview, HA.class' "chat-input-preview message-content" ] ] - , HE.div [ HA.class' { hidden: not available || toggleChatModal == ShowPreview || DM.isNothing chatting && DM.isNothing suggesting } ] + , HE.div [ HA.class' { hidden: not available || toggleChatModal == ShowPreview || DM.isNothing chatting && DA.null model.suggestions } ] [ HE.div [ HA.class' "chat-input-options" ] [ bold , italic @@ -155,7 +153,7 @@ chatBarInput ] where available = DM.fromMaybe true $ getContact ((_ /= Unavailable) <<< _.availability <<< _.user) - recipientName = DM.fromMaybe "" $ getContact (_.name <<< _.user) <|> getProperty suggesting suggestions _.name + recipientName = DM.fromMaybe "" $ getContact (_.name <<< _.user) <|> getProperty (Just model.suggesting) model.suggestions _.name getContact ∷ ∀ a. (Contact → a) → Maybe a getContact = getProperty chatting contacts @@ -301,7 +299,7 @@ emojiModal { toggleChatModal } = HE.div [ HA.class' { "emoji-wrapper": true, hid , HE.div_ $ map (HE.span_ <<< _.s) pairs ] -emojiClickEvent :: (Event -> ImMessage) -> NodeData ImMessage +emojiClickEvent ∷ (Event → ImMessage) → NodeData ImMessage emojiClickEvent message = HA.createRawEvent "click" handler where handler event diff --git a/src/Shared/Im/View/ContactList.purs b/src/Shared/Im/View/ContactList.purs index b61dc2bd..85889bab 100644 --- a/src/Shared/Im/View/ContactList.purs +++ b/src/Shared/Im/View/ContactList.purs @@ -62,13 +62,12 @@ contactList displayContactListEntry index { history, user, typing } = let - justIndex = Just index contact = user numberUnreadMessages = countUnread history lastHistoryEntry = SU.fromJust $ DA.last history isContextMenuVisible = toggleContextMenu == ShowContactContextMenu user.id avatarClasses - | DM.isNothing contact.avatar = "avatar-contact-list" <> SA.avatarColorClass justIndex + | DM.isNothing contact.avatar = "avatar-contact-list" <> SA.avatarColorClass index | otherwise = "avatar-contact-list" in @@ -77,7 +76,7 @@ contactList , HA.onClick $ ResumeChat user.id ] [ HE.div [ HA.class' "avatar-contact-list-div", HA.title $ if contact.onlineStatus && onlineStatus then show contact.availability else "" ] - [ HE.img [ SA.async, SA.decoding "lazy", HA.class' avatarClasses, HA.src $ SA.avatarForRecipient justIndex contact.avatar ] + [ HE.img [ SA.async, SA.decoding "lazy", HA.class' avatarClasses, HA.src $ SA.avatarForRecipient index contact.avatar ] , HE.div' [ HA.class' { "online-indicator": true, hidden: contact.availability /= Online || not contact.onlineStatus || not onlineStatus } ] ] , HE.div [ HA.class' "contact-profile" ] diff --git a/src/Shared/Im/View/NotificationMobile.purs b/src/Shared/Im/View/NotificationMobile.purs index 846459cc..2d7506b6 100644 --- a/src/Shared/Im/View/NotificationMobile.purs +++ b/src/Shared/Im/View/NotificationMobile.purs @@ -21,5 +21,5 @@ unreadNotification { smallScreen, contacts, user: { id } } = HE.div [ HA.onClick in if DA.length all > 5 then DA.snoc (DA.take 5 all) $ HE.text "..." else all unread index { history, user: { avatar } } - | DF.any (\{ status, sender } → status < Read && sender /= id) history = Just $ HE.img [ HA.class' $ "avatar-notification-mobile" <> SA.avatarColorClass (Just index), HA.src $ SA.avatarForRecipient (Just index) avatar ] + | DF.any (\{ status, sender } → status < Read && sender /= id) history = Just $ HE.img [ HA.class' $ "avatar-notification-mobile" <> SA.avatarColorClass index, HA.src $ SA.avatarForRecipient index avatar ] | otherwise = Nothing \ No newline at end of file diff --git a/src/Shared/Im/View/SuggestionCall.purs b/src/Shared/Im/View/SuggestionCall.purs index ead91a4d..0b31c8f4 100644 --- a/src/Shared/Im/View/SuggestionCall.purs +++ b/src/Shared/Im/View/SuggestionCall.purs @@ -27,19 +27,13 @@ suggestionCall { contacts, suggesting, chatting, suggestions, toggleModal } Just { avatar, name } | not $ DA.null contacts → HE.div (HA.class' "side-suggestions-container") [ HE.div [ HA.class' "side-suggestion" ] [ HE.div [ HA.class' "avatar-contact-list-div faded", HA.onClick $ SpecialRequest PreviousSuggestion, HA.title "Move to this chat suggestion" ] - [ let - previousIndex = map (_ - 1) suggesting - in - SA.avatar [ HA.class' $ "avatar-contact-list" <> SA.avatarColorClass previousIndex, HA.src $ SA.avatarForRecipient previousIndex $ getAvatar previousIndex ] + [ SA.avatar [ HA.class' $ "avatar-contact-list" <> SA.avatarColorClass (suggesting - 1), HA.src $ SA.avatarForRecipient (suggesting - 1) $ getAvatar (suggesting - 1) ] ] , HE.div [ HA.class' "avatar-contact-list-div margin-less-z", HA.onClick FocusCurrentSuggestion, HA.title "Move to this chat suggestion" ] [ SA.avatar [ HA.class' $ avatarClasses avatar, HA.src $ SA.avatarForRecipient suggesting avatar ] ] , HE.div [ HA.class' "avatar-contact-list-div margin-less faded", HA.onClick $ SpecialRequest NextSuggestion, HA.title "Move to this chat suggestion" ] - [ let - nextIndex = map (_ + 1) suggesting - in - SA.avatar [ HA.class' $ "avatar-contact-list" <> SA.avatarColorClass nextIndex, HA.src $ SA.avatarForRecipient nextIndex $ getAvatar nextIndex ] + [ SA.avatar [ HA.class' $ "avatar-contact-list" <> SA.avatarColorClass (suggesting + 1), HA.src $ SA.avatarForRecipient (suggesting + 1) $ getAvatar (suggesting + 1) ] ] , HE.div [ HA.class' "contact-profile", HA.title "Your chat suggestions" ] [ HE.span (HA.class' "contact-name") name @@ -49,13 +43,10 @@ suggestionCall { contacts, suggesting, chatting, suggestions, toggleModal } _ → HE.div' (HA.class' "side-suggestions-container") where - suggs = do - index ← suggesting - suggestions !! index + suggs = suggestions !! suggesting getAvatar index = do - i ← index - user ← suggestions !! i + user ← suggestions !! index user.avatar avatarClasses avatar diff --git a/src/Shared/Im/View/SuggestionProfile.purs b/src/Shared/Im/View/SuggestionProfile.purs index 4bf4dcaf..c5c998ef 100644 --- a/src/Shared/Im/View/SuggestionProfile.purs +++ b/src/Shared/Im/View/SuggestionProfile.purs @@ -49,19 +49,18 @@ suggestionProfile model = else if DA.null model.suggestions && notChatting then emptySuggestions else - case model.chatting, model.suggesting of - i@(Just index), _ → + case model.chatting of + Just index → let contact = model.contacts !@ index in if contact.user.availability == Unavailable then unavailable contact.user.name else if model.fullContactProfileVisible then - fullProfile FullContactProfile i model contact.user + fullProfile FullContactProfile index model contact.user else compactProfile model contact - Nothing, (Just index) → suggestionCards model index - _, _ → emptySuggestions + Nothing → suggestionCards model model.suggesting where notChatting = DM.isNothing model.chatting @@ -93,7 +92,7 @@ compactProfile model contact = HE.div (HA.class' { "profile-contact": true, highlighted: model.toggleModal == Tutorial Chatting }) [ HE.div (HA.class' "profile-contact-top") [ SIA.arrow [ HA.class' "svg-back-card", HA.onClick $ ToggleInitialScreen true ] - , HE.img $ [ SA.async, SA.decoding "lazy", HA.class' avatarClasses, HA.src $ SA.avatarForRecipient model.chatting contact.user.avatar ] <> showProfileAction + , HE.img $ [ SA.async, SA.decoding "lazy", HA.class' avatarClasses, HA.src $ SA.avatarForRecipient (DM.fromMaybe 0 model.chatting) contact.user.avatar ] <> showProfileAction , HE.div (HA.class' "profile-contact-header" : showProfileAction) [ HE.div (HA.class' "contact-name-badge") $ HE.h1 (HA.class' "contact-name") contact.user.name : badges contact.user.badges , typingNotice @@ -112,7 +111,7 @@ compactProfile model contact = showProfileAction = [ HA.title "Click to see full profile", HA.onClick ToggleContactProfile ] avatarClasses - | DM.isNothing contact.user.avatar = "avatar-profile " <> SA.avatarColorClass model.chatting + | DM.isNothing contact.user.avatar = "avatar-profile " <> SA.avatarColorClass (DM.fromMaybe 0 model.chatting) | otherwise = "avatar-profile" isTyping = (model.contacts !@ SU.fromJust model.chatting).typing @@ -130,7 +129,7 @@ compactProfile model contact = ] -- | Suggestion cards/full screen profile view -fullProfile ∷ ProfilePresentation → Maybe Int → ImModel → ImUser → Html ImMessage +fullProfile ∷ ProfilePresentation → Int → ImModel → ImUser → Html ImMessage fullProfile presentation index model@{ toggleContextMenu, freeToFetchSuggestions, toggleModal } user@{ id } = case presentation of FullContactProfile → HE.div [ HA.class' "suggestion old" ] $ fullProfileMenu : profile @@ -213,7 +212,7 @@ fullProfile presentation index model@{ toggleContextMenu, freeToFetchSuggestions ] ] -displayProfile ∷ Maybe Int → ImUser → ImUser → Maybe ImMessage → Array (Html ImMessage) +displayProfile ∷ Int → ImUser → ImUser → Maybe ImMessage → Array (Html ImMessage) displayProfile index loggedUser profileUser temporaryUserMessage = [ SA.avatar [ HA.onClick <<< SpecialRequest <<< ToggleModal $ ShowAvatar index, HA.class' avatarClasses, HA.src $ SA.avatarForRecipient index profileUser.avatar ] , HE.h1 (HA.class' "profile-name") profileUser.name @@ -315,7 +314,7 @@ suggestionCards model@{ user, suggestions, toggleModal } index = | isCenter = [ HA.class' { "card card-center": true, highlighted: toggleModal == Tutorial ChatSuggestions } ] | otherwise = [ HA.class' "card card-sides faded" ] in - HE.div attrs $ fullProfile (if isCenter then CenterCard else if isPrevious then PreviousCard else NextCard) (Just suggesting) model profile + HE.div attrs $ fullProfile (if isCenter then CenterCard else if isPrevious then PreviousCard else NextCard) suggesting model profile isNotTutorial = case toggleModal of Tutorial _ → false diff --git a/src/Shared/KarmaPrivileges/View.purs b/src/Shared/KarmaPrivileges/View.purs index 7d8a32ff..31ecfa2f 100644 --- a/src/Shared/KarmaPrivileges/View.purs +++ b/src/Shared/KarmaPrivileges/View.purs @@ -90,11 +90,11 @@ view { top10, inBetween10, userPosition, toggleBoard, privileges, stats: { sent, leaderboardEntry index { position, avatar, name, karma } = let avatarClasses - | DM.isNothing avatar = "avatar-leaderboard" <> SA.avatarColorClass (Just index) + | DM.isNothing avatar = "avatar-leaderboard" <> SA.avatarColorClass index | otherwise = "avatar-leaderboard" in HE.div (HA.class' $ "board-position" <> if position == userPosition then " user" else "") - [ HE.div (HA.class' "avatar-leaderboard-div") $ HE.img [ HA.class' avatarClasses, HA.src $ SA.avatarForRecipient (Just index) avatar ] + [ HE.div (HA.class' "avatar-leaderboard-div") $ HE.img [ HA.class' avatarClasses, HA.src $ SA.avatarForRecipient index avatar ] , HE.div (HA.class' "name-karma") [ HE.div_ [ HE.div (HA.class' "name") name diff --git a/test/Client/Im/Chat.purs b/test/Client/Im/Chat.purs index e07eac54..40a5fe03 100644 --- a/test/Client/Im/Chat.purs +++ b/test/Client/Im/Chat.purs @@ -29,7 +29,7 @@ tests = do model' = model { suggestions = suggestion : modelSuggestions , chatting = Nothing - , suggesting = Just 0 + , suggesting = 0 } { contacts } = DT.fst $ CIC.beforeSendMessage content model' TUA.equal (_.user <$> DA.head contacts) $ Just suggestion @@ -39,7 +39,7 @@ tests = do model' = model { suggestions = [ contact.user ] , chatting = Nothing - , suggesting = Just 0 + , suggesting = 0 , contacts = [ contact ] } { contacts } = DT.fst $ CIC.beforeSendMessage content model' @@ -50,7 +50,7 @@ tests = do model' = model { suggestions = [ contact.user ] , chatting = Nothing - , suggesting = Just 0 + , suggesting = 0 , contacts = [ SIC.defaultContact 789 contact.user { id = 8 }, contact ] } { chatting } = DT.fst $ CIC.beforeSendMessage content model' @@ -61,7 +61,7 @@ tests = do model' = model { suggestions = suggestion : modelSuggestions , chatting = Nothing - , suggesting = Just 0 + , suggesting = 0 } { chatting } = DT.fst $ CIC.beforeSendMessage content model' TUA.equal (Just 0) chatting diff --git a/test/Client/Im/Main.purs b/test/Client/Im/Main.purs index c5edec9a..4ebc7f51 100644 --- a/test/Client/Im/Main.purs +++ b/test/Client/Im/Main.purs @@ -180,7 +180,7 @@ tests = do ) $ model { contacts = [ contact ] , chatting = Just 0 - , suggesting = Nothing + , suggesting = 0 } TUA.equal [ Tuple newMessageID Read ] $ map (\({ id, status }) → Tuple id status) (contacts !@ 0).history @@ -199,7 +199,7 @@ tests = do ) $ model { contacts = [ contact ] , chatting = Just 0 - , suggesting = Nothing + , suggesting = 0 } TUA.equal [ Tuple newMessageID Delivered ] $ map (\({ id, status }) → Tuple id status) (contacts !@ 0).history diff --git a/test/Client/Im/Suggestion.purs b/test/Client/Im/Suggestion.purs index b4c51d42..59c47f81 100644 --- a/test/Client/Im/Suggestion.purs +++ b/test/Client/Im/Suggestion.purs @@ -15,29 +15,21 @@ import Test.Unit.Assert as TUA tests ∷ TestSuite tests = do TU.suite "im suggestion update" do - TU.test "nextSuggestion sets suggesting to zero if Nothing" do - let - { suggesting } = DT.fst <<< CIS.nextSuggestion $ model - { suggestions = [ imUser ] - , suggesting = Nothing - } - TUA.equal (Just 0) suggesting - TU.test "nextSuggestion bumps suggesting" do let { suggesting } = DT.fst <<< CIS.nextSuggestion $ model { suggestions = [ imUser, imUser ] - , suggesting = Just 0 + , suggesting = 0 } - TUA.equal (Just 1) suggesting + TUA.equal 1 suggesting TU.test "nextSuggestion does not go over suggestions length" do let { suggesting } = DT.fst <<< CIS.nextSuggestion $ model { suggestions = [ imUser, imUser, imUser ] - , suggesting = Just 2 + , suggesting = 2 } - TUA.equal (Just 2) suggesting + TUA.equal 2 suggesting TU.test "nextSuggestion clears chatting" do let @@ -51,17 +43,17 @@ tests = do let { suggesting } = DT.fst <<< CIS.previousSuggestion $ model { suggestions = [ imUser, imUser ] - , suggesting = Just 1 + , suggesting = 1 } - TUA.equal (Just 0) suggesting + TUA.equal 0 suggesting TU.test "previousSuggestion does not go bellow zero" do let { suggesting } = DT.fst <<< CIS.previousSuggestion $ model { suggestions = [ imUser, imUser, imUser ] - , suggesting = Just 0 + , suggesting = 0 } - TUA.equal (Just 0) suggesting + TUA.equal 0 suggesting TU.test "displayMoreSuggestions clears chatting" do let @@ -74,10 +66,10 @@ tests = do TU.test "displayMoreSuggestions sets suggesting to 0 if there is 1 or fewer new suggestions" do let { suggesting } = DT.fst <<< CIS.displayMoreSuggestions [ imUser ] $ model - { suggesting = Nothing + { suggesting = 0 , suggestions = [] } - TUA.equal (Just 0) suggesting + TUA.equal 0 suggesting TU.test "blockUser removes user from suggestions" do let diff --git a/test/Client/Model.purs b/test/Client/Model.purs index 23f2e30c..1328561b 100644 --- a/test/Client/Model.purs +++ b/test/Client/Model.purs @@ -62,7 +62,7 @@ model = , user: imUser , suggestions: [ suggestion ] , temporaryId: 0 - , suggesting: Just 0 + , suggesting: 0 , freeToFetchChatHistory: true , contacts: [ contact ] , isWebSocketConnected: true