Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
nheko
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Nheko Reborn
nheko
Commits
a21db789
Commit
a21db789
authored
6 years ago
by
Konstantinos Sideris
Browse files
Options
Downloads
Patches
Plain Diff
Fix double href links on username pills
parent
896fe069
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/Utils.cpp
+51
-0
51 additions, 0 deletions
src/Utils.cpp
src/Utils.h
+5
-1
5 additions, 1 deletion
src/Utils.h
src/timeline/TimelineItem.cpp
+3
-8
3 additions, 8 deletions
src/timeline/TimelineItem.cpp
with
59 additions
and
9 deletions
src/Utils.cpp
+
51
−
0
View file @
a21db789
...
...
@@ -3,10 +3,13 @@
#include
<QApplication>
#include
<QDesktopWidget>
#include
<QSettings>
#include
<QXmlStreamReader>
#include
<cmath>
#include
<boost/variant.hpp>
#include
"Config.h"
using
TimelineEvent
=
mtx
::
events
::
collections
::
TimelineEvents
;
QString
...
...
@@ -276,3 +279,51 @@ utils::humanReadableFingerprint(const QString &ed25519)
}
return
fingerprintList
.
join
(
" "
);
}
QString
utils
::
linkifyMessage
(
const
QString
&
body
)
{
QXmlStreamReader
xml
{
"<html>"
+
body
+
"</html>"
};
QString
textString
;
while
(
!
xml
.
atEnd
()
&&
!
xml
.
hasError
())
{
auto
t
=
xml
.
readNext
();
switch
(
t
)
{
case
QXmlStreamReader
::
Characters
:
{
auto
text
=
xml
.
text
().
toString
();
text
.
replace
(
conf
::
strings
::
url_regex
,
conf
::
strings
::
url_html
);
textString
+=
text
;
break
;
}
case
QXmlStreamReader
::
StartDocument
:
case
QXmlStreamReader
::
EndDocument
:
break
;
case
QXmlStreamReader
::
StartElement
:
{
if
(
xml
.
name
()
==
"html"
)
break
;
textString
+=
"<"
+
xml
.
name
()
+
">"
;
break
;
}
case
QXmlStreamReader
::
EndElement
:
{
if
(
xml
.
name
()
==
"html"
)
break
;
textString
+=
"</"
+
xml
.
name
()
+
">"
;
break
;
}
default
:
{
break
;
}
}
}
if
(
xml
.
hasError
())
{
// qWarning() << "error while parsing xml";
return
body
;
}
return
textString
;
}
This diff is collapsed.
Click to expand it.
src/Utils.h
+
5
−
1
View file @
a21db789
...
...
@@ -201,7 +201,7 @@ humanReadableFingerprint(const QString &ed25519);
//! If the `format` of the message is not supported we fallback to `body`.
template
<
typename
RoomMessageT
>
QString
get
_m
essage
_b
ody
(
const
RoomMessageT
&
event
)
get
M
essage
B
ody
(
const
RoomMessageT
&
event
)
{
if
(
event
.
content
.
format
.
empty
())
return
QString
::
fromStdString
(
event
.
content
.
body
);
...
...
@@ -211,4 +211,8 @@ get_message_body(const RoomMessageT &event)
return
QString
::
fromStdString
(
event
.
content
.
formatted_body
);
}
//! Replace raw URLs in text with HTML link tags.
QString
linkifyMessage
(
const
QString
&
body
);
}
This diff is collapsed.
Click to expand it.
src/timeline/TimelineItem.cpp
+
3
−
8
View file @
a21db789
...
...
@@ -437,7 +437,7 @@ TimelineItem::TimelineItem(const mtx::events::RoomEvent<mtx::events::msg::Notice
const
auto
sender
=
QString
::
fromStdString
(
event
.
sender
);
const
auto
timestamp
=
QDateTime
::
fromMSecsSinceEpoch
(
event
.
origin_server_ts
);
auto
formatted_body
=
utils
::
get_m
essage
_b
ody
(
event
).
trimmed
();
auto
formatted_body
=
utils
::
linkifyMessage
(
utils
::
getM
essage
B
ody
(
event
).
trimmed
()
)
;
auto
body
=
QString
::
fromStdString
(
event
.
content
.
body
).
trimmed
();
descriptionMsg_
=
{
Cache
::
displayName
(
room_id_
,
sender
),
...
...
@@ -448,7 +448,6 @@ TimelineItem::TimelineItem(const mtx::events::RoomEvent<mtx::events::msg::Notice
generateTimestamp
(
timestamp
);
formatted_body
.
replace
(
conf
::
strings
::
url_regex
,
conf
::
strings
::
url_html
);
formatted_body
=
"<i>"
+
formatted_body
+
"</i>"
;
if
(
with_sender
)
{
...
...
@@ -485,7 +484,7 @@ TimelineItem::TimelineItem(const mtx::events::RoomEvent<mtx::events::msg::Emote>
event_id_
=
QString
::
fromStdString
(
event
.
event_id
);
const
auto
sender
=
QString
::
fromStdString
(
event
.
sender
);
auto
formatted_body
=
utils
::
get_m
essage
_b
ody
(
event
).
trimmed
();
auto
formatted_body
=
utils
::
linkifyMessage
(
utils
::
getM
essage
B
ody
(
event
).
trimmed
()
)
;
auto
body
=
QString
::
fromStdString
(
event
.
content
.
body
).
trimmed
();
auto
timestamp
=
QDateTime
::
fromMSecsSinceEpoch
(
event
.
origin_server_ts
);
...
...
@@ -494,8 +493,6 @@ TimelineItem::TimelineItem(const mtx::events::RoomEvent<mtx::events::msg::Emote>
descriptionMsg_
=
{
""
,
sender
,
emoteMsg
,
utils
::
descriptiveTime
(
timestamp
),
timestamp
};
formatted_body
.
replace
(
conf
::
strings
::
url_regex
,
conf
::
strings
::
url_html
);
generateTimestamp
(
timestamp
);
if
(
with_sender
)
{
...
...
@@ -530,14 +527,12 @@ TimelineItem::TimelineItem(const mtx::events::RoomEvent<mtx::events::msg::Text>
event_id_
=
QString
::
fromStdString
(
event
.
event_id
);
const
auto
sender
=
QString
::
fromStdString
(
event
.
sender
);
auto
formatted_body
=
utils
::
get_m
essage
_b
ody
(
event
).
trimmed
();
auto
formatted_body
=
utils
::
linkifyMessage
(
utils
::
getM
essage
B
ody
(
event
).
trimmed
()
)
;
auto
body
=
QString
::
fromStdString
(
event
.
content
.
body
).
trimmed
();
auto
timestamp
=
QDateTime
::
fromMSecsSinceEpoch
(
event
.
origin_server_ts
);
auto
displayName
=
Cache
::
displayName
(
room_id_
,
sender
);
formatted_body
.
replace
(
conf
::
strings
::
url_regex
,
conf
::
strings
::
url_html
);
QSettings
settings
;
descriptionMsg_
=
{
sender
==
settings
.
value
(
"auth/user_id"
)
?
"You"
:
displayName
,
sender
,
...
...
This diff is collapsed.
Click to expand it.
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