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
297259fd
Commit
297259fd
authored
Sep 22, 2014
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remember toggle state of control box. updates #222
parent
21d96556
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
93 additions
and
63 deletions
+93
-63
converse.js
converse.js
+80
-53
spec/chatbox.js
spec/chatbox.js
+8
-5
spec/chatroom.js
spec/chatroom.js
+5
-5
No files found.
converse.js
View file @
297259fd
...
@@ -1432,9 +1432,7 @@
...
@@ -1432,9 +1432,7 @@
},
},
close
:
function
(
ev
)
{
close
:
function
(
ev
)
{
if
(
ev
&&
ev
.
preventDefault
)
{
if
(
ev
&&
ev
.
preventDefault
)
{
ev
.
preventDefault
();
}
ev
.
preventDefault
();
}
if
(
converse
.
connection
.
connected
)
{
if
(
converse
.
connection
.
connected
)
{
this
.
model
.
destroy
();
this
.
model
.
destroy
();
}
else
{
}
else
{
...
@@ -1915,23 +1913,34 @@
...
@@ -1915,23 +1913,34 @@
initialize
:
function
()
{
initialize
:
function
()
{
this
.
$el
.
insertAfter
(
converse
.
controlboxtoggle
.
$el
);
this
.
$el
.
insertAfter
(
converse
.
controlboxtoggle
.
$el
);
this
.
model
.
on
(
'
change:connected
'
,
$
.
proxy
(
function
(
item
)
{
this
.
model
.
on
(
'
change:connected
'
,
this
.
onConnected
,
this
);
if
(
this
.
model
.
get
(
'
connected
'
))
{
this
.
render
();
this
.
initRoster
();
converse
.
features
.
off
(
'
add
'
,
this
.
featureAdded
,
this
);
converse
.
features
.
on
(
'
add
'
,
this
.
featureAdded
,
this
);
// Features could have been added before the controlbox was
// initialized. Currently we're only interested in MUC
var
feature
=
converse
.
features
.
findWhere
({
'
var
'
:
'
http://jabber.org/protocol/muc
'
});
if
(
feature
)
{
this
.
featureAdded
(
feature
);
}
}
},
this
));
this
.
model
.
on
(
'
show
'
,
this
.
show
,
this
);
this
.
model
.
on
(
'
destroy
'
,
this
.
hide
,
this
);
this
.
model
.
on
(
'
destroy
'
,
this
.
hide
,
this
);
this
.
model
.
on
(
'
hide
'
,
this
.
hide
,
this
);
this
.
model
.
on
(
'
hide
'
,
this
.
hide
,
this
);
this
.
model
.
on
(
'
show
'
,
this
.
show
,
this
);
this
.
model
.
on
(
'
change:closed
'
,
this
.
ensureClosedState
,
this
);
this
.
render
();
if
(
this
.
model
.
get
(
'
connected
'
))
{
this
.
initRoster
();
}
if
(
!
this
.
model
.
get
(
'
closed
'
))
{
this
.
show
();
}
else
{
this
.
hide
();
}
},
onConnected
:
function
()
{
if
(
this
.
model
.
get
(
'
connected
'
))
{
this
.
render
().
initRoster
();
converse
.
features
.
off
(
'
add
'
,
this
.
featureAdded
,
this
);
converse
.
features
.
on
(
'
add
'
,
this
.
featureAdded
,
this
);
// Features could have been added before the controlbox was
// initialized. Currently we're only interested in MUC
var
feature
=
converse
.
features
.
findWhere
({
'
var
'
:
'
http://jabber.org/protocol/muc
'
});
if
(
feature
)
{
this
.
featureAdded
(
feature
);
}
}
},
},
initRoster
:
function
()
{
initRoster
:
function
()
{
...
@@ -1948,6 +1957,7 @@
...
@@ -1948,6 +1957,7 @@
this
.
contactspanel
.
$el
.
append
(
converse
.
rosterview
.
$el
);
this
.
contactspanel
.
$el
.
append
(
converse
.
rosterview
.
$el
);
converse
.
rosterview
.
render
().
fetch
().
update
();
converse
.
rosterview
.
render
().
fetch
().
update
();
converse
.
connection
.
roster
.
get
(
function
()
{});
converse
.
connection
.
roster
.
get
(
function
()
{});
return
this
;
},
},
render
:
function
()
{
render
:
function
()
{
...
@@ -1985,6 +1995,25 @@
...
@@ -1985,6 +1995,25 @@
this
.
initDragResize
();
this
.
initDragResize
();
},
},
close
:
function
(
ev
)
{
if
(
ev
&&
ev
.
preventDefault
)
{
ev
.
preventDefault
();
}
if
(
converse
.
connection
.
connected
)
{
this
.
model
.
save
({
'
closed
'
:
true
});
}
else
{
this
.
model
.
trigger
(
'
hide
'
);
}
converse
.
emit
(
'
controlBoxClosed
'
,
this
);
return
this
;
},
ensureClosedState
:
function
()
{
if
(
this
.
model
.
get
(
'
closed
'
))
{
this
.
hide
();
}
else
{
this
.
show
();
}
},
hide
:
function
(
callback
)
{
hide
:
function
(
callback
)
{
this
.
$el
.
hide
(
'
fast
'
,
function
()
{
this
.
$el
.
hide
(
'
fast
'
,
function
()
{
converse
.
refreshWebkit
();
converse
.
refreshWebkit
();
...
@@ -1995,6 +2024,7 @@
...
@@ -1995,6 +2024,7 @@
}
}
});
});
});
});
return
this
;
},
},
show
:
function
()
{
show
:
function
()
{
...
@@ -2745,24 +2775,17 @@
...
@@ -2745,24 +2775,17 @@
onConnected
:
function
()
{
onConnected
:
function
()
{
this
.
browserStorage
=
new
Backbone
.
BrowserStorage
[
converse
.
storage
](
this
.
browserStorage
=
new
Backbone
.
BrowserStorage
[
converse
.
storage
](
b64_sha1
(
'
converse.chatboxes-
'
+
converse
.
bare_jid
));
b64_sha1
(
'
converse.chatboxes-
'
+
converse
.
bare_jid
));
if
(
!
this
.
get
(
'
controlbox
'
))
{
this
.
add
({
id
:
'
controlbox
'
,
box_id
:
'
controlbox
'
});
}
this
.
get
(
'
controlbox
'
).
fetch
();
// This line below will make sure the Roster is set up
this
.
get
(
'
controlbox
'
).
save
({
connected
:
true
});
this
.
registerMessageHandler
();
this
.
registerMessageHandler
();
// Get cached chatboxes from localstorage
this
.
fetch
({
this
.
fetch
({
add
:
true
,
add
:
true
,
success
:
$
.
proxy
(
function
(
collection
,
resp
)
{
success
:
$
.
proxy
(
function
(
collection
,
resp
)
{
if
(
_
.
include
(
_
.
pluck
(
resp
,
'
id
'
),
'
controlbox
'
))
{
if
(
!
_
.
include
(
_
.
pluck
(
resp
,
'
id
'
),
'
controlbox
'
))
{
// If the controlbox was saved in localstorage, it must be visible
this
.
add
({
this
.
get
(
'
controlbox
'
).
trigger
(
'
show
'
);
id
:
'
controlbox
'
,
box_id
:
'
controlbox
'
});
}
}
this
.
get
(
'
controlbox
'
).
save
({
connected
:
true
});
},
this
)
},
this
)
});
});
},
},
...
@@ -2909,7 +2932,7 @@
...
@@ -2909,7 +2932,7 @@
if
(
item
.
get
(
'
chatroom
'
))
{
if
(
item
.
get
(
'
chatroom
'
))
{
view
=
new
converse
.
ChatRoomView
({
'
model
'
:
item
});
view
=
new
converse
.
ChatRoomView
({
'
model
'
:
item
});
}
else
if
(
item
.
get
(
'
box_id
'
)
===
'
controlbox
'
)
{
}
else
if
(
item
.
get
(
'
box_id
'
)
===
'
controlbox
'
)
{
view
=
new
converse
.
ControlBoxView
({
model
:
item
})
.
render
()
;
view
=
new
converse
.
ControlBoxView
({
model
:
item
});
}
else
{
}
else
{
view
=
new
converse
.
ChatBoxView
({
model
:
item
});
view
=
new
converse
.
ChatBoxView
({
model
:
item
});
}
}
...
@@ -3053,9 +3076,7 @@
...
@@ -3053,9 +3076,7 @@
},
},
close
:
function
(
ev
)
{
close
:
function
(
ev
)
{
if
(
ev
&&
ev
.
preventDefault
)
{
if
(
ev
&&
ev
.
preventDefault
)
{
ev
.
preventDefault
();
}
ev
.
preventDefault
();
}
this
.
remove
();
this
.
remove
();
this
.
model
.
destroy
();
this
.
model
.
destroy
();
converse
.
emit
(
'
chatBoxClosed
'
,
this
);
converse
.
emit
(
'
chatBoxClosed
'
,
this
);
...
@@ -4460,15 +4481,16 @@
...
@@ -4460,15 +4481,16 @@
},
},
render
:
function
()
{
render
:
function
()
{
var
toggle
=
this
.
$el
.
html
(
$
(
'
#conversejs
'
).
prepend
(
this
.
$el
.
html
(
converse
.
templates
.
controlbox_toggle
({
converse
.
templates
.
controlbox_toggle
({
'
label_toggle
'
:
__
(
'
Toggle chat
'
)
'
label_toggle
'
:
__
(
'
Toggle chat
'
)
})
})
);
));
if
(
converse
.
show_controlbox_by_default
)
{
// We let the render method of ControlBoxView decide whether
toggle
.
hide
();
// It's either or
// the ControlBox or the Toggle must be shown. This prevents
}
// artifacts (i.e. on page load the toggle is shown only to then
$
(
'
#conversejs
'
).
prepend
(
toggle
);
// seconds later be hidden in favor of the control box).
this
.
$el
.
hide
();
return
this
;
return
this
;
},
},
...
@@ -4483,17 +4505,13 @@
...
@@ -4483,17 +4505,13 @@
showControlBox
:
function
()
{
showControlBox
:
function
()
{
var
controlbox
=
converse
.
chatboxes
.
get
(
'
controlbox
'
);
var
controlbox
=
converse
.
chatboxes
.
get
(
'
controlbox
'
);
if
(
!
controlbox
)
{
if
(
!
controlbox
)
{
converse
.
chatboxes
.
add
({
controlbox
=
converse
.
addControlBox
();
id
:
'
controlbox
'
,
}
box_id
:
'
controlbox
'
,
if
(
converse
.
connection
.
connected
)
{
height
:
converse
.
default_box_height
controlbox
.
save
({
closed
:
false
});
});
}
else
{
controlbox
=
converse
.
chatboxes
.
get
(
'
controlbox
'
);
controlbox
.
trigger
(
'
show
'
);
if
(
converse
.
connection
.
connected
)
{
converse
.
chatboxes
.
get
(
'
controlbox
'
).
save
();
}
}
}
controlbox
.
trigger
(
'
show
'
);
},
},
onClick
:
function
(
e
)
{
onClick
:
function
(
e
)
{
...
@@ -4501,7 +4519,7 @@
...
@@ -4501,7 +4519,7 @@
if
(
$
(
"
div#controlbox
"
).
is
(
'
:visible
'
))
{
if
(
$
(
"
div#controlbox
"
).
is
(
'
:visible
'
))
{
var
controlbox
=
converse
.
chatboxes
.
get
(
'
controlbox
'
);
var
controlbox
=
converse
.
chatboxes
.
get
(
'
controlbox
'
);
if
(
converse
.
connection
.
connected
)
{
if
(
converse
.
connection
.
connected
)
{
controlbox
.
destroy
(
);
controlbox
.
save
({
closed
:
true
}
);
}
else
{
}
else
{
controlbox
.
trigger
(
'
hide
'
);
controlbox
.
trigger
(
'
hide
'
);
}
}
...
@@ -4511,6 +4529,15 @@
...
@@ -4511,6 +4529,15 @@
}
}
});
});
this
.
addControlBox
=
function
()
{
return
this
.
chatboxes
.
add
({
id
:
'
controlbox
'
,
box_id
:
'
controlbox
'
,
height
:
this
.
default_box_height
,
closed
:
!
this
.
show_controlbox_by_default
});
};
this
.
initConnection
=
function
()
{
this
.
initConnection
=
function
()
{
var
rid
,
sid
,
jid
;
var
rid
,
sid
,
jid
;
if
(
this
.
connection
)
{
if
(
this
.
connection
)
{
...
@@ -4579,6 +4606,7 @@
...
@@ -4579,6 +4606,7 @@
this
.
otr
=
new
this
.
OTR
();
this
.
otr
=
new
this
.
OTR
();
this
.
initSession
();
this
.
initSession
();
this
.
initConnection
();
this
.
initConnection
();
this
.
addControlBox
();
return
this
;
return
this
;
};
};
...
@@ -4586,7 +4614,6 @@
...
@@ -4586,7 +4614,6 @@
// --------------
// --------------
// This is the end of the initialize method.
// This is the end of the initialize method.
this
.
_initialize
();
this
.
_initialize
();
if
(
this
.
show_controlbox_by_default
)
{
this
.
controlboxtoggle
.
showControlBox
();
}
this
.
registerGlobalEventHandlers
();
this
.
registerGlobalEventHandlers
();
converse
.
emit
(
'
initialized
'
);
converse
.
emit
(
'
initialized
'
);
};
};
...
...
spec/chatbox.js
View file @
297259fd
...
@@ -209,22 +209,25 @@
...
@@ -209,22 +209,25 @@
runs
(
function
()
{
runs
(
function
()
{
test_utils
.
closeControlBox
();
test_utils
.
closeControlBox
();
});
});
waits
(
2
50
);
waits
(
50
);
runs
(
function
()
{
runs
(
function
()
{
expect
(
converse
.
emit
).
toHaveBeenCalledWith
(
'
chatBoxClosed
'
,
jasmine
.
any
(
Object
));
expect
(
converse
.
emit
).
toHaveBeenCalledWith
(
'
chatBoxClosed
'
,
jasmine
.
any
(
Object
));
expect
(
converse
.
chatboxes
.
length
).
toEqual
(
0
);
expect
(
converse
.
chatboxes
.
length
).
toEqual
(
1
);
expect
(
converse
.
chatboxes
.
pluck
(
'
id
'
)).
toEqual
([
'
controlbox
'
]);
test_utils
.
openChatBoxes
(
6
);
test_utils
.
openChatBoxes
(
6
);
expect
(
converse
.
chatboxviews
.
trimChats
).
toHaveBeenCalled
();
expect
(
converse
.
chatboxviews
.
trimChats
).
toHaveBeenCalled
();
expect
(
converse
.
chatboxes
.
length
).
toEqual
(
6
);
expect
(
converse
.
chatboxes
.
length
).
toEqual
(
7
);
expect
(
converse
.
emit
).
toHaveBeenCalledWith
(
'
chatBoxOpened
'
,
jasmine
.
any
(
Object
));
expect
(
converse
.
emit
).
toHaveBeenCalledWith
(
'
chatBoxOpened
'
,
jasmine
.
any
(
Object
));
test_utils
.
closeAllChatBoxes
();
test_utils
.
closeAllChatBoxes
();
});
});
waits
(
2
50
);
waits
(
50
);
runs
(
function
()
{
runs
(
function
()
{
expect
(
converse
.
chatboxes
.
length
).
toEqual
(
0
);
expect
(
converse
.
chatboxes
.
length
).
toEqual
(
1
);
expect
(
converse
.
chatboxes
.
pluck
(
'
id
'
)).
toEqual
([
'
controlbox
'
]);
expect
(
converse
.
emit
).
toHaveBeenCalledWith
(
'
chatBoxClosed
'
,
jasmine
.
any
(
Object
));
expect
(
converse
.
emit
).
toHaveBeenCalledWith
(
'
chatBoxClosed
'
,
jasmine
.
any
(
Object
));
var
newchatboxes
=
new
this
.
ChatBoxes
();
var
newchatboxes
=
new
this
.
ChatBoxes
();
expect
(
newchatboxes
.
length
).
toEqual
(
0
);
expect
(
newchatboxes
.
length
).
toEqual
(
0
);
expect
(
converse
.
chatboxes
.
pluck
(
'
id
'
)).
toEqual
([
'
controlbox
'
]);
// onConnected will fetch chatboxes in browserStorage, but
// onConnected will fetch chatboxes in browserStorage, but
// because there aren't any open chatboxes, there won't be any
// because there aren't any open chatboxes, there won't be any
// in browserStorage either. XXX except for the controlbox
// in browserStorage either. XXX except for the controlbox
...
...
spec/chatroom.js
View file @
297259fd
...
@@ -95,13 +95,15 @@
...
@@ -95,13 +95,15 @@
"
reason='
"
+
reason
+
"
'/>
"
+
"
reason='
"
+
reason
+
"
'/>
"
+
"
</message>
"
"
</message>
"
)[
0
];
)[
0
];
expect
(
converse
.
chatboxes
.
models
.
length
).
toBe
(
0
);
expect
(
converse
.
chatboxes
.
models
.
length
).
toBe
(
1
);
expect
(
converse
.
chatboxes
.
models
[
0
].
id
).
toBe
(
"
controlbox
"
);
converse
.
chatboxes
.
onInvite
(
message
);
converse
.
chatboxes
.
onInvite
(
message
);
expect
(
window
.
confirm
).
toHaveBeenCalledWith
(
expect
(
window
.
confirm
).
toHaveBeenCalledWith
(
name
+
'
has invited you to join a chat room:
'
+
room_jid
+
name
+
'
has invited you to join a chat room:
'
+
room_jid
+
'
, and left the following reason: "
'
+
reason
+
'
"
'
);
'
, and left the following reason: "
'
+
reason
+
'
"
'
);
expect
(
converse
.
chatboxes
.
models
.
length
).
toBe
(
1
);
expect
(
converse
.
chatboxes
.
models
.
length
).
toBe
(
2
);
expect
(
converse
.
chatboxes
.
models
[
0
].
id
).
toBe
(
room_jid
);
expect
(
converse
.
chatboxes
.
models
[
0
].
id
).
toBe
(
'
controlbox
'
);
expect
(
converse
.
chatboxes
.
models
[
1
].
id
).
toBe
(
room_jid
);
},
converse
));
},
converse
));
it
(
"
shows received groupchat messages
"
,
$
.
proxy
(
function
()
{
it
(
"
shows received groupchat messages
"
,
$
.
proxy
(
function
()
{
...
@@ -269,14 +271,12 @@
...
@@ -269,14 +271,12 @@
test_utils
.
openChatRoom
(
'
lounge
'
,
'
localhost
'
,
'
dummy
'
);
test_utils
.
openChatRoom
(
'
lounge
'
,
'
localhost
'
,
'
dummy
'
);
// We instantiate a new ChatBoxes collection, which by default
// We instantiate a new ChatBoxes collection, which by default
// will be empty.
// will be empty.
spyOn
(
this
.
chatboxviews
,
'
trimChats
'
);
test_utils
.
openControlBox
();
test_utils
.
openControlBox
();
var
newchatboxes
=
new
this
.
ChatBoxes
();
var
newchatboxes
=
new
this
.
ChatBoxes
();
expect
(
newchatboxes
.
length
).
toEqual
(
0
);
expect
(
newchatboxes
.
length
).
toEqual
(
0
);
// The chatboxes will then be fetched from browserStorage inside the
// The chatboxes will then be fetched from browserStorage inside the
// onConnected method
// onConnected method
newchatboxes
.
onConnected
();
newchatboxes
.
onConnected
();
expect
(
this
.
chatboxviews
.
trimChats
).
toHaveBeenCalled
();
expect
(
newchatboxes
.
length
).
toEqual
(
2
);
// XXX: Includes controlbox, is this a bug?
expect
(
newchatboxes
.
length
).
toEqual
(
2
);
// XXX: Includes controlbox, is this a bug?
// Check that the chatrooms retrieved from browserStorage
// Check that the chatrooms retrieved from browserStorage
// have the same attributes values as the original ones.
// have the same attributes values as the original ones.
...
...
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