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
7ca79437
Commit
7ca79437
authored
Sep 22, 2016
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Indicate whether a chatroom has been bookmarked.
parent
33630416
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
67 additions
and
36 deletions
+67
-36
spec/bookmarks.js
spec/bookmarks.js
+17
-7
spec/chatroom.js
spec/chatroom.js
+4
-4
src/converse-bookmarks.js
src/converse-bookmarks.js
+46
-25
No files found.
spec/bookmarks.js
View file @
7ca79437
...
@@ -27,7 +27,6 @@
...
@@ -27,7 +27,6 @@
var
view
=
converse
.
chatboxviews
.
get
(
jid
);
var
view
=
converse
.
chatboxviews
.
get
(
jid
);
spyOn
(
view
,
'
renderBookmarkForm
'
).
andCallThrough
();
spyOn
(
view
,
'
renderBookmarkForm
'
).
andCallThrough
();
spyOn
(
view
,
'
cancelConfiguration
'
).
andCallThrough
();
spyOn
(
view
,
'
cancelConfiguration
'
).
andCallThrough
();
spyOn
(
view
,
'
onBookmarkAdded
'
).
andCallThrough
();
spyOn
(
view
,
'
onBookmarkError
'
).
andCallThrough
();
spyOn
(
view
,
'
onBookmarkError
'
).
andCallThrough
();
var
$bookmark
=
view
.
$el
.
find
(
'
.icon-pushpin
'
);
var
$bookmark
=
view
.
$el
.
find
(
'
.icon-pushpin
'
);
...
@@ -72,11 +71,13 @@
...
@@ -72,11 +71,13 @@
* </pubsub>
* </pubsub>
* </iq>
* </iq>
*/
*/
expect
(
view
.
model
.
get
(
'
bookmarked
'
)).
toBeFalsy
();
var
$form
=
view
.
$el
.
find
(
'
.chatroom-form
'
);
var
$form
=
view
.
$el
.
find
(
'
.chatroom-form
'
);
$form
.
find
(
'
input[name="name"]
'
).
val
(
'
Play's the Thing
'
);
$form
.
find
(
'
input[name="name"]
'
).
val
(
'
Play's the Thing
'
);
$form
.
find
(
'
input[name="autojoin"]
'
).
prop
(
'
checked
'
,
true
);
$form
.
find
(
'
input[name="autojoin"]
'
).
prop
(
'
checked
'
,
true
);
$form
.
find
(
'
input[name="nick"]
'
).
val
(
'
JC
'
);
$form
.
find
(
'
input[name="nick"]
'
).
val
(
'
JC
'
);
$form
.
submit
();
$form
.
submit
();
expect
(
view
.
model
.
get
(
'
bookmarked
'
)).
toBeTruthy
();
expect
(
$bookmark
.
hasClass
(
'
on-button
'
),
true
);
expect
(
$bookmark
.
hasClass
(
'
on-button
'
),
true
);
expect
(
sent_stanza
.
toLocaleString
()).
toBe
(
expect
(
sent_stanza
.
toLocaleString
()).
toBe
(
...
@@ -118,16 +119,25 @@
...
@@ -118,16 +119,25 @@
'
id
'
:
IQ_id
'
id
'
:
IQ_id
});
});
converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
stanza
));
converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
stanza
));
expect
(
view
.
onBookmarkAdded
).
toHaveBeenCalled
();
// We ignore this IQ stanza... (unless it's an error stanza), so
// nothing to test for here.
});
});
describe
(
"
when bookmarked
"
,
function
()
{
describe
(
"
when bookmarked
"
,
function
()
{
it
(
"
displays that it's bookmarked through its bookmark icon
"
,
function
()
{
it
(
"
displays that it's bookmarked through its bookmark icon
"
,
function
()
{
// TODO
runs
(
function
()
{
// Mock bookmark data received from the server.
test_utils
.
openChatRoom
(
'
lounge
'
,
'
localhost
'
,
'
dummy
'
);
// Open the room
});
// Check that the icon has 'button-on' class.
waits
(
100
);
runs
(
function
()
{
var
view
=
converse
.
chatboxviews
.
get
(
'
lounge@localhost
'
);
var
$bookmark_icon
=
view
.
$
(
'
.icon-pushpin
'
);
expect
(
$bookmark_icon
.
hasClass
(
'
button-on
'
)).
toBeFalsy
();
view
.
model
.
set
(
'
bookmarked
'
,
true
);
expect
(
$bookmark_icon
.
hasClass
(
'
button-on
'
)).
toBeTruthy
();
view
.
model
.
set
(
'
bookmarked
'
,
false
);
expect
(
$bookmark_icon
.
hasClass
(
'
button-on
'
)).
toBeFalsy
();
});
});
});
it
(
"
can be unbookmarked
"
,
function
()
{
it
(
"
can be unbookmarked
"
,
function
()
{
...
...
spec/chatroom.js
View file @
7ca79437
...
@@ -699,7 +699,7 @@
...
@@ -699,7 +699,7 @@
it
(
"
can be closed again by clicking a DOM element with class 'close-chatbox-button'
"
,
function
()
{
it
(
"
can be closed again by clicking a DOM element with class 'close-chatbox-button'
"
,
function
()
{
test_utils
.
openChatRoom
(
'
lounge
'
,
'
localhost
'
,
'
dummy
'
);
test_utils
.
openChatRoom
(
'
lounge
'
,
'
localhost
'
,
'
dummy
'
);
var
view
=
this
.
chatboxviews
.
get
(
'
lounge@localhost
'
);
var
view
=
converse
.
chatboxviews
.
get
(
'
lounge@localhost
'
);
spyOn
(
view
,
'
close
'
).
andCallThrough
();
spyOn
(
view
,
'
close
'
).
andCallThrough
();
spyOn
(
converse
,
'
emit
'
);
spyOn
(
converse
,
'
emit
'
);
spyOn
(
view
,
'
leave
'
);
spyOn
(
view
,
'
leave
'
);
...
@@ -711,9 +711,9 @@
...
@@ -711,9 +711,9 @@
runs
(
function
()
{
runs
(
function
()
{
expect
(
view
.
close
).
toHaveBeenCalled
();
expect
(
view
.
close
).
toHaveBeenCalled
();
expect
(
view
.
leave
).
toHaveBeenCalled
();
expect
(
view
.
leave
).
toHaveBeenCalled
();
expect
(
this
.
emit
).
toHaveBeenCalledWith
(
'
chatBoxClosed
'
,
jasmine
.
any
(
Object
));
expect
(
converse
.
emit
).
toHaveBeenCalledWith
(
'
chatBoxClosed
'
,
jasmine
.
any
(
Object
));
}
.
bind
(
converse
)
);
});
}
.
bind
(
converse
)
);
});
}.
bind
(
converse
));
}.
bind
(
converse
));
...
...
src/converse-bookmarks.js
View file @
7ca79437
...
@@ -49,15 +49,25 @@
...
@@ -49,15 +49,25 @@
'
click .toggle-bookmark
'
:
'
toggleBookmark
'
'
click .toggle-bookmark
'
:
'
toggleBookmark
'
},
},
initialize
:
function
()
{
this
.
__super__
.
initialize
.
apply
(
this
,
arguments
);
this
.
model
.
on
(
'
change:bookmarked
'
,
this
.
onBookmarked
,
this
);
},
render
:
function
(
options
)
{
render
:
function
(
options
)
{
this
.
__super__
.
render
.
apply
(
this
,
arguments
);
this
.
__super__
.
render
.
apply
(
this
,
arguments
);
var
label_bookmark
=
_
(
'
Bookmark this room
'
);
var
label_bookmark
=
_
(
'
Bookmark this room
'
);
// TODO: check if bookmarked, and if so, add button-on class
var
button
=
'
<a class="chatbox-btn toggle-bookmark icon-pushpin
'
+
this
.
$el
.
find
(
'
.chat-head-chatroom .icon-wrench
'
).
before
(
(
this
.
model
.
get
(
'
bookmarked
'
)
?
'
button-on"
'
:
'
"
'
)
+
'
<a class="chatbox-btn toggle-bookmark icon-pushpin" title="
'
+
label_bookmark
+
'
"></a>
'
);
'
title="
'
+
label_bookmark
+
'
"></a>
'
;
this
.
$el
.
find
(
'
.chat-head-chatroom .icon-wrench
'
).
before
(
button
);
return
this
;
return
this
;
},
},
onBookmarked
:
function
()
{
this
.
$
(
'
.icon-pushpin
'
).
toggleClass
(
'
button-on
'
);
},
renderBookmarkForm
:
function
()
{
renderBookmarkForm
:
function
()
{
var
$body
=
this
.
$
(
'
.chatroom-body
'
);
var
$body
=
this
.
$
(
'
.chatroom-body
'
);
$body
.
children
().
addClass
(
'
hidden
'
);
$body
.
children
().
addClass
(
'
hidden
'
);
...
@@ -77,14 +87,13 @@
...
@@ -77,14 +87,13 @@
addBookmark
:
function
(
ev
)
{
addBookmark
:
function
(
ev
)
{
ev
.
preventDefault
();
ev
.
preventDefault
();
converse
.
bookmarks
.
create
({
converse
.
bookmarks
.
create
({
'
id
'
:
this
.
model
.
get
(
'
id
'
),
'
jid
'
:
this
.
model
.
get
(
'
j
id
'
),
'
autojoin
'
:
this
.
$el
.
find
(
'
.chatroom-form
'
).
find
(
'
input[name=autojoin]
'
).
val
(),
'
autojoin
'
:
this
.
$el
.
find
(
'
.chatroom-form
'
).
find
(
'
input[name=autojoin]
'
).
val
(),
'
name
'
:
this
.
$el
.
find
(
'
.chatroom-form
'
).
find
(
'
input[name=name]
'
).
val
(),
'
name
'
:
this
.
$el
.
find
(
'
.chatroom-form
'
).
find
(
'
input[name=name]
'
).
val
(),
'
nick
'
:
this
.
$el
.
find
(
'
.chatroom-form
'
).
find
(
'
input[name=nick]
'
).
val
()
'
nick
'
:
this
.
$el
.
find
(
'
.chatroom-form
'
).
find
(
'
input[name=nick]
'
).
val
()
});
});
this
.
$
(
'
.icon-pushpin
'
).
addClass
(
'
button-on
'
);
this
.
model
.
save
(
'
bookmarked
'
,
true
);
var
that
=
this
,
var
that
=
this
,
$form
=
$
(
ev
.
target
);
$form
=
$
(
ev
.
target
);
...
@@ -127,17 +136,13 @@
...
@@ -127,17 +136,13 @@
.
c
(
'
value
'
).
t
(
'
true
'
).
up
().
up
()
.
c
(
'
value
'
).
t
(
'
true
'
).
up
().
up
()
.
c
(
'
field
'
,
{
'
var
'
:
'
pubsub#access_model
'
})
.
c
(
'
field
'
,
{
'
var
'
:
'
pubsub#access_model
'
})
.
c
(
'
value
'
).
t
(
'
whitelist
'
);
.
c
(
'
value
'
).
t
(
'
whitelist
'
);
converse
.
connection
.
sendIQ
(
stanza
,
this
.
onBookmarkAdded
,
this
.
onBookmarkError
);
converse
.
connection
.
sendIQ
(
stanza
,
null
,
this
.
onBookmarkError
.
bind
(
this
)
);
},
},
onBookmarkAdded
:
function
(
iq
)
{
converse
.
log
(
"
Bookmark successfully added
"
);
converse
.
log
(
iq
);
},
onBookmarkError
:
function
(
iq
)
{
onBookmarkError
:
function
(
iq
)
{
converse
.
log
(
"
Error while trying to add bookmark
"
);
converse
.
log
(
"
Error while trying to add bookmark
"
,
"
error
"
);
converse
.
log
(
iq
);
converse
.
log
(
iq
);
this
.
model
.
save
(
'
bookmarked
'
,
false
);
window
.
alert
(
__
(
"
Sorry, something went wrong while trying to save your bookmark.
"
));
window
.
alert
(
__
(
"
Sorry, something went wrong while trying to save your bookmark.
"
));
},
},
...
@@ -163,30 +168,46 @@
...
@@ -163,30 +168,46 @@
* loaded by converse.js's plugin machinery.
* loaded by converse.js's plugin machinery.
*/
*/
var
converse
=
this
.
converse
;
var
converse
=
this
.
converse
;
converse
.
Bookmarks
=
Backbone
.
Collection
.
extend
({
converse
.
Bookmarks
=
Backbone
.
Collection
.
extend
({
onCachedBookmarksFetched
:
function
()
{
onCachedBookmarksFetched
:
function
()
{
if
(
!
window
.
sessionStorage
.
getItem
(
this
.
browserStorage
.
name
)
||
this
.
models
.
length
>
0
)
{
if
(
!
window
.
sessionStorage
.
getItem
(
this
.
browserStorage
.
name
))
{
// There
weren't any cached bookmarks, so we query to XMPP
// There
aren't any cached bookmarks, so we query the
//
server
//
XMPP server.
var
stanza
=
$iq
({
var
stanza
=
$iq
({
'
from
'
:
converse
.
connection
.
jid
,
'
from
'
:
converse
.
connection
.
jid
,
'
type
'
:
'
get
'
,
'
type
'
:
'
get
'
,
}).
c
(
'
pubsub
'
,
{
'
xmlns
'
:
Strophe
.
NS
.
PUBSUB
})
}).
c
(
'
pubsub
'
,
{
'
xmlns
'
:
Strophe
.
NS
.
PUBSUB
})
.
c
(
'
items
'
,
{
'
node
'
:
'
storage:bookmarks
'
});
.
c
(
'
items
'
,
{
'
node
'
:
'
storage:bookmarks
'
});
converse
.
connection
.
sendIQ
(
stanza
,
this
.
onBookmarksReceived
.
bind
(
this
),
this
.
onBookmarksReceivedError
);
converse
.
connection
.
sendIQ
(
stanza
,
this
.
onBookmarksReceived
.
bind
(
this
),
this
.
onBookmarksReceivedError
);
}
else
{
this
.
models
.
each
(
this
.
markRoomAsBookmarked
);
}
},
markRoomAsBookmarked
:
function
(
bookmark
)
{
var
room
=
converse
.
chatboxes
.
get
(
bookmark
.
get
(
'
jid
'
));
if
(
!
_
.
isUndefined
(
room
))
{
room
.
save
(
'
bookmarked
'
,
true
);
}
}
},
},
onBookmarksReceived
:
function
(
iq
)
{
onBookmarksReceived
:
function
(
iq
)
{
var
rooms
=
$
(
iq
).
find
(
'
items[node="storage:bookmarks"] item[id="current"] storage conference
'
);
var
bookmarks
=
$
(
iq
).
find
(
_
.
each
(
rooms
,
function
(
room
)
{
'
items[node="storage:bookmarks"] item[id="current"] storage conference
'
this
.
create
({
);
'
jid
'
:
room
.
jid
,
_
.
each
(
bookmarks
,
function
(
bookmark
)
{
'
name
'
:
room
.
name
,
this
.
markRoomAsBookmarked
(
this
.
create
({
'
autojoin
'
:
room
.
autojoin
,
'
jid
'
:
bookmark
.
getAttribute
(
'
jid
'
),
'
nick
'
:
room
.
querySelector
(
'
nick
'
).
text
'
name
'
:
bookmark
.
getAttribute
(
'
name
'
),
});
'
autojoin
'
:
bookmark
.
getAttribute
(
'
autojoin
'
),
'
nick
'
:
bookmark
.
querySelector
(
'
nick
'
).
textContent
}));
}.
bind
(
this
));
}.
bind
(
this
));
},
},
...
...
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