Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
37486118
Commit
37486118
authored
Oct 19, 2012
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Store open chats in localstorage, removing the need for jquery.cookie
parent
bd2492e6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
107 deletions
+60
-107
converse.js
converse.js
+60
-63
jquery.cookie.js
jquery.cookie.js
+0
-44
No files found.
converse.js
View file @
37486118
...
...
@@ -97,7 +97,7 @@
};
xmppchat
.
ClientStorage
=
Backbone
.
Model
.
extend
({
// TODO: Messages must be encrypted with a key and salt
initialize
:
function
(
own_jid
)
{
this
.
set
({
'
own_jid
'
:
own_jid
});
},
...
...
@@ -115,12 +115,45 @@
getMessages
:
function
(
jid
)
{
var
bare_jid
=
Strophe
.
getBareJidFromJid
(
jid
),
decrypted_msgs
=
[];
decrypted_msgs
=
[]
,
i
;
var
msgs
=
store
.
get
(
hex_sha1
(
this
.
get
(
'
own_jid
'
)
+
bare_jid
))
||
[];
for
(
var
i
=
0
;
i
<
msgs
.
length
;
i
++
)
{
for
(
i
=
0
;
i
<
msgs
.
length
;
i
++
)
{
decrypted_msgs
.
push
(
sjcl
.
decrypt
(
hex_sha1
(
this
.
get
(
'
own_jid
'
)),
msgs
[
i
]));
}
return
decrypted_msgs
return
decrypted_msgs
;
},
getOpenChats
:
function
()
{
var
key
=
hex_sha1
(
this
.
get
(
'
own_jid
'
)
+
'
-open-chats
'
),
chats
=
store
.
get
(
key
)
||
[],
decrypted_chats
=
[],
i
;
for
(
i
=
0
;
i
<
chats
.
length
;
i
++
)
{
decrypted_chats
.
push
(
chats
[
i
]);
}
return
decrypted_chats
;
},
addOpenChat
:
function
(
jid
)
{
// TODO: Hash stored chats?
var
key
=
hex_sha1
(
this
.
get
(
'
own_jid
'
)
+
'
-open-chats
'
),
chats
=
store
.
get
(
key
)
||
[];
if
(
_
.
indexOf
(
chats
,
jid
)
==
-
1
)
{
chats
.
push
(
jid
);
}
store
.
set
(
key
,
chats
);
},
removeOpenChat
:
function
(
jid
)
{
var
key
=
hex_sha1
(
this
.
get
(
'
own_jid
'
)
+
'
-open-chats
'
),
chats
=
store
.
get
(
key
)
||
[];
if
(
_
.
has
(
chats
,
jid
)
!=
-
1
)
{
chats
.
splice
(
_
.
indexOf
(
chats
,
jid
),
1
);
}
store
.
set
(
key
,
chats
);
}
});
...
...
@@ -324,49 +357,18 @@
}
},
addChatToCookie
:
function
()
{
var
cookie
=
jQuery
.
cookie
(
'
chats-open-
'
+
xmppchat
.
username
),
jid
=
this
.
model
.
get
(
'
jid
'
),
new_cookie
,
open_chats
=
[];
if
(
cookie
)
{
open_chats
=
cookie
.
split
(
'
|
'
);
}
if
(
!
_
.
has
(
open_chats
,
jid
))
{
// Update the cookie if this new chat is not yet in it.
open_chats
.
push
(
jid
);
new_cookie
=
open_chats
.
join
(
'
|
'
);
jQuery
.
cookie
(
'
chats-open-
'
+
xmppchat
.
username
,
new_cookie
,
{
path
:
'
/
'
});
console
.
log
(
'
updated cookie =
'
+
new_cookie
+
'
\n
'
);
}
saveChatToStorage
:
function
()
{
xmppchat
.
storage
.
addOpenChat
(
this
.
model
.
get
(
'
jid
'
));
},
removeChatFromCookie
:
function
()
{
var
cookie
=
jQuery
.
cookie
(
'
chats-open-
'
+
xmppchat
.
username
),
open_chats
=
[],
new_chats
=
[];
if
(
cookie
)
{
open_chats
=
cookie
.
split
(
'
|
'
);
}
for
(
var
i
=
0
;
i
<
open_chats
.
length
;
i
++
)
{
if
(
open_chats
[
i
]
!=
this
.
model
.
get
(
'
jid
'
))
{
new_chats
.
push
(
open_chats
[
i
]);
}
}
if
(
new_chats
.
length
)
{
jQuery
.
cookie
(
'
chats-open-
'
+
xmppchat
.
username
,
new_chats
.
join
(
'
|
'
),
{
path
:
'
/
'
});
}
else
{
jQuery
.
cookie
(
'
chats-open-
'
+
xmppchat
.
username
,
null
,
{
path
:
'
/
'
});
}
removeChatFromStorage
:
function
()
{
xmppchat
.
storage
.
removeOpenChat
(
this
.
model
.
get
(
'
jid
'
));
},
closeChat
:
function
()
{
var
that
=
this
;
$
(
'
#
'
+
this
.
model
.
get
(
'
box_id
'
)).
hide
(
'
fast
'
,
function
()
{
that
.
removeChatFrom
Cooki
e
(
that
.
model
.
get
(
'
id
'
));
that
.
removeChatFrom
Storag
e
(
that
.
model
.
get
(
'
id
'
));
});
},
...
...
@@ -786,31 +788,26 @@
el
:
'
#collective-xmpp-chat-data
'
,
restoreOpenChats
:
function
()
{
var
cookie
=
jQuery
.
cookie
(
'
chats-open-
'
+
xmppchat
.
username
),
open_chats
=
[],
var
open_chats
=
xmppchat
.
storage
.
getOpenChats
(),
that
=
this
;
jQuery
.
cookie
(
'
chats-open-
'
+
xmppchat
.
username
,
null
,
{
path
:
'
/
'
});
if
(
cookie
)
{
open_chats
=
cookie
.
split
(
'
|
'
);
if
(
_
.
indexOf
(
open_chats
,
'
controlbox
'
)
!=
-
1
)
{
this
.
renderChat
(
'
controlbox
'
);
}
_
.
each
(
open_chats
,
$
.
proxy
(
function
(
jid
)
{
if
(
jid
!=
'
controlbox
'
)
{
if
(
_
.
str
.
include
(
jid
,
xmppchat
.
connection
.
muc_domain
))
{
this
.
renderChat
(
jid
);
}
else
{
// XXX: Can this be optimised somehow? Would be nice to get
// fullnames from xmppchat.Roster but it's not yet
// populated at this stage...
$
.
getJSON
(
portal_url
+
"
/xmpp-userinfo?user_id=
"
+
Strophe
.
getNodeFromJid
(
jid
),
function
(
data
)
{
that
.
renderChat
(
jid
,
data
.
fullname
);
});
}
}
},
this
));
if
(
_
.
indexOf
(
open_chats
,
'
controlbox
'
)
!=
-
1
)
{
this
.
renderChat
(
'
controlbox
'
);
}
_
.
each
(
open_chats
,
$
.
proxy
(
function
(
jid
)
{
if
(
jid
!=
'
controlbox
'
)
{
if
(
_
.
str
.
include
(
jid
,
xmppchat
.
connection
.
muc_domain
))
{
this
.
renderChat
(
jid
);
}
else
{
// XXX: Can this be optimised somehow? Would be nice to get
// fullnames from xmppchat.Roster but it's not yet
// populated at this stage...
$
.
getJSON
(
portal_url
+
"
/xmpp-userinfo?user_id=
"
+
Strophe
.
getNodeFromJid
(
jid
),
function
(
data
)
{
that
.
renderChat
(
jid
,
data
.
fullname
);
});
}
}
},
this
));
},
isChatRoom
:
function
(
jid
)
{
...
...
@@ -868,7 +865,7 @@
view
.
scrolldown
();
view
.
focus
();
}
view
.
addChatToCooki
e
();
view
.
saveChatToStorag
e
();
}
return
view
;
},
...
...
jquery.cookie.js
deleted
100644 → 0
View file @
bd2492e6
/* Copyright (c) 2006 Klaus Hartl (stilbuero.de) */
jQuery
.
cookie
=
function
(
name
,
value
,
options
)
{
if
(
typeof
value
!=
'
undefined
'
)
{
// name and value given, set cookie
options
=
options
||
{};
if
(
value
===
null
)
{
value
=
''
;
options
.
expires
=
-
1
;
}
var
expires
=
''
;
if
(
options
.
expires
&&
(
typeof
options
.
expires
==
'
number
'
||
options
.
expires
.
toUTCString
))
{
var
date
;
if
(
typeof
options
.
expires
==
'
number
'
)
{
date
=
new
Date
();
date
.
setTime
(
date
.
getTime
()
+
(
options
.
expires
*
24
*
60
*
60
*
1000
));
}
else
{
date
=
options
.
expires
;
}
expires
=
'
; expires=
'
+
date
.
toUTCString
();
// use expires attribute, max-age is not supported by IE
}
// CAUTION: Needed to parenthesize options.path and options.domain
// in the following expressions, otherwise they evaluate to undefined
// in the packed version for some reason...
var
path
=
options
.
path
?
'
; path=
'
+
(
options
.
path
)
:
''
;
var
domain
=
options
.
domain
?
'
; domain=
'
+
(
options
.
domain
)
:
''
;
var
secure
=
options
.
secure
?
'
; secure
'
:
''
;
document
.
cookie
=
[
name
,
'
=
'
,
encodeURIComponent
(
value
),
expires
,
path
,
domain
,
secure
].
join
(
''
);
}
else
{
// only name given, get cookie
var
cookieValue
=
null
;
if
(
document
.
cookie
&&
document
.
cookie
!=
''
)
{
var
cookies
=
document
.
cookie
.
split
(
'
;
'
);
for
(
var
i
=
0
;
i
<
cookies
.
length
;
i
++
)
{
var
cookie
=
jQuery
.
trim
(
cookies
[
i
]);
// Does this cookie string begin with the name we want?
if
(
cookie
.
substring
(
0
,
name
.
length
+
1
)
==
(
name
+
'
=
'
))
{
cookieValue
=
decodeURIComponent
(
cookie
.
substring
(
name
.
length
+
1
));
break
;
}
}
}
return
cookieValue
;
}
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment