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
a7595eab
Commit
a7595eab
authored
5 years ago
by
Nicolas Werner
Browse files
Options
Downloads
Patches
Plain Diff
Reimplement sending basic text messages
parent
a1c97fc8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/timeline2/TimelineModel.h
+29
-0
29 additions, 0 deletions
src/timeline2/TimelineModel.h
src/timeline2/TimelineViewManager.cpp
+38
-0
38 additions, 0 deletions
src/timeline2/TimelineViewManager.cpp
src/timeline2/TimelineViewManager.h
+2
-2
2 additions, 2 deletions
src/timeline2/TimelineViewManager.h
with
69 additions
and
2 deletions
src/timeline2/TimelineModel.h
+
29
−
0
View file @
a7595eab
...
...
@@ -7,6 +7,9 @@
#include
<QDate>
#include
<QHash>
#include
"Logging.h"
#include
"MatrixClient.h"
namespace
qml_mtx_events
{
Q_NAMESPACE
...
...
@@ -110,6 +113,8 @@ public:
Q_INVOKABLE
void
viewRawMessage
(
QString
id
)
const
;
void
addEvents
(
const
mtx
::
responses
::
Timeline
&
events
);
template
<
class
T
>
void
sendMessage
(
const
T
&
msg
);
public
slots
:
void
fetchHistory
();
...
...
@@ -121,6 +126,8 @@ private slots:
signals
:
void
oldMessagesRetrieved
(
const
mtx
::
responses
::
Messages
&
res
);
void
messageFailed
(
const
std
::
string
txn_id
);
void
messageSent
(
const
std
::
string
txn_id
,
std
::
string
event_id
);
private
:
DecryptionResult
decryptEvent
(
...
...
@@ -139,3 +146,25 @@ private:
QHash
<
QString
,
QColor
>
userColors
;
};
template
<
class
T
>
void
TimelineModel
::
sendMessage
(
const
T
&
msg
)
{
auto
txn_id
=
http
::
client
()
->
generate_txn_id
();
http
::
client
()
->
send_room_message
<
T
,
mtx
::
events
::
EventType
::
RoomMessage
>
(
room_id_
.
toStdString
(),
txn_id
,
msg
,
[
this
,
txn_id
](
const
mtx
::
responses
::
EventId
&
res
,
mtx
::
http
::
RequestErr
err
)
{
if
(
err
)
{
const
int
status_code
=
static_cast
<
int
>
(
err
->
status_code
);
nhlog
::
net
()
->
warn
(
"[{}] failed to send message: {} {}"
,
txn_id
,
err
->
matrix_error
.
error
,
status_code
);
emit
messageFailed
(
txn_id
);
}
emit
messageSent
(
txn_id
,
res
.
event_id
.
to_string
());
});
}
This diff is collapsed.
Click to expand it.
src/timeline2/TimelineViewManager.cpp
+
38
−
0
View file @
a7595eab
...
...
@@ -62,3 +62,41 @@ TimelineViewManager::initWithMessages(const std::map<QString, mtx::responses::Ti
models
.
value
(
e
.
first
)
->
addEvents
(
e
.
second
);
}
}
void
TimelineViewManager
::
queueTextMessage
(
const
QString
&
msg
)
{
mtx
::
events
::
msg
::
Text
text
=
{};
text
.
body
=
msg
.
trimmed
().
toStdString
();
text
.
format
=
"org.matrix.custom.html"
;
text
.
formatted_body
=
utils
::
markdownToHtml
(
msg
).
toStdString
();
if
(
timeline_
)
timeline_
->
sendMessage
(
text
);
}
void
TimelineViewManager
::
queueReplyMessage
(
const
QString
&
reply
,
const
RelatedInfo
&
related
)
{
mtx
::
events
::
msg
::
Text
text
=
{};
QString
body
;
bool
firstLine
=
true
;
for
(
const
auto
&
line
:
related
.
quoted_body
.
splitRef
(
"
\n
"
))
{
if
(
firstLine
)
{
firstLine
=
false
;
body
=
QString
(
"> <%1> %2
\n
"
).
arg
(
related
.
quoted_user
).
arg
(
line
);
}
else
{
body
=
QString
(
"%1
\n
> %2
\n
"
).
arg
(
body
).
arg
(
line
);
}
}
text
.
body
=
QString
(
"%1
\n
%2"
).
arg
(
body
).
arg
(
reply
).
toStdString
();
text
.
format
=
"org.matrix.custom.html"
;
text
.
formatted_body
=
utils
::
getFormattedQuoteBody
(
related
,
utils
::
markdownToHtml
(
reply
)).
toStdString
();
text
.
relates_to
.
in_reply_to
.
event_id
=
related
.
related_event
;
if
(
timeline_
)
timeline_
->
sendMessage
(
text
);
}
This diff is collapsed.
Click to expand it.
src/timeline2/TimelineViewManager.h
+
2
−
2
View file @
a7595eab
...
...
@@ -46,8 +46,8 @@ public slots:
void
setHistoryView
(
const
QString
&
room_id
);
void
queueTextMessage
(
const
QString
&
msg
)
{}
void
queueReplyMessage
(
const
QString
&
reply
,
const
RelatedInfo
&
related
)
{}
void
queueTextMessage
(
const
QString
&
msg
)
;
void
queueReplyMessage
(
const
QString
&
reply
,
const
RelatedInfo
&
related
)
;
void
queueEmoteMessage
(
const
QString
&
msg
)
{}
void
queueImageMessage
(
const
QString
&
roomid
,
const
QString
&
filename
,
...
...
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