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
ed411c22
Commit
ed411c22
authored
Feb 13, 2020
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid creating Message objects for empty messages
parent
f6f7d05c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
17 deletions
+26
-17
src/headless/converse-chat.js
src/headless/converse-chat.js
+9
-5
src/headless/converse-muc.js
src/headless/converse-muc.js
+6
-12
src/headless/utils/core.js
src/headless/utils/core.js
+11
-0
No files found.
src/headless/converse-chat.js
View file @
ed411c22
...
...
@@ -87,7 +87,10 @@ converse.plugins.add('converse-chat', {
async
initialize
()
{
this
.
initialized
=
u
.
getResolveablePromise
();
this
.
on
(
'
invalid
'
,
()
=>
{
log
.
error
(
"
Message not created due to validation error!
"
);
log
.
error
(
this
.
toJSON
());
});
if
(
this
.
get
(
'
type
'
)
===
'
chat
'
)
{
ModelWithContact
.
prototype
.
initialize
.
apply
(
this
,
arguments
);
this
.
setRosterContact
(
Strophe
.
getBareJidFromJid
(
this
.
get
(
'
from
'
)));
...
...
@@ -106,6 +109,10 @@ converse.plugins.add('converse-chat', {
this
.
initialized
.
resolve
();
},
validate
(
attrs
)
{
return
!
u
.
shouldCreateMessage
(
attrs
);
},
/**
* Sets an auto-destruct timer for this message, if it's is_ephemeral.
* @private
...
...
@@ -382,10 +389,7 @@ converse.plugins.add('converse-chat', {
return
;
}
this
.
setEditable
(
attrs
,
attrs
.
time
,
stanza
);
if
(
attrs
[
'
chat_state
'
]
||
attrs
[
'
retracted
'
]
||
// Retraction received *before* the message
!
u
.
isEmptyMessage
(
attrs
)
)
{
if
(
u
.
shouldCreateMessage
(
attrs
))
{
const
msg
=
this
.
handleCorrection
(
attrs
)
||
this
.
messages
.
create
(
attrs
);
this
.
incrementUnreadMsgCounter
(
msg
);
}
...
...
src/headless/converse-muc.js
View file @
ed411c22
...
...
@@ -256,6 +256,10 @@ converse.plugins.add('converse-muc', {
_converse
.
api
.
trigger
(
'
chatRoomMessageInitialized
'
,
this
);
},
validate
(
attrs
)
{
return
!
u
.
shouldCreateGroupchatMessage
(
attrs
);
},
onOccupantRemoved
()
{
this
.
stopListening
(
this
.
occupant
);
delete
this
.
occupant
;
...
...
@@ -1710,15 +1714,6 @@ converse.plugins.add('converse-muc', {
return
false
;
},
createMessageObject
(
attrs
)
{
return
new
Promise
((
success
,
reject
)
=>
{
this
.
messages
.
create
(
attrs
,
{
success
,
'
error
'
:
(
m
,
e
)
=>
reject
(
e
)
}
)
});
},
/**
* Handler for all MUC messages sent to this groupchat.
* @private
...
...
@@ -1764,14 +1759,13 @@ converse.plugins.add('converse-muc', {
}
this
.
setEditable
(
attrs
,
attrs
.
time
);
if
(
attrs
.
nick
&&
(
attrs
.
is_tombstone
||
u
.
isNewMessage
(
attrs
)
||
!
u
.
isEmptyMessage
(
attrs
)
))
{
const
msg
=
this
.
handleCorrection
(
attrs
)
||
await
this
.
createMessageObject
(
attrs
);
if
(
u
.
shouldCreateGroupchatMessage
(
attrs
))
{
const
msg
=
this
.
handleCorrection
(
attrs
)
||
await
this
.
messages
.
create
(
attrs
,
{
promise
:
true
}
);
this
.
incrementUnreadMsgCounter
(
msg
);
}
_converse
.
api
.
trigger
(
'
message
'
,
{
'
stanza
'
:
original_stanza
,
'
chatbox
'
:
this
});
},
handleModifyError
(
pres
)
{
const
text
=
get
(
pres
.
querySelector
(
'
error text
'
),
'
textContent
'
);
if
(
text
)
{
...
...
src/headless/utils/core.js
View file @
ed411c22
...
...
@@ -123,6 +123,17 @@ u.isNewMessage = function (message) {
return
!
(
message
[
'
is_delayed
'
]
&&
message
[
'
is_archived
'
]);
};
u
.
shouldCreateMessage
=
function
(
attrs
)
{
return
attrs
[
'
chat_state
'
]
||
attrs
[
'
retracted
'
]
||
// Retraction received *before* the message
!
u
.
isEmptyMessage
(
attrs
);
}
u
.
shouldCreateGroupchatMessage
=
function
(
attrs
)
{
return
attrs
.
nick
&&
(
u
.
shouldCreateMessage
(
attrs
)
||
attrs
.
is_tombstone
);
},
u
.
isEmptyMessage
=
function
(
attrs
)
{
if
(
attrs
instanceof
Model
)
{
attrs
=
attrs
.
attributes
;
...
...
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