Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
galene
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
galene
Commits
0fc91367
Commit
0fc91367
authored
Dec 08, 2023
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow HTML elements in addToChatbox.
parent
96e2db03
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
34 deletions
+34
-34
static/galene.css
static/galene.css
+4
-0
static/galene.js
static/galene.js
+27
-32
static/protocol.js
static/protocol.js
+3
-2
No files found.
static/galene.css
View file @
0fc91367
...
...
@@ -426,6 +426,10 @@ textarea.form-reply {
margin-right
:
0.33em
;
}
.message-me-content
{
white-space
:
pre-wrap
;
}
.video-container
{
height
:
calc
(
var
(
--vh
,
1vh
)
*
100
-
56px
);
position
:
relative
;
...
...
static/galene.js
View file @
0fc91367
...
...
@@ -2830,18 +2830,18 @@ function formatToken(token, details) {
const
urlRegexp
=
/https
?
:
\/\/[
-a-zA-Z0-9@:%
/
._
\\
+~#&()=?
]
+
[
-a-zA-Z0-9@:%
/
_
\\
+~#&()=
]
/g
;
/**
* @param {string}
line
* @returns {
Array.<Text|HTMLElement>
}
* @param {string}
text
* @returns {
HTMLDivElement
}
*/
function
format
Line
(
line
)
{
function
format
Text
(
text
)
{
let
r
=
new
RegExp
(
urlRegexp
);
let
result
=
[];
let
pos
=
0
;
while
(
true
)
{
let
m
=
r
.
exec
(
line
);
let
m
=
r
.
exec
(
text
);
if
(
!
m
)
break
;
result
.
push
(
document
.
createTextNode
(
line
.
slice
(
pos
,
m
.
index
)));
result
.
push
(
document
.
createTextNode
(
text
.
slice
(
pos
,
m
.
index
)));
let
a
=
document
.
createElement
(
'
a
'
);
a
.
href
=
m
[
0
];
a
.
textContent
=
m
[
0
];
...
...
@@ -2850,25 +2850,13 @@ function formatLine(line) {
result
.
push
(
a
);
pos
=
m
.
index
+
m
[
0
].
length
;
}
result
.
push
(
document
.
createTextNode
(
line
.
slice
(
pos
)));
return
result
;
}
result
.
push
(
document
.
createTextNode
(
text
.
slice
(
pos
)));
/**
* @param {string[]} lines
* @returns {HTMLElement}
*/
function
formatLines
(
lines
)
{
let
elts
=
[];
if
(
lines
.
length
>
0
)
elts
=
formatLine
(
lines
[
0
]);
for
(
let
i
=
1
;
i
<
lines
.
length
;
i
++
)
{
elts
.
push
(
document
.
createElement
(
'
br
'
));
elts
=
elts
.
concat
(
formatLine
(
lines
[
i
]));
}
let
elt
=
document
.
createElement
(
'
p
'
);
elts
.
forEach
(
e
=>
elt
.
appendChild
(
e
));
return
elt
;
let
div
=
document
.
createElement
(
'
div
'
);
result
.
forEach
(
e
=>
{
div
.
appendChild
(
e
);
});
return
div
;
}
/**
...
...
@@ -2902,7 +2890,7 @@ let lastMessage = {};
* @param {boolean} privileged
* @param {boolean} history
* @param {string} kind
* @param {
unknown
} message
* @param {
string|HTMLElement
} message
*/
function
addToChatbox
(
peerId
,
dest
,
nick
,
time
,
privileged
,
history
,
kind
,
message
)
{
let
row
=
document
.
createElement
(
'
div
'
);
...
...
@@ -2919,8 +2907,17 @@ function addToChatbox(peerId, dest, nick, time, privileged, history, kind, messa
if
(
dest
)
container
.
classList
.
add
(
'
message-private
'
);
/** @type{HTMLElement} */
let
body
;
if
(
message
instanceof
HTMLElement
)
{
body
=
message
;
}
else
if
(
typeof
message
===
'
string
'
)
{
body
=
formatText
(
message
);
}
else
{
throw
new
Error
(
'
Cannot add element to chatbox
'
);
}
if
(
kind
!==
'
me
'
)
{
let
p
=
formatLines
(
message
.
toString
().
split
(
'
\n
'
));
let
doHeader
=
true
;
if
(
lastMessage
.
nick
!==
(
nick
||
null
)
||
lastMessage
.
peerId
!==
(
peerId
||
null
)
||
...
...
@@ -2952,6 +2949,8 @@ function addToChatbox(peerId, dest, nick, time, privileged, history, kind, messa
}
}
let
p
=
document
.
createElement
(
'
p
'
);
p
.
appendChild
(
body
);
p
.
classList
.
add
(
'
message-content
'
);
container
.
appendChild
(
p
);
lastMessage
.
nick
=
(
nick
||
null
);
...
...
@@ -2965,14 +2964,10 @@ function addToChatbox(peerId, dest, nick, time, privileged, history, kind, messa
let
user
=
document
.
createElement
(
'
span
'
);
user
.
textContent
=
nick
||
'
(anon)
'
;
user
.
classList
.
add
(
'
message-me-user
'
);
let
content
=
document
.
createElement
(
'
span
'
);
formatLine
(
message
.
toString
()).
forEach
(
elt
=>
{
content
.
appendChild
(
elt
);
});
content
.
classList
.
add
(
'
message-me-content
'
);
body
.
classList
.
add
(
'
message-me-content
'
);
container
.
appendChild
(
asterisk
);
container
.
appendChild
(
user
);
container
.
appendChild
(
content
);
container
.
appendChild
(
body
);
container
.
classList
.
add
(
'
message-me
'
);
lastMessage
=
{};
}
...
...
@@ -2988,7 +2983,7 @@ function addToChatbox(peerId, dest, nick, time, privileged, history, kind, messa
}
/**
* @param {string} message
* @param {string
|HTMLElement
} message
*/
function
localMessage
(
message
)
{
return
addToChatbox
(
null
,
null
,
null
,
new
Date
(),
false
,
false
,
''
,
message
);
...
...
static/protocol.js
View file @
0fc91367
...
...
@@ -193,7 +193,7 @@ function ServerConnection() {
/**
* onchat is called whenever a new chat message is received.
*
* @type {(this: ServerConnection, id: string, dest: string, username: string, time: Date, privileged: boolean, history: boolean, kind: string, message:
unknown
) => void}
* @type {(this: ServerConnection, id: string, dest: string, username: string, time: Date, privileged: boolean, history: boolean, kind: string, message:
string
) => void}
*/
this
.
onchat
=
null
;
/**
...
...
@@ -437,7 +437,8 @@ ServerConnection.prototype.connect = async function(url) {
if
(
sc
.
onchat
)
sc
.
onchat
.
call
(
sc
,
m
.
source
,
m
.
dest
,
m
.
username
,
parseTime
(
m
.
time
),
m
.
privileged
,
m
.
type
===
'
chathistory
'
,
m
.
kind
,
m
.
value
,
m
.
privileged
,
m
.
type
===
'
chathistory
'
,
m
.
kind
,
''
+
m
.
value
,
);
break
;
case
'
usermessage
'
:
...
...
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