Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
jami-daemon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository 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
savoirfairelinux
jami-daemon
Commits
67f74aae
Commit
67f74aae
authored
8 years ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
multi-device: add text message support
Tuleap:
#938
Change-Id: I92e6116702b5eb70d39ec1e0a6f6b876c98ce2cb
parent
4b3ca5c7
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/ringdht/ringaccount.cpp
+45
-23
45 additions, 23 deletions
src/ringdht/ringaccount.cpp
with
45 additions
and
23 deletions
src/ringdht/ringaccount.cpp
+
45
−
23
View file @
67f74aae
...
@@ -1532,9 +1532,8 @@ RingAccount::doRegister_()
...
@@ -1532,9 +1532,8 @@ RingAccount::doRegister_()
}
}
// Listen for incoming calls
// Listen for incoming calls
auto
ringDeviceId
=
identity_
.
first
->
getPublicKey
().
getId
().
toString
();
callKey_
=
dht
::
InfoHash
::
get
(
"callto:"
+
ringDeviceId_
);
callKey_
=
dht
::
InfoHash
::
get
(
"callto:"
+
ringDeviceId
);
RING_DBG
(
"Listening on callto:%s : %s"
,
ringDeviceId_
.
c_str
(),
callKey_
.
toString
().
c_str
());
RING_DBG
(
"Listening on callto:%s : %s"
,
ringDeviceId
.
c_str
(),
callKey_
.
toString
().
c_str
());
dht_
.
listen
<
dht
::
IceCandidates
>
(
dht_
.
listen
<
dht
::
IceCandidates
>
(
callKey_
,
callKey_
,
[
shared
]
(
dht
::
IceCandidates
&&
msg
)
{
[
shared
]
(
dht
::
IceCandidates
&&
msg
)
{
...
@@ -1623,9 +1622,10 @@ RingAccount::doRegister_()
...
@@ -1623,9 +1622,10 @@ RingAccount::doRegister_()
}
}
);
);
auto
inboxDeviceKey
=
dht
::
InfoHash
::
get
(
"inbox:"
+
ringDeviceId_
);
dht_
.
listen
<
dht
::
ImMessage
>
(
dht_
.
listen
<
dht
::
ImMessage
>
(
inboxKey
,
inbox
Device
Key
,
[
shared
,
inboxKey
](
dht
::
ImMessage
&&
v
)
{
[
shared
,
inbox
Device
Key
](
dht
::
ImMessage
&&
v
)
{
auto
&
this_
=
*
shared
.
get
();
auto
&
this_
=
*
shared
.
get
();
auto
res
=
this_
.
treatedMessages_
.
insert
(
v
.
id
);
auto
res
=
this_
.
treatedMessages_
.
insert
(
v
.
id
);
if
(
!
res
.
second
)
if
(
!
res
.
second
)
...
@@ -1638,7 +1638,7 @@ RingAccount::doRegister_()
...
@@ -1638,7 +1638,7 @@ RingAccount::doRegister_()
utf8_make_valid
(
v
.
msg
)}};
utf8_make_valid
(
v
.
msg
)}};
shared
->
onTextMessage
(
from
,
payloads
);
shared
->
onTextMessage
(
from
,
payloads
);
RING_DBG
(
"Sending message confirmation %"
PRIu64
,
v
.
id
);
RING_DBG
(
"Sending message confirmation %"
PRIu64
,
v
.
id
);
this_
.
dht_
.
putEncrypted
(
inboxKey
,
this_
.
dht_
.
putEncrypted
(
inbox
Device
Key
,
v
.
from
,
v
.
from
,
dht
::
ImMessage
(
v
.
id
,
std
::
string
(),
now
));
dht
::
ImMessage
(
v
.
id
,
std
::
string
(),
now
));
return
true
;
return
true
;
...
@@ -2123,20 +2123,40 @@ RingAccount::sendTextMessage(const std::string& to, const std::map<std::string,
...
@@ -2123,20 +2123,40 @@ RingAccount::sendTextMessage(const std::string& to, const std::map<std::string,
messageEngine_
.
onMessageSent
(
token
,
false
);
messageEngine_
.
onMessageSent
(
token
,
false
);
return
;
return
;
}
}
if
(
payloads
.
size
()
!=
1
)
{
// Multi-part message
// TODO: not supported yet
RING_ERR
(
"Multi-part im is not supported yet by RingAccount"
);
messageEngine_
.
onMessageSent
(
token
,
false
);
return
;
}
std
::
weak_ptr
<
RingAccount
>
wshared
=
std
::
static_pointer_cast
<
RingAccount
>
(
shared_from_this
());
auto
toUri
=
parseRingUri
(
to
);
auto
toUri
=
parseRingUri
(
to
);
auto
toH
=
dht
::
InfoHash
(
toUri
);
auto
toH
=
dht
::
InfoHash
(
toUri
);
auto
now
=
system_clock
::
to_time_t
(
system_clock
::
now
());
auto
now
=
system_clock
::
to_time_t
(
system_clock
::
now
());
auto
treatedDevices_
=
std
::
make_shared
<
std
::
set
<
dht
::
InfoHash
>>
();
struct
PendingConfirmation
{
bool
replied
{
false
};
std
::
map
<
dht
::
InfoHash
,
std
::
future
<
size_t
>>
listenTokens
{};
};
auto
confirm
=
std
::
make_shared
<
PendingConfirmation
>
();
// Find listening Ring devices for this account
dht_
.
get
<
DeviceAnnouncement
>
(
toH
,
[
=
](
DeviceAnnouncement
&&
dev
)
{
if
(
dev
.
from
!=
toH
)
return
true
;
if
(
not
treatedDevices_
->
emplace
(
dev
.
dev
).
second
)
return
true
;
// Single-part message
if
(
payloads
.
size
()
==
1
)
{
auto
e
=
sentMessages_
.
emplace
(
token
,
PendingMessage
{});
auto
e
=
sentMessages_
.
emplace
(
token
,
PendingMessage
{});
e
.
first
->
second
.
to
=
toH
;
e
.
first
->
second
.
to
=
dev
.
dev
;
auto
h
=
dht
::
InfoHash
::
get
(
"inbox:"
+
toUri
);
auto
h
=
dht
::
InfoHash
::
get
(
"inbox:"
+
dev
.
dev
.
toString
()
);
std
::
weak_ptr
<
RingAccount
>
wshared
=
std
::
static_pointer_cast
<
RingAccount
>
(
shared_from_this
());
RING_DBG
(
"Found device to send message %s -> %s"
,
dev
.
dev
.
toString
().
c_str
(),
h
.
toString
().
c_str
());
dht_
.
listen
<
dht
::
ImMessage
>
(
h
,
[
wshared
,
token
](
dht
::
ImMessage
&&
msg
)
{
auto
list_token
=
dht_
.
listen
<
dht
::
ImMessage
>
(
h
,
[
h
,
wshared
,
token
,
confirm
](
dht
::
ImMessage
&&
msg
)
{
if
(
auto
this_
=
wshared
.
lock
())
{
if
(
auto
this_
=
wshared
.
lock
())
{
// check expected message confirmation
// check expected message confirmation
if
(
msg
.
id
!=
token
)
if
(
msg
.
id
!=
token
)
...
@@ -2165,27 +2185,29 @@ RingAccount::sendTextMessage(const std::string& to, const std::map<std::string,
...
@@ -2165,27 +2185,29 @@ RingAccount::sendTextMessage(const std::string& to, const std::map<std::string,
this_
->
saveTreatedMessages
();
this_
->
saveTreatedMessages
();
// report message as confirmed received
// report message as confirmed received
for
(
auto
&
t
:
confirm
->
listenTokens
)
this_
->
dht_
.
cancelListen
(
t
.
first
,
t
.
second
.
get
());
confirm
->
listenTokens
.
clear
();
confirm
->
replied
=
true
;
this_
->
messageEngine_
.
onMessageSent
(
token
,
true
);
this_
->
messageEngine_
.
onMessageSent
(
token
,
true
);
}
}
return
false
;
return
false
;
});
});
confirm
->
listenTokens
.
emplace
(
h
,
std
::
move
(
list_token
));
dht_
.
putEncrypted
(
h
,
dht_
.
putEncrypted
(
h
,
toH
,
dev
.
dev
,
dht
::
ImMessage
(
token
,
std
::
string
(
payloads
.
begin
()
->
second
),
now
),
dht
::
ImMessage
(
token
,
std
::
string
(
payloads
.
begin
()
->
second
),
now
),
[
wshared
,
token
](
bool
ok
)
{
[
wshared
,
token
,
confirm
,
h
](
bool
ok
)
{
if
(
auto
this_
=
wshared
.
lock
())
{
if
(
auto
this_
=
wshared
.
lock
())
{
if
(
not
ok
)
if
(
not
ok
)
{
confirm
->
listenTokens
.
erase
(
h
);
if
(
confirm
->
listenTokens
.
empty
()
and
not
confirm
->
replied
)
this_
->
messageEngine_
.
onMessageSent
(
token
,
false
);
this_
->
messageEngine_
.
onMessageSent
(
token
,
false
);
}
}
});
return
;
}
}
});
// Multi-part message
});
// TODO: not supported yet
RING_ERR
(
"Multi-part im is not supported yet by RingAccount"
);
messageEngine_
.
onMessageSent
(
token
,
false
);
}
}
}
// namespace ring
}
// namespace ring
This diff is collapsed.
Click to expand it.
Jami Bot
@RingBot
mentioned in commit
6e323fa5
·
7 years ago
mentioned in commit
6e323fa5
mentioned in commit 6e323fa54f29ae76c375084d3d14939529700e68
Toggle commit list
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