2020-12-07 05:22:02 +01:00
|
|
|
package org.session.libsession.messaging.sending_receiving
|
|
|
|
|
2021-01-11 23:58:38 +01:00
|
|
|
import android.text.TextUtils
|
2022-03-14 23:24:15 +01:00
|
|
|
import org.session.libsession.avatars.AvatarHelper
|
2021-04-26 03:14:45 +02:00
|
|
|
import org.session.libsession.messaging.MessagingModuleConfiguration
|
Performance improvements and bug fixes (#869)
* refactor: fail on testSnode instead of recursively using up snode list. add call timeout on http client
* refactor: refactoring batch message receives and pollers
* refactor: reduce thread utils pool count to a 2 thread fixed pool. Do a check against pubkey instead of room names for oxenHostedOpenGroup
* refactor: caching lib with potential loader fixes and no-cache for giphy
* refactor: remove store and instead use ConcurrentHashMap with a backing update coroutine
* refactor: queue trim thread jobs instead of add every message processed
* fix: wrapping auth token and initial sync for open groups in a threadutils queued runnable, getting initial sync times down
* fix: fixing the user contacts cache in ConversationAdapter.kt
* refactor: improve polling and initial sync, move group joins from config messages into a background job fetching image.
* refactor: improving the job queuing for open groups, replacing placeholder avatar generation with a custom glide loader and archiving initial sync of open groups
* feat: add OpenGroupDeleteJob.kt
* feat: add open group delete job to process deletions after batch adding
* feat: add vacuum and fix job queue re-adding jobs forever, only try to set message hash values in DB if they have changed
* refactor: remove redundant inflation for profile image views throughout app
* refactor(wip): reducing layout inflation and starting to refactor the open group deletion issues taking a long time
* refactor(wip): refactoring group deletion to not iterate through and delete messages individually
* refactor(wip): refactoring group deletion to not iterate through and delete messages individually
* fix: group deletion optimisation
* build: bump build number
* build: bump build number and fix batch message receive retry logic
* fix: clear out open group deletes
* fix: update visible ConversationAdapter.kt binding for initial contact fetching and better traces for debugging background jobs
* fix: add in check for / force sync latest encryption key pair from linked devices if we already have that closed group
* Rename .java to .kt
* refactor: change MmsDatabase to kotlin to make list operations easier
* fix: nullable type
* fix: compilation issues and constants in .kt instead of .java
* fix: bug fix expiration timer on closed group recipient
* feat: use the job queue properly across executors
* feat: start on open group dispatcher-specific logic, probably a queue factory based on openGroupId if that is the same across new message and deletion jobs to ensure consistent entry and removal
* refactor: removing redundant code and fixing jobqueue per opengroup
* fix: allow attachments in note to self
* fix: make the minWidth in quote view bind max of text / title and body, wrapped ?
* fix: fixing up layouts and code view layouts
* fix: remove TODO, remove timestamp binding
* feat: fix view logic, avatars and padding, downloading attachments lazily (on bind), fixing potential crash, add WindowDebouncer.kt
* fix: NPE on viewModel recipient from removed thread while tearing down the Recipient observer in ConversationActivityV2.kt
* refactor: replace conversation notification debouncer handler with handlerthread, same as conversation list debouncer
* refactor: UI for groups and poller improvements
* fix: revert some changes in poller
* feat: add header back in for message requests
* refactor: remove Trace calls, add more conditions to the HomeDiffUtil for updating more efficiently
* feat: try update the home adapter if we get a profile picture modified event
* feat: bump build numbers
* fix: try to start with list in homeViewModel if we don't have already, render quotes to be width of attachment slide view instead of fixed
* fix: set channel to be conflated instead of no buffer
* fix: set unreads based off last local user message vs incrementing unreads to be all amount
* feat: add profile update flag, update build number
* fix: link preview thumbnails download on bind
* fix: centercrop placeholder in glide request
* feat: recycle the contact selection list and profile image in unbind
* fix: try to prevent user KP crash at weird times
* fix: remove additional log, improve attachment download success rate, fix share logs dialog issue
2022-06-08 09:12:34 +02:00
|
|
|
import org.session.libsession.messaging.jobs.BackgroundGroupAddJob
|
2021-01-08 01:13:05 +01:00
|
|
|
import org.session.libsession.messaging.jobs.JobQueue
|
2020-12-07 05:22:02 +01:00
|
|
|
import org.session.libsession.messaging.messages.Message
|
Add one on one calls over clearnet (#864)
* feat: adding basic webrtc deps and test activity
* more testing code
* feat: add protos and bump version
* feat: added basic call functionality
* feat: adding UI and flipping cameras
* feat: add stats and starting call bottom sheet
* feat: hanging up and bottom sheet behaviors should work now
* feat: add call stats report on frontend
* feat: add relay toggle for answer and offer
* fix: add keep screen on and more end call message on back pressed / on finish
* refactor: removing and replacing dagger 1 dep with android hilt
* feat: include latest proto
* feat: update to utilise call ID
* feat: add stun and turn
* refactor: playing around with deps and transport types
* feat: adding call service functionality and permissions for calls
* feat: add call manager and more static intent building functions for WebRtcCallService.kt
* feat: adding ringers and more audio boilerplate
* feat: audio manager call service boilerplate
* feat: update kotlin and add in call view model and more management functions
* refactor: moving call code around to service and viewmodel interactions
* feat: plugging CallManager.kt into view model and service, fixing up dependencies
* feat: implementing more WebRtcCallService.kt functions and handlers for actions as well as lifecycle
* feat: adding more lifecycle vm and callmanager / call service functionality
* feat: adding more command handlers in WebRtcCallService.kt
* feat: more commands handled, adding lock manager and bluetooth permissions
* feat: adding remainder of basic functionality to services and CallManager.kt
* feat: hooking up calls and fixing broken dependencies and compile errors
* fix: add timestamp to incoming call
* feat: some connection and service launching / ring lifecycle
* feat: call establishing and displaying
* fix: fixing call connect flows
* feat: ringers and better state handling
* feat: updating call layout
* feat: add fixes to bluetooth and begin the network renegotiation
* feat: add call related permissions and more network handover tests
* fix: don't display call option in conversation and don't show notification if option not enabled
* fix: incoming ringer fix on receiving call, call notification priorities and notification channel update
* build: update build number for testing
* fix: bluetooth auto-connection and re-connection fixes, removing finished todos, allowing self-send call messages for deduping answers
* feat: add pre-offer information and action handling in web rtc call service
* refactor: discard offer messages from non-matching pre-offers we are already expecting
* build: build numbers and version name update
* feat: handle discarding pending calls from linked devices
* feat: add signing props to release config build
* docs: fix comment on time being 300s (5m) instead of 30s
* feat: adding call messages for incoming/outgoing/missed
* refactor: handle in-thread call notifications better and replace deny button intent with denyCallIntent instead of hangup
* feat: add a hangup via data channel message
* feat: process microphone enabled events and remove debuggable from build.gradle
* feat: add first call notification
* refactor: set the buttons to match iOS in terms of enable disable and colours
* refactor: change the call logos in control messages
* refactor: more bluetooth improvements
* refactor: move start ringer and init of audio manager to CallManager.kt and string fix up
* build: remove debuggable for release build
* refactor: replace call icons
* feat: adding a call time display
* refactor: change the call time to update every second
* refactor: testing out the full screen intents
* refactor: wrapper use corrected session description, set title to recipient displayName, indicate session calls
* fix: crash on view with a parent already attached
* refactor: aspect ratio fit preserved
* refactor: add wantsToAnswer ability in pre-init for fullscreenintent
* refactor: prevent calls from non hasSent participants
* build: update gradle code
* refactor: replace timeout schedule with a seconds count
* fix: various bug fixes for calls
* fix: remove end call from busy
* refactor: use answerCall instead of manual intent building again
* build: new version
* feat: add silenced notifications for call notification builder. check pre-offer and connecting state for pending connection
* build: update build number
* fix: text color uses overridden style value
* fix: remove wrap content for renderers and look more at recovering from network switches
* build: update build number
* refactor: remove whitespace
* build: update build number
* refactor: used shared number for BatchMessageReceiveJob.kt parameter across pollers
* fix: glide in update crash
* fix: bug fixes for self-send answer / hangup messages
* build: update build number
* build: update build.gradle number
* refactor: compile errors and refactoring to view binding
* fix: set the content to binding.root view
* build: increase build number
* build: update build numbers
* feat: adding base for rotation and picking random subset of turn servers
* feat: starting the screen rotation processing
* feat: setting up rotation for the remote render view
* refactor: applying rotation and mirroring based on front / rear cameras that wraps nicely, only scale reworking needed
* refactor: calls video stretching but consistent
* refactor: state machine and tests for the transition events
* feat: new call state processing
* refactor: adding reconnecting logic and visuals
* feat: state machine reconnect logic wip
* feat: add reconnecting and merge fixes
* feat: check new session based off current state
* feat: reconnection logic works correctly now
* refactor: reduce TIMEOUT_SECONDS to 30 from 90
* feat: reset peer connection on DC to prevent ICE messages from old connection or stale state in reconnecting
* refactor: add null case
* fix: set approved on new outgoing threads, use approved more deeply and invalidate the options menu on recipient modified. Add approvedMe flag toggles for visible message receive
* fix: add name update in action bar on modified, change where approvedMe is set
* build: increment build number
* build: update build number
* fix: merge compile errors and increment build number
* refactor: remove negotiation based on which party dropped connection
* refactor: call reconnection improvement tested cross platform to re-establish
* refactor: failed and disconnect events only handled if either the reconnect or the timeout runnables are not set
* build: update version number
* fix: reduce timeout
* fix: fixes the incoming hangup logic for linked devices
* refactor: match iOS styling for call activity closer
* chore: upgrade build numbers
* feat: add in call settings dialog for if calls is disabled in conversation
* feat: add a first call missed control message and info popup with link to privacy settings
* fix: looking at crash for specific large transaction in NotificationManager
* refactor: removing the people in case transaction size reduces to fix notif crash
* fix: comment out the entire send multiple to see if it fixes the issue
* refactor: revert to including the full notification process in a try/catch to handle weird responses from NotificationManager
* fix: add in notification settings prompt for calls and try to fall back to dirty full screen intent / start activity if we're allowed
* build: upgrade build number
2022-04-19 06:25:40 +02:00
|
|
|
import org.session.libsession.messaging.messages.control.CallMessage
|
2022-03-04 07:46:39 +01:00
|
|
|
import org.session.libsession.messaging.messages.control.ClosedGroupControlMessage
|
|
|
|
import org.session.libsession.messaging.messages.control.ConfigurationMessage
|
|
|
|
import org.session.libsession.messaging.messages.control.DataExtractionNotification
|
|
|
|
import org.session.libsession.messaging.messages.control.ExpirationTimerUpdate
|
|
|
|
import org.session.libsession.messaging.messages.control.MessageRequestResponse
|
|
|
|
import org.session.libsession.messaging.messages.control.ReadReceipt
|
|
|
|
import org.session.libsession.messaging.messages.control.TypingIndicator
|
|
|
|
import org.session.libsession.messaging.messages.control.UnsendRequest
|
2020-12-18 06:48:45 +01:00
|
|
|
import org.session.libsession.messaging.messages.visible.Attachment
|
2020-12-07 05:22:02 +01:00
|
|
|
import org.session.libsession.messaging.messages.visible.VisibleMessage
|
2021-01-11 23:58:38 +01:00
|
|
|
import org.session.libsession.messaging.sending_receiving.attachments.PointerAttachment
|
2021-04-26 03:23:09 +02:00
|
|
|
import org.session.libsession.messaging.sending_receiving.data_extraction.DataExtractionNotificationInfoMessage
|
|
|
|
import org.session.libsession.messaging.sending_receiving.link_preview.LinkPreview
|
2020-12-07 05:22:02 +01:00
|
|
|
import org.session.libsession.messaging.sending_receiving.notifications.PushNotificationAPI
|
2021-05-21 05:12:34 +02:00
|
|
|
import org.session.libsession.messaging.sending_receiving.pollers.ClosedGroupPollerV2
|
2021-01-11 23:58:38 +01:00
|
|
|
import org.session.libsession.messaging.sending_receiving.quotes.QuoteModel
|
Add one on one calls over clearnet (#864)
* feat: adding basic webrtc deps and test activity
* more testing code
* feat: add protos and bump version
* feat: added basic call functionality
* feat: adding UI and flipping cameras
* feat: add stats and starting call bottom sheet
* feat: hanging up and bottom sheet behaviors should work now
* feat: add call stats report on frontend
* feat: add relay toggle for answer and offer
* fix: add keep screen on and more end call message on back pressed / on finish
* refactor: removing and replacing dagger 1 dep with android hilt
* feat: include latest proto
* feat: update to utilise call ID
* feat: add stun and turn
* refactor: playing around with deps and transport types
* feat: adding call service functionality and permissions for calls
* feat: add call manager and more static intent building functions for WebRtcCallService.kt
* feat: adding ringers and more audio boilerplate
* feat: audio manager call service boilerplate
* feat: update kotlin and add in call view model and more management functions
* refactor: moving call code around to service and viewmodel interactions
* feat: plugging CallManager.kt into view model and service, fixing up dependencies
* feat: implementing more WebRtcCallService.kt functions and handlers for actions as well as lifecycle
* feat: adding more lifecycle vm and callmanager / call service functionality
* feat: adding more command handlers in WebRtcCallService.kt
* feat: more commands handled, adding lock manager and bluetooth permissions
* feat: adding remainder of basic functionality to services and CallManager.kt
* feat: hooking up calls and fixing broken dependencies and compile errors
* fix: add timestamp to incoming call
* feat: some connection and service launching / ring lifecycle
* feat: call establishing and displaying
* fix: fixing call connect flows
* feat: ringers and better state handling
* feat: updating call layout
* feat: add fixes to bluetooth and begin the network renegotiation
* feat: add call related permissions and more network handover tests
* fix: don't display call option in conversation and don't show notification if option not enabled
* fix: incoming ringer fix on receiving call, call notification priorities and notification channel update
* build: update build number for testing
* fix: bluetooth auto-connection and re-connection fixes, removing finished todos, allowing self-send call messages for deduping answers
* feat: add pre-offer information and action handling in web rtc call service
* refactor: discard offer messages from non-matching pre-offers we are already expecting
* build: build numbers and version name update
* feat: handle discarding pending calls from linked devices
* feat: add signing props to release config build
* docs: fix comment on time being 300s (5m) instead of 30s
* feat: adding call messages for incoming/outgoing/missed
* refactor: handle in-thread call notifications better and replace deny button intent with denyCallIntent instead of hangup
* feat: add a hangup via data channel message
* feat: process microphone enabled events and remove debuggable from build.gradle
* feat: add first call notification
* refactor: set the buttons to match iOS in terms of enable disable and colours
* refactor: change the call logos in control messages
* refactor: more bluetooth improvements
* refactor: move start ringer and init of audio manager to CallManager.kt and string fix up
* build: remove debuggable for release build
* refactor: replace call icons
* feat: adding a call time display
* refactor: change the call time to update every second
* refactor: testing out the full screen intents
* refactor: wrapper use corrected session description, set title to recipient displayName, indicate session calls
* fix: crash on view with a parent already attached
* refactor: aspect ratio fit preserved
* refactor: add wantsToAnswer ability in pre-init for fullscreenintent
* refactor: prevent calls from non hasSent participants
* build: update gradle code
* refactor: replace timeout schedule with a seconds count
* fix: various bug fixes for calls
* fix: remove end call from busy
* refactor: use answerCall instead of manual intent building again
* build: new version
* feat: add silenced notifications for call notification builder. check pre-offer and connecting state for pending connection
* build: update build number
* fix: text color uses overridden style value
* fix: remove wrap content for renderers and look more at recovering from network switches
* build: update build number
* refactor: remove whitespace
* build: update build number
* refactor: used shared number for BatchMessageReceiveJob.kt parameter across pollers
* fix: glide in update crash
* fix: bug fixes for self-send answer / hangup messages
* build: update build number
* build: update build.gradle number
* refactor: compile errors and refactoring to view binding
* fix: set the content to binding.root view
* build: increase build number
* build: update build numbers
* feat: adding base for rotation and picking random subset of turn servers
* feat: starting the screen rotation processing
* feat: setting up rotation for the remote render view
* refactor: applying rotation and mirroring based on front / rear cameras that wraps nicely, only scale reworking needed
* refactor: calls video stretching but consistent
* refactor: state machine and tests for the transition events
* feat: new call state processing
* refactor: adding reconnecting logic and visuals
* feat: state machine reconnect logic wip
* feat: add reconnecting and merge fixes
* feat: check new session based off current state
* feat: reconnection logic works correctly now
* refactor: reduce TIMEOUT_SECONDS to 30 from 90
* feat: reset peer connection on DC to prevent ICE messages from old connection or stale state in reconnecting
* refactor: add null case
* fix: set approved on new outgoing threads, use approved more deeply and invalidate the options menu on recipient modified. Add approvedMe flag toggles for visible message receive
* fix: add name update in action bar on modified, change where approvedMe is set
* build: increment build number
* build: update build number
* fix: merge compile errors and increment build number
* refactor: remove negotiation based on which party dropped connection
* refactor: call reconnection improvement tested cross platform to re-establish
* refactor: failed and disconnect events only handled if either the reconnect or the timeout runnables are not set
* build: update version number
* fix: reduce timeout
* fix: fixes the incoming hangup logic for linked devices
* refactor: match iOS styling for call activity closer
* chore: upgrade build numbers
* feat: add in call settings dialog for if calls is disabled in conversation
* feat: add a first call missed control message and info popup with link to privacy settings
* fix: looking at crash for specific large transaction in NotificationManager
* refactor: removing the people in case transaction size reduces to fix notif crash
* fix: comment out the entire send multiple to see if it fixes the issue
* refactor: revert to including the full notification process in a try/catch to handle weird responses from NotificationManager
* fix: add in notification settings prompt for calls and try to fall back to dirty full screen intent / start activity if we're allowed
* build: upgrade build number
2022-04-19 06:25:40 +02:00
|
|
|
import org.session.libsession.messaging.utilities.WebRtcUtils
|
2021-08-10 08:00:06 +02:00
|
|
|
import org.session.libsession.snode.SnodeAPI
|
2022-03-04 07:46:39 +01:00
|
|
|
import org.session.libsession.utilities.Address
|
|
|
|
import org.session.libsession.utilities.GroupRecord
|
|
|
|
import org.session.libsession.utilities.GroupUtil
|
|
|
|
import org.session.libsession.utilities.ProfileKeyUtil
|
|
|
|
import org.session.libsession.utilities.SSKEnvironment
|
|
|
|
import org.session.libsession.utilities.TextSecurePreferences
|
2021-05-18 08:03:47 +02:00
|
|
|
import org.session.libsession.utilities.recipients.Recipient
|
2021-05-18 01:21:56 +02:00
|
|
|
import org.session.libsignal.crypto.ecc.DjbECPrivateKey
|
|
|
|
import org.session.libsignal.crypto.ecc.DjbECPublicKey
|
|
|
|
import org.session.libsignal.crypto.ecc.ECKeyPair
|
2021-05-18 01:50:16 +02:00
|
|
|
import org.session.libsignal.messages.SignalServiceGroup
|
2021-05-18 01:44:06 +02:00
|
|
|
import org.session.libsignal.protos.SignalServiceProtos
|
2021-03-30 07:23:12 +02:00
|
|
|
import org.session.libsignal.utilities.Base64
|
2021-05-18 01:12:33 +02:00
|
|
|
import org.session.libsignal.utilities.Log
|
2021-09-15 08:08:40 +02:00
|
|
|
import org.session.libsignal.utilities.guava.Optional
|
|
|
|
import org.session.libsignal.utilities.removing05PrefixIfNeeded
|
|
|
|
import org.session.libsignal.utilities.toHexString
|
2021-01-08 01:13:05 +01:00
|
|
|
import java.security.MessageDigest
|
2022-03-04 07:46:39 +01:00
|
|
|
import java.util.LinkedList
|
2020-12-07 05:22:02 +01:00
|
|
|
|
2021-05-13 07:27:08 +02:00
|
|
|
internal fun MessageReceiver.isBlocked(publicKey: String): Boolean {
|
2021-04-26 03:14:45 +02:00
|
|
|
val context = MessagingModuleConfiguration.shared.context
|
2021-01-13 07:11:30 +01:00
|
|
|
val recipient = Recipient.from(context, Address.fromSerialized(publicKey), false)
|
|
|
|
return recipient.isBlocked
|
2020-12-07 05:22:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fun MessageReceiver.handle(message: Message, proto: SignalServiceProtos.Content, openGroupID: String?) {
|
|
|
|
when (message) {
|
|
|
|
is ReadReceipt -> handleReadReceipt(message)
|
|
|
|
is TypingIndicator -> handleTypingIndicator(message)
|
2021-02-09 01:45:38 +01:00
|
|
|
is ClosedGroupControlMessage -> handleClosedGroupControlMessage(message)
|
2021-03-25 04:55:23 +01:00
|
|
|
is ExpirationTimerUpdate -> handleExpirationTimerUpdate(message)
|
2021-03-16 04:56:47 +01:00
|
|
|
is DataExtractionNotification -> handleDataExtractionNotification(message)
|
2021-02-09 01:45:38 +01:00
|
|
|
is ConfigurationMessage -> handleConfigurationMessage(message)
|
2021-08-10 08:00:06 +02:00
|
|
|
is UnsendRequest -> handleUnsendRequest(message)
|
2022-03-04 07:46:39 +01:00
|
|
|
is MessageRequestResponse -> handleMessageRequestResponse(message)
|
Performance improvements and bug fixes (#869)
* refactor: fail on testSnode instead of recursively using up snode list. add call timeout on http client
* refactor: refactoring batch message receives and pollers
* refactor: reduce thread utils pool count to a 2 thread fixed pool. Do a check against pubkey instead of room names for oxenHostedOpenGroup
* refactor: caching lib with potential loader fixes and no-cache for giphy
* refactor: remove store and instead use ConcurrentHashMap with a backing update coroutine
* refactor: queue trim thread jobs instead of add every message processed
* fix: wrapping auth token and initial sync for open groups in a threadutils queued runnable, getting initial sync times down
* fix: fixing the user contacts cache in ConversationAdapter.kt
* refactor: improve polling and initial sync, move group joins from config messages into a background job fetching image.
* refactor: improving the job queuing for open groups, replacing placeholder avatar generation with a custom glide loader and archiving initial sync of open groups
* feat: add OpenGroupDeleteJob.kt
* feat: add open group delete job to process deletions after batch adding
* feat: add vacuum and fix job queue re-adding jobs forever, only try to set message hash values in DB if they have changed
* refactor: remove redundant inflation for profile image views throughout app
* refactor(wip): reducing layout inflation and starting to refactor the open group deletion issues taking a long time
* refactor(wip): refactoring group deletion to not iterate through and delete messages individually
* refactor(wip): refactoring group deletion to not iterate through and delete messages individually
* fix: group deletion optimisation
* build: bump build number
* build: bump build number and fix batch message receive retry logic
* fix: clear out open group deletes
* fix: update visible ConversationAdapter.kt binding for initial contact fetching and better traces for debugging background jobs
* fix: add in check for / force sync latest encryption key pair from linked devices if we already have that closed group
* Rename .java to .kt
* refactor: change MmsDatabase to kotlin to make list operations easier
* fix: nullable type
* fix: compilation issues and constants in .kt instead of .java
* fix: bug fix expiration timer on closed group recipient
* feat: use the job queue properly across executors
* feat: start on open group dispatcher-specific logic, probably a queue factory based on openGroupId if that is the same across new message and deletion jobs to ensure consistent entry and removal
* refactor: removing redundant code and fixing jobqueue per opengroup
* fix: allow attachments in note to self
* fix: make the minWidth in quote view bind max of text / title and body, wrapped ?
* fix: fixing up layouts and code view layouts
* fix: remove TODO, remove timestamp binding
* feat: fix view logic, avatars and padding, downloading attachments lazily (on bind), fixing potential crash, add WindowDebouncer.kt
* fix: NPE on viewModel recipient from removed thread while tearing down the Recipient observer in ConversationActivityV2.kt
* refactor: replace conversation notification debouncer handler with handlerthread, same as conversation list debouncer
* refactor: UI for groups and poller improvements
* fix: revert some changes in poller
* feat: add header back in for message requests
* refactor: remove Trace calls, add more conditions to the HomeDiffUtil for updating more efficiently
* feat: try update the home adapter if we get a profile picture modified event
* feat: bump build numbers
* fix: try to start with list in homeViewModel if we don't have already, render quotes to be width of attachment slide view instead of fixed
* fix: set channel to be conflated instead of no buffer
* fix: set unreads based off last local user message vs incrementing unreads to be all amount
* feat: add profile update flag, update build number
* fix: link preview thumbnails download on bind
* fix: centercrop placeholder in glide request
* feat: recycle the contact selection list and profile image in unbind
* fix: try to prevent user KP crash at weird times
* fix: remove additional log, improve attachment download success rate, fix share logs dialog issue
2022-06-08 09:12:34 +02:00
|
|
|
is VisibleMessage -> handleVisibleMessage(message, proto, openGroupID,
|
|
|
|
runIncrement = true,
|
|
|
|
runThreadUpdate = true,
|
|
|
|
runProfileUpdate = true
|
|
|
|
)
|
Add one on one calls over clearnet (#864)
* feat: adding basic webrtc deps and test activity
* more testing code
* feat: add protos and bump version
* feat: added basic call functionality
* feat: adding UI and flipping cameras
* feat: add stats and starting call bottom sheet
* feat: hanging up and bottom sheet behaviors should work now
* feat: add call stats report on frontend
* feat: add relay toggle for answer and offer
* fix: add keep screen on and more end call message on back pressed / on finish
* refactor: removing and replacing dagger 1 dep with android hilt
* feat: include latest proto
* feat: update to utilise call ID
* feat: add stun and turn
* refactor: playing around with deps and transport types
* feat: adding call service functionality and permissions for calls
* feat: add call manager and more static intent building functions for WebRtcCallService.kt
* feat: adding ringers and more audio boilerplate
* feat: audio manager call service boilerplate
* feat: update kotlin and add in call view model and more management functions
* refactor: moving call code around to service and viewmodel interactions
* feat: plugging CallManager.kt into view model and service, fixing up dependencies
* feat: implementing more WebRtcCallService.kt functions and handlers for actions as well as lifecycle
* feat: adding more lifecycle vm and callmanager / call service functionality
* feat: adding more command handlers in WebRtcCallService.kt
* feat: more commands handled, adding lock manager and bluetooth permissions
* feat: adding remainder of basic functionality to services and CallManager.kt
* feat: hooking up calls and fixing broken dependencies and compile errors
* fix: add timestamp to incoming call
* feat: some connection and service launching / ring lifecycle
* feat: call establishing and displaying
* fix: fixing call connect flows
* feat: ringers and better state handling
* feat: updating call layout
* feat: add fixes to bluetooth and begin the network renegotiation
* feat: add call related permissions and more network handover tests
* fix: don't display call option in conversation and don't show notification if option not enabled
* fix: incoming ringer fix on receiving call, call notification priorities and notification channel update
* build: update build number for testing
* fix: bluetooth auto-connection and re-connection fixes, removing finished todos, allowing self-send call messages for deduping answers
* feat: add pre-offer information and action handling in web rtc call service
* refactor: discard offer messages from non-matching pre-offers we are already expecting
* build: build numbers and version name update
* feat: handle discarding pending calls from linked devices
* feat: add signing props to release config build
* docs: fix comment on time being 300s (5m) instead of 30s
* feat: adding call messages for incoming/outgoing/missed
* refactor: handle in-thread call notifications better and replace deny button intent with denyCallIntent instead of hangup
* feat: add a hangup via data channel message
* feat: process microphone enabled events and remove debuggable from build.gradle
* feat: add first call notification
* refactor: set the buttons to match iOS in terms of enable disable and colours
* refactor: change the call logos in control messages
* refactor: more bluetooth improvements
* refactor: move start ringer and init of audio manager to CallManager.kt and string fix up
* build: remove debuggable for release build
* refactor: replace call icons
* feat: adding a call time display
* refactor: change the call time to update every second
* refactor: testing out the full screen intents
* refactor: wrapper use corrected session description, set title to recipient displayName, indicate session calls
* fix: crash on view with a parent already attached
* refactor: aspect ratio fit preserved
* refactor: add wantsToAnswer ability in pre-init for fullscreenintent
* refactor: prevent calls from non hasSent participants
* build: update gradle code
* refactor: replace timeout schedule with a seconds count
* fix: various bug fixes for calls
* fix: remove end call from busy
* refactor: use answerCall instead of manual intent building again
* build: new version
* feat: add silenced notifications for call notification builder. check pre-offer and connecting state for pending connection
* build: update build number
* fix: text color uses overridden style value
* fix: remove wrap content for renderers and look more at recovering from network switches
* build: update build number
* refactor: remove whitespace
* build: update build number
* refactor: used shared number for BatchMessageReceiveJob.kt parameter across pollers
* fix: glide in update crash
* fix: bug fixes for self-send answer / hangup messages
* build: update build number
* build: update build.gradle number
* refactor: compile errors and refactoring to view binding
* fix: set the content to binding.root view
* build: increase build number
* build: update build numbers
* feat: adding base for rotation and picking random subset of turn servers
* feat: starting the screen rotation processing
* feat: setting up rotation for the remote render view
* refactor: applying rotation and mirroring based on front / rear cameras that wraps nicely, only scale reworking needed
* refactor: calls video stretching but consistent
* refactor: state machine and tests for the transition events
* feat: new call state processing
* refactor: adding reconnecting logic and visuals
* feat: state machine reconnect logic wip
* feat: add reconnecting and merge fixes
* feat: check new session based off current state
* feat: reconnection logic works correctly now
* refactor: reduce TIMEOUT_SECONDS to 30 from 90
* feat: reset peer connection on DC to prevent ICE messages from old connection or stale state in reconnecting
* refactor: add null case
* fix: set approved on new outgoing threads, use approved more deeply and invalidate the options menu on recipient modified. Add approvedMe flag toggles for visible message receive
* fix: add name update in action bar on modified, change where approvedMe is set
* build: increment build number
* build: update build number
* fix: merge compile errors and increment build number
* refactor: remove negotiation based on which party dropped connection
* refactor: call reconnection improvement tested cross platform to re-establish
* refactor: failed and disconnect events only handled if either the reconnect or the timeout runnables are not set
* build: update version number
* fix: reduce timeout
* fix: fixes the incoming hangup logic for linked devices
* refactor: match iOS styling for call activity closer
* chore: upgrade build numbers
* feat: add in call settings dialog for if calls is disabled in conversation
* feat: add a first call missed control message and info popup with link to privacy settings
* fix: looking at crash for specific large transaction in NotificationManager
* refactor: removing the people in case transaction size reduces to fix notif crash
* fix: comment out the entire send multiple to see if it fixes the issue
* refactor: revert to including the full notification process in a try/catch to handle weird responses from NotificationManager
* fix: add in notification settings prompt for calls and try to fall back to dirty full screen intent / start activity if we're allowed
* build: upgrade build number
2022-04-19 06:25:40 +02:00
|
|
|
is CallMessage -> handleCallMessage(message)
|
2020-12-07 05:22:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-17 07:18:41 +02:00
|
|
|
// region Control Messages
|
2020-12-07 05:22:02 +01:00
|
|
|
private fun MessageReceiver.handleReadReceipt(message: ReadReceipt) {
|
2021-04-26 03:14:45 +02:00
|
|
|
val context = MessagingModuleConfiguration.shared.context
|
2021-03-05 00:17:34 +01:00
|
|
|
SSKEnvironment.shared.readReceiptManager.processReadReceipts(context, message.sender!!, message.timestamps!!, message.receivedTimestamp!!)
|
2020-12-07 05:22:02 +01:00
|
|
|
}
|
|
|
|
|
Add one on one calls over clearnet (#864)
* feat: adding basic webrtc deps and test activity
* more testing code
* feat: add protos and bump version
* feat: added basic call functionality
* feat: adding UI and flipping cameras
* feat: add stats and starting call bottom sheet
* feat: hanging up and bottom sheet behaviors should work now
* feat: add call stats report on frontend
* feat: add relay toggle for answer and offer
* fix: add keep screen on and more end call message on back pressed / on finish
* refactor: removing and replacing dagger 1 dep with android hilt
* feat: include latest proto
* feat: update to utilise call ID
* feat: add stun and turn
* refactor: playing around with deps and transport types
* feat: adding call service functionality and permissions for calls
* feat: add call manager and more static intent building functions for WebRtcCallService.kt
* feat: adding ringers and more audio boilerplate
* feat: audio manager call service boilerplate
* feat: update kotlin and add in call view model and more management functions
* refactor: moving call code around to service and viewmodel interactions
* feat: plugging CallManager.kt into view model and service, fixing up dependencies
* feat: implementing more WebRtcCallService.kt functions and handlers for actions as well as lifecycle
* feat: adding more lifecycle vm and callmanager / call service functionality
* feat: adding more command handlers in WebRtcCallService.kt
* feat: more commands handled, adding lock manager and bluetooth permissions
* feat: adding remainder of basic functionality to services and CallManager.kt
* feat: hooking up calls and fixing broken dependencies and compile errors
* fix: add timestamp to incoming call
* feat: some connection and service launching / ring lifecycle
* feat: call establishing and displaying
* fix: fixing call connect flows
* feat: ringers and better state handling
* feat: updating call layout
* feat: add fixes to bluetooth and begin the network renegotiation
* feat: add call related permissions and more network handover tests
* fix: don't display call option in conversation and don't show notification if option not enabled
* fix: incoming ringer fix on receiving call, call notification priorities and notification channel update
* build: update build number for testing
* fix: bluetooth auto-connection and re-connection fixes, removing finished todos, allowing self-send call messages for deduping answers
* feat: add pre-offer information and action handling in web rtc call service
* refactor: discard offer messages from non-matching pre-offers we are already expecting
* build: build numbers and version name update
* feat: handle discarding pending calls from linked devices
* feat: add signing props to release config build
* docs: fix comment on time being 300s (5m) instead of 30s
* feat: adding call messages for incoming/outgoing/missed
* refactor: handle in-thread call notifications better and replace deny button intent with denyCallIntent instead of hangup
* feat: add a hangup via data channel message
* feat: process microphone enabled events and remove debuggable from build.gradle
* feat: add first call notification
* refactor: set the buttons to match iOS in terms of enable disable and colours
* refactor: change the call logos in control messages
* refactor: more bluetooth improvements
* refactor: move start ringer and init of audio manager to CallManager.kt and string fix up
* build: remove debuggable for release build
* refactor: replace call icons
* feat: adding a call time display
* refactor: change the call time to update every second
* refactor: testing out the full screen intents
* refactor: wrapper use corrected session description, set title to recipient displayName, indicate session calls
* fix: crash on view with a parent already attached
* refactor: aspect ratio fit preserved
* refactor: add wantsToAnswer ability in pre-init for fullscreenintent
* refactor: prevent calls from non hasSent participants
* build: update gradle code
* refactor: replace timeout schedule with a seconds count
* fix: various bug fixes for calls
* fix: remove end call from busy
* refactor: use answerCall instead of manual intent building again
* build: new version
* feat: add silenced notifications for call notification builder. check pre-offer and connecting state for pending connection
* build: update build number
* fix: text color uses overridden style value
* fix: remove wrap content for renderers and look more at recovering from network switches
* build: update build number
* refactor: remove whitespace
* build: update build number
* refactor: used shared number for BatchMessageReceiveJob.kt parameter across pollers
* fix: glide in update crash
* fix: bug fixes for self-send answer / hangup messages
* build: update build number
* build: update build.gradle number
* refactor: compile errors and refactoring to view binding
* fix: set the content to binding.root view
* build: increase build number
* build: update build numbers
* feat: adding base for rotation and picking random subset of turn servers
* feat: starting the screen rotation processing
* feat: setting up rotation for the remote render view
* refactor: applying rotation and mirroring based on front / rear cameras that wraps nicely, only scale reworking needed
* refactor: calls video stretching but consistent
* refactor: state machine and tests for the transition events
* feat: new call state processing
* refactor: adding reconnecting logic and visuals
* feat: state machine reconnect logic wip
* feat: add reconnecting and merge fixes
* feat: check new session based off current state
* feat: reconnection logic works correctly now
* refactor: reduce TIMEOUT_SECONDS to 30 from 90
* feat: reset peer connection on DC to prevent ICE messages from old connection or stale state in reconnecting
* refactor: add null case
* fix: set approved on new outgoing threads, use approved more deeply and invalidate the options menu on recipient modified. Add approvedMe flag toggles for visible message receive
* fix: add name update in action bar on modified, change where approvedMe is set
* build: increment build number
* build: update build number
* fix: merge compile errors and increment build number
* refactor: remove negotiation based on which party dropped connection
* refactor: call reconnection improvement tested cross platform to re-establish
* refactor: failed and disconnect events only handled if either the reconnect or the timeout runnables are not set
* build: update version number
* fix: reduce timeout
* fix: fixes the incoming hangup logic for linked devices
* refactor: match iOS styling for call activity closer
* chore: upgrade build numbers
* feat: add in call settings dialog for if calls is disabled in conversation
* feat: add a first call missed control message and info popup with link to privacy settings
* fix: looking at crash for specific large transaction in NotificationManager
* refactor: removing the people in case transaction size reduces to fix notif crash
* fix: comment out the entire send multiple to see if it fixes the issue
* refactor: revert to including the full notification process in a try/catch to handle weird responses from NotificationManager
* fix: add in notification settings prompt for calls and try to fall back to dirty full screen intent / start activity if we're allowed
* build: upgrade build number
2022-04-19 06:25:40 +02:00
|
|
|
private fun MessageReceiver.handleCallMessage(message: CallMessage) {
|
|
|
|
// TODO: refactor this out to persistence, just to help debug the flow and send/receive in synchronous testing
|
|
|
|
WebRtcUtils.SIGNAL_QUEUE.trySend(message)
|
|
|
|
}
|
|
|
|
|
2020-12-07 05:22:02 +01:00
|
|
|
private fun MessageReceiver.handleTypingIndicator(message: TypingIndicator) {
|
|
|
|
when (message.kind!!) {
|
|
|
|
TypingIndicator.Kind.STARTED -> showTypingIndicatorIfNeeded(message.sender!!)
|
|
|
|
TypingIndicator.Kind.STOPPED -> hideTypingIndicatorIfNeeded(message.sender!!)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fun MessageReceiver.showTypingIndicatorIfNeeded(senderPublicKey: String) {
|
2021-04-26 03:14:45 +02:00
|
|
|
val context = MessagingModuleConfiguration.shared.context
|
2021-01-08 01:13:05 +01:00
|
|
|
val address = Address.fromSerialized(senderPublicKey)
|
2021-05-21 07:02:34 +02:00
|
|
|
val threadID = MessagingModuleConfiguration.shared.storage.getThreadId(address) ?: return
|
2021-01-20 06:29:52 +01:00
|
|
|
SSKEnvironment.shared.typingIndicators.didReceiveTypingStartedMessage(context, threadID, address, 1)
|
2020-12-07 05:22:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fun MessageReceiver.hideTypingIndicatorIfNeeded(senderPublicKey: String) {
|
2021-04-26 03:14:45 +02:00
|
|
|
val context = MessagingModuleConfiguration.shared.context
|
2021-01-08 01:13:05 +01:00
|
|
|
val address = Address.fromSerialized(senderPublicKey)
|
2021-05-21 07:02:34 +02:00
|
|
|
val threadID = MessagingModuleConfiguration.shared.storage.getThreadId(address) ?: return
|
2021-01-20 06:29:52 +01:00
|
|
|
SSKEnvironment.shared.typingIndicators.didReceiveTypingStoppedMessage(context, threadID, address, 1, false)
|
2020-12-07 05:22:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fun MessageReceiver.cancelTypingIndicatorsIfNeeded(senderPublicKey: String) {
|
2021-04-26 03:14:45 +02:00
|
|
|
val context = MessagingModuleConfiguration.shared.context
|
2021-01-08 01:13:05 +01:00
|
|
|
val address = Address.fromSerialized(senderPublicKey)
|
2021-05-21 07:02:34 +02:00
|
|
|
val threadID = MessagingModuleConfiguration.shared.storage.getThreadId(address) ?: return
|
2021-01-20 06:29:52 +01:00
|
|
|
SSKEnvironment.shared.typingIndicators.didReceiveIncomingMessage(context, threadID, address, 1)
|
2020-12-07 05:22:02 +01:00
|
|
|
}
|
|
|
|
|
2021-03-25 04:55:23 +01:00
|
|
|
private fun MessageReceiver.handleExpirationTimerUpdate(message: ExpirationTimerUpdate) {
|
2020-12-07 05:22:02 +01:00
|
|
|
if (message.duration!! > 0) {
|
2021-03-25 04:55:23 +01:00
|
|
|
SSKEnvironment.shared.messageExpirationManager.setExpirationTimer(message)
|
2020-12-07 05:22:02 +01:00
|
|
|
} else {
|
2021-03-25 04:55:23 +01:00
|
|
|
SSKEnvironment.shared.messageExpirationManager.disableExpirationTimer(message)
|
2020-12-07 05:22:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-16 04:56:47 +01:00
|
|
|
private fun MessageReceiver.handleDataExtractionNotification(message: DataExtractionNotification) {
|
2021-05-13 07:42:14 +02:00
|
|
|
// We don't handle data extraction messages for groups (they shouldn't be sent, but just in case we filter them here too)
|
2021-04-09 08:06:12 +02:00
|
|
|
if (message.groupPublicKey != null) return
|
2021-04-26 03:14:45 +02:00
|
|
|
val storage = MessagingModuleConfiguration.shared.storage
|
2021-03-16 04:56:47 +01:00
|
|
|
val senderPublicKey = message.sender!!
|
|
|
|
val notification: DataExtractionNotificationInfoMessage = when(message.kind) {
|
|
|
|
is DataExtractionNotification.Kind.Screenshot -> DataExtractionNotificationInfoMessage(DataExtractionNotificationInfoMessage.Kind.SCREENSHOT)
|
2021-04-20 09:07:21 +02:00
|
|
|
is DataExtractionNotification.Kind.MediaSaved -> DataExtractionNotificationInfoMessage(DataExtractionNotificationInfoMessage.Kind.MEDIA_SAVED)
|
2021-03-16 04:56:47 +01:00
|
|
|
else -> return
|
|
|
|
}
|
2021-04-09 08:06:12 +02:00
|
|
|
storage.insertDataExtractionNotificationMessage(senderPublicKey, notification, message.sentTimestamp!!)
|
2021-03-16 04:56:47 +01:00
|
|
|
}
|
|
|
|
|
2021-04-26 07:18:12 +02:00
|
|
|
private fun handleConfigurationMessage(message: ConfigurationMessage) {
|
2021-04-26 03:14:45 +02:00
|
|
|
val context = MessagingModuleConfiguration.shared.context
|
|
|
|
val storage = MessagingModuleConfiguration.shared.storage
|
2021-05-13 07:42:14 +02:00
|
|
|
if (TextSecurePreferences.getConfigurationMessageSynced(context)
|
|
|
|
&& !TextSecurePreferences.shouldUpdateProfile(context, message.sentTimestamp!!)) return
|
2021-03-30 07:23:12 +02:00
|
|
|
val userPublicKey = storage.getUserPublicKey()
|
|
|
|
if (userPublicKey == null || message.sender != storage.getUserPublicKey()) return
|
2022-03-09 07:48:31 +01:00
|
|
|
|
|
|
|
val firstTimeSync = !TextSecurePreferences.getConfigurationMessageSynced(context)
|
|
|
|
|
2021-03-30 07:23:12 +02:00
|
|
|
TextSecurePreferences.setConfigurationMessageSynced(context, true)
|
|
|
|
TextSecurePreferences.setLastProfileUpdateTime(context, message.sentTimestamp!!)
|
Performance improvements and bug fixes (#869)
* refactor: fail on testSnode instead of recursively using up snode list. add call timeout on http client
* refactor: refactoring batch message receives and pollers
* refactor: reduce thread utils pool count to a 2 thread fixed pool. Do a check against pubkey instead of room names for oxenHostedOpenGroup
* refactor: caching lib with potential loader fixes and no-cache for giphy
* refactor: remove store and instead use ConcurrentHashMap with a backing update coroutine
* refactor: queue trim thread jobs instead of add every message processed
* fix: wrapping auth token and initial sync for open groups in a threadutils queued runnable, getting initial sync times down
* fix: fixing the user contacts cache in ConversationAdapter.kt
* refactor: improve polling and initial sync, move group joins from config messages into a background job fetching image.
* refactor: improving the job queuing for open groups, replacing placeholder avatar generation with a custom glide loader and archiving initial sync of open groups
* feat: add OpenGroupDeleteJob.kt
* feat: add open group delete job to process deletions after batch adding
* feat: add vacuum and fix job queue re-adding jobs forever, only try to set message hash values in DB if they have changed
* refactor: remove redundant inflation for profile image views throughout app
* refactor(wip): reducing layout inflation and starting to refactor the open group deletion issues taking a long time
* refactor(wip): refactoring group deletion to not iterate through and delete messages individually
* refactor(wip): refactoring group deletion to not iterate through and delete messages individually
* fix: group deletion optimisation
* build: bump build number
* build: bump build number and fix batch message receive retry logic
* fix: clear out open group deletes
* fix: update visible ConversationAdapter.kt binding for initial contact fetching and better traces for debugging background jobs
* fix: add in check for / force sync latest encryption key pair from linked devices if we already have that closed group
* Rename .java to .kt
* refactor: change MmsDatabase to kotlin to make list operations easier
* fix: nullable type
* fix: compilation issues and constants in .kt instead of .java
* fix: bug fix expiration timer on closed group recipient
* feat: use the job queue properly across executors
* feat: start on open group dispatcher-specific logic, probably a queue factory based on openGroupId if that is the same across new message and deletion jobs to ensure consistent entry and removal
* refactor: removing redundant code and fixing jobqueue per opengroup
* fix: allow attachments in note to self
* fix: make the minWidth in quote view bind max of text / title and body, wrapped ?
* fix: fixing up layouts and code view layouts
* fix: remove TODO, remove timestamp binding
* feat: fix view logic, avatars and padding, downloading attachments lazily (on bind), fixing potential crash, add WindowDebouncer.kt
* fix: NPE on viewModel recipient from removed thread while tearing down the Recipient observer in ConversationActivityV2.kt
* refactor: replace conversation notification debouncer handler with handlerthread, same as conversation list debouncer
* refactor: UI for groups and poller improvements
* fix: revert some changes in poller
* feat: add header back in for message requests
* refactor: remove Trace calls, add more conditions to the HomeDiffUtil for updating more efficiently
* feat: try update the home adapter if we get a profile picture modified event
* feat: bump build numbers
* fix: try to start with list in homeViewModel if we don't have already, render quotes to be width of attachment slide view instead of fixed
* fix: set channel to be conflated instead of no buffer
* fix: set unreads based off last local user message vs incrementing unreads to be all amount
* feat: add profile update flag, update build number
* fix: link preview thumbnails download on bind
* fix: centercrop placeholder in glide request
* feat: recycle the contact selection list and profile image in unbind
* fix: try to prevent user KP crash at weird times
* fix: remove additional log, improve attachment download success rate, fix share logs dialog issue
2022-06-08 09:12:34 +02:00
|
|
|
val allClosedGroupPublicKeys = storage.getAllClosedGroupPublicKeys()
|
|
|
|
for (closedGroup in message.closedGroups) {
|
|
|
|
if (allClosedGroupPublicKeys.contains(closedGroup.publicKey)) {
|
|
|
|
// just handle the closed group encryption key pairs to avoid sync'd devices getting out of sync
|
|
|
|
storage.addClosedGroupEncryptionKeyPair(closedGroup.encryptionKeyPair!!, closedGroup.publicKey)
|
|
|
|
} else if (firstTimeSync) {
|
|
|
|
// only handle new closed group if it's first time sync
|
2022-03-09 07:48:31 +01:00
|
|
|
handleNewClosedGroup(message.sender!!, message.sentTimestamp!!, closedGroup.publicKey, closedGroup.name,
|
|
|
|
closedGroup.encryptionKeyPair!!, closedGroup.members, closedGroup.admins, message.sentTimestamp!!, closedGroup.expirationTimer)
|
|
|
|
}
|
2021-02-09 01:45:38 +01:00
|
|
|
}
|
2021-05-12 06:48:13 +02:00
|
|
|
val allV2OpenGroups = storage.getAllV2OpenGroups().map { it.value.joinURL }
|
2021-02-09 01:45:38 +01:00
|
|
|
for (openGroup in message.openGroups) {
|
2021-05-21 07:02:34 +02:00
|
|
|
if (allV2OpenGroups.contains(openGroup)) continue
|
Performance improvements and bug fixes (#869)
* refactor: fail on testSnode instead of recursively using up snode list. add call timeout on http client
* refactor: refactoring batch message receives and pollers
* refactor: reduce thread utils pool count to a 2 thread fixed pool. Do a check against pubkey instead of room names for oxenHostedOpenGroup
* refactor: caching lib with potential loader fixes and no-cache for giphy
* refactor: remove store and instead use ConcurrentHashMap with a backing update coroutine
* refactor: queue trim thread jobs instead of add every message processed
* fix: wrapping auth token and initial sync for open groups in a threadutils queued runnable, getting initial sync times down
* fix: fixing the user contacts cache in ConversationAdapter.kt
* refactor: improve polling and initial sync, move group joins from config messages into a background job fetching image.
* refactor: improving the job queuing for open groups, replacing placeholder avatar generation with a custom glide loader and archiving initial sync of open groups
* feat: add OpenGroupDeleteJob.kt
* feat: add open group delete job to process deletions after batch adding
* feat: add vacuum and fix job queue re-adding jobs forever, only try to set message hash values in DB if they have changed
* refactor: remove redundant inflation for profile image views throughout app
* refactor(wip): reducing layout inflation and starting to refactor the open group deletion issues taking a long time
* refactor(wip): refactoring group deletion to not iterate through and delete messages individually
* refactor(wip): refactoring group deletion to not iterate through and delete messages individually
* fix: group deletion optimisation
* build: bump build number
* build: bump build number and fix batch message receive retry logic
* fix: clear out open group deletes
* fix: update visible ConversationAdapter.kt binding for initial contact fetching and better traces for debugging background jobs
* fix: add in check for / force sync latest encryption key pair from linked devices if we already have that closed group
* Rename .java to .kt
* refactor: change MmsDatabase to kotlin to make list operations easier
* fix: nullable type
* fix: compilation issues and constants in .kt instead of .java
* fix: bug fix expiration timer on closed group recipient
* feat: use the job queue properly across executors
* feat: start on open group dispatcher-specific logic, probably a queue factory based on openGroupId if that is the same across new message and deletion jobs to ensure consistent entry and removal
* refactor: removing redundant code and fixing jobqueue per opengroup
* fix: allow attachments in note to self
* fix: make the minWidth in quote view bind max of text / title and body, wrapped ?
* fix: fixing up layouts and code view layouts
* fix: remove TODO, remove timestamp binding
* feat: fix view logic, avatars and padding, downloading attachments lazily (on bind), fixing potential crash, add WindowDebouncer.kt
* fix: NPE on viewModel recipient from removed thread while tearing down the Recipient observer in ConversationActivityV2.kt
* refactor: replace conversation notification debouncer handler with handlerthread, same as conversation list debouncer
* refactor: UI for groups and poller improvements
* fix: revert some changes in poller
* feat: add header back in for message requests
* refactor: remove Trace calls, add more conditions to the HomeDiffUtil for updating more efficiently
* feat: try update the home adapter if we get a profile picture modified event
* feat: bump build numbers
* fix: try to start with list in homeViewModel if we don't have already, render quotes to be width of attachment slide view instead of fixed
* fix: set channel to be conflated instead of no buffer
* fix: set unreads based off last local user message vs incrementing unreads to be all amount
* feat: add profile update flag, update build number
* fix: link preview thumbnails download on bind
* fix: centercrop placeholder in glide request
* feat: recycle the contact selection list and profile image in unbind
* fix: try to prevent user KP crash at weird times
* fix: remove additional log, improve attachment download success rate, fix share logs dialog issue
2022-06-08 09:12:34 +02:00
|
|
|
Log.d("OpenGroup", "All open groups doesn't contain $openGroup")
|
|
|
|
if (!storage.hasBackgroundGroupAddJob(openGroup)) {
|
|
|
|
Log.d("OpenGroup", "Doesn't contain background job for $openGroup, adding")
|
|
|
|
JobQueue.shared.add(BackgroundGroupAddJob(openGroup))
|
|
|
|
}
|
2021-02-09 01:45:38 +01:00
|
|
|
}
|
2021-04-22 02:48:19 +02:00
|
|
|
val profileManager = SSKEnvironment.shared.profileManager
|
|
|
|
val recipient = Recipient.from(context, Address.fromSerialized(userPublicKey), false)
|
2021-03-30 07:23:12 +02:00
|
|
|
if (message.displayName.isNotEmpty()) {
|
|
|
|
TextSecurePreferences.setProfileName(context, message.displayName)
|
2021-05-21 07:56:38 +02:00
|
|
|
profileManager.setName(context, recipient, message.displayName)
|
2021-03-30 07:23:12 +02:00
|
|
|
}
|
2021-05-13 07:42:14 +02:00
|
|
|
if (message.profileKey.isNotEmpty() && !message.profilePicture.isNullOrEmpty()
|
|
|
|
&& TextSecurePreferences.getProfilePictureURL(context) != message.profilePicture) {
|
2021-03-30 07:23:12 +02:00
|
|
|
val profileKey = Base64.encodeBytes(message.profileKey)
|
|
|
|
ProfileKeyUtil.setEncodedProfileKey(context, profileKey)
|
2021-04-22 02:48:19 +02:00
|
|
|
profileManager.setProfileKey(context, recipient, message.profileKey)
|
2021-03-30 07:23:12 +02:00
|
|
|
if (!message.profilePicture.isNullOrEmpty() && TextSecurePreferences.getProfilePictureURL(context) != message.profilePicture) {
|
2021-05-21 07:21:24 +02:00
|
|
|
storage.setUserProfilePictureURL(message.profilePicture!!)
|
2021-03-30 07:23:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
storage.addContacts(message.contacts)
|
2021-02-09 01:45:38 +01:00
|
|
|
}
|
2021-08-10 08:00:06 +02:00
|
|
|
|
|
|
|
fun MessageReceiver.handleUnsendRequest(message: UnsendRequest) {
|
2021-10-27 08:26:44 +02:00
|
|
|
val userPublicKey = MessagingModuleConfiguration.shared.storage.getUserPublicKey()
|
|
|
|
if (message.sender != message.author && (message.sender != userPublicKey && userPublicKey != null)) { return }
|
2021-08-10 08:00:06 +02:00
|
|
|
val context = MessagingModuleConfiguration.shared.context
|
|
|
|
val storage = MessagingModuleConfiguration.shared.storage
|
|
|
|
val messageDataProvider = MessagingModuleConfiguration.shared.messageDataProvider
|
|
|
|
val timestamp = message.timestamp ?: return
|
|
|
|
val author = message.author ?: return
|
|
|
|
val messageIdToDelete = storage.getMessageIdInDatabase(timestamp, author) ?: return
|
|
|
|
messageDataProvider.getServerHashForMessage(messageIdToDelete)?.let { serverHash ->
|
|
|
|
SnodeAPI.deleteMessage(author, listOf(serverHash))
|
|
|
|
}
|
2021-08-12 06:14:37 +02:00
|
|
|
messageDataProvider.updateMessageAsDeleted(timestamp, author)
|
2021-08-16 02:58:07 +02:00
|
|
|
if (!messageDataProvider.isOutgoingMessage(messageIdToDelete)) {
|
|
|
|
SSKEnvironment.shared.notificationManager.updateNotification(context)
|
|
|
|
}
|
2021-08-10 08:00:06 +02:00
|
|
|
}
|
2022-03-04 07:46:39 +01:00
|
|
|
|
|
|
|
fun handleMessageRequestResponse(message: MessageRequestResponse) {
|
|
|
|
MessagingModuleConfiguration.shared.storage.insertMessageRequestResponse(message)
|
|
|
|
}
|
2021-04-30 08:09:11 +02:00
|
|
|
//endregion
|
2021-02-09 01:45:38 +01:00
|
|
|
|
Performance improvements and bug fixes (#869)
* refactor: fail on testSnode instead of recursively using up snode list. add call timeout on http client
* refactor: refactoring batch message receives and pollers
* refactor: reduce thread utils pool count to a 2 thread fixed pool. Do a check against pubkey instead of room names for oxenHostedOpenGroup
* refactor: caching lib with potential loader fixes and no-cache for giphy
* refactor: remove store and instead use ConcurrentHashMap with a backing update coroutine
* refactor: queue trim thread jobs instead of add every message processed
* fix: wrapping auth token and initial sync for open groups in a threadutils queued runnable, getting initial sync times down
* fix: fixing the user contacts cache in ConversationAdapter.kt
* refactor: improve polling and initial sync, move group joins from config messages into a background job fetching image.
* refactor: improving the job queuing for open groups, replacing placeholder avatar generation with a custom glide loader and archiving initial sync of open groups
* feat: add OpenGroupDeleteJob.kt
* feat: add open group delete job to process deletions after batch adding
* feat: add vacuum and fix job queue re-adding jobs forever, only try to set message hash values in DB if they have changed
* refactor: remove redundant inflation for profile image views throughout app
* refactor(wip): reducing layout inflation and starting to refactor the open group deletion issues taking a long time
* refactor(wip): refactoring group deletion to not iterate through and delete messages individually
* refactor(wip): refactoring group deletion to not iterate through and delete messages individually
* fix: group deletion optimisation
* build: bump build number
* build: bump build number and fix batch message receive retry logic
* fix: clear out open group deletes
* fix: update visible ConversationAdapter.kt binding for initial contact fetching and better traces for debugging background jobs
* fix: add in check for / force sync latest encryption key pair from linked devices if we already have that closed group
* Rename .java to .kt
* refactor: change MmsDatabase to kotlin to make list operations easier
* fix: nullable type
* fix: compilation issues and constants in .kt instead of .java
* fix: bug fix expiration timer on closed group recipient
* feat: use the job queue properly across executors
* feat: start on open group dispatcher-specific logic, probably a queue factory based on openGroupId if that is the same across new message and deletion jobs to ensure consistent entry and removal
* refactor: removing redundant code and fixing jobqueue per opengroup
* fix: allow attachments in note to self
* fix: make the minWidth in quote view bind max of text / title and body, wrapped ?
* fix: fixing up layouts and code view layouts
* fix: remove TODO, remove timestamp binding
* feat: fix view logic, avatars and padding, downloading attachments lazily (on bind), fixing potential crash, add WindowDebouncer.kt
* fix: NPE on viewModel recipient from removed thread while tearing down the Recipient observer in ConversationActivityV2.kt
* refactor: replace conversation notification debouncer handler with handlerthread, same as conversation list debouncer
* refactor: UI for groups and poller improvements
* fix: revert some changes in poller
* feat: add header back in for message requests
* refactor: remove Trace calls, add more conditions to the HomeDiffUtil for updating more efficiently
* feat: try update the home adapter if we get a profile picture modified event
* feat: bump build numbers
* fix: try to start with list in homeViewModel if we don't have already, render quotes to be width of attachment slide view instead of fixed
* fix: set channel to be conflated instead of no buffer
* fix: set unreads based off last local user message vs incrementing unreads to be all amount
* feat: add profile update flag, update build number
* fix: link preview thumbnails download on bind
* fix: centercrop placeholder in glide request
* feat: recycle the contact selection list and profile image in unbind
* fix: try to prevent user KP crash at weird times
* fix: remove additional log, improve attachment download success rate, fix share logs dialog issue
2022-06-08 09:12:34 +02:00
|
|
|
fun MessageReceiver.handleVisibleMessage(message: VisibleMessage,
|
|
|
|
proto: SignalServiceProtos.Content,
|
|
|
|
openGroupID: String?,
|
|
|
|
runIncrement: Boolean,
|
|
|
|
runThreadUpdate: Boolean,
|
|
|
|
runProfileUpdate: Boolean): Long? {
|
2021-04-26 03:14:45 +02:00
|
|
|
val storage = MessagingModuleConfiguration.shared.storage
|
|
|
|
val context = MessagingModuleConfiguration.shared.context
|
2021-04-27 01:38:07 +02:00
|
|
|
val userPublicKey = storage.getUserPublicKey()
|
2022-03-14 23:24:15 +01:00
|
|
|
val messageSender: String? = message.sender
|
2021-04-29 09:13:42 +02:00
|
|
|
// Get or create thread
|
2021-05-13 07:42:14 +02:00
|
|
|
// FIXME: In case this is an open group this actually * doesn't * create the thread if it doesn't yet
|
|
|
|
// exist. This is intentional, but it's very non-obvious.
|
2021-04-29 09:13:42 +02:00
|
|
|
val threadID = storage.getOrCreateThreadIdFor(message.syncTarget
|
2022-03-14 23:24:15 +01:00
|
|
|
?: messageSender!!, message.groupPublicKey, openGroupID)
|
2021-05-12 08:48:18 +02:00
|
|
|
if (threadID < 0) {
|
2021-05-13 07:42:14 +02:00
|
|
|
// Thread doesn't exist; should only be reached in a case where we are processing open group messages for a no longer existent thread
|
2021-05-12 08:48:18 +02:00
|
|
|
throw MessageReceiver.Error.NoThread
|
|
|
|
}
|
2020-12-18 06:48:45 +01:00
|
|
|
// Update profile if needed
|
2022-03-14 23:24:15 +01:00
|
|
|
val recipient = Recipient.from(context, Address.fromSerialized(messageSender!!), false)
|
Performance improvements and bug fixes (#869)
* refactor: fail on testSnode instead of recursively using up snode list. add call timeout on http client
* refactor: refactoring batch message receives and pollers
* refactor: reduce thread utils pool count to a 2 thread fixed pool. Do a check against pubkey instead of room names for oxenHostedOpenGroup
* refactor: caching lib with potential loader fixes and no-cache for giphy
* refactor: remove store and instead use ConcurrentHashMap with a backing update coroutine
* refactor: queue trim thread jobs instead of add every message processed
* fix: wrapping auth token and initial sync for open groups in a threadutils queued runnable, getting initial sync times down
* fix: fixing the user contacts cache in ConversationAdapter.kt
* refactor: improve polling and initial sync, move group joins from config messages into a background job fetching image.
* refactor: improving the job queuing for open groups, replacing placeholder avatar generation with a custom glide loader and archiving initial sync of open groups
* feat: add OpenGroupDeleteJob.kt
* feat: add open group delete job to process deletions after batch adding
* feat: add vacuum and fix job queue re-adding jobs forever, only try to set message hash values in DB if they have changed
* refactor: remove redundant inflation for profile image views throughout app
* refactor(wip): reducing layout inflation and starting to refactor the open group deletion issues taking a long time
* refactor(wip): refactoring group deletion to not iterate through and delete messages individually
* refactor(wip): refactoring group deletion to not iterate through and delete messages individually
* fix: group deletion optimisation
* build: bump build number
* build: bump build number and fix batch message receive retry logic
* fix: clear out open group deletes
* fix: update visible ConversationAdapter.kt binding for initial contact fetching and better traces for debugging background jobs
* fix: add in check for / force sync latest encryption key pair from linked devices if we already have that closed group
* Rename .java to .kt
* refactor: change MmsDatabase to kotlin to make list operations easier
* fix: nullable type
* fix: compilation issues and constants in .kt instead of .java
* fix: bug fix expiration timer on closed group recipient
* feat: use the job queue properly across executors
* feat: start on open group dispatcher-specific logic, probably a queue factory based on openGroupId if that is the same across new message and deletion jobs to ensure consistent entry and removal
* refactor: removing redundant code and fixing jobqueue per opengroup
* fix: allow attachments in note to self
* fix: make the minWidth in quote view bind max of text / title and body, wrapped ?
* fix: fixing up layouts and code view layouts
* fix: remove TODO, remove timestamp binding
* feat: fix view logic, avatars and padding, downloading attachments lazily (on bind), fixing potential crash, add WindowDebouncer.kt
* fix: NPE on viewModel recipient from removed thread while tearing down the Recipient observer in ConversationActivityV2.kt
* refactor: replace conversation notification debouncer handler with handlerthread, same as conversation list debouncer
* refactor: UI for groups and poller improvements
* fix: revert some changes in poller
* feat: add header back in for message requests
* refactor: remove Trace calls, add more conditions to the HomeDiffUtil for updating more efficiently
* feat: try update the home adapter if we get a profile picture modified event
* feat: bump build numbers
* fix: try to start with list in homeViewModel if we don't have already, render quotes to be width of attachment slide view instead of fixed
* fix: set channel to be conflated instead of no buffer
* fix: set unreads based off last local user message vs incrementing unreads to be all amount
* feat: add profile update flag, update build number
* fix: link preview thumbnails download on bind
* fix: centercrop placeholder in glide request
* feat: recycle the contact selection list and profile image in unbind
* fix: try to prevent user KP crash at weird times
* fix: remove additional log, improve attachment download success rate, fix share logs dialog issue
2022-06-08 09:12:34 +02:00
|
|
|
if (runProfileUpdate) {
|
|
|
|
val profile = message.profile
|
|
|
|
if (profile != null && userPublicKey != messageSender) {
|
|
|
|
val profileManager = SSKEnvironment.shared.profileManager
|
|
|
|
val name = profile.displayName!!
|
|
|
|
if (name.isNotEmpty()) {
|
|
|
|
profileManager.setName(context, recipient, name)
|
|
|
|
}
|
|
|
|
val newProfileKey = profile.profileKey
|
2022-03-14 23:24:15 +01:00
|
|
|
|
Performance improvements and bug fixes (#869)
* refactor: fail on testSnode instead of recursively using up snode list. add call timeout on http client
* refactor: refactoring batch message receives and pollers
* refactor: reduce thread utils pool count to a 2 thread fixed pool. Do a check against pubkey instead of room names for oxenHostedOpenGroup
* refactor: caching lib with potential loader fixes and no-cache for giphy
* refactor: remove store and instead use ConcurrentHashMap with a backing update coroutine
* refactor: queue trim thread jobs instead of add every message processed
* fix: wrapping auth token and initial sync for open groups in a threadutils queued runnable, getting initial sync times down
* fix: fixing the user contacts cache in ConversationAdapter.kt
* refactor: improve polling and initial sync, move group joins from config messages into a background job fetching image.
* refactor: improving the job queuing for open groups, replacing placeholder avatar generation with a custom glide loader and archiving initial sync of open groups
* feat: add OpenGroupDeleteJob.kt
* feat: add open group delete job to process deletions after batch adding
* feat: add vacuum and fix job queue re-adding jobs forever, only try to set message hash values in DB if they have changed
* refactor: remove redundant inflation for profile image views throughout app
* refactor(wip): reducing layout inflation and starting to refactor the open group deletion issues taking a long time
* refactor(wip): refactoring group deletion to not iterate through and delete messages individually
* refactor(wip): refactoring group deletion to not iterate through and delete messages individually
* fix: group deletion optimisation
* build: bump build number
* build: bump build number and fix batch message receive retry logic
* fix: clear out open group deletes
* fix: update visible ConversationAdapter.kt binding for initial contact fetching and better traces for debugging background jobs
* fix: add in check for / force sync latest encryption key pair from linked devices if we already have that closed group
* Rename .java to .kt
* refactor: change MmsDatabase to kotlin to make list operations easier
* fix: nullable type
* fix: compilation issues and constants in .kt instead of .java
* fix: bug fix expiration timer on closed group recipient
* feat: use the job queue properly across executors
* feat: start on open group dispatcher-specific logic, probably a queue factory based on openGroupId if that is the same across new message and deletion jobs to ensure consistent entry and removal
* refactor: removing redundant code and fixing jobqueue per opengroup
* fix: allow attachments in note to self
* fix: make the minWidth in quote view bind max of text / title and body, wrapped ?
* fix: fixing up layouts and code view layouts
* fix: remove TODO, remove timestamp binding
* feat: fix view logic, avatars and padding, downloading attachments lazily (on bind), fixing potential crash, add WindowDebouncer.kt
* fix: NPE on viewModel recipient from removed thread while tearing down the Recipient observer in ConversationActivityV2.kt
* refactor: replace conversation notification debouncer handler with handlerthread, same as conversation list debouncer
* refactor: UI for groups and poller improvements
* fix: revert some changes in poller
* feat: add header back in for message requests
* refactor: remove Trace calls, add more conditions to the HomeDiffUtil for updating more efficiently
* feat: try update the home adapter if we get a profile picture modified event
* feat: bump build numbers
* fix: try to start with list in homeViewModel if we don't have already, render quotes to be width of attachment slide view instead of fixed
* fix: set channel to be conflated instead of no buffer
* fix: set unreads based off last local user message vs incrementing unreads to be all amount
* feat: add profile update flag, update build number
* fix: link preview thumbnails download on bind
* fix: centercrop placeholder in glide request
* feat: recycle the contact selection list and profile image in unbind
* fix: try to prevent user KP crash at weird times
* fix: remove additional log, improve attachment download success rate, fix share logs dialog issue
2022-06-08 09:12:34 +02:00
|
|
|
val needsProfilePicture = !AvatarHelper.avatarFileExists(context, Address.fromSerialized(messageSender))
|
|
|
|
val profileKeyValid = newProfileKey?.isNotEmpty() == true && (newProfileKey.size == 16 || newProfileKey.size == 32) && profile.profilePictureURL?.isNotEmpty() == true
|
|
|
|
val profileKeyChanged = (recipient.profileKey == null || !MessageDigest.isEqual(recipient.profileKey, newProfileKey))
|
2022-03-14 23:24:15 +01:00
|
|
|
|
Performance improvements and bug fixes (#869)
* refactor: fail on testSnode instead of recursively using up snode list. add call timeout on http client
* refactor: refactoring batch message receives and pollers
* refactor: reduce thread utils pool count to a 2 thread fixed pool. Do a check against pubkey instead of room names for oxenHostedOpenGroup
* refactor: caching lib with potential loader fixes and no-cache for giphy
* refactor: remove store and instead use ConcurrentHashMap with a backing update coroutine
* refactor: queue trim thread jobs instead of add every message processed
* fix: wrapping auth token and initial sync for open groups in a threadutils queued runnable, getting initial sync times down
* fix: fixing the user contacts cache in ConversationAdapter.kt
* refactor: improve polling and initial sync, move group joins from config messages into a background job fetching image.
* refactor: improving the job queuing for open groups, replacing placeholder avatar generation with a custom glide loader and archiving initial sync of open groups
* feat: add OpenGroupDeleteJob.kt
* feat: add open group delete job to process deletions after batch adding
* feat: add vacuum and fix job queue re-adding jobs forever, only try to set message hash values in DB if they have changed
* refactor: remove redundant inflation for profile image views throughout app
* refactor(wip): reducing layout inflation and starting to refactor the open group deletion issues taking a long time
* refactor(wip): refactoring group deletion to not iterate through and delete messages individually
* refactor(wip): refactoring group deletion to not iterate through and delete messages individually
* fix: group deletion optimisation
* build: bump build number
* build: bump build number and fix batch message receive retry logic
* fix: clear out open group deletes
* fix: update visible ConversationAdapter.kt binding for initial contact fetching and better traces for debugging background jobs
* fix: add in check for / force sync latest encryption key pair from linked devices if we already have that closed group
* Rename .java to .kt
* refactor: change MmsDatabase to kotlin to make list operations easier
* fix: nullable type
* fix: compilation issues and constants in .kt instead of .java
* fix: bug fix expiration timer on closed group recipient
* feat: use the job queue properly across executors
* feat: start on open group dispatcher-specific logic, probably a queue factory based on openGroupId if that is the same across new message and deletion jobs to ensure consistent entry and removal
* refactor: removing redundant code and fixing jobqueue per opengroup
* fix: allow attachments in note to self
* fix: make the minWidth in quote view bind max of text / title and body, wrapped ?
* fix: fixing up layouts and code view layouts
* fix: remove TODO, remove timestamp binding
* feat: fix view logic, avatars and padding, downloading attachments lazily (on bind), fixing potential crash, add WindowDebouncer.kt
* fix: NPE on viewModel recipient from removed thread while tearing down the Recipient observer in ConversationActivityV2.kt
* refactor: replace conversation notification debouncer handler with handlerthread, same as conversation list debouncer
* refactor: UI for groups and poller improvements
* fix: revert some changes in poller
* feat: add header back in for message requests
* refactor: remove Trace calls, add more conditions to the HomeDiffUtil for updating more efficiently
* feat: try update the home adapter if we get a profile picture modified event
* feat: bump build numbers
* fix: try to start with list in homeViewModel if we don't have already, render quotes to be width of attachment slide view instead of fixed
* fix: set channel to be conflated instead of no buffer
* fix: set unreads based off last local user message vs incrementing unreads to be all amount
* feat: add profile update flag, update build number
* fix: link preview thumbnails download on bind
* fix: centercrop placeholder in glide request
* feat: recycle the contact selection list and profile image in unbind
* fix: try to prevent user KP crash at weird times
* fix: remove additional log, improve attachment download success rate, fix share logs dialog issue
2022-06-08 09:12:34 +02:00
|
|
|
if ((profileKeyValid && profileKeyChanged) || (profileKeyValid && needsProfilePicture)) {
|
|
|
|
profileManager.setProfileKey(context, recipient, newProfileKey!!)
|
|
|
|
profileManager.setUnidentifiedAccessMode(context, recipient, Recipient.UnidentifiedAccessMode.UNKNOWN)
|
|
|
|
profileManager.setProfilePictureURL(context, recipient, profile.profilePictureURL!!)
|
|
|
|
}
|
2021-01-08 01:13:05 +01:00
|
|
|
}
|
2020-12-18 06:48:45 +01:00
|
|
|
}
|
|
|
|
// Parse quote if needed
|
2021-01-11 23:58:38 +01:00
|
|
|
var quoteModel: QuoteModel? = null
|
2020-12-18 06:48:45 +01:00
|
|
|
if (message.quote != null && proto.dataMessage.hasQuote()) {
|
2021-01-11 23:58:38 +01:00
|
|
|
val quote = proto.dataMessage.quote
|
|
|
|
val author = Address.fromSerialized(quote.author)
|
2021-05-13 07:42:14 +02:00
|
|
|
val messageDataProvider = MessagingModuleConfiguration.shared.messageDataProvider
|
|
|
|
val messageInfo = messageDataProvider.getMessageForQuote(quote.id, author)
|
2021-03-30 04:09:40 +02:00
|
|
|
if (messageInfo != null) {
|
2021-05-13 07:42:14 +02:00
|
|
|
val attachments = if (messageInfo.second) messageDataProvider.getAttachmentsAndLinkPreviewFor(messageInfo.first) else ArrayList()
|
|
|
|
quoteModel = QuoteModel(quote.id, author, messageDataProvider.getMessageBodyFor(quote.id, quote.author), false, attachments)
|
2021-01-11 23:58:38 +01:00
|
|
|
} else {
|
|
|
|
quoteModel = QuoteModel(quote.id, author, quote.text, true, PointerAttachment.forPointers(proto.dataMessage.quote.attachmentsList))
|
|
|
|
}
|
2020-12-18 06:48:45 +01:00
|
|
|
}
|
|
|
|
// Parse link preview if needed
|
2021-01-11 23:58:38 +01:00
|
|
|
val linkPreviews: MutableList<LinkPreview?> = mutableListOf()
|
2020-12-18 06:48:45 +01:00
|
|
|
if (message.linkPreview != null && proto.dataMessage.previewCount > 0) {
|
2021-01-11 23:58:38 +01:00
|
|
|
for (preview in proto.dataMessage.previewList) {
|
|
|
|
val thumbnail = PointerAttachment.forPointer(preview.image)
|
|
|
|
val url = Optional.fromNullable(preview.url)
|
|
|
|
val title = Optional.fromNullable(preview.title)
|
|
|
|
val hasContent = !TextUtils.isEmpty(title.or("")) || thumbnail.isPresent
|
|
|
|
if (hasContent) {
|
|
|
|
val linkPreview = LinkPreview(url.get(), title.or(""), thumbnail)
|
|
|
|
linkPreviews.add(linkPreview)
|
|
|
|
} else {
|
|
|
|
Log.w("Loki", "Discarding an invalid link preview. hasContent: $hasContent")
|
|
|
|
}
|
|
|
|
}
|
2020-12-18 06:48:45 +01:00
|
|
|
}
|
2021-05-13 07:42:14 +02:00
|
|
|
// Parse attachments if needed
|
Performance improvements and bug fixes (#869)
* refactor: fail on testSnode instead of recursively using up snode list. add call timeout on http client
* refactor: refactoring batch message receives and pollers
* refactor: reduce thread utils pool count to a 2 thread fixed pool. Do a check against pubkey instead of room names for oxenHostedOpenGroup
* refactor: caching lib with potential loader fixes and no-cache for giphy
* refactor: remove store and instead use ConcurrentHashMap with a backing update coroutine
* refactor: queue trim thread jobs instead of add every message processed
* fix: wrapping auth token and initial sync for open groups in a threadutils queued runnable, getting initial sync times down
* fix: fixing the user contacts cache in ConversationAdapter.kt
* refactor: improve polling and initial sync, move group joins from config messages into a background job fetching image.
* refactor: improving the job queuing for open groups, replacing placeholder avatar generation with a custom glide loader and archiving initial sync of open groups
* feat: add OpenGroupDeleteJob.kt
* feat: add open group delete job to process deletions after batch adding
* feat: add vacuum and fix job queue re-adding jobs forever, only try to set message hash values in DB if they have changed
* refactor: remove redundant inflation for profile image views throughout app
* refactor(wip): reducing layout inflation and starting to refactor the open group deletion issues taking a long time
* refactor(wip): refactoring group deletion to not iterate through and delete messages individually
* refactor(wip): refactoring group deletion to not iterate through and delete messages individually
* fix: group deletion optimisation
* build: bump build number
* build: bump build number and fix batch message receive retry logic
* fix: clear out open group deletes
* fix: update visible ConversationAdapter.kt binding for initial contact fetching and better traces for debugging background jobs
* fix: add in check for / force sync latest encryption key pair from linked devices if we already have that closed group
* Rename .java to .kt
* refactor: change MmsDatabase to kotlin to make list operations easier
* fix: nullable type
* fix: compilation issues and constants in .kt instead of .java
* fix: bug fix expiration timer on closed group recipient
* feat: use the job queue properly across executors
* feat: start on open group dispatcher-specific logic, probably a queue factory based on openGroupId if that is the same across new message and deletion jobs to ensure consistent entry and removal
* refactor: removing redundant code and fixing jobqueue per opengroup
* fix: allow attachments in note to self
* fix: make the minWidth in quote view bind max of text / title and body, wrapped ?
* fix: fixing up layouts and code view layouts
* fix: remove TODO, remove timestamp binding
* feat: fix view logic, avatars and padding, downloading attachments lazily (on bind), fixing potential crash, add WindowDebouncer.kt
* fix: NPE on viewModel recipient from removed thread while tearing down the Recipient observer in ConversationActivityV2.kt
* refactor: replace conversation notification debouncer handler with handlerthread, same as conversation list debouncer
* refactor: UI for groups and poller improvements
* fix: revert some changes in poller
* feat: add header back in for message requests
* refactor: remove Trace calls, add more conditions to the HomeDiffUtil for updating more efficiently
* feat: try update the home adapter if we get a profile picture modified event
* feat: bump build numbers
* fix: try to start with list in homeViewModel if we don't have already, render quotes to be width of attachment slide view instead of fixed
* fix: set channel to be conflated instead of no buffer
* fix: set unreads based off last local user message vs incrementing unreads to be all amount
* feat: add profile update flag, update build number
* fix: link preview thumbnails download on bind
* fix: centercrop placeholder in glide request
* feat: recycle the contact selection list and profile image in unbind
* fix: try to prevent user KP crash at weird times
* fix: remove additional log, improve attachment download success rate, fix share logs dialog issue
2022-06-08 09:12:34 +02:00
|
|
|
val attachments = proto.dataMessage.attachmentsList.mapNotNull { attachmentProto ->
|
|
|
|
val attachment = Attachment.fromProto(attachmentProto)
|
2021-03-15 03:35:05 +01:00
|
|
|
if (!attachment.isValid()) {
|
|
|
|
return@mapNotNull null
|
|
|
|
} else {
|
|
|
|
return@mapNotNull attachment
|
|
|
|
}
|
|
|
|
}
|
2020-12-18 06:48:45 +01:00
|
|
|
// Persist the message
|
|
|
|
message.threadID = threadID
|
Performance improvements and bug fixes (#869)
* refactor: fail on testSnode instead of recursively using up snode list. add call timeout on http client
* refactor: refactoring batch message receives and pollers
* refactor: reduce thread utils pool count to a 2 thread fixed pool. Do a check against pubkey instead of room names for oxenHostedOpenGroup
* refactor: caching lib with potential loader fixes and no-cache for giphy
* refactor: remove store and instead use ConcurrentHashMap with a backing update coroutine
* refactor: queue trim thread jobs instead of add every message processed
* fix: wrapping auth token and initial sync for open groups in a threadutils queued runnable, getting initial sync times down
* fix: fixing the user contacts cache in ConversationAdapter.kt
* refactor: improve polling and initial sync, move group joins from config messages into a background job fetching image.
* refactor: improving the job queuing for open groups, replacing placeholder avatar generation with a custom glide loader and archiving initial sync of open groups
* feat: add OpenGroupDeleteJob.kt
* feat: add open group delete job to process deletions after batch adding
* feat: add vacuum and fix job queue re-adding jobs forever, only try to set message hash values in DB if they have changed
* refactor: remove redundant inflation for profile image views throughout app
* refactor(wip): reducing layout inflation and starting to refactor the open group deletion issues taking a long time
* refactor(wip): refactoring group deletion to not iterate through and delete messages individually
* refactor(wip): refactoring group deletion to not iterate through and delete messages individually
* fix: group deletion optimisation
* build: bump build number
* build: bump build number and fix batch message receive retry logic
* fix: clear out open group deletes
* fix: update visible ConversationAdapter.kt binding for initial contact fetching and better traces for debugging background jobs
* fix: add in check for / force sync latest encryption key pair from linked devices if we already have that closed group
* Rename .java to .kt
* refactor: change MmsDatabase to kotlin to make list operations easier
* fix: nullable type
* fix: compilation issues and constants in .kt instead of .java
* fix: bug fix expiration timer on closed group recipient
* feat: use the job queue properly across executors
* feat: start on open group dispatcher-specific logic, probably a queue factory based on openGroupId if that is the same across new message and deletion jobs to ensure consistent entry and removal
* refactor: removing redundant code and fixing jobqueue per opengroup
* fix: allow attachments in note to self
* fix: make the minWidth in quote view bind max of text / title and body, wrapped ?
* fix: fixing up layouts and code view layouts
* fix: remove TODO, remove timestamp binding
* feat: fix view logic, avatars and padding, downloading attachments lazily (on bind), fixing potential crash, add WindowDebouncer.kt
* fix: NPE on viewModel recipient from removed thread while tearing down the Recipient observer in ConversationActivityV2.kt
* refactor: replace conversation notification debouncer handler with handlerthread, same as conversation list debouncer
* refactor: UI for groups and poller improvements
* fix: revert some changes in poller
* feat: add header back in for message requests
* refactor: remove Trace calls, add more conditions to the HomeDiffUtil for updating more efficiently
* feat: try update the home adapter if we get a profile picture modified event
* feat: bump build numbers
* fix: try to start with list in homeViewModel if we don't have already, render quotes to be width of attachment slide view instead of fixed
* fix: set channel to be conflated instead of no buffer
* fix: set unreads based off last local user message vs incrementing unreads to be all amount
* feat: add profile update flag, update build number
* fix: link preview thumbnails download on bind
* fix: centercrop placeholder in glide request
* feat: recycle the contact selection list and profile image in unbind
* fix: try to prevent user KP crash at weird times
* fix: remove additional log, improve attachment download success rate, fix share logs dialog issue
2022-06-08 09:12:34 +02:00
|
|
|
val messageID = storage.persist(
|
|
|
|
message, quoteModel, linkPreviews,
|
|
|
|
message.groupPublicKey, openGroupID,
|
|
|
|
attachments, runIncrement, runThreadUpdate
|
|
|
|
) ?: return null
|
2021-04-29 09:13:42 +02:00
|
|
|
val openGroupServerID = message.openGroupServerMessageID
|
|
|
|
if (openGroupServerID != null) {
|
2021-05-14 07:55:38 +02:00
|
|
|
val isSms = !(message.isMediaMessage() || attachments.isNotEmpty())
|
|
|
|
storage.setOpenGroupServerMessageID(messageID, openGroupServerID, threadID, isSms)
|
2021-04-29 09:13:42 +02:00
|
|
|
}
|
2021-01-11 23:58:38 +01:00
|
|
|
// Cancel any typing indicators if needed
|
|
|
|
cancelTypingIndicatorsIfNeeded(message.sender!!)
|
Performance improvements and bug fixes (#869)
* refactor: fail on testSnode instead of recursively using up snode list. add call timeout on http client
* refactor: refactoring batch message receives and pollers
* refactor: reduce thread utils pool count to a 2 thread fixed pool. Do a check against pubkey instead of room names for oxenHostedOpenGroup
* refactor: caching lib with potential loader fixes and no-cache for giphy
* refactor: remove store and instead use ConcurrentHashMap with a backing update coroutine
* refactor: queue trim thread jobs instead of add every message processed
* fix: wrapping auth token and initial sync for open groups in a threadutils queued runnable, getting initial sync times down
* fix: fixing the user contacts cache in ConversationAdapter.kt
* refactor: improve polling and initial sync, move group joins from config messages into a background job fetching image.
* refactor: improving the job queuing for open groups, replacing placeholder avatar generation with a custom glide loader and archiving initial sync of open groups
* feat: add OpenGroupDeleteJob.kt
* feat: add open group delete job to process deletions after batch adding
* feat: add vacuum and fix job queue re-adding jobs forever, only try to set message hash values in DB if they have changed
* refactor: remove redundant inflation for profile image views throughout app
* refactor(wip): reducing layout inflation and starting to refactor the open group deletion issues taking a long time
* refactor(wip): refactoring group deletion to not iterate through and delete messages individually
* refactor(wip): refactoring group deletion to not iterate through and delete messages individually
* fix: group deletion optimisation
* build: bump build number
* build: bump build number and fix batch message receive retry logic
* fix: clear out open group deletes
* fix: update visible ConversationAdapter.kt binding for initial contact fetching and better traces for debugging background jobs
* fix: add in check for / force sync latest encryption key pair from linked devices if we already have that closed group
* Rename .java to .kt
* refactor: change MmsDatabase to kotlin to make list operations easier
* fix: nullable type
* fix: compilation issues and constants in .kt instead of .java
* fix: bug fix expiration timer on closed group recipient
* feat: use the job queue properly across executors
* feat: start on open group dispatcher-specific logic, probably a queue factory based on openGroupId if that is the same across new message and deletion jobs to ensure consistent entry and removal
* refactor: removing redundant code and fixing jobqueue per opengroup
* fix: allow attachments in note to self
* fix: make the minWidth in quote view bind max of text / title and body, wrapped ?
* fix: fixing up layouts and code view layouts
* fix: remove TODO, remove timestamp binding
* feat: fix view logic, avatars and padding, downloading attachments lazily (on bind), fixing potential crash, add WindowDebouncer.kt
* fix: NPE on viewModel recipient from removed thread while tearing down the Recipient observer in ConversationActivityV2.kt
* refactor: replace conversation notification debouncer handler with handlerthread, same as conversation list debouncer
* refactor: UI for groups and poller improvements
* fix: revert some changes in poller
* feat: add header back in for message requests
* refactor: remove Trace calls, add more conditions to the HomeDiffUtil for updating more efficiently
* feat: try update the home adapter if we get a profile picture modified event
* feat: bump build numbers
* fix: try to start with list in homeViewModel if we don't have already, render quotes to be width of attachment slide view instead of fixed
* fix: set channel to be conflated instead of no buffer
* fix: set unreads based off last local user message vs incrementing unreads to be all amount
* feat: add profile update flag, update build number
* fix: link preview thumbnails download on bind
* fix: centercrop placeholder in glide request
* feat: recycle the contact selection list and profile image in unbind
* fix: try to prevent user KP crash at weird times
* fix: remove additional log, improve attachment download success rate, fix share logs dialog issue
2022-06-08 09:12:34 +02:00
|
|
|
return messageID
|
2020-12-07 05:22:02 +01:00
|
|
|
}
|
2021-04-30 08:09:11 +02:00
|
|
|
//endregion
|
2020-12-07 05:22:02 +01:00
|
|
|
|
2021-05-17 07:18:41 +02:00
|
|
|
// region Closed Groups
|
2021-02-09 01:45:38 +01:00
|
|
|
private fun MessageReceiver.handleClosedGroupControlMessage(message: ClosedGroupControlMessage) {
|
2020-12-07 05:22:02 +01:00
|
|
|
when (message.kind!!) {
|
2021-02-09 01:45:38 +01:00
|
|
|
is ClosedGroupControlMessage.Kind.New -> handleNewClosedGroup(message)
|
|
|
|
is ClosedGroupControlMessage.Kind.EncryptionKeyPair -> handleClosedGroupEncryptionKeyPair(message)
|
|
|
|
is ClosedGroupControlMessage.Kind.NameChange -> handleClosedGroupNameChanged(message)
|
|
|
|
is ClosedGroupControlMessage.Kind.MembersAdded -> handleClosedGroupMembersAdded(message)
|
|
|
|
is ClosedGroupControlMessage.Kind.MembersRemoved -> handleClosedGroupMembersRemoved(message)
|
2021-03-04 05:16:47 +01:00
|
|
|
is ClosedGroupControlMessage.Kind.MemberLeft -> handleClosedGroupMemberLeft(message)
|
2020-12-07 05:22:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-09 01:45:38 +01:00
|
|
|
private fun MessageReceiver.handleNewClosedGroup(message: ClosedGroupControlMessage) {
|
|
|
|
val kind = message.kind!! as? ClosedGroupControlMessage.Kind.New ?: return
|
2022-03-04 07:46:39 +01:00
|
|
|
val recipient = Recipient.from(MessagingModuleConfiguration.shared.context, Address.fromSerialized(message.sender!!), false)
|
|
|
|
if (!recipient.isApproved) return
|
2021-02-09 01:45:38 +01:00
|
|
|
val groupPublicKey = kind.publicKey.toByteArray().toHexString()
|
|
|
|
val members = kind.members.map { it.toByteArray().toHexString() }
|
|
|
|
val admins = kind.admins.map { it.toByteArray().toHexString() }
|
2021-06-21 06:03:08 +02:00
|
|
|
val expireTimer = kind.expirationTimer
|
2021-06-09 06:31:05 +02:00
|
|
|
handleNewClosedGroup(message.sender!!, message.sentTimestamp!!, groupPublicKey, kind.name, kind.encryptionKeyPair!!, members, admins, message.sentTimestamp!!, expireTimer)
|
2021-02-09 01:45:38 +01:00
|
|
|
}
|
|
|
|
|
2021-06-09 06:31:05 +02:00
|
|
|
private fun handleNewClosedGroup(sender: String, sentTimestamp: Long, groupPublicKey: String, name: String, encryptionKeyPair: ECKeyPair, members: List<String>, admins: List<String>, formationTimestamp: Long, expireTimer: Int) {
|
2021-04-26 03:14:45 +02:00
|
|
|
val context = MessagingModuleConfiguration.shared.context
|
|
|
|
val storage = MessagingModuleConfiguration.shared.storage
|
2021-06-10 09:34:48 +02:00
|
|
|
val userPublicKey = TextSecurePreferences.getLocalNumber(context)
|
2020-12-07 05:22:02 +01:00
|
|
|
// Create the group
|
2021-02-09 01:45:38 +01:00
|
|
|
val groupID = GroupUtil.doubleEncodeGroupID(groupPublicKey)
|
2021-09-15 08:08:40 +02:00
|
|
|
val groupExists = storage.getGroup(groupID) != null
|
|
|
|
if (groupExists) {
|
2020-12-07 05:22:02 +01:00
|
|
|
// Update the group
|
2021-06-07 06:46:54 +02:00
|
|
|
if (!storage.isGroupActive(groupPublicKey)) {
|
2021-06-10 09:34:48 +02:00
|
|
|
// Clear zombie list if the group wasn't active
|
2021-06-04 08:32:19 +02:00
|
|
|
storage.setZombieMembers(groupID, listOf())
|
2021-06-10 09:34:48 +02:00
|
|
|
// Update the formation timestamp
|
|
|
|
storage.updateFormationTimestamp(groupID, formationTimestamp)
|
2021-06-04 08:32:19 +02:00
|
|
|
}
|
2020-12-10 05:33:57 +01:00
|
|
|
storage.updateTitle(groupID, name)
|
|
|
|
storage.updateMembers(groupID, members.map { Address.fromSerialized(it) })
|
2020-12-07 05:22:02 +01:00
|
|
|
} else {
|
2020-12-10 05:33:57 +01:00
|
|
|
storage.createGroup(groupID, name, LinkedList(members.map { Address.fromSerialized(it) }),
|
2021-05-13 07:42:14 +02:00
|
|
|
null, null, LinkedList(admins.map { Address.fromSerialized(it) }), formationTimestamp)
|
2020-12-07 05:22:02 +01:00
|
|
|
}
|
2020-12-10 05:33:57 +01:00
|
|
|
storage.setProfileSharing(Address.fromSerialized(groupID), true)
|
2020-12-07 05:22:02 +01:00
|
|
|
// Add the group to the user's set of public keys to poll for
|
2021-02-09 01:45:38 +01:00
|
|
|
storage.addClosedGroupPublicKey(groupPublicKey)
|
|
|
|
// Store the encryption key pair
|
|
|
|
storage.addClosedGroupEncryptionKeyPair(encryptionKeyPair, groupPublicKey)
|
2021-06-09 06:31:05 +02:00
|
|
|
// Set expiration timer
|
|
|
|
storage.setExpirationTimer(groupID, expireTimer)
|
2021-02-09 01:45:38 +01:00
|
|
|
// Notify the PN server
|
|
|
|
PushNotificationAPI.performOperation(PushNotificationAPI.ClosedGroupOperation.Subscribe, groupPublicKey, storage.getUserPublicKey()!!)
|
2021-06-10 09:34:48 +02:00
|
|
|
// Notify the user
|
2021-09-15 08:08:40 +02:00
|
|
|
if (userPublicKey == sender && !groupExists) {
|
2021-06-10 09:34:48 +02:00
|
|
|
val threadID = storage.getOrCreateThreadIdFor(Address.fromSerialized(groupID))
|
|
|
|
storage.insertOutgoingInfoMessage(context, groupID, SignalServiceGroup.Type.CREATION, name, members, admins, threadID, sentTimestamp)
|
2021-09-15 08:08:40 +02:00
|
|
|
} else if (userPublicKey != sender) {
|
2021-06-10 09:34:48 +02:00
|
|
|
storage.insertIncomingInfoMessage(context, sender, groupID, SignalServiceGroup.Type.CREATION, name, members, admins, sentTimestamp)
|
|
|
|
}
|
2021-05-21 05:12:34 +02:00
|
|
|
// Start polling
|
|
|
|
ClosedGroupPollerV2.shared.startPolling(groupPublicKey)
|
2020-12-07 05:22:02 +01:00
|
|
|
}
|
|
|
|
|
2021-02-09 01:45:38 +01:00
|
|
|
private fun MessageReceiver.handleClosedGroupEncryptionKeyPair(message: ClosedGroupControlMessage) {
|
|
|
|
// Prepare
|
2021-04-26 03:14:45 +02:00
|
|
|
val storage = MessagingModuleConfiguration.shared.storage
|
2021-02-09 01:45:38 +01:00
|
|
|
val senderPublicKey = message.sender ?: return
|
|
|
|
val kind = message.kind!! as? ClosedGroupControlMessage.Kind.EncryptionKeyPair ?: return
|
2021-04-23 08:35:24 +02:00
|
|
|
var groupPublicKey = kind.publicKey?.toByteArray()?.toHexString()
|
|
|
|
if (groupPublicKey.isNullOrEmpty()) groupPublicKey = message.groupPublicKey ?: return
|
2021-01-08 01:13:05 +01:00
|
|
|
val userPublicKey = storage.getUserPublicKey()!!
|
2021-02-09 01:45:38 +01:00
|
|
|
val userKeyPair = storage.getUserX25519KeyPair()
|
|
|
|
// Unwrap the message
|
|
|
|
val groupID = GroupUtil.doubleEncodeGroupID(groupPublicKey)
|
|
|
|
val group = storage.getGroup(groupID) ?: run {
|
2021-05-13 07:42:14 +02:00
|
|
|
Log.d("Loki", "Ignoring closed group encryption key pair for nonexistent group.")
|
2021-02-09 01:45:38 +01:00
|
|
|
return
|
|
|
|
}
|
2021-03-23 00:00:51 +01:00
|
|
|
if (!group.isActive) {
|
2021-05-13 07:42:14 +02:00
|
|
|
Log.d("Loki", "Ignoring closed group encryption key pair for inactive group.")
|
2021-03-23 00:00:51 +01:00
|
|
|
return
|
|
|
|
}
|
2021-03-26 05:46:37 +01:00
|
|
|
if (!group.admins.map { it.toString() }.contains(senderPublicKey)) {
|
2021-04-23 06:07:10 +02:00
|
|
|
Log.d("Loki", "Ignoring closed group encryption key pair from non-admin.")
|
2021-02-09 01:45:38 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
// Find our wrapper and decrypt it if possible
|
2021-03-26 05:46:37 +01:00
|
|
|
val wrapper = kind.wrappers.firstOrNull { it.publicKey!! == userPublicKey } ?: return
|
2021-02-09 01:45:38 +01:00
|
|
|
val encryptedKeyPair = wrapper.encryptedKeyPair!!.toByteArray()
|
2021-05-13 07:27:08 +02:00
|
|
|
val plaintext = MessageDecrypter.decrypt(encryptedKeyPair, userKeyPair).first
|
2021-02-09 01:45:38 +01:00
|
|
|
// Parse it
|
|
|
|
val proto = SignalServiceProtos.KeyPair.parseFrom(plaintext)
|
|
|
|
val keyPair = ECKeyPair(DjbECPublicKey(proto.publicKey.toByteArray().removing05PrefixIfNeeded()), DjbECPrivateKey(proto.privateKey.toByteArray()))
|
2021-02-10 06:48:03 +01:00
|
|
|
// Store it if needed
|
|
|
|
val closedGroupEncryptionKeyPairs = storage.getClosedGroupEncryptionKeyPairs(groupPublicKey)
|
|
|
|
if (closedGroupEncryptionKeyPairs.contains(keyPair)) {
|
|
|
|
Log.d("Loki", "Ignoring duplicate closed group encryption key pair.")
|
|
|
|
return
|
|
|
|
}
|
2021-02-09 01:45:38 +01:00
|
|
|
storage.addClosedGroupEncryptionKeyPair(keyPair, groupPublicKey)
|
2021-05-13 07:42:14 +02:00
|
|
|
Log.d("Loki", "Received a new closed group encryption key pair.")
|
2021-02-09 01:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private fun MessageReceiver.handleClosedGroupNameChanged(message: ClosedGroupControlMessage) {
|
2021-04-26 03:14:45 +02:00
|
|
|
val context = MessagingModuleConfiguration.shared.context
|
|
|
|
val storage = MessagingModuleConfiguration.shared.storage
|
2021-03-26 05:46:37 +01:00
|
|
|
val userPublicKey = TextSecurePreferences.getLocalNumber(context)
|
2021-02-09 01:45:38 +01:00
|
|
|
val senderPublicKey = message.sender ?: return
|
|
|
|
val kind = message.kind!! as? ClosedGroupControlMessage.Kind.NameChange ?: return
|
|
|
|
val groupPublicKey = message.groupPublicKey ?: return
|
|
|
|
// Check that the sender is a member of the group (before the update)
|
|
|
|
val groupID = GroupUtil.doubleEncodeGroupID(groupPublicKey)
|
|
|
|
val group = storage.getGroup(groupID) ?: run {
|
2021-05-13 07:42:14 +02:00
|
|
|
Log.d("Loki", "Ignoring closed group update for nonexistent group.")
|
2021-02-09 01:45:38 +01:00
|
|
|
return
|
|
|
|
}
|
2021-03-23 00:00:51 +01:00
|
|
|
if (!group.isActive) {
|
2021-05-13 07:42:14 +02:00
|
|
|
Log.d("Loki", "Ignoring closed group update for inactive group.")
|
2021-03-23 00:00:51 +01:00
|
|
|
return
|
|
|
|
}
|
2021-02-09 01:45:38 +01:00
|
|
|
// Check common group update logic
|
|
|
|
if (!isValidGroupUpdate(group, message.sentTimestamp!!, senderPublicKey)) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
val members = group.members.map { it.serialize() }
|
|
|
|
val admins = group.admins.map { it.serialize() }
|
|
|
|
val name = kind.name
|
|
|
|
storage.updateTitle(groupID, name)
|
2021-03-26 05:46:37 +01:00
|
|
|
// Notify the user
|
|
|
|
if (userPublicKey == senderPublicKey) {
|
|
|
|
val threadID = storage.getOrCreateThreadIdFor(Address.fromSerialized(groupID))
|
2021-04-14 08:37:04 +02:00
|
|
|
storage.insertOutgoingInfoMessage(context, groupID, SignalServiceGroup.Type.NAME_CHANGE, name, members, admins, threadID, message.sentTimestamp!!)
|
2021-03-26 05:46:37 +01:00
|
|
|
} else {
|
2021-04-14 08:37:04 +02:00
|
|
|
storage.insertIncomingInfoMessage(context, senderPublicKey, groupID, SignalServiceGroup.Type.NAME_CHANGE, name, members, admins, message.sentTimestamp!!)
|
2021-03-26 05:46:37 +01:00
|
|
|
}
|
2021-02-09 01:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private fun MessageReceiver.handleClosedGroupMembersAdded(message: ClosedGroupControlMessage) {
|
2021-04-26 03:14:45 +02:00
|
|
|
val context = MessagingModuleConfiguration.shared.context
|
|
|
|
val storage = MessagingModuleConfiguration.shared.storage
|
2021-03-12 00:21:09 +01:00
|
|
|
val userPublicKey = storage.getUserPublicKey()!!
|
2021-02-09 01:45:38 +01:00
|
|
|
val senderPublicKey = message.sender ?: return
|
|
|
|
val kind = message.kind!! as? ClosedGroupControlMessage.Kind.MembersAdded ?: return
|
|
|
|
val groupPublicKey = message.groupPublicKey ?: return
|
|
|
|
val groupID = GroupUtil.doubleEncodeGroupID(groupPublicKey)
|
|
|
|
val group = storage.getGroup(groupID) ?: run {
|
2021-05-13 07:42:14 +02:00
|
|
|
Log.d("Loki", "Ignoring closed group update for nonexistent group.")
|
2021-01-08 01:13:05 +01:00
|
|
|
return
|
|
|
|
}
|
2021-03-23 00:00:51 +01:00
|
|
|
if (!group.isActive) {
|
2021-05-13 07:42:14 +02:00
|
|
|
Log.d("Loki", "Ignoring closed group update for inactive group.")
|
2021-03-23 00:00:51 +01:00
|
|
|
return
|
|
|
|
}
|
2021-03-12 00:21:09 +01:00
|
|
|
if (!isValidGroupUpdate(group, message.sentTimestamp!!, senderPublicKey)) { return }
|
2021-02-09 01:45:38 +01:00
|
|
|
val name = group.title
|
|
|
|
// Check common group update logic
|
|
|
|
val members = group.members.map { it.serialize() }
|
|
|
|
val admins = group.admins.map { it.serialize() }
|
|
|
|
|
|
|
|
val updateMembers = kind.members.map { it.toByteArray().toHexString() }
|
|
|
|
val newMembers = members + updateMembers
|
|
|
|
storage.updateMembers(groupID, newMembers.map { Address.fromSerialized(it) })
|
2021-04-26 08:33:54 +02:00
|
|
|
|
2021-06-04 08:32:19 +02:00
|
|
|
// Update zombie members in case the added members are zombies
|
2021-05-25 08:15:51 +02:00
|
|
|
val zombies = storage.getZombieMembers(groupID)
|
2021-06-04 08:32:19 +02:00
|
|
|
if (zombies.intersect(updateMembers).isNotEmpty()) {
|
2021-05-25 08:15:51 +02:00
|
|
|
storage.setZombieMembers(groupID, zombies.minus(updateMembers).map { Address.fromSerialized(it) })
|
2021-06-04 08:32:19 +02:00
|
|
|
}
|
2021-05-06 06:49:28 +02:00
|
|
|
|
2021-03-26 05:46:37 +01:00
|
|
|
// Notify the user
|
2021-03-12 00:21:09 +01:00
|
|
|
if (userPublicKey == senderPublicKey) {
|
|
|
|
val threadID = storage.getOrCreateThreadIdFor(Address.fromSerialized(groupID))
|
2021-04-14 08:37:04 +02:00
|
|
|
storage.insertOutgoingInfoMessage(context, groupID, SignalServiceGroup.Type.MEMBER_ADDED, name, updateMembers, admins, threadID, message.sentTimestamp!!)
|
2021-03-12 00:21:09 +01:00
|
|
|
} else {
|
2021-04-14 08:37:04 +02:00
|
|
|
storage.insertIncomingInfoMessage(context, senderPublicKey, groupID, SignalServiceGroup.Type.MEMBER_ADDED, name, updateMembers, admins, message.sentTimestamp!!)
|
2021-03-12 00:21:09 +01:00
|
|
|
}
|
|
|
|
if (userPublicKey in admins) {
|
2021-05-13 07:42:14 +02:00
|
|
|
// Send the latest encryption key pair to the added members if the current user is the admin of the group
|
|
|
|
//
|
|
|
|
// This fixes a race condition where:
|
|
|
|
// • A member removes another member.
|
|
|
|
// • A member adds someone to the group and sends them the latest group key pair.
|
|
|
|
// • The admin is offline during all of this.
|
|
|
|
// • When the admin comes back online they see the member removed message and generate + distribute a new key pair,
|
|
|
|
// but they don't know about the added member yet.
|
|
|
|
// • Now they see the member added message.
|
|
|
|
//
|
|
|
|
// Without the code below, the added member(s) would never get the key pair that was generated by the admin when they saw
|
|
|
|
// the member removed message.
|
2021-05-13 08:14:54 +02:00
|
|
|
val encryptionKeyPair = pendingKeyPairs[groupPublicKey]?.orNull()
|
2021-05-13 07:42:14 +02:00
|
|
|
?: storage.getLatestClosedGroupEncryptionKeyPair(groupPublicKey)
|
2021-03-12 00:21:09 +01:00
|
|
|
if (encryptionKeyPair == null) {
|
2021-06-15 08:47:35 +02:00
|
|
|
Log.d("Loki", "Couldn't get encryption key pair for closed group.")
|
2021-03-12 00:21:09 +01:00
|
|
|
} else {
|
|
|
|
for (user in updateMembers) {
|
|
|
|
MessageSender.sendEncryptionKeyPair(groupPublicKey, encryptionKeyPair, setOf(user), targetUser = user, force = false)
|
|
|
|
}
|
2021-02-11 06:57:43 +01:00
|
|
|
}
|
|
|
|
}
|
2020-12-07 05:22:02 +01:00
|
|
|
}
|
|
|
|
|
2021-04-23 06:07:10 +02:00
|
|
|
/// Removes the given members from the group IF
|
|
|
|
/// • it wasn't the admin that was removed (that should happen through a `MEMBER_LEFT` message).
|
|
|
|
/// • the admin sent the message (only the admin can truly remove members).
|
|
|
|
/// If we're among the users that were removed, delete all encryption key pairs and the group public key, unsubscribe
|
|
|
|
/// from push notifications for this closed group, and remove the given members from the zombie list for this group.
|
2021-02-09 01:45:38 +01:00
|
|
|
private fun MessageReceiver.handleClosedGroupMembersRemoved(message: ClosedGroupControlMessage) {
|
2021-04-26 03:14:45 +02:00
|
|
|
val context = MessagingModuleConfiguration.shared.context
|
|
|
|
val storage = MessagingModuleConfiguration.shared.storage
|
2021-02-09 01:45:38 +01:00
|
|
|
val userPublicKey = storage.getUserPublicKey()!!
|
|
|
|
val senderPublicKey = message.sender ?: return
|
|
|
|
val kind = message.kind!! as? ClosedGroupControlMessage.Kind.MembersRemoved ?: return
|
|
|
|
val groupPublicKey = message.groupPublicKey ?: return
|
|
|
|
val groupID = GroupUtil.doubleEncodeGroupID(groupPublicKey)
|
|
|
|
val group = storage.getGroup(groupID) ?: run {
|
2021-05-13 07:42:14 +02:00
|
|
|
Log.d("Loki", "Ignoring closed group update for nonexistent group.")
|
2021-01-08 01:13:05 +01:00
|
|
|
return
|
|
|
|
}
|
2021-03-23 00:00:51 +01:00
|
|
|
if (!group.isActive) {
|
2021-05-13 07:42:14 +02:00
|
|
|
Log.d("Loki", "Ignoring closed group update for inactive group.")
|
2021-03-23 00:00:51 +01:00
|
|
|
return
|
|
|
|
}
|
2021-02-09 01:45:38 +01:00
|
|
|
val name = group.title
|
|
|
|
// Check common group update logic
|
|
|
|
val members = group.members.map { it.serialize() }
|
|
|
|
val admins = group.admins.map { it.toString() }
|
2021-05-13 07:42:14 +02:00
|
|
|
val removedMembers = kind.members.map { it.toByteArray().toHexString() }
|
2021-05-25 08:15:51 +02:00
|
|
|
val zombies: Set<String> = storage.getZombieMembers(groupID)
|
2021-04-23 06:07:10 +02:00
|
|
|
// Check that the admin wasn't removed
|
2021-05-13 07:42:14 +02:00
|
|
|
if (removedMembers.contains(admins.first())) {
|
2021-04-23 06:07:10 +02:00
|
|
|
Log.d("Loki", "Ignoring invalid closed group update.")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// Check that the message was sent by the group admin
|
|
|
|
if (!admins.contains(senderPublicKey)) {
|
|
|
|
Log.d("Loki", "Ignoring invalid closed group update.")
|
|
|
|
return
|
|
|
|
}
|
2021-02-09 01:45:38 +01:00
|
|
|
if (!isValidGroupUpdate(group, message.sentTimestamp!!, senderPublicKey)) { return }
|
2021-05-13 07:42:14 +02:00
|
|
|
// If the admin leaves the group is disbanded
|
|
|
|
val didAdminLeave = admins.any { it in removedMembers }
|
|
|
|
val newMembers = members - removedMembers
|
|
|
|
// A user should be posting a MEMBERS_LEFT in case they leave, so this shouldn't be encountered
|
|
|
|
val senderLeft = senderPublicKey in removedMembers
|
2021-02-09 01:45:38 +01:00
|
|
|
if (senderLeft) {
|
2021-05-13 07:42:14 +02:00
|
|
|
Log.d("Loki", "Received a MEMBERS_REMOVED instead of a MEMBERS_LEFT from sender: $senderPublicKey.")
|
2021-02-09 01:45:38 +01:00
|
|
|
}
|
2021-05-13 07:42:14 +02:00
|
|
|
val wasCurrentUserRemoved = userPublicKey in removedMembers
|
|
|
|
// Admin should send a MEMBERS_LEFT message but handled here just in case
|
2021-02-09 01:45:38 +01:00
|
|
|
if (didAdminLeave || wasCurrentUserRemoved) {
|
|
|
|
disableLocalGroupAndUnsubscribe(groupPublicKey, groupID, userPublicKey)
|
|
|
|
} else {
|
|
|
|
storage.updateMembers(groupID, newMembers.map { Address.fromSerialized(it) })
|
2021-05-25 07:45:43 +02:00
|
|
|
// Update zombie members
|
2021-05-25 08:15:51 +02:00
|
|
|
storage.setZombieMembers(groupID, zombies.minus(removedMembers).map { Address.fromSerialized(it) })
|
2021-02-09 01:45:38 +01:00
|
|
|
}
|
2021-05-25 07:45:43 +02:00
|
|
|
|
2021-03-26 05:46:37 +01:00
|
|
|
// Notify the user
|
2021-05-25 07:45:43 +02:00
|
|
|
val type = if (senderLeft) SignalServiceGroup.Type.QUIT else SignalServiceGroup.Type.MEMBER_REMOVED
|
2021-05-13 07:42:14 +02:00
|
|
|
// We don't display zombie members in the notification as users have already been notified when those members left
|
|
|
|
val notificationMembers = removedMembers.minus(zombies)
|
2021-04-26 08:33:54 +02:00
|
|
|
if (notificationMembers.isNotEmpty()) {
|
2021-05-13 07:42:14 +02:00
|
|
|
// No notification to display when only zombies have been removed
|
2021-04-26 08:33:54 +02:00
|
|
|
if (userPublicKey == senderPublicKey) {
|
|
|
|
val threadID = storage.getOrCreateThreadIdFor(Address.fromSerialized(groupID))
|
|
|
|
storage.insertOutgoingInfoMessage(context, groupID, type, name, notificationMembers, admins, threadID, message.sentTimestamp!!)
|
|
|
|
} else {
|
|
|
|
storage.insertIncomingInfoMessage(context, senderPublicKey, groupID, type, name, notificationMembers, admins, message.sentTimestamp!!)
|
|
|
|
}
|
2021-03-26 05:46:37 +01:00
|
|
|
}
|
2021-02-09 01:45:38 +01:00
|
|
|
}
|
|
|
|
|
2021-04-23 06:07:10 +02:00
|
|
|
/// If a regular member left:
|
|
|
|
/// • Mark them as a zombie (to be removed by the admin later).
|
|
|
|
/// If the admin left:
|
|
|
|
/// • Unsubscribe from PNs, delete the group public key, etc. as the group will be disbanded.
|
2021-02-09 01:45:38 +01:00
|
|
|
private fun MessageReceiver.handleClosedGroupMemberLeft(message: ClosedGroupControlMessage) {
|
2021-04-26 03:14:45 +02:00
|
|
|
val context = MessagingModuleConfiguration.shared.context
|
|
|
|
val storage = MessagingModuleConfiguration.shared.storage
|
2021-02-09 01:45:38 +01:00
|
|
|
val senderPublicKey = message.sender ?: return
|
|
|
|
val userPublicKey = storage.getUserPublicKey()!!
|
2021-02-10 06:48:03 +01:00
|
|
|
if (message.kind!! !is ClosedGroupControlMessage.Kind.MemberLeft) return
|
2021-02-09 01:45:38 +01:00
|
|
|
val groupPublicKey = message.groupPublicKey ?: return
|
|
|
|
val groupID = GroupUtil.doubleEncodeGroupID(groupPublicKey)
|
|
|
|
val group = storage.getGroup(groupID) ?: run {
|
2021-05-13 07:42:14 +02:00
|
|
|
Log.d("Loki", "Ignoring closed group update for nonexistent group.")
|
2021-02-09 01:45:38 +01:00
|
|
|
return
|
|
|
|
}
|
2021-03-23 00:00:51 +01:00
|
|
|
if (!group.isActive) {
|
2021-05-13 07:42:14 +02:00
|
|
|
Log.d("Loki", "Ignoring closed group update for inactive group.")
|
2021-03-23 00:00:51 +01:00
|
|
|
return
|
|
|
|
}
|
2021-02-09 01:45:38 +01:00
|
|
|
val name = group.title
|
|
|
|
// Check common group update logic
|
|
|
|
val members = group.members.map { it.serialize() }
|
|
|
|
val admins = group.admins.map { it.toString() }
|
|
|
|
if (!isValidGroupUpdate(group, message.sentTimestamp!!, senderPublicKey)) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// If admin leaves the group is disbanded
|
|
|
|
val didAdminLeave = admins.contains(senderPublicKey)
|
|
|
|
val updatedMemberList = members - senderPublicKey
|
2021-03-26 05:46:37 +01:00
|
|
|
val userLeft = (userPublicKey == senderPublicKey)
|
|
|
|
if (didAdminLeave || userLeft) {
|
2021-02-09 01:45:38 +01:00
|
|
|
disableLocalGroupAndUnsubscribe(groupPublicKey, groupID, userPublicKey)
|
|
|
|
} else {
|
|
|
|
storage.updateMembers(groupID, updatedMemberList.map { Address.fromSerialized(it) })
|
2021-05-13 07:42:14 +02:00
|
|
|
// Update zombie members
|
2021-05-21 07:02:34 +02:00
|
|
|
val zombies = storage.getZombieMembers(groupID)
|
|
|
|
storage.setZombieMembers(groupID, zombies.plus(senderPublicKey).map { Address.fromSerialized(it) })
|
2021-02-09 01:45:38 +01:00
|
|
|
}
|
2021-03-26 05:46:37 +01:00
|
|
|
// Notify the user
|
|
|
|
if (userLeft) {
|
|
|
|
val threadID = storage.getOrCreateThreadIdFor(Address.fromSerialized(groupID))
|
2021-04-14 08:37:04 +02:00
|
|
|
storage.insertOutgoingInfoMessage(context, groupID, SignalServiceGroup.Type.QUIT, name, members, admins, threadID, message.sentTimestamp!!)
|
2021-03-26 05:46:37 +01:00
|
|
|
} else {
|
2021-04-14 08:37:04 +02:00
|
|
|
storage.insertIncomingInfoMessage(context, senderPublicKey, groupID, SignalServiceGroup.Type.QUIT, name, members, admins, message.sentTimestamp!!)
|
2021-03-26 05:46:37 +01:00
|
|
|
}
|
2021-02-09 01:45:38 +01:00
|
|
|
}
|
|
|
|
|
2021-05-13 07:42:14 +02:00
|
|
|
private fun isValidGroupUpdate(group: GroupRecord, sentTimestamp: Long, senderPublicKey: String): Boolean {
|
2021-02-09 01:45:38 +01:00
|
|
|
val oldMembers = group.members.map { it.serialize() }
|
|
|
|
// Check that the message isn't from before the group was created
|
2021-02-16 01:14:27 +01:00
|
|
|
if (group.formationTimestamp > sentTimestamp) {
|
2021-06-15 08:47:35 +02:00
|
|
|
Log.d("Loki", "Ignoring closed group update from before thread was created.")
|
2021-02-09 01:45:38 +01:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
// Check that the sender is a member of the group (before the update)
|
|
|
|
if (senderPublicKey !in oldMembers) {
|
2021-06-15 08:47:35 +02:00
|
|
|
Log.d("Loki", "Ignoring closed group info message from non-member.")
|
2021-02-09 01:45:38 +01:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2021-02-09 04:45:22 +01:00
|
|
|
fun MessageReceiver.disableLocalGroupAndUnsubscribe(groupPublicKey: String, groupID: String, userPublicKey: String) {
|
2021-04-26 03:14:45 +02:00
|
|
|
val storage = MessagingModuleConfiguration.shared.storage
|
2021-02-09 01:45:38 +01:00
|
|
|
storage.removeClosedGroupPublicKey(groupPublicKey)
|
|
|
|
// Remove the key pairs
|
|
|
|
storage.removeAllClosedGroupEncryptionKeyPairs(groupPublicKey)
|
|
|
|
// Mark the group as inactive
|
|
|
|
storage.setActive(groupID, false)
|
|
|
|
storage.removeMember(groupID, Address.fromSerialized(userPublicKey))
|
|
|
|
// Notify the PN server
|
|
|
|
PushNotificationAPI.performOperation(PushNotificationAPI.ClosedGroupOperation.Unsubscribe, groupPublicKey, userPublicKey)
|
2021-05-21 05:12:34 +02:00
|
|
|
// Stop polling
|
|
|
|
ClosedGroupPollerV2.shared.stopPolling(groupPublicKey)
|
2021-04-30 08:09:11 +02:00
|
|
|
}
|
2021-05-17 07:18:41 +02:00
|
|
|
// endregion
|