Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
BC
public
liblinphone
Commits
87c7236d
Commit
87c7236d
authored
Nov 09, 2017
by
Ronan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(MainDb): fetch contents of messages
parent
fd1084b8
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
90 additions
and
40 deletions
+90
-40
src/content/content-type.cpp
src/content/content-type.cpp
+15
-10
src/content/content-type.h
src/content/content-type.h
+2
-0
src/content/content.cpp
src/content/content.cpp
+1
-1
src/content/content.h
src/content/content.h
+3
-1
src/db/main-db.cpp
src/db/main-db.cpp
+69
-28
No files found.
src/content/content-type.cpp
View file @
87c7236d
...
...
@@ -154,16 +154,8 @@ bool ContentType::isValid () const {
return
!
d
->
type
.
empty
()
&&
!
d
->
subType
.
empty
();
}
bool
ContentType
::
isFile
()
const
{
//TODO Improve
if
(
*
this
!=
ContentType
::
FileTransfer
&&
*
this
!=
ContentType
::
PlainText
&&
*
this
!=
ContentType
::
ExternalBody
&&
*
this
!=
ContentType
::
Imdn
&&
*
this
!=
ContentType
::
ImIsComposing
&&
*
this
!=
ContentType
::
ResourceLists
&&
*
this
!=
ContentType
::
Sdp
&&
*
this
!=
ContentType
::
Cpim
&&
*
this
!=
ContentType
::
ConferenceInfo
)
{
return
true
;
}
return
false
;
bool
ContentType
::
isFile
()
const
{
return
isFile
(
*
this
);
}
string
ContentType
::
asString
()
const
{
...
...
@@ -178,4 +170,17 @@ string ContentType::asString () const {
return
""
;
}
bool
ContentType
::
isFile
(
const
ContentType
&
contentType
)
{
// TODO Improve.
return
contentType
!=
FileTransfer
&&
contentType
!=
PlainText
&&
contentType
!=
ExternalBody
&&
contentType
!=
Imdn
&&
contentType
!=
ImIsComposing
&&
contentType
!=
ResourceLists
&&
contentType
!=
Sdp
&&
contentType
!=
Cpim
&&
contentType
!=
ConferenceInfo
;
}
LINPHONE_END_NAMESPACE
src/content/content-type.h
View file @
87c7236d
...
...
@@ -59,6 +59,8 @@ public:
std
::
string
asString
()
const
;
static
bool
isFile
(
const
ContentType
&
contentType
);
static
const
ContentType
Cpim
;
static
const
ContentType
ExternalBody
;
static
const
ContentType
FileTransfer
;
...
...
src/content/content.cpp
View file @
87c7236d
...
...
@@ -121,7 +121,7 @@ void Content::setBody (const vector<char> &body) {
d
->
body
=
body
;
}
void
Content
::
setBody
(
std
::
vector
<
char
>
&&
body
)
{
void
Content
::
setBody
(
vector
<
char
>
&&
body
)
{
L_D
();
d
->
body
=
move
(
body
);
}
...
...
src/content/content.h
View file @
87c7236d
...
...
@@ -22,9 +22,11 @@
#include <vector>
// TODO: Remove me.
#include "linphone/content.h"
#include "object/app-data-container.h"
#include "object/clonable-object.h"
#include "linphone/content.h"
// =============================================================================
...
...
src/db/main-db.cpp
View file @
87c7236d
...
...
@@ -289,37 +289,78 @@ MainDb::MainDb (const shared_ptr<Core> &core) : AbstractDb(*new MainDbPrivate),
if
(
!
chatRoom
)
return
nullptr
;
string
localSipAddress
;
string
remoteSipAddress
;
string
imdnMessageId
;
int
state
;
int
direction
;
int
isSecured
;
soci
::
session
*
session
=
dbSession
.
getBackendSession
<
soci
::
session
>
();
*
session
<<
"SELECT local_sip_address.value, remote_sip_address.value, imdn_message_id, state, direction, is_secured"
" FROM event, conference_chat_message_event, sip_address AS local_sip_address,"
" sip_address AS remote_sip_address"
" WHERE event_id = :eventId"
" AND event_id = event.id"
" AND local_sip_address_id = local_sip_address.id"
" AND remote_sip_address_id = remote_sip_address.id"
,
soci
::
into
(
localSipAddress
),
soci
::
into
(
remoteSipAddress
),
soci
::
into
(
imdnMessageId
),
soci
::
into
(
state
),
soci
::
into
(
direction
),
soci
::
into
(
isSecured
),
soci
::
use
(
eventId
);
// TODO: Create me.
// TODO: Use cache, do not fetch the same message twice.
shared_ptr
<
ChatMessage
>
chatMessage
=
make_shared
<
ChatMessage
>
(
chatRoom
);
chatMessage
->
getPrivate
()
->
setState
(
static_cast
<
ChatMessage
::
State
>
(
state
),
true
);
chatMessage
->
getPrivate
()
->
setDirection
(
static_cast
<
ChatMessage
::
Direction
>
(
direction
));
chatMessage
->
setIsSecured
(
static_cast
<
bool
>
(
isSecured
));
// 1 - Fetch chat message.
shared_ptr
<
ChatMessage
>
chatMessage
=
make_shared
<
ChatMessage
>
(
chatRoom
);
{
string
localSipAddress
;
string
remoteSipAddress
;
string
imdnMessageId
;
int
state
;
int
direction
;
int
isSecured
;
soci
::
session
*
session
=
dbSession
.
getBackendSession
<
soci
::
session
>
();
*
session
<<
"SELECT local_sip_address.value, remote_sip_address.value, imdn_message_id, state, direction, is_secured"
" FROM event, conference_chat_message_event, sip_address AS local_sip_address,"
" sip_address AS remote_sip_address"
" WHERE event_id = :eventId"
" AND event_id = event.id"
" AND local_sip_address_id = local_sip_address.id"
" AND remote_sip_address_id = remote_sip_address.id"
,
soci
::
into
(
localSipAddress
),
soci
::
into
(
remoteSipAddress
),
soci
::
into
(
imdnMessageId
),
soci
::
into
(
state
),
soci
::
into
(
direction
),
soci
::
into
(
isSecured
),
soci
::
use
(
eventId
);
chatMessage
->
getPrivate
()
->
setState
(
static_cast
<
ChatMessage
::
State
>
(
state
),
true
);
chatMessage
->
getPrivate
()
->
setDirection
(
static_cast
<
ChatMessage
::
Direction
>
(
direction
));
chatMessage
->
setIsSecured
(
static_cast
<
bool
>
(
isSecured
));
if
(
direction
==
static_cast
<
int
>
(
ChatMessage
::
Direction
::
Outgoing
))
{
chatMessage
->
setFromAddress
(
Address
(
localSipAddress
));
chatMessage
->
setToAddress
(
Address
(
remoteSipAddress
));
}
else
{
chatMessage
->
setFromAddress
(
Address
(
remoteSipAddress
));
chatMessage
->
setToAddress
(
Address
(
localSipAddress
));
}
}
if
(
direction
==
static_cast
<
int
>
(
ChatMessage
::
Direction
::
Outgoing
))
{
chatMessage
->
setFromAddress
(
Address
(
localSipAddress
));
chatMessage
->
setToAddress
(
Address
(
remoteSipAddress
));
}
else
{
chatMessage
->
setFromAddress
(
Address
(
remoteSipAddress
));
chatMessage
->
setToAddress
(
Address
(
localSipAddress
));
// 2 - Fetch contents.
{
soci
::
session
*
session
=
dbSession
.
getBackendSession
<
soci
::
session
>
();
const
string
query
=
"SELECT content_type.value, body FROM chat_message_content, content_type"
" WHERE event_id = :eventId AND content_type_id = content_type.id"
;
soci
::
rowset
<
soci
::
row
>
rows
=
(
session
->
prepare
<<
query
,
soci
::
use
(
eventId
));
for
(
const
auto
&
row
:
rows
)
{
ContentType
contentType
(
row
.
get
<
string
>
(
1
));
Content
*
content
;
if
(
contentType
==
ContentType
::
FileTransfer
)
content
=
new
FileTransferContent
();
else
if
(
contentType
.
isFile
())
{
long
long
contentId
=
q
->
getBackend
()
==
AbstractDb
::
Sqlite3
?
static_cast
<
long
long
>
(
row
.
get
<
int
>
(
0
))
:
row
.
get
<
long
long
>
(
0
);
string
name
;
int
size
;
string
path
;
*
session
<<
"SELECT name, size, path FROM chat_message_file_content"
" WHERE chat_message_content_id = :contentId"
,
soci
::
use
(
contentId
);
FileContent
*
fileContent
=
new
FileContent
();
fileContent
->
setFileName
(
name
);
fileContent
->
setFileSize
(
static_cast
<
size_t
>
(
size
));
fileContent
->
setFilePath
(
path
);
content
=
fileContent
;
}
else
Content
*
content
=
new
Content
();
content
->
setContentType
(
contentType
);
content
->
setBody
(
row
.
get
<
string
>
(
2
));
chatMessage
.
addContent
(
content
);
}
}
// TODO: Use cache.
...
...
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