summaryrefslogtreecommitdiff
path: root/Assistant/XMPP/Git.hs
blob: 154cbc86d7a78125a6a76d0f999b8f6fc055f830 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
{- git over XMPP
 -
 - Copyright 2012 Joey Hess <joey@kitenet.net>
 -
 - Licensed under the GNU GPL version 3 or higher.
 -}

module Assistant.XMPP.Git where

import Assistant.Common
import Assistant.XMPP
import Assistant.XMPP.Buddies
import Assistant.DaemonStatus
import Assistant.Alert
import Assistant.MakeRemote
import Assistant.Sync
import Annex.UUID
import Config
import qualified Types.Remote as Remote

import Network.Protocol.XMPP
import qualified Data.Text as T

finishXMPPPairing :: JID -> UUID -> Assistant ()
finishXMPPPairing jid u = void $ alertWhile alert $
	makeXMPPGitRemote buddy (baseJID jid) u
  where
	buddy = T.unpack $ buddyName jid
	alert = pairRequestAcknowledgedAlert buddy Nothing

{- A git remote for an XMPP user? This is represented as a git remote
 - that has no location set. The user's XMPP address is stored in the
 - xmppaddress setting.
 -
 - The UUID of their remote is also stored as usual.
 -}
makeXMPPGitRemote :: String -> JID -> UUID -> Assistant Bool
makeXMPPGitRemote buddyname jid u = do
	remote <- liftAnnex $ addRemote $ makeGitRemote buddyname "" -- no location
	liftAnnex $ do
		let r = Remote.repo remote
		storeUUID (remoteConfig r "uuid") u
		setConfig (remoteConfig r "xmppaddress") xmppaddress
	syncNewRemote remote
	return True
  where
	xmppaddress = T.unpack $ formatJID $ baseJID jid