From d6a0e4d44044aa4d93739104c000f44fd497f911 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Tue, 1 Dec 2015 11:24:10 -0500 Subject: [PATCH] Search bookmarks for short room name on /join Closes #1 --- Main.hs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Main.hs b/Main.hs index d12fe35..c8756ae 100644 --- a/Main.hs +++ b/Main.hs @@ -553,6 +553,11 @@ createRoom toComponent componentHost (server:otherServers) tel name = Just jid = parseJID $ fromString $ "create@" <> componentHost <> "/" <> intercalate "|" (tel:name:otherServers) createRoom _ _ [] _ _ = return False +mucShortMatch tel short muc = + node == short || T.stripSuffix (fromString "_" <> tel) node == Just short + where + node = fromMaybe mempty $ fmap strNode (jidNode =<< parseJID muc) + processSMS db toVitelity toComponent componentHost conferenceServers tel txt = do nick <- maybe tel fromString <$> TC.runTCM (TC.get db $ tcKey tel "nick") existingRoom <- (parseJID <=< fmap bareTxt) <$> tcGetJID db tel "joined" @@ -572,7 +577,10 @@ processSMS db toVitelity toComponent componentHost conferenceServers tel txt = d writeStanzaChan toVitelity $ mkSMS tel (fromString "Invalid group name") Just (Join room) -> do leaveRoom db toComponent componentHost tel "Joined a different room." - joinRoom db toComponent componentHost tel room + bookmarks <- fmap (fromMaybe [] . (readZ =<<)) (TC.runTCM $ TC.get db (tcKey tel "bookmarks")) + joinRoom db toComponent componentHost tel $ + fromMaybe room $ parseJID =<< (fmap (<> fromString "/" <> nick) $ + find (mucShortMatch tel (strDomain $ jidDomain room)) bookmarks) Just Leave -> leaveRoom db toComponent componentHost tel "Typed /leave" Just Who -> do let room = maybe "" (T.unpack . bareTxt) existingRoom -- 2.45.2