Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
solid-xmpp-chat
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Components
solid-xmpp-chat
Commits
0bad6d9b
Commit
0bad6d9b
authored
4 years ago
by
Xavier Ferrer de la Penyita
Browse files
Options
Downloads
Patches
Plain Diff
clear room messages when leaving a room if there are more than 30
parent
3c55d578
No related branches found
No related tags found
2 merge requests
!69
Beta
,
!67
Clear room messages
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/solid-xmpp-chat.js
+50
-1
50 additions, 1 deletion
src/solid-xmpp-chat.js
with
50 additions
and
1 deletion
src/solid-xmpp-chat.js
+
50
−
1
View file @
0bad6d9b
...
@@ -116,6 +116,31 @@ export const SolidXMPPChat = {
...
@@ -116,6 +116,31 @@ export const SolidXMPPChat = {
// Change chat plugin
// Change chat plugin
converse_sib
.
service
.
plugins
.
sibChat
=
new
(
class
{
converse_sib
.
service
.
plugins
.
sibChat
=
new
(
class
{
changeChat
(
jid
,
is_groupchat
,
root
)
{
changeChat
(
jid
,
is_groupchat
,
root
)
{
function
isEmptyMessage
(
attrs
)
{
if
(
attrs
&&
attrs
.
attributes
)
{
attrs
=
attrs
.
attributes
;
}
return
!
attrs
[
'
oob_url
'
]
&&
!
attrs
[
'
file
'
]
&&
!
(
attrs
[
'
is_encrypted
'
]
&&
attrs
[
'
plaintext
'
])
&&
!
attrs
[
'
message
'
];
};
function
removeUnnecessaryDayIndicators
(
view
)
{
const
pred
=
(
el
)
=>
el
.
matches
(
'
.date-separator
'
)
&&
el
.
nextElementSibling
.
matches
(
'
.date-separator
'
);
const
container
=
view
.
el
.
querySelector
(
'
.chat-content__messages
'
);
const
to_remove
=
Array
.
from
(
container
.
children
).
filter
(
pred
);
to_remove
.
forEach
((
el
)
=>
el
.
parentElement
.
removeChild
(
el
));
};
function
isHidden
(
classList
){
for
(
let
i
=
0
;
i
<
classList
.
length
;
i
++
){
if
(
classList
[
i
]
===
'
hidden
'
){
return
true
;
}
}
return
false
;
}
if
(
!
jid
)
{
if
(
!
jid
)
{
return
;
return
;
}
}
...
@@ -130,6 +155,29 @@ export const SolidXMPPChat = {
...
@@ -130,6 +155,29 @@ export const SolidXMPPChat = {
if
(
converse_el
)
{
if
(
converse_el
)
{
root
.
appendChild
(
converse_el
);
root
.
appendChild
(
converse_el
);
if
(
is_groupchat
)
{
const
jid_to_clear
=
converse_el
.
getElementsByClassName
(
'
converse-chatboxes
'
);
let
room_to_clear_view
=
''
;
if
(
jid_to_clear
.
length
&&
jid_to_clear
[
0
].
children
.
length
){
for
(
let
i
=
0
;
i
<
jid_to_clear
[
0
].
children
.
length
;
i
++
)
{
if
(
!
isHidden
(
jid_to_clear
[
0
].
children
[
i
].
classList
)){
room_to_clear_view
=
this
.
_converse
.
chatboxviews
.
views
[
jid_to_clear
[
0
].
children
[
i
].
id
.
split
(
'
-
'
)[
1
]];
break
;
}
}
}
if
(
room_to_clear_view
)
{
if
(
room_to_clear_view
.
model
.
messages
.
length
>
30
)
{
const
non_empty_messages
=
room_to_clear_view
.
model
.
messages
.
filter
((
m
)
=>
!
isEmptyMessage
(
m
));
if
(
non_empty_messages
.
length
>
30
)
{
while
(
non_empty_messages
.
length
>
30
)
{
non_empty_messages
.
shift
().
destroy
();
}
removeUnnecessaryDayIndicators
(
room_to_clear_view
);
}
}
}
}
}
}
if
(
is_groupchat
)
{
if
(
is_groupchat
)
{
this
.
_converse
.
api
.
rooms
.
open
(
jid
,
{},
true
);
this
.
_converse
.
api
.
rooms
.
open
(
jid
,
{},
true
);
...
@@ -138,6 +186,7 @@ export const SolidXMPPChat = {
...
@@ -138,6 +186,7 @@ export const SolidXMPPChat = {
}
}
}
}
});
});
// Initialize deferred resolution plugin
setTimeout
(
async
()
=>
{
setTimeout
(
async
()
=>
{
// Initialize change change plugin
// Initialize change change plugin
converse
.
plugins
.
add
(
'
conversejs-changechat
'
,
converse_sib
.
service
.
plugins
.
sibChat
);
converse
.
plugins
.
add
(
'
conversejs-changechat
'
,
converse_sib
.
service
.
plugins
.
sibChat
);
...
@@ -292,7 +341,7 @@ export const SolidXMPPChat = {
...
@@ -292,7 +341,7 @@ export const SolidXMPPChat = {
'
root
'
:
this
.
element
.
shadowRoot
,
'
root
'
:
this
.
element
.
shadowRoot
,
'
show_client_info
'
:
false
,
'
show_client_info
'
:
false
,
'
show_desktop_notifications
'
:
false
,
'
show_desktop_notifications
'
:
false
,
'
persistent_store
'
:
'
IndexedDB
'
,
'
persistent_store
'
:
'
localStorage
'
,
'
sounds_path
'
:
ComponentPath
+
'
/dist/conversejs/
'
,
'
sounds_path
'
:
ComponentPath
+
'
/dist/conversejs/
'
,
'
show_send_button
'
:
false
,
'
show_send_button
'
:
false
,
'
view_mode
'
:
'
fullscreen
'
,
'
view_mode
'
:
'
fullscreen
'
,
...
...
This diff is collapsed.
Click to expand it.
Jean-Baptiste Pasquier
@jbpasquier
mentioned in issue
#260 (closed)
·
3 years ago
mentioned in issue
#260 (closed)
mentioned in issue #260
Toggle commit list
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment