@ -103,7 +103,8 @@ class LokiPublicChatPoller(private val context: Context, private val group: Loki
} else {
} else {
null
null
}
}
val attachments = message . attachments . map { attachment ->
val attachments = message . attachments . mapNotNull { attachment ->
if ( attachment . kind != LokiPublicChatMessage . Attachment . Kind . Attachment ) { return @mapNotNull null }
SignalServiceAttachmentPointer (
SignalServiceAttachmentPointer (
attachment . serverID ,
attachment . serverID ,
attachment . contentType ,
attachment . contentType ,
@ -117,8 +118,25 @@ class LokiPublicChatPoller(private val context: Context, private val group: Loki
Optional . fromNullable ( attachment . caption ) ,
Optional . fromNullable ( attachment . caption ) ,
attachment . url )
attachment . url )
}
}
val linkPreview = message . attachments . firstOrNull { it . kind == LokiPublicChatMessage . Attachment . Kind . LinkPreview }
val signalLinkPreviews = mutableListOf < SignalServiceDataMessage . Preview > ( )
if ( linkPreview != null ) {
val attachment = SignalServiceAttachmentPointer (
linkPreview . serverID ,
linkPreview . contentType ,
ByteArray ( 0 ) ,
Optional . of ( linkPreview . size ) ,
Optional . absent ( ) ,
linkPreview . width , linkPreview . height ,
Optional . absent ( ) ,
Optional . of ( linkPreview . fileName ) ,
false ,
Optional . fromNullable ( linkPreview . caption ) ,
linkPreview . url )
signalLinkPreviews . add ( SignalServiceDataMessage . Preview ( linkPreview . linkPreviewURL !! , linkPreview . linkPreviewTitle !! , Optional . of ( attachment ) ) )
}
val body = if ( message . body == message . timestamp . toString ( ) ) " " else message . body // Workaround for the fact that the back-end doesn't accept messages without a body
val body = if ( message . body == message . timestamp . toString ( ) ) " " else message . body // Workaround for the fact that the back-end doesn't accept messages without a body
val serviceDataMessage = SignalServiceDataMessage ( message . timestamp , serviceGroup , attachments , body , false , 0 , false , null , false , quote , null , null , null )
val serviceDataMessage = SignalServiceDataMessage ( message . timestamp , serviceGroup , attachments , body , false , 0 , false , null , false , quote , null , signalLinkPreviews , null )
val serviceContent = SignalServiceContent ( serviceDataMessage , message . hexEncodedPublicKey , SignalServiceAddress . DEFAULT _DEVICE _ID , message . timestamp , false )
val serviceContent = SignalServiceContent ( serviceDataMessage , message . hexEncodedPublicKey , SignalServiceAddress . DEFAULT _DEVICE _ID , message . timestamp , false )
val senderDisplayName = " ${message.displayName} (... ${message.hexEncodedPublicKey.takeLast(8)} ) "
val senderDisplayName = " ${message.displayName} (... ${message.hexEncodedPublicKey.takeLast(8)} ) "
DatabaseFactory . getLokiUserDatabase ( context ) . setServerDisplayName ( group . id , message . hexEncodedPublicKey , senderDisplayName )
DatabaseFactory . getLokiUserDatabase ( context ) . setServerDisplayName ( group . id , message . hexEncodedPublicKey , senderDisplayName )