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
briar
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Julian Dehm
briar
Commits
159fd34c
Verified
Commit
159fd34c
authored
Sep 03, 2018
by
Torsten Grote
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use Conversation Manager for message retrieval
parent
9e7a387e
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
142 additions
and
16 deletions
+142
-16
briar-headless/src/main/java/org/briarproject/briar/headless/messaging/Extensions.kt
...a/org/briarproject/briar/headless/messaging/Extensions.kt
+30
-3
briar-headless/src/main/java/org/briarproject/briar/headless/messaging/MessagingControllerImpl.kt
...oject/briar/headless/messaging/MessagingControllerImpl.kt
+16
-10
briar-headless/src/main/java/org/briarproject/briar/headless/messaging/OutputPrivateMessage.kt
...rproject/briar/headless/messaging/OutputPrivateMessage.kt
+11
-3
briar-headless/src/main/java/org/briarproject/briar/headless/messaging/OutputPrivateRequest.kt
...rproject/briar/headless/messaging/OutputPrivateRequest.kt
+42
-0
briar-headless/src/main/java/org/briarproject/briar/headless/messaging/OutputPrivateResponse.kt
...project/briar/headless/messaging/OutputPrivateResponse.kt
+43
-0
No files found.
briar-headless/src/main/java/org/briarproject/briar/headless/messaging/Extensions.kt
View file @
159fd34c
package
org.briarproject.briar.headless.messaging
package
org.briarproject.briar.headless.messaging
import
org.briarproject.bramble.api.contact.ContactId
import
org.briarproject.bramble.api.contact.ContactId
import
org.briarproject.briar.api.introduction.IntroductionRequest
import
org.briarproject.briar.api.introduction.IntroductionResponse
import
org.briarproject.briar.api.messaging.PrivateMessage
import
org.briarproject.briar.api.messaging.PrivateMessage
import
org.briarproject.briar.api.messaging.PrivateMessageHeader
import
org.briarproject.briar.api.messaging.PrivateMessageHeader
import
org.briarproject.briar.api.messaging.PrivateRequest
import
org.briarproject.briar.api.messaging.PrivateResponse
import
org.briarproject.briar.api.messaging.event.PrivateMessageReceivedEvent
import
org.briarproject.briar.api.messaging.event.PrivateMessageReceivedEvent
import
org.briarproject.briar.api.sharing.InvitationRequest
import
org.briarproject.briar.api.sharing.InvitationResponse
internal
fun
PrivateMessageHeader
.
output
(
contactId
:
ContactId
,
body
:
String
)
=
internal
fun
PrivateMessageHeader
.
output
(
OutputPrivateMessage
(
this
,
contactId
,
body
)
contactId
:
ContactId
,
body
:
String
?
)
=
OutputPrivateMessage
(
this
,
contactId
,
body
)
internal
fun
PrivateMessage
.
output
(
contactId
:
ContactId
,
body
:
String
)
=
internal
fun
PrivateMessage
.
output
(
contactId
:
ContactId
,
body
:
String
)
=
OutputPrivateMessage
(
this
,
contactId
,
body
)
OutputPrivateMessage
(
this
,
contactId
,
body
)
internal
fun
PrivateMessageReceivedEvent
.
output
(
body
:
String
)
=
internal
fun
PrivateMessageReceivedEvent
<*>
.
output
(
body
:
String
)
=
messageHeader
.
output
(
contactId
,
body
)
messageHeader
.
output
(
contactId
,
body
)
internal
fun
IntroductionRequest
.
output
(
contactId
:
ContactId
)
=
OutputIntroductionRequest
(
this
,
contactId
)
internal
fun
PrivateRequest
<*>.
output
(
contactId
:
ContactId
):
OutputPrivateMessage
{
return
when
(
this
)
{
is
IntroductionRequest
->
OutputIntroductionRequest
(
this
,
contactId
)
is
InvitationRequest
->
OutputInvitationRequest
(
this
,
contactId
)
else
->
throw
AssertionError
(
"Unknown PrivateRequest"
)
}
}
internal
fun
PrivateResponse
.
output
(
contactId
:
ContactId
):
OutputPrivateMessage
{
return
when
(
this
)
{
is
IntroductionResponse
->
OutputIntroductionResponse
(
this
,
contactId
)
is
InvitationResponse
->
OutputInvitationResponse
(
this
,
contactId
)
else
->
throw
AssertionError
(
"Unknown PrivateResponse"
)
}
}
briar-headless/src/main/java/org/briarproject/briar/headless/messaging/MessagingControllerImpl.kt
View file @
159fd34c
...
@@ -11,9 +11,8 @@ import org.briarproject.bramble.api.db.NoSuchContactException
...
@@ -11,9 +11,8 @@ import org.briarproject.bramble.api.db.NoSuchContactException
import
org.briarproject.bramble.api.event.Event
import
org.briarproject.bramble.api.event.Event
import
org.briarproject.bramble.api.event.EventListener
import
org.briarproject.bramble.api.event.EventListener
import
org.briarproject.bramble.api.system.Clock
import
org.briarproject.bramble.api.system.Clock
import
org.briarproject.briar.api.messaging.*
import
org.briarproject.briar.api.messaging.MessagingConstants.MAX_PRIVATE_MESSAGE_BODY_LENGTH
import
org.briarproject.briar.api.messaging.MessagingConstants.MAX_PRIVATE_MESSAGE_BODY_LENGTH
import
org.briarproject.briar.api.messaging.MessagingManager
import
org.briarproject.briar.api.messaging.PrivateMessageFactory
import
org.briarproject.briar.api.messaging.event.PrivateMessageReceivedEvent
import
org.briarproject.briar.api.messaging.event.PrivateMessageReceivedEvent
import
org.briarproject.briar.headless.WebSocketController
import
org.briarproject.briar.headless.WebSocketController
import
java.util.concurrent.Executor
import
java.util.concurrent.Executor
...
@@ -21,11 +20,15 @@ import javax.annotation.concurrent.Immutable
...
@@ -21,11 +20,15 @@ import javax.annotation.concurrent.Immutable
import
javax.inject.Inject
import
javax.inject.Inject
import
javax.inject.Singleton
import
javax.inject.Singleton
private
const
val
EVENT_PRIVATE_MESSAGE
=
"org.briarproject.briar.api.messaging.event.PrivateMessageReceivedEvent"
@Immutable
@Immutable
@Singleton
@Singleton
internal
class
MessagingControllerImpl
@Inject
internal
class
MessagingControllerImpl
@Inject
constructor
(
constructor
(
private
val
messagingManager
:
MessagingManager
,
private
val
messagingManager
:
MessagingManager
,
private
val
conversationManager
:
ConversationManager
,
private
val
privateMessageFactory
:
PrivateMessageFactory
,
private
val
privateMessageFactory
:
PrivateMessageFactory
,
private
val
contactManager
:
ContactManager
,
private
val
contactManager
:
ContactManager
,
private
val
webSocketController
:
WebSocketController
,
private
val
webSocketController
:
WebSocketController
,
...
@@ -35,10 +38,15 @@ constructor(
...
@@ -35,10 +38,15 @@ constructor(
override
fun
list
(
ctx
:
Context
):
Context
{
override
fun
list
(
ctx
:
Context
):
Context
{
val
contact
=
getContact
(
ctx
)
val
contact
=
getContact
(
ctx
)
val
messages
=
conversationManager
.
getMessageHeaders
(
contact
.
id
).
map
{
header
->
val
messages
=
messagingManager
.
getMessageHeaders
(
contact
.
id
).
map
{
header
->
when
(
header
)
{
val
body
=
messagingManager
.
getMessageBody
(
header
.
id
)
is
PrivateRequest
<
*
>
->
header
.
output
(
contact
.
id
)
header
.
output
(
contact
.
id
,
body
)
is
PrivateResponse
->
header
.
output
(
contact
.
id
)
else
->
{
val
body
=
messagingManager
.
getMessageBody
(
header
.
id
)
header
.
output
(
contact
.
id
,
body
)
}
}
}
}
return
ctx
.
json
(
messages
)
return
ctx
.
json
(
messages
)
}
}
...
@@ -62,11 +70,9 @@ constructor(
...
@@ -62,11 +70,9 @@ constructor(
override
fun
eventOccurred
(
e
:
Event
)
{
override
fun
eventOccurred
(
e
:
Event
)
{
when
(
e
)
{
when
(
e
)
{
is
PrivateMessageReceivedEvent
->
dbExecutor
.
run
{
is
PrivateMessageReceivedEvent
<
*
>
->
dbExecutor
.
run
{
val
name
=
"org.briarproject.briar.api.messaging.event.PrivateMessageReceivedEvent"
val
body
=
messagingManager
.
getMessageBody
(
e
.
messageHeader
.
id
)
val
body
=
messagingManager
.
getMessageBody
(
e
.
messageHeader
.
id
)
webSocketController
.
sendEvent
(
name
,
e
.
output
(
body
))
webSocketController
.
sendEvent
(
EVENT_PRIVATE_MESSAGE
,
e
.
output
(
body
))
}
}
}
}
}
}
...
...
briar-headless/src/main/java/org/briarproject/briar/headless/messaging/OutputPrivateMessage.kt
View file @
159fd34c
@
file
:
Suppress
(
"MemberVisibilityCanBePrivate"
,
"unused"
)
package
org.briarproject.briar.headless.messaging
package
org.briarproject.briar.headless.messaging
import
org.briarproject.bramble.api.contact.ContactId
import
org.briarproject.bramble.api.contact.ContactId
...
@@ -6,8 +8,8 @@ import org.briarproject.briar.api.messaging.PrivateMessageHeader
...
@@ -6,8 +8,8 @@ import org.briarproject.briar.api.messaging.PrivateMessageHeader
import
javax.annotation.concurrent.Immutable
import
javax.annotation.concurrent.Immutable
@Immutable
@Immutable
internal
data
class
OutputPrivateMessage
(
internal
open
class
OutputPrivateMessage
(
val
body
:
String
,
val
body
:
String
?
,
val
timestamp
:
Long
,
val
timestamp
:
Long
,
val
read
:
Boolean
,
val
read
:
Boolean
,
val
seen
:
Boolean
,
val
seen
:
Boolean
,
...
@@ -17,7 +19,13 @@ internal data class OutputPrivateMessage(
...
@@ -17,7 +19,13 @@ internal data class OutputPrivateMessage(
val
groupId
:
ByteArray
,
val
groupId
:
ByteArray
,
val
contactId
:
Int
val
contactId
:
Int
)
{
)
{
internal
constructor
(
header
:
PrivateMessageHeader
,
contactId
:
ContactId
,
body
:
String
)
:
this
(
open
val
type
=
"org.briarproject.briar.api.messaging.PrivateMessageHeader"
internal
constructor
(
header
:
PrivateMessageHeader
,
contactId
:
ContactId
,
body
:
String
?
)
:
this
(
body
=
body
,
body
=
body
,
timestamp
=
header
.
timestamp
,
timestamp
=
header
.
timestamp
,
read
=
header
.
isRead
,
read
=
header
.
isRead
,
...
...
briar-headless/src/main/java/org/briarproject/briar/headless/messaging/OutputPrivateRequest.kt
0 → 100644
View file @
159fd34c
@
file
:
Suppress
(
"MemberVisibilityCanBePrivate"
,
"unused"
)
package
org.briarproject.briar.headless.messaging
import
org.briarproject.bramble.api.contact.ContactId
import
org.briarproject.briar.api.blog.BlogInvitationRequest
import
org.briarproject.briar.api.forum.ForumInvitationRequest
import
org.briarproject.briar.api.introduction.IntroductionRequest
import
org.briarproject.briar.api.messaging.PrivateRequest
import
org.briarproject.briar.api.privategroup.invitation.GroupInvitationRequest
import
org.briarproject.briar.api.sharing.InvitationRequest
import
javax.annotation.concurrent.Immutable
@Immutable
internal
abstract
class
OutputPrivateRequest
(
header
:
PrivateRequest
<
*
>,
contactId
:
ContactId
)
:
OutputPrivateMessage
(
header
,
contactId
,
header
.
message
)
{
val
sessionId
:
ByteArray
=
header
.
sessionId
.
bytes
val
name
:
String
=
header
.
name
val
answered
=
header
.
wasAnswered
()
}
@Immutable
internal
class
OutputIntroductionRequest
(
header
:
IntroductionRequest
,
contactId
:
ContactId
)
:
OutputPrivateRequest
(
header
,
contactId
)
{
override
val
type
=
"org.briarproject.briar.api.introduction.IntroductionRequest"
val
alreadyContact
=
header
.
isContact
}
@Immutable
internal
class
OutputInvitationRequest
(
header
:
InvitationRequest
<
*
>,
contactId
:
ContactId
)
:
OutputPrivateRequest
(
header
,
contactId
)
{
override
val
type
=
when
(
header
)
{
is
ForumInvitationRequest
->
"org.briarproject.briar.api.forum.ForumInvitationRequest"
is
BlogInvitationRequest
->
"org.briarproject.briar.api.blog.BlogInvitationRequest"
is
GroupInvitationRequest
->
"org.briarproject.briar.api.privategroup.invitation.GroupInvitationRequest"
else
->
throw
AssertionError
(
"Unknown InvitationRequest"
)
}
val
canBeOpened
=
header
.
canBeOpened
()
}
briar-headless/src/main/java/org/briarproject/briar/headless/messaging/OutputPrivateResponse.kt
0 → 100644
View file @
159fd34c
@
file
:
Suppress
(
"MemberVisibilityCanBePrivate"
,
"unused"
)
package
org.briarproject.briar.headless.messaging
import
org.briarproject.bramble.api.contact.ContactId
import
org.briarproject.briar.api.blog.BlogInvitationResponse
import
org.briarproject.briar.api.forum.ForumInvitationResponse
import
org.briarproject.briar.api.introduction.IntroductionResponse
import
org.briarproject.briar.api.messaging.PrivateResponse
import
org.briarproject.briar.api.privategroup.invitation.GroupInvitationResponse
import
org.briarproject.briar.api.sharing.InvitationResponse
import
org.briarproject.briar.headless.output
import
javax.annotation.concurrent.Immutable
@Immutable
internal
abstract
class
OutputPrivateResponse
(
header
:
PrivateResponse
,
contactId
:
ContactId
)
:
OutputPrivateMessage
(
header
,
contactId
,
null
)
{
val
sessionId
:
ByteArray
=
header
.
sessionId
.
bytes
val
accepted
=
header
.
wasAccepted
()
}
@Immutable
internal
class
OutputIntroductionResponse
(
header
:
IntroductionResponse
,
contactId
:
ContactId
)
:
OutputPrivateResponse
(
header
,
contactId
)
{
override
val
type
=
"org.briarproject.briar.api.introduction.IntroductionResponse"
val
introducedAuthor
=
header
.
introducedAuthor
.
output
()
val
introducer
=
header
.
isIntroducer
}
@Immutable
internal
class
OutputInvitationResponse
(
header
:
InvitationResponse
,
contactId
:
ContactId
)
:
OutputPrivateResponse
(
header
,
contactId
)
{
override
val
type
=
when
(
header
)
{
is
ForumInvitationResponse
->
"org.briarproject.briar.api.forum.ForumInvitationResponse"
is
BlogInvitationResponse
->
"org.briarproject.briar.api.blog.BlogInvitationResponse"
is
GroupInvitationResponse
->
"org.briarproject.briar.api.privategroup.invitation.GroupInvitationResponse"
else
->
throw
AssertionError
(
"Unknown InvitationResponse"
)
}
val
shareableId
:
ByteArray
=
header
.
shareableId
.
bytes
}
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