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
d9c5867f
Commit
d9c5867f
authored
Aug 16, 2018
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check references when incrementing unread messages counter
parent
b7eb19e2
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
92 additions
and
88 deletions
+92
-88
spec/messages.js
spec/messages.js
+5
-5
spec/notification.js
spec/notification.js
+4
-3
spec/roomslist.js
spec/roomslist.js
+53
-58
src/converse-chatboxes.js
src/converse-chatboxes.js
+14
-11
src/converse-message-view.js
src/converse-message-view.js
+1
-1
src/converse-muc.js
src/converse-muc.js
+15
-10
No files found.
spec/messages.js
View file @
d9c5867f
...
...
@@ -2168,14 +2168,14 @@
expect
(
references
.
length
).
toBe
(
1
);
expect
(
text
).
toBe
(
'
hello z3r0
'
);
expect
(
JSON
.
stringify
(
references
))
.
toBe
(
'
[{"begin":6,"end":10,"type":"mention","uri":"xmpp:z3r0@localhost"}]
'
);
.
toBe
(
'
[{"begin":6,"end":10,"
value":"z3r0","
type":"mention","uri":"xmpp:z3r0@localhost"}]
'
);
[
text
,
references
]
=
view
.
model
.
parseTextForReferences
(
'
hello @some1 @z3r0 @gibson @mr.robot, how are you?
'
)
expect
(
text
).
toBe
(
'
hello @some1 z3r0 gibson mr.robot, how are you?
'
);
expect
(
JSON
.
stringify
(
references
))
.
toBe
(
'
[{"begin":13,"end":17,"type":"mention","uri":"xmpp:z3r0@localhost"},
'
+
'
{"begin":18,"end":24,"type":"mention","uri":"xmpp:gibson@localhost"},
'
+
'
{"begin":25,"end":33,"type":"mention","uri":"xmpp:mr.robot@localhost"}]
'
);
.
toBe
(
'
[{"begin":13,"end":17,"
value":"z3r0","
type":"mention","uri":"xmpp:z3r0@localhost"},
'
+
'
{"begin":18,"end":24,"
value":"gibson","
type":"mention","uri":"xmpp:gibson@localhost"},
'
+
'
{"begin":25,"end":33,"
value":"mr.robot","
type":"mention","uri":"xmpp:mr.robot@localhost"}]
'
);
[
text
,
references
]
=
view
.
model
.
parseTextForReferences
(
'
yo @gib
'
)
expect
(
text
).
toBe
(
'
yo @gib
'
);
...
...
@@ -2189,7 +2189,7 @@
expect
(
text
).
toBe
(
'
gibson
'
);
expect
(
references
.
length
).
toBe
(
1
);
expect
(
JSON
.
stringify
(
references
))
.
toBe
(
'
[{"begin":0,"end":6,"type":"mention","uri":"xmpp:gibson@localhost"}]
'
);
.
toBe
(
'
[{"begin":0,"end":6,"
value":"gibson","
type":"mention","uri":"xmpp:gibson@localhost"}]
'
);
done
();
return
;
...
...
spec/notification.js
View file @
d9c5867f
...
...
@@ -2,8 +2,9 @@
define
([
"
jquery
"
,
"
jasmine
"
,
"
mock
"
,
"
test-utils
"
],
factory
);
}
(
this
,
function
(
$
,
jasmine
,
mock
,
test_utils
)
{
"
use strict
"
;
var
_
=
converse
.
env
.
_
;
var
$msg
=
converse
.
env
.
$msg
;
const
Strophe
=
converse
.
env
.
Strophe
,
_
=
converse
.
env
.
_
,
$msg
=
converse
.
env
.
$msg
;
describe
(
"
Notifications
"
,
function
()
{
// Implement the protocol defined in https://xmpp.org/extensions/xep-0313.html#config
...
...
@@ -74,7 +75,7 @@
delete
window
.
Notification
;
}
done
();
});
})
.
catch
(
_
.
partial
(
_converse
.
log
,
_
,
Strophe
.
LogLevel
.
FATAL
))
;
}));
it
(
"
is shown for headline messages
"
,
...
...
spec/roomslist.js
View file @
d9c5867f
...
...
@@ -229,18 +229,14 @@
// have to mock stanza traffic.
},
function
(
done
,
_converse
)
{
test_utils
.
waitUntil
(
function
()
{
return
!
_
.
isUndefined
(
_converse
.
rooms_list_view
)
},
500
)
.
then
(
function
()
{
var
room_jid
=
'
kitchen@conference.shakespeare.lit
'
;
test_utils
.
openAndEnterChatRoom
(
_converse
,
'
kitchen
'
,
'
conference.shakespeare.lit
'
,
'
romeo
'
).
then
(
function
()
{
var
view
=
_converse
.
chatboxviews
.
get
(
room_jid
);
test_utils
.
waitUntil
(()
=>
!
_
.
isUndefined
(
_converse
.
rooms_list_view
),
500
)
.
then
(()
=>
test_utils
.
openAndEnterChatRoom
(
_converse
,
'
kitchen
'
,
'
conference.shakespeare.lit
'
,
'
romeo
'
))
.
then
(()
=>
{
const
room_jid
=
'
kitchen@conference.shakespeare.lit
'
;
const
view
=
_converse
.
chatboxviews
.
get
(
room_jid
);
view
.
model
.
set
({
'
minimized
'
:
true
});
var
contact_jid
=
mock
.
cur_names
[
5
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
var
nick
=
mock
.
chatroom_names
[
0
];
const
contact_jid
=
mock
.
cur_names
[
5
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
const
nick
=
mock
.
chatroom_names
[
0
];
view
.
model
.
onMessage
(
$msg
({
from
:
room_jid
+
'
/
'
+
nick
,
...
...
@@ -285,8 +281,7 @@
room_el
=
_converse
.
rooms_list_view
.
el
.
querySelector
(
"
.available-chatroom
"
);
expect
(
_
.
includes
(
room_el
.
classList
,
'
unread-msgs
'
)).
toBeFalsy
();
done
();
});
});
}).
catch
(
_
.
partial
(
_converse
.
log
,
_
,
Strophe
.
LogLevel
.
FATAL
));
}));
});
}));
src/converse-chatboxes.js
View file @
d9c5867f
...
...
@@ -461,11 +461,15 @@
},
getReferencesFromStanza
(
stanza
)
{
const
text
=
_
.
propertyOf
(
stanza
.
querySelector
(
'
body
'
))(
'
textContent
'
);
return
sizzle
(
`reference[xmlns="
${
Strophe
.
NS
.
REFERENCE
}
"]`
,
stanza
).
map
(
ref
=>
{
const
begin
=
ref
.
getAttribute
(
'
begin
'
),
end
=
ref
.
getAttribute
(
'
end
'
);
return
{
'
begin
'
:
ref
.
getAttribute
(
'
begin
'
)
,
'
end
'
:
ref
.
getAttribute
(
'
end
'
)
,
'
begin
'
:
begin
,
'
end
'
:
end
,
'
type
'
:
ref
.
getAttribute
(
'
type
'
),
'
value
'
:
text
.
slice
(
begin
,
end
),
'
uri
'
:
ref
.
getAttribute
(
'
uri
'
)
};
});
...
...
@@ -494,6 +498,8 @@
stanza
.
getElementsByTagName
(
_converse
.
ACTIVE
).
length
&&
_converse
.
ACTIVE
||
stanza
.
getElementsByTagName
(
_converse
.
GONE
).
length
&&
_converse
.
GONE
;
const
attrs
=
{
'
chat_state
'
:
chat_state
,
'
is_archived
'
:
!
_
.
isNil
(
archive
),
...
...
@@ -561,14 +567,13 @@
_converse
.
windowState
===
'
hidden
'
;
},
incrementUnreadMsgCounter
(
stanza
)
{
incrementUnreadMsgCounter
(
message
)
{
/* 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
.
isHidden
())
{
if
(
!
message
)
{
return
;
}
if
(
_
.
isNil
(
message
.
get
(
'
message
'
)))
{
return
;
}
if
(
utils
.
isNewMessage
(
message
)
&&
this
.
isHidden
())
{
this
.
save
({
'
num_unread
'
:
this
.
get
(
'
num_unread
'
)
+
1
});
_converse
.
incrementMsgCounter
();
}
...
...
@@ -719,10 +724,8 @@
if
(
chatbox
&&
!
chatbox
.
handleMessageCorrection
(
stanza
))
{
const
msgid
=
stanza
.
getAttribute
(
'
id
'
),
message
=
msgid
&&
chatbox
.
messages
.
findWhere
({
msgid
});
if
(
!
message
)
{
// Only create the message when we're sure it's not a duplicate
chatbox
.
incrementUnreadMsgCounter
(
original_stanza
);
chatbox
.
createMessage
(
stanza
,
original_stanza
);
if
(
!
message
)
{
// Only create the message when we're sure it's not a duplicate
chatbox
.
incrementUnreadMsgCounter
(
chatbox
.
createMessage
(
stanza
,
original_stanza
));
}
}
_converse
.
emit
(
'
message
'
,
{
'
stanza
'
:
original_stanza
,
'
chatbox
'
:
chatbox
});
...
...
src/converse-message-view.js
View file @
d9c5867f
...
...
@@ -260,7 +260,7 @@
getExtraMessageClasses
()
{
let
extra_classes
=
this
.
model
.
get
(
'
is_delayed
'
)
&&
'
delayed
'
||
''
;
if
(
this
.
model
.
get
(
'
type
'
)
===
'
groupchat
'
&&
this
.
model
.
get
(
'
sender
'
)
===
'
them
'
)
{
if
(
this
.
model
.
collection
.
chatbox
.
isUserMentioned
(
this
.
model
.
get
(
'
message
'
)
))
{
if
(
this
.
model
.
collection
.
chatbox
.
isUserMentioned
(
this
.
model
))
{
// Add special class to mark groupchat messages
// in which we are mentioned.
extra_classes
+=
'
mentioned
'
;
...
...
src/converse-muc.js
View file @
d9c5867f
...
...
@@ -326,6 +326,7 @@
const
obj
=
{
'
begin
'
:
index
,
'
end
'
:
index
+
longest_match
.
length
,
'
value
'
:
longest_match
,
'
type
'
:
'
mention
'
};
if
(
occupant
.
get
(
'
jid
'
))
{
...
...
@@ -921,8 +922,7 @@
if
(
sender
===
''
)
{
return
;
}
this
.
incrementUnreadMsgCounter
(
original_stanza
);
this
.
createMessage
(
stanza
,
original_stanza
);
this
.
incrementUnreadMsgCounter
(
this
.
createMessage
(
stanza
,
original_stanza
));
}
if
(
sender
!==
this
.
get
(
'
nick
'
))
{
// We only emit an event if it's not our own message
...
...
@@ -1001,23 +1001,28 @@
* Parameters:
* (String): The text message
*/
return
(
new
RegExp
(
`\\b
${
this
.
get
(
'
nick
'
)}
\\b`
)).
test
(
message
);
const
nick
=
this
.
get
(
'
nick
'
);
if
(
message
.
get
(
'
references
'
).
length
)
{
const
mentions
=
message
.
get
(
'
references
'
).
filter
(
ref
=>
(
ref
.
type
===
'
mention
'
)).
map
(
ref
=>
ref
.
value
);
return
_
.
includes
(
mentions
,
nick
);
}
else
{
return
(
new
RegExp
(
`\\b
${
nick
}
\\b`
)).
test
(
message
.
get
(
'
message
'
));
}
},
incrementUnreadMsgCounter
(
stanza
)
{
incrementUnreadMsgCounter
(
message
)
{
/* Given a newly received message, update the unread counter if
* necessary.
*
* Parameters:
* (XMLElement): The <messsage> stanza
*/
const
body
=
stanza
.
querySelector
(
'
body
'
);
if
(
_
.
isNull
(
body
))
{
return
;
// The message has no text
}
if
(
u
.
isNewMessage
(
stanza
)
&&
this
.
isHidden
())
{
if
(
!
message
)
{
return
;
}
const
body
=
message
.
get
(
'
message
'
);
if
(
_
.
isNil
(
body
))
{
return
;
}
if
(
u
.
isNewMessage
(
message
)
&&
this
.
isHidden
())
{
const
settings
=
{
'
num_unread_general
'
:
this
.
get
(
'
num_unread_general
'
)
+
1
};
if
(
this
.
isUserMentioned
(
body
.
textContent
))
{
if
(
this
.
isUserMentioned
(
message
))
{
settings
.
num_unread
=
this
.
get
(
'
num_unread
'
)
+
1
;
_converse
.
incrementMsgCounter
();
}
...
...
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