@ -1,19 +1,23 @@
package org.session.libsession.messaging.utilities
import android.content.Context
import android.text.SpannableString
import org.session.libsession.R
import org.session.libsession.messaging.MessagingConfiguration
import org.session.libsession.messaging.messages.control.ExpirationTimerUpdate
import org.session.libsession.utilities.ExpirationUtil
import org.session.libsignal.service.api.messages.SignalServiceGroup
import org.session.libsignal.service.internal.push.SignalServiceProtos
object UpdateMessageBuilder {
fun buildGroupUpdateMessage ( context : Context , groupInfo : SignalServiceGroup , sender : String , isOutgoing : Boolean = false ) : String {
fun buildGroupUpdateMessage ( context : Context , groupInfo : SignalServiceGroup , sender : String ? = null , isOutgoing : Boolean = false ) : String {
val updateType = groupInfo . type
val senderName : String = if ( !is Outgoing ) {
MessagingConfiguration . shared . storage . getDisplayNameForRecipient ( sender ) ?: sender
} else { sender }
var message : String = " "
if ( !is Outgoing && sender == null ) return message
val senderName : String ? = if ( !is Outgoing ) {
MessagingConfiguration . shared . storage . getDisplayNameForRecipient ( sender !! ) ?: sender
} else { sender }
when ( updateType ) {
SignalServiceGroup . Type . NEW _GROUP -> {
message = if ( isOutgoing ) {
@ -40,13 +44,25 @@ object UpdateMessageBuilder {
}
}
SignalServiceGroup . Type . MEMBER _REMOVED -> {
val members = groupInfo . members . get ( ) . joinToString ( " , " ) {
MessagingConfiguration . shared . storage . getDisplayNameForRecipient ( it ) ?: it
}
message = if ( isOutgoing ) {
context . getString ( R . string . MessageRecord _you _removed _s _from _the _group , members )
val storage = MessagingConfiguration . shared . storage
val userPublicKey = storage . getUserPublicKey ( ) !!
// 1st case: you are part of the removed members
message = if ( userPublicKey in groupInfo . members . get ( ) ) {
if ( isOutgoing ) {
context . getString ( R . string . MessageRecord _left _group )
} else {
context . getString ( R . string . MessageRecord _you _were _removed _from _the _group )
}
} else {
context . getString ( R . string . MessageRecord _s _removed _s _from _the _group , senderName , members )
// 2nd case: you are not part of the removed members
val members = groupInfo . members . get ( ) . joinToString ( " , " ) {
storage . getDisplayNameForRecipient ( it ) ?: it
}
if ( isOutgoing ) {
context . getString ( R . string . MessageRecord _you _removed _s _from _the _group , members )
} else {
context . getString ( R . string . MessageRecord _s _removed _s _from _the _group , senderName , members )
}
}
}
SignalServiceGroup . Type . QUIT -> {
@ -63,8 +79,20 @@ object UpdateMessageBuilder {
return message
}
fun buildExpirationTimerMessage ( ) : String {
return " "
fun buildExpirationTimerMessage ( context : Context , duration : Int , sender : String ? = null , isOutgoing : Boolean = false ) : String {
val seconds = ( duration !! / 1000 )
if ( !is Outgoing && sender == null ) return " "
val senderName : String ? = if ( !is Outgoing ) {
MessagingConfiguration . shared . storage . getDisplayNameForRecipient ( sender !! ) ?: sender
} else { sender }
return if ( seconds <= 0 ) {
if ( isOutgoing ) context . getString ( R . string . MessageRecord _you _disabled _disappearing _messages )
else context . getString ( R . string . MessageRecord _s _disabled _disappearing _messages , senderName )
} else {
val time = ExpirationUtil . getExpirationDisplayValue ( context , seconds )
if ( isOutgoing ) context . getString ( R . string . MessageRecord _you _set _disappearing _message _time _to _s , time )
else context . getString ( R . string . MessageRecord _s _set _disappearing _message _time _to _s , senderName , time )
}
}
fun buildDataExtractionMessage ( ) : String {