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
4f94a1f1
Commit
4f94a1f1
authored
May 16, 2017
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor code that increments unread messages counter
Removed the "fetching_messages" hack.
parent
023a6845
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
46 deletions
+40
-46
src/converse-chatview.js
src/converse-chatview.js
+4
-32
src/converse-core.js
src/converse-core.js
+29
-3
src/converse-rosterview.js
src/converse-rosterview.js
+7
-11
No files found.
src/converse-chatview.js
View file @
4f94a1f1
...
...
@@ -151,7 +151,6 @@
},
afterMessagesFetched
:
function
()
{
this
.
model
.
set
(
'
fetching_messages
'
,
false
);
this
.
insertIntoDOM
();
this
.
scrollDown
();
// We only start listening for the scroll event after
...
...
@@ -160,7 +159,6 @@
},
fetchMessages
:
function
()
{
this
.
model
.
set
(
'
fetching_messages
'
,
true
);
this
.
model
.
messages
.
fetch
({
'
add
'
:
true
,
'
success
'
:
this
.
afterMessagesFetched
.
bind
(
this
),
...
...
@@ -420,38 +418,12 @@
return
!
this
.
$el
.
is
(
'
:visible
'
);
},
updateNewMessageIndicators
:
function
(
message
)
{
/* We have two indicators of new messages. The unread messages
* counter, which shows the number of unread messages in
* the document.title, and the "new messages" indicator in
* a chat area, if it's scrolled up so that new messages
* aren't visible.
*
* In both cases we ignore MAM messages.
*/
if
(
!
message
.
get
(
'
archive_id
'
))
{
if
(
this
.
model
.
get
(
'
scrolled
'
,
true
))
{
this
.
$el
.
find
(
'
.new-msgs-indicator
'
).
removeClass
(
'
hidden
'
);
}
if
(
this
.
isNewMessageHidden
())
{
this
.
model
.
incrementUnreadMsgCounter
();
}
}
},
isNewMessageHidden
:
function
()
{
if
(
this
.
model
.
get
(
'
fetching_messages
'
))
{
// We seem to be busy fetching sessionStorage archived
// messages, so the message is not considered new.
return
false
;
}
return
_converse
.
windowState
===
'
hidden
'
||
this
.
model
.
isScrolledUp
();
},
handleTextMessage
:
function
(
message
)
{
this
.
showMessage
(
_
.
clone
(
message
.
attributes
));
if
(
message
.
get
(
'
sender
'
)
!==
'
me
'
)
{
this
.
updateNewMessageIndicators
(
message
);
if
(
!
message
.
get
(
'
archive_id
'
)
&&
this
.
model
.
get
(
'
scrolled
'
,
true
))
{
this
.
$el
.
find
(
'
.new-msgs-indicator
'
).
removeClass
(
'
hidden
'
);
}
}
else
{
// We remove the "scrolled" flag so that the chat area
// gets scrolled down. We always want to scroll down
...
...
@@ -908,7 +880,7 @@
},
onWindowStateChanged
:
function
(
state
)
{
if
(
this
.
model
.
get
(
'
num_unread
'
,
0
)
&&
!
this
.
isNewMessag
eHidden
())
{
if
(
this
.
model
.
get
(
'
num_unread
'
,
0
)
&&
!
this
.
model
.
newMessageWillB
eHidden
())
{
this
.
model
.
clearUnreadMsgCounter
();
}
}
...
...
src/converse-core.js
View file @
4f94a1f1
...
...
@@ -1423,9 +1423,34 @@
return
this
.
messages
.
create
(
this
.
getMessageAttributes
.
apply
(
this
,
arguments
));
},
incrementUnreadMsgCounter
:
function
()
{
this
.
save
({
'
num_unread
'
:
this
.
get
(
'
num_unread
'
)
+
1
});
_converse
.
incrementMsgCounter
();
isNewMessage
:
function
(
stanza
)
{
/* Given a message stanza, determine whether it's a new
* message, i.e. not an archived one.
*/
return
!
(
sizzle
(
'
result[xmlns="
'
+
Strophe
.
NS
.
MAM
+
'
"]
'
,
stanza
).
length
);
},
newMessageWillBeHidden
:
function
()
{
/* 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
:
function
(
stanza
)
{
/* Given a newly received message, update the unread counter if
* necessary.
*/
if
(
_
.
isNull
(
stanza
.
querySelector
(
'
body
'
)))
{
return
;
// The message has no text
}
if
(
this
.
isNewMessage
(
stanza
)
&&
this
.
newMessageWillBeHidden
())
{
this
.
save
({
'
num_unread
'
:
this
.
get
(
'
num_unread
'
)
+
1
});
_converse
.
incrementMsgCounter
();
}
},
clearUnreadMsgCounter
:
function
()
{
...
...
@@ -1555,6 +1580,7 @@
if
(
_
.
isEmpty
(
messages
))
{
// Only create the message when we're sure it's not a
// duplicate
chatbox
.
incrementUnreadMsgCounter
(
original_stanza
);
chatbox
.
createMessage
(
message
,
delay
,
original_stanza
);
}
}
...
...
src/converse-rosterview.js
View file @
4f94a1f1
...
...
@@ -947,7 +947,7 @@
var
onMessageReceived
=
function
(
data
)
{
/* Given a newly received message, update the unread counter on
* the relevant roster contact
(TODO: or chat room)
.
* the relevant roster contact.
*/
var
chatbox
=
data
.
chatbox
;
if
(
_
.
isUndefined
(
chatbox
))
{
...
...
@@ -956,17 +956,13 @@
if
(
_
.
isNull
(
data
.
stanza
.
querySelector
(
'
body
'
)))
{
return
;
// The message has no text
}
var
new_message
=
!
(
sizzle
(
'
result[xmlns="
'
+
Strophe
.
NS
.
MAM
+
'
"]
'
,
data
.
stanza
).
length
);
var
is_new_message_hidden
=
chatbox
.
get
(
'
hidden
'
)
||
chatbox
.
get
(
'
minimized
'
)
||
chatbox
.
isScrolledUp
();
if
(
chatbox
.
get
(
'
type
'
)
!==
'
chatroom
'
&&
chatbox
.
isNewMessage
(
data
.
stanza
)
&&
chatbox
.
newMessageWillBeHidden
())
{
if
(
is_new_message_hidden
&&
new_message
)
{
if
(
chatbox
.
get
(
'
type
'
)
===
'
chatroom
'
)
{
// TODO
}
else
{
var
contact
=
_
.
head
(
_converse
.
roster
.
where
({
'
jid
'
:
chatbox
.
get
(
'
jid
'
)}));
if
(
!
_
.
isUndefined
(
contact
))
{
contact
.
save
({
'
num_unread
'
:
contact
.
get
(
'
num_unread
'
)
+
1
});
}
var
contact
=
_
.
head
(
_converse
.
roster
.
where
({
'
jid
'
:
chatbox
.
get
(
'
jid
'
)}));
if
(
!
_
.
isUndefined
(
contact
))
{
contact
.
save
({
'
num_unread
'
:
contact
.
get
(
'
num_unread
'
)
+
1
});
}
}
};
...
...
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