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
8cd75aa0
Commit
8cd75aa0
authored
Dec 06, 2017
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move ChatBox, Message and Messages to converse-chatboxes
parent
a4a1c80b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
122 additions
and
120 deletions
+122
-120
src/converse-chatboxes.js
src/converse-chatboxes.js
+122
-1
src/converse-core.js
src/converse-core.js
+0
-119
No files found.
src/converse-chatboxes.js
View file @
8cd75aa0
...
...
@@ -10,7 +10,7 @@
define
([
"
converse-core
"
],
factory
);
}(
this
,
function
(
converse
)
{
"
use strict
"
;
const
{
Backbone
,
Promise
,
Strophe
,
b64_sha1
,
utils
,
_
}
=
converse
.
env
;
const
{
Backbone
,
Promise
,
Strophe
,
b64_sha1
,
moment
,
utils
,
_
}
=
converse
.
env
;
converse
.
plugins
.
add
(
'
converse-chatboxes
'
,
{
...
...
@@ -72,6 +72,127 @@
_converse
.
router
.
route
(
'
converse/chat?jid=:jid
'
,
openChat
);
_converse
.
Message
=
Backbone
.
Model
.
extend
({
defaults
(){
return
{
msgid
:
_converse
.
connection
.
getUniqueId
()
};
}
});
_converse
.
Messages
=
Backbone
.
Collection
.
extend
({
model
:
_converse
.
Message
,
comparator
:
'
time
'
});
_converse
.
ChatBox
=
Backbone
.
Model
.
extend
({
defaults
:
{
'
type
'
:
'
chatbox
'
,
'
bookmarked
'
:
false
,
'
chat_state
'
:
undefined
,
'
num_unread
'
:
0
,
'
url
'
:
''
},
initialize
()
{
this
.
messages
=
new
_converse
.
Messages
();
this
.
messages
.
browserStorage
=
new
Backbone
.
BrowserStorage
[
_converse
.
message_storage
](
b64_sha1
(
`converse.messages
${
this
.
get
(
'
jid
'
)}${
_converse
.
bare_jid
}
`
));
this
.
save
({
// The chat_state will be set to ACTIVE once the chat box is opened
// and we listen for change:chat_state, so shouldn't set it to ACTIVE here.
'
box_id
'
:
b64_sha1
(
this
.
get
(
'
jid
'
)),
'
time_opened
'
:
this
.
get
(
'
time_opened
'
)
||
moment
().
valueOf
(),
'
user_id
'
:
Strophe
.
getNodeFromJid
(
this
.
get
(
'
jid
'
))
});
},
getMessageBody
(
message
)
{
const
type
=
message
.
getAttribute
(
'
type
'
);
return
(
type
===
'
error
'
)
?
_
.
propertyOf
(
message
.
querySelector
(
'
error text
'
))(
'
textContent
'
)
:
_
.
propertyOf
(
message
.
querySelector
(
'
body
'
))(
'
textContent
'
);
},
getMessageAttributes
(
message
,
delay
,
original_stanza
)
{
delay
=
delay
||
message
.
querySelector
(
'
delay
'
);
const
type
=
message
.
getAttribute
(
'
type
'
),
body
=
this
.
getMessageBody
(
message
);
const
delayed
=
!
_
.
isNull
(
delay
),
is_groupchat
=
type
===
'
groupchat
'
,
chat_state
=
message
.
getElementsByTagName
(
_converse
.
COMPOSING
).
length
&&
_converse
.
COMPOSING
||
message
.
getElementsByTagName
(
_converse
.
PAUSED
).
length
&&
_converse
.
PAUSED
||
message
.
getElementsByTagName
(
_converse
.
INACTIVE
).
length
&&
_converse
.
INACTIVE
||
message
.
getElementsByTagName
(
_converse
.
ACTIVE
).
length
&&
_converse
.
ACTIVE
||
message
.
getElementsByTagName
(
_converse
.
GONE
).
length
&&
_converse
.
GONE
;
let
from
;
if
(
is_groupchat
)
{
from
=
Strophe
.
unescapeNode
(
Strophe
.
getResourceFromJid
(
message
.
getAttribute
(
'
from
'
)));
}
else
{
from
=
Strophe
.
getBareJidFromJid
(
message
.
getAttribute
(
'
from
'
));
}
const
time
=
delayed
?
delay
.
getAttribute
(
'
stamp
'
)
:
moment
().
format
();
let
sender
,
fullname
;
if
((
is_groupchat
&&
from
===
this
.
get
(
'
nick
'
))
||
(
!
is_groupchat
&&
from
===
_converse
.
bare_jid
))
{
sender
=
'
me
'
;
fullname
=
_converse
.
xmppstatus
.
get
(
'
fullname
'
)
||
from
;
}
else
{
sender
=
'
them
'
;
fullname
=
this
.
get
(
'
fullname
'
)
||
from
;
}
return
{
'
type
'
:
type
,
'
chat_state
'
:
chat_state
,
'
delayed
'
:
delayed
,
'
fullname
'
:
fullname
,
'
message
'
:
body
||
undefined
,
'
msgid
'
:
message
.
getAttribute
(
'
id
'
),
'
sender
'
:
sender
,
'
time
'
:
time
};
},
createMessage
(
message
,
delay
,
original_stanza
)
{
return
this
.
messages
.
create
(
this
.
getMessageAttributes
.
apply
(
this
,
arguments
));
},
newMessageWillBeHidden
()
{
/* Returns a boolean to indicate whether a newly received
* message will be visible to the user or not.
*/
return
this
.
get
(
'
hidden
'
)
||
this
.
get
(
'
minimized
'
)
||
this
.
isScrolledUp
()
||
_converse
.
windowState
===
'
hidden
'
;
},
incrementUnreadMsgCounter
(
stanza
)
{
/* Given a newly received message, update the unread counter if
* necessary.
*/
if
(
_
.
isNull
(
stanza
.
querySelector
(
'
body
'
)))
{
return
;
// The message has no text
}
if
(
utils
.
isNewMessage
(
stanza
)
&&
this
.
newMessageWillBeHidden
())
{
this
.
save
({
'
num_unread
'
:
this
.
get
(
'
num_unread
'
)
+
1
});
_converse
.
incrementMsgCounter
();
}
},
clearUnreadMsgCounter
()
{
this
.
save
({
'
num_unread
'
:
0
});
},
isScrolledUp
()
{
return
this
.
get
(
'
scrolled
'
,
true
);
}
});
_converse
.
ChatBoxes
=
Backbone
.
Collection
.
extend
({
comparator
:
'
time_opened
'
,
...
...
src/converse-core.js
View file @
8cd75aa0
...
...
@@ -1457,126 +1457,7 @@
});
this
.
Message
=
Backbone
.
Model
.
extend
({
defaults
(){
return
{
msgid
:
_converse
.
connection
.
getUniqueId
()
};
}
});
this
.
Messages
=
Backbone
.
Collection
.
extend
({
model
:
_converse
.
Message
,
comparator
:
'
time
'
});
this
.
ChatBox
=
Backbone
.
Model
.
extend
({
defaults
:
{
'
type
'
:
'
chatbox
'
,
'
bookmarked
'
:
false
,
'
chat_state
'
:
undefined
,
'
num_unread
'
:
0
,
'
url
'
:
''
},
initialize
()
{
this
.
messages
=
new
_converse
.
Messages
();
this
.
messages
.
browserStorage
=
new
Backbone
.
BrowserStorage
[
_converse
.
message_storage
](
b64_sha1
(
`converse.messages
${
this
.
get
(
'
jid
'
)}${
_converse
.
bare_jid
}
`
));
this
.
save
({
// The chat_state will be set to ACTIVE once the chat box is opened
// and we listen for change:chat_state, so shouldn't set it to ACTIVE here.
'
box_id
'
:
b64_sha1
(
this
.
get
(
'
jid
'
)),
'
time_opened
'
:
this
.
get
(
'
time_opened
'
)
||
moment
().
valueOf
(),
'
user_id
'
:
Strophe
.
getNodeFromJid
(
this
.
get
(
'
jid
'
))
});
},
getMessageBody
(
message
)
{
const
type
=
message
.
getAttribute
(
'
type
'
);
return
(
type
===
'
error
'
)
?
_
.
propertyOf
(
message
.
querySelector
(
'
error text
'
))(
'
textContent
'
)
:
_
.
propertyOf
(
message
.
querySelector
(
'
body
'
))(
'
textContent
'
);
},
getMessageAttributes
(
message
,
delay
,
original_stanza
)
{
delay
=
delay
||
message
.
querySelector
(
'
delay
'
);
const
type
=
message
.
getAttribute
(
'
type
'
),
body
=
this
.
getMessageBody
(
message
);
const
delayed
=
!
_
.
isNull
(
delay
),
is_groupchat
=
type
===
'
groupchat
'
,
chat_state
=
message
.
getElementsByTagName
(
_converse
.
COMPOSING
).
length
&&
_converse
.
COMPOSING
||
message
.
getElementsByTagName
(
_converse
.
PAUSED
).
length
&&
_converse
.
PAUSED
||
message
.
getElementsByTagName
(
_converse
.
INACTIVE
).
length
&&
_converse
.
INACTIVE
||
message
.
getElementsByTagName
(
_converse
.
ACTIVE
).
length
&&
_converse
.
ACTIVE
||
message
.
getElementsByTagName
(
_converse
.
GONE
).
length
&&
_converse
.
GONE
;
let
from
;
if
(
is_groupchat
)
{
from
=
Strophe
.
unescapeNode
(
Strophe
.
getResourceFromJid
(
message
.
getAttribute
(
'
from
'
)));
}
else
{
from
=
Strophe
.
getBareJidFromJid
(
message
.
getAttribute
(
'
from
'
));
}
const
time
=
delayed
?
delay
.
getAttribute
(
'
stamp
'
)
:
moment
().
format
();
let
sender
,
fullname
;
if
((
is_groupchat
&&
from
===
this
.
get
(
'
nick
'
))
||
(
!
is_groupchat
&&
from
===
_converse
.
bare_jid
))
{
sender
=
'
me
'
;
fullname
=
_converse
.
xmppstatus
.
get
(
'
fullname
'
)
||
from
;
}
else
{
sender
=
'
them
'
;
fullname
=
this
.
get
(
'
fullname
'
)
||
from
;
}
return
{
'
type
'
:
type
,
'
chat_state
'
:
chat_state
,
'
delayed
'
:
delayed
,
'
fullname
'
:
fullname
,
'
message
'
:
body
||
undefined
,
'
msgid
'
:
message
.
getAttribute
(
'
id
'
),
'
sender
'
:
sender
,
'
time
'
:
time
};
},
createMessage
(
message
,
delay
,
original_stanza
)
{
return
this
.
messages
.
create
(
this
.
getMessageAttributes
.
apply
(
this
,
arguments
));
},
newMessageWillBeHidden
()
{
/* Returns a boolean to indicate whether a newly received
* message will be visible to the user or not.
*/
return
this
.
get
(
'
hidden
'
)
||
this
.
get
(
'
minimized
'
)
||
this
.
isScrolledUp
()
||
_converse
.
windowState
===
'
hidden
'
;
},
incrementUnreadMsgCounter
(
stanza
)
{
/* Given a newly received message, update the unread counter if
* necessary.
*/
if
(
_
.
isNull
(
stanza
.
querySelector
(
'
body
'
)))
{
return
;
// The message has no text
}
if
(
utils
.
isNewMessage
(
stanza
)
&&
this
.
newMessageWillBeHidden
())
{
this
.
save
({
'
num_unread
'
:
this
.
get
(
'
num_unread
'
)
+
1
});
_converse
.
incrementMsgCounter
();
}
},
clearUnreadMsgCounter
()
{
this
.
save
({
'
num_unread
'
:
0
});
},
isScrolledUp
()
{
return
this
.
get
(
'
scrolled
'
,
true
);
}
});
this
.
ConnectionFeedback
=
Backbone
.
Model
.
extend
({
defaults
:
{
'
connection_status
'
:
undefined
,
'
message
'
:
''
...
...
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