Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
biboumi
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
88
Issues
88
List
Boards
Labels
Service Desk
Milestones
Merge Requests
7
Merge Requests
7
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
louiz’
biboumi
Commits
8ec823be
Commit
8ec823be
authored
Aug 12, 2016
by
louiz’
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Save received and sent messages into the database
parent
7ffe278e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
61 additions
and
3 deletions
+61
-3
database/database.xml
database/database.xml
+12
-3
src/bridge/bridge.cpp
src/bridge/bridge.cpp
+10
-0
src/database/database.cpp
src/database/database.cpp
+31
-0
src/database/database.hpp
src/database/database.hpp
+8
-0
No files found.
database/database.xml
View file @
8ec823be
...
...
@@ -39,8 +39,17 @@
</index>
</object>
<object
name=
"LogLine"
>
<field
name=
"date"
type=
"date"
/>
<field
name=
"body"
type=
"string"
length=
"4096"
/>
<object
name=
"MucLogLine"
>
<field
name=
"uuid"
type=
"string"
length=
"36"
/>
<!-- The bare JID of the user for which we stored the line. It's
the JID associated with the Bridge -->
<field
name=
"owner"
type=
"string"
length=
"4096"
/>
<!-- The room IID -->
<field
name=
"ircChanName"
type=
"string"
length=
"4096"
/>
<field
name=
"ircServerName"
type=
"string"
length=
"4096"
/>
<field
name=
"date"
type=
"datetime"
/>
<field
name=
"body"
type=
"string"
length=
"65536"
/>
<field
name=
"nick"
type=
"string"
length=
"4096"
/>
</object>
</database>
src/bridge/bridge.cpp
View file @
8ec823be
...
...
@@ -224,6 +224,11 @@ void Bridge::send_channel_message(const Iid& iid, const std::string& body)
irc
->
send_channel_message
(
iid
.
get_local
(),
action_prefix
+
line
.
substr
(
4
)
+
"
\01
"
);
else
irc
->
send_channel_message
(
iid
.
get_local
(),
line
);
const
auto
xmpp_body
=
this
->
make_xmpp_body
(
line
);
Database
::
store_muc_message
(
this
->
get_bare_jid
(),
iid
,
std
::
chrono
::
system_clock
::
now
(),
std
::
get
<
0
>
(
xmpp_body
),
irc
->
get_own_nick
());
for
(
const
auto
&
resource
:
this
->
resources_in_chan
[
iid
.
to_tuple
()])
this
->
xmpp
.
send_muc_message
(
std
::
to_string
(
iid
),
irc
->
get_own_nick
(),
this
->
make_xmpp_body
(
line
),
this
->
user_jid
+
"/"
+
resource
);
...
...
@@ -578,10 +583,15 @@ void Bridge::send_message(const Iid& iid, const std::string& nick, const std::st
const
auto
encoding
=
in_encoding_for
(
*
this
,
iid
);
if
(
muc
)
{
const
auto
xmpp_body
=
this
->
make_xmpp_body
(
body
,
encoding
);
Database
::
store_muc_message
(
this
->
get_bare_jid
(),
iid
,
std
::
chrono
::
system_clock
::
now
(),
std
::
get
<
0
>
(
xmpp_body
),
nick
);
for
(
const
auto
&
resource
:
this
->
resources_in_chan
[
iid
.
to_tuple
()])
{
this
->
xmpp
.
send_muc_message
(
std
::
to_string
(
iid
),
nick
,
this
->
make_xmpp_body
(
body
,
encoding
),
this
->
user_jid
+
"/"
+
resource
);
}
}
else
...
...
src/database/database.cpp
View file @
8ec823be
...
...
@@ -3,7 +3,9 @@
#include <database/database.hpp>
#include <logger/logger.hpp>
#include <irc/iid.hpp>
#include <string>
#include <uuid.h>
using
namespace
std
::
string_literals
;
...
...
@@ -79,9 +81,38 @@ db::IrcChannelOptions Database::get_irc_channel_options_with_server_default(cons
return
coptions
;
}
void
Database
::
store_muc_message
(
const
std
::
string
&
owner
,
const
Iid
&
iid
,
Database
::
time_point
date
,
const
std
::
string
&
body
,
const
std
::
string
&
nick
)
{
db
::
MucLogLine
line
(
*
Database
::
db
);
line
.
uuid
=
Database
::
gen_uuid
();
line
.
owner
=
owner
;
line
.
ircChanName
=
iid
.
get_local
();
line
.
ircServerName
=
iid
.
get_server
();
line
.
date
=
date
.
time_since_epoch
().
count
();
line
.
body
=
body
;
line
.
nick
=
nick
;
line
.
update
();
}
void
Database
::
close
()
{
Database
::
db
.
reset
(
nullptr
);
}
std
::
string
Database
::
gen_uuid
()
{
char
uuid_str
[
37
];
uuid_t
uuid
;
uuid_generate
(
uuid
);
uuid_unparse
(
uuid
,
uuid_str
);
return
uuid_str
;
}
#endif
src/database/database.hpp
View file @
8ec823be
...
...
@@ -9,10 +9,14 @@
#include <memory>
#include <litesql.hpp>
#include <chrono>
class
Iid
;
class
Database
{
public:
using
time_point
=
std
::
chrono
::
system_clock
::
time_point
;
Database
()
=
default
;
~
Database
()
=
default
;
...
...
@@ -41,11 +45,15 @@ public:
const
std
::
string
&
server
,
const
std
::
string
&
channel
);
static
void
store_muc_message
(
const
std
::
string
&
owner
,
const
Iid
&
iid
,
time_point
date
,
const
std
::
string
&
body
,
const
std
::
string
&
nick
);
static
void
close
();
static
void
open
(
const
std
::
string
&
filename
,
const
std
::
string
&
db_type
=
"sqlite3"
);
private:
static
std
::
string
gen_uuid
();
static
std
::
unique_ptr
<
db
::
BibouDB
>
db
;
};
#endif
/* USE_DATABASE */
...
...
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