~singpolyma/cheogram

d6a0e4d44044aa4d93739104c000f44fd497f911 — Stephen Paul Weber 8 years ago ce5dcf3
Search bookmarks for short room name on /join

Closes #1
1 files changed, 9 insertions(+), 1 deletions(-)

M Main.hs
M Main.hs => Main.hs +9 -1
@@ 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