123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168 |
- /*
- * Nextcloud Talk application
- *
- * @author Mario Danic
- * @author Marcel Hibbe
- * @author Andy Scherzinger
- * @author Tim Krüger
- * Copyright (C) 2021 Tim Krüger <t@timkrueger.me>
- * Copyright (C) 2021 Andy Scherzinger <info@andy-scherzinger.de>
- * Copyright (C) 2021 Marcel Hibbe <dev@mhibbe.de>
- * Copyright (C) 2017-2019 Mario Danic <mario@lovelyhq.com>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- package com.nextcloud.talk.controllers
- import android.Manifest
- import android.annotation.SuppressLint
- import android.app.Activity.RESULT_OK
- import android.content.ClipData
- import android.content.ClipboardManager
- import android.content.Context
- import android.content.Intent
- import android.content.pm.PackageManager
- import android.content.res.AssetFileDescriptor
- import android.content.res.Resources
- import android.database.Cursor
- import android.graphics.Bitmap
- import android.graphics.drawable.ColorDrawable
- import android.media.MediaPlayer
- import android.media.MediaRecorder
- import android.net.Uri
- import android.os.Build
- import android.os.Build.VERSION_CODES.O
- import android.os.Bundle
- import android.os.Handler
- import android.os.Parcelable
- import android.os.SystemClock
- import android.os.VibrationEffect
- import android.os.Vibrator
- import android.provider.ContactsContract
- import android.text.Editable
- import android.text.InputFilter
- import android.text.TextUtils
- import android.text.TextWatcher
- import android.util.Log
- import android.util.TypedValue
- import android.view.Gravity
- import android.view.Menu
- import android.view.MenuInflater
- import android.view.MenuItem
- import android.view.MotionEvent
- import android.view.View
- import android.view.animation.AlphaAnimation
- import android.view.animation.Animation
- import android.view.animation.LinearInterpolator
- import android.widget.AbsListView
- import android.widget.ImageButton
- import android.widget.ImageView
- import android.widget.PopupMenu
- import android.widget.RelativeLayout
- import android.widget.Toast
- import androidx.appcompat.view.ContextThemeWrapper
- import androidx.core.content.ContextCompat
- import androidx.core.content.FileProvider
- import androidx.core.content.PermissionChecker
- import androidx.core.graphics.drawable.RoundedBitmapDrawableFactory
- import androidx.core.widget.doAfterTextChanged
- import androidx.emoji.text.EmojiCompat
- import androidx.emoji.widget.EmojiTextView
- import androidx.recyclerview.widget.ItemTouchHelper
- import androidx.recyclerview.widget.LinearLayoutManager
- import androidx.recyclerview.widget.RecyclerView
- import androidx.work.Data
- import androidx.work.OneTimeWorkRequest
- import androidx.work.WorkInfo
- import androidx.work.WorkManager
- import autodagger.AutoInjector
- import coil.load
- import com.bluelinelabs.conductor.RouterTransaction
- import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler
- import com.bluelinelabs.conductor.changehandler.VerticalChangeHandler
- import com.facebook.common.executors.UiThreadImmediateExecutorService
- import com.facebook.common.references.CloseableReference
- import com.facebook.datasource.DataSource
- import com.facebook.drawee.backends.pipeline.Fresco
- import com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber
- import com.facebook.imagepipeline.image.CloseableImage
- import com.google.android.flexbox.FlexboxLayout
- import com.nextcloud.talk.BuildConfig
- import com.nextcloud.talk.R
- import com.nextcloud.talk.activities.CallActivity
- import com.nextcloud.talk.activities.MainActivity
- import com.nextcloud.talk.activities.TakePhotoActivity
- import com.nextcloud.talk.adapters.messages.IncomingLocationMessageViewHolder
- import com.nextcloud.talk.adapters.messages.IncomingPreviewMessageViewHolder
- import com.nextcloud.talk.adapters.messages.IncomingVoiceMessageViewHolder
- import com.nextcloud.talk.adapters.messages.MagicIncomingTextMessageViewHolder
- import com.nextcloud.talk.adapters.messages.MagicOutcomingTextMessageViewHolder
- import com.nextcloud.talk.adapters.messages.MagicSystemMessageViewHolder
- import com.nextcloud.talk.adapters.messages.MagicUnreadNoticeMessageViewHolder
- import com.nextcloud.talk.adapters.messages.OutcomingLocationMessageViewHolder
- import com.nextcloud.talk.adapters.messages.OutcomingPreviewMessageViewHolder
- import com.nextcloud.talk.adapters.messages.OutcomingVoiceMessageViewHolder
- import com.nextcloud.talk.adapters.messages.PreviewMessageInterface
- import com.nextcloud.talk.adapters.messages.ReactionsInterface
- import com.nextcloud.talk.adapters.messages.TalkMessagesListAdapter
- import com.nextcloud.talk.adapters.messages.VoiceMessageInterface
- import com.nextcloud.talk.api.NcApi
- import com.nextcloud.talk.application.NextcloudTalkApplication
- import com.nextcloud.talk.callbacks.MentionAutocompleteCallback
- import com.nextcloud.talk.components.filebrowser.controllers.BrowserController
- import com.nextcloud.talk.components.filebrowser.controllers.BrowserForSharingController
- import com.nextcloud.talk.controllers.base.NewBaseController
- import com.nextcloud.talk.controllers.util.viewBinding
- import com.nextcloud.talk.databinding.ControllerChatBinding
- import com.nextcloud.talk.events.UserMentionClickEvent
- import com.nextcloud.talk.events.WebSocketCommunicationEvent
- import com.nextcloud.talk.jobs.DownloadFileToCacheWorker
- import com.nextcloud.talk.jobs.UploadAndShareFilesWorker
- import com.nextcloud.talk.messagesearch.MessageSearchActivity
- import com.nextcloud.talk.models.database.CapabilitiesUtil
- import com.nextcloud.talk.models.database.UserEntity
- import com.nextcloud.talk.models.json.chat.ChatMessage
- import com.nextcloud.talk.models.json.chat.ChatOverall
- import com.nextcloud.talk.models.json.chat.ChatOverallSingleMessage
- import com.nextcloud.talk.models.json.chat.ReadStatus
- import com.nextcloud.talk.models.json.conversations.Conversation
- import com.nextcloud.talk.models.json.conversations.RoomOverall
- import com.nextcloud.talk.models.json.conversations.RoomsOverall
- import com.nextcloud.talk.models.json.generic.GenericOverall
- import com.nextcloud.talk.models.json.mention.Mention
- import com.nextcloud.talk.presenters.MentionAutocompletePresenter
- import com.nextcloud.talk.shareditems.activities.SharedItemsActivity
- import com.nextcloud.talk.ui.bottom.sheet.ProfileBottomSheet
- import com.nextcloud.talk.ui.dialog.AttachmentDialog
- import com.nextcloud.talk.ui.dialog.MessageActionsDialog
- import com.nextcloud.talk.ui.dialog.ShowReactionsDialog
- import com.nextcloud.talk.ui.recyclerview.MessageSwipeActions
- import com.nextcloud.talk.ui.recyclerview.MessageSwipeCallback
- import com.nextcloud.talk.utils.ApiUtils
- import com.nextcloud.talk.utils.AttendeePermissionsUtil
- import com.nextcloud.talk.utils.ConductorRemapping
- import com.nextcloud.talk.utils.ConductorRemapping.remapChatController
- import com.nextcloud.talk.utils.ContactUtils
- import com.nextcloud.talk.utils.DateUtils
- import com.nextcloud.talk.utils.DisplayUtils
- import com.nextcloud.talk.utils.ImageEmojiEditText
- import com.nextcloud.talk.utils.MagicCharPolicy
- import com.nextcloud.talk.utils.NotificationUtils
- import com.nextcloud.talk.utils.UriUtils
- import com.nextcloud.talk.utils.bundle.BundleKeys
- import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ACTIVE_CONVERSATION
- import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_CONVERSATION_NAME
- import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ROOM_ID
- import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ROOM_TOKEN
- import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_USER_ENTITY
- import com.nextcloud.talk.utils.database.user.UserUtils
- import com.nextcloud.talk.utils.singletons.ApplicationWideCurrentRoomHolder
- import com.nextcloud.talk.utils.text.Spans
- import com.nextcloud.talk.webrtc.MagicWebSocketInstance
- import com.nextcloud.talk.webrtc.WebSocketConnectionHelper
- import com.otaliastudios.autocomplete.Autocomplete
- import com.stfalcon.chatkit.commons.ImageLoader
- import com.stfalcon.chatkit.commons.models.IMessage
- import com.stfalcon.chatkit.messages.MessageHolders
- import com.stfalcon.chatkit.messages.MessageHolders.ContentChecker
- import com.stfalcon.chatkit.messages.MessagesListAdapter
- import com.stfalcon.chatkit.utils.DateFormatter
- import com.vanniktech.emoji.EmojiPopup
- import com.yarolegovich.lovelydialog.LovelyStandardDialog
- import io.reactivex.Observer
- import io.reactivex.android.schedulers.AndroidSchedulers
- import io.reactivex.disposables.Disposable
- import io.reactivex.schedulers.Schedulers
- import kotlinx.android.synthetic.main.view_message_input.view.*
- import org.greenrobot.eventbus.EventBus
- import org.greenrobot.eventbus.Subscribe
- import org.greenrobot.eventbus.ThreadMode
- import org.parceler.Parcels
- import retrofit2.HttpException
- import retrofit2.Response
- import java.io.File
- import java.io.IOException
- import java.net.HttpURLConnection
- import java.text.SimpleDateFormat
- import java.util.Date
- import java.util.Objects
- import java.util.concurrent.ExecutionException
- import javax.inject.Inject
- import kotlin.math.roundToInt
- @AutoInjector(NextcloudTalkApplication::class)
- class ChatController(args: Bundle) :
- NewBaseController(
- R.layout.controller_chat,
- args
- ),
- MessagesListAdapter.OnLoadMoreListener,
- MessagesListAdapter.Formatter<Date>,
- MessagesListAdapter.OnMessageViewLongClickListener<IMessage>,
- ContentChecker<ChatMessage>,
- VoiceMessageInterface,
- ReactionsInterface,
- PreviewMessageInterface {
- private val binding: ControllerChatBinding by viewBinding(ControllerChatBinding::bind)
- @Inject
- @JvmField
- var ncApi: NcApi? = null
- @Inject
- @JvmField
- var userUtils: UserUtils? = null
- @Inject
- @JvmField
- var eventBus: EventBus? = null
- val disposableList = ArrayList<Disposable>()
- var roomToken: String? = null
- val conversationUser: UserEntity?
- val roomPassword: String
- var credentials: String? = null
- var currentConversation: Conversation? = null
- var inConversation = false
- var historyRead = false
- var globalLastKnownFutureMessageId = -1
- var globalLastKnownPastMessageId = -1
- var adapter: TalkMessagesListAdapter<ChatMessage>? = null
- var mentionAutocomplete: Autocomplete<*>? = null
- var layoutManager: LinearLayoutManager? = null
- var pullChatMessagesPending = false
- var lookingIntoFuture = false
- var newMessagesCount = 0
- var startCallFromNotification: Boolean? = null
- val roomId: String
- val voiceOnly: Boolean
- var isFirstMessagesProcessing = true
- var emojiPopup: EmojiPopup? = null
- var myFirstMessage: CharSequence? = null
- var checkingLobbyStatus: Boolean = false
- var conversationInfoMenuItem: MenuItem? = null
- var conversationVoiceCallMenuItem: MenuItem? = null
- var conversationVideoMenuItem: MenuItem? = null
- var conversationSharedItemsItem: MenuItem? = null
- var magicWebSocketInstance: MagicWebSocketInstance? = null
- var lobbyTimerHandler: Handler? = null
- var pastPreconditionFailed = false
- var futurePreconditionFailed = false
- val filesToUpload: MutableList<String> = ArrayList()
- var sharedText: String
- var isVoiceRecordingInProgress: Boolean = false
- var currentVoiceRecordFile: String = ""
- private var recorder: MediaRecorder? = null
- var mediaPlayer: MediaPlayer? = null
- lateinit var mediaPlayerHandler: Handler
- var currentlyPlayedVoiceMessage: ChatMessage? = null
- var hasChatPermission: Boolean = false
- init {
- Log.d(TAG, "init ChatController: " + System.identityHashCode(this).toString())
- setHasOptionsMenu(true)
- NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this)
- this.conversationUser = args.getParcelable(KEY_USER_ENTITY)
- this.roomId = args.getString(KEY_ROOM_ID, "")
- this.roomToken = args.getString(KEY_ROOM_TOKEN, "")
- this.sharedText = args.getString(BundleKeys.KEY_SHARED_TEXT, "")
- Log.d(TAG, " roomToken = $roomToken")
- if (roomToken.isNullOrEmpty()) {
- Log.d(TAG, " roomToken was null or empty!")
- }
- if (args.containsKey(KEY_ACTIVE_CONVERSATION)) {
- this.currentConversation = Parcels.unwrap<Conversation>(args.getParcelable(KEY_ACTIVE_CONVERSATION))
- }
- this.roomPassword = args.getString(BundleKeys.KEY_CONVERSATION_PASSWORD, "")
- if (conversationUser?.userId == "?") {
- credentials = null
- } else {
- credentials = ApiUtils.getCredentials(conversationUser!!.username, conversationUser.token)
- }
- if (args.containsKey(BundleKeys.KEY_FROM_NOTIFICATION_START_CALL)) {
- this.startCallFromNotification = args.getBoolean(BundleKeys.KEY_FROM_NOTIFICATION_START_CALL)
- }
- this.voiceOnly = args.getBoolean(BundleKeys.KEY_CALL_VOICE_ONLY, false)
- }
- private fun getRoomInfo() {
- val shouldRepeat = CapabilitiesUtil.hasSpreedFeatureCapability(conversationUser, "webinary-lobby")
- if (shouldRepeat) {
- checkingLobbyStatus = true
- }
- if (conversationUser != null) {
- val apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(ApiUtils.APIv4, 1))
- val startNanoTime = System.nanoTime()
- Log.d(TAG, "getRoomInfo - getRoom - calling: " + startNanoTime)
- ncApi?.getRoom(credentials, ApiUtils.getUrlForRoom(apiVersion, conversationUser.baseUrl, roomToken))
- ?.subscribeOn(Schedulers.io())
- ?.observeOn(AndroidSchedulers.mainThread())
- ?.subscribe(object : Observer<RoomOverall> {
- override fun onSubscribe(d: Disposable) {
- disposableList.add(d)
- }
- @Suppress("Detekt.TooGenericExceptionCaught")
- override fun onNext(roomOverall: RoomOverall) {
- Log.d(TAG, "getRoomInfo - getRoom - got response: " + startNanoTime)
- currentConversation = roomOverall.ocs!!.data
- Log.d(
- TAG,
- "getRoomInfo. token: " + currentConversation?.token +
- " sessionId: " + currentConversation?.sessionId
- )
- loadAvatarForStatusBar()
- setTitle()
- hasChatPermission =
- AttendeePermissionsUtil(currentConversation!!.permissions).hasChatPermission(
- conversationUser
- )
- try {
- setupMentionAutocomplete()
- checkShowCallButtons()
- checkShowMessageInputView()
- checkLobbyState()
- if (!inConversation) {
- joinRoomWithPassword()
- }
- } catch (npe: NullPointerException) {
- // view binding can be null
- // since this is called asynchrously and UI might have been destroyed in the meantime
- Log.i(TAG, "UI destroyed - view binding already gone")
- }
- }
- override fun onError(e: Throwable) {
- Log.e(TAG, "getRoomInfo - getRoom - ERROR", e)
- }
- override fun onComplete() {
- Log.d(TAG, "getRoomInfo - getRoom - onComplete: " + startNanoTime)
- if (shouldRepeat) {
- if (lobbyTimerHandler == null) {
- lobbyTimerHandler = Handler()
- }
- lobbyTimerHandler?.postDelayed({ getRoomInfo() }, LOBBY_TIMER_DELAY)
- }
- }
- })
- }
- }
- private fun handleFromNotification() {
- var apiVersion = 1
- // FIXME Can this be called for guests?
- if (conversationUser != null) {
- apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(ApiUtils.APIv4, 1))
- }
- Log.d(TAG, "handleFromNotification - getRooms - calling")
- ncApi?.getRooms(credentials, ApiUtils.getUrlForRooms(apiVersion, conversationUser?.baseUrl))
- ?.subscribeOn(Schedulers.io())?.observeOn(AndroidSchedulers.mainThread())
- ?.subscribe(object : Observer<RoomsOverall> {
- override fun onSubscribe(d: Disposable) {
- disposableList.add(d)
- }
- override fun onNext(roomsOverall: RoomsOverall) {
- Log.d(TAG, "handleFromNotification - getRooms - got response")
- for (conversation in roomsOverall.ocs!!.data!!) {
- if (roomId == conversation.roomId) {
- roomToken = conversation.token
- currentConversation = conversation
- setTitle()
- getRoomInfo()
- break
- }
- }
- }
- override fun onError(e: Throwable) {
- Log.e(TAG, "handleFromNotification - getRooms - ERROR: ", e)
- }
- override fun onComplete() {
- // unused atm
- }
- })
- }
- private fun loadAvatarForStatusBar() {
- if (inOneToOneCall() && activity != null) {
- val imageRequest = DisplayUtils.getImageRequestForUrl(
- ApiUtils.getUrlForAvatar(
- conversationUser?.baseUrl,
- currentConversation?.name, true
- ),
- conversationUser!!
- )
- val imagePipeline = Fresco.getImagePipeline()
- val dataSource = imagePipeline.fetchDecodedImage(imageRequest, null)
- dataSource.subscribe(
- object : BaseBitmapDataSubscriber() {
- override fun onNewResultImpl(bitmap: Bitmap?) {
- if (actionBar != null && bitmap != null && resources != null) {
- val avatarSize = (actionBar?.height!! / TOOLBAR_AVATAR_RATIO).roundToInt()
- if (avatarSize > 0) {
- val bitmapResized = Bitmap.createScaledBitmap(bitmap, avatarSize, avatarSize, false)
- val roundedBitmapDrawable =
- RoundedBitmapDrawableFactory.create(resources!!, bitmapResized)
- roundedBitmapDrawable.isCircular = true
- roundedBitmapDrawable.setAntiAlias(true)
- actionBar?.setIcon(roundedBitmapDrawable)
- } else {
- Log.d(TAG, "loadAvatarForStatusBar avatarSize <= 0")
- }
- }
- }
- override fun onFailureImpl(dataSource: DataSource<CloseableReference<CloseableImage>>) {
- // unused atm
- }
- },
- UiThreadImmediateExecutorService.getInstance()
- )
- }
- }
- private fun inOneToOneCall() = currentConversation != null && currentConversation?.type != null &&
- currentConversation?.type == Conversation.ConversationType
- .ROOM_TYPE_ONE_TO_ONE_CALL
- @Suppress("Detekt.TooGenericExceptionCaught")
- override fun onViewBound(view: View) {
- Log.d(TAG, "onViewBound: " + System.identityHashCode(this).toString())
- actionBar?.show()
- var adapterWasNull = false
- if (adapter == null) {
- binding.progressBar.visibility = View.VISIBLE
- adapterWasNull = true
- val messageHolders = MessageHolders()
- val profileBottomSheet = ProfileBottomSheet(ncApi!!, conversationUser!!, router)
- messageHolders.setIncomingTextConfig(
- MagicIncomingTextMessageViewHolder::class.java,
- R.layout.item_custom_incoming_text_message,
- profileBottomSheet
- )
- messageHolders.setOutcomingTextConfig(
- MagicOutcomingTextMessageViewHolder::class.java,
- R.layout.item_custom_outcoming_text_message
- )
- messageHolders.setIncomingImageConfig(
- IncomingPreviewMessageViewHolder::class.java,
- R.layout.item_custom_incoming_preview_message,
- profileBottomSheet
- )
- messageHolders.setOutcomingImageConfig(
- OutcomingPreviewMessageViewHolder::class.java,
- R.layout.item_custom_outcoming_preview_message
- )
- messageHolders.registerContentType(
- CONTENT_TYPE_SYSTEM_MESSAGE,
- MagicSystemMessageViewHolder::class.java,
- R.layout.item_system_message,
- MagicSystemMessageViewHolder::class.java,
- R.layout.item_system_message,
- this
- )
- messageHolders.registerContentType(
- CONTENT_TYPE_UNREAD_NOTICE_MESSAGE,
- MagicUnreadNoticeMessageViewHolder::class.java,
- R.layout.item_date_header,
- MagicUnreadNoticeMessageViewHolder::class.java,
- R.layout.item_date_header,
- this
- )
- messageHolders.registerContentType(
- CONTENT_TYPE_LOCATION,
- IncomingLocationMessageViewHolder::class.java,
- profileBottomSheet,
- R.layout.item_custom_incoming_location_message,
- OutcomingLocationMessageViewHolder::class.java,
- null,
- R.layout.item_custom_outcoming_location_message,
- this
- )
- messageHolders.registerContentType(
- CONTENT_TYPE_VOICE_MESSAGE,
- IncomingVoiceMessageViewHolder::class.java,
- profileBottomSheet,
- R.layout.item_custom_incoming_voice_message,
- OutcomingVoiceMessageViewHolder::class.java,
- null,
- R.layout.item_custom_outcoming_voice_message,
- this
- )
- var senderId = ""
- if (!conversationUser?.userId.equals("?")) {
- senderId = "users/" + conversationUser?.userId
- } else {
- senderId = currentConversation?.actorType + "/" + currentConversation?.actorId
- }
- Log.d(TAG, "Initialize TalkMessagesListAdapter with senderId: " + senderId)
- adapter = TalkMessagesListAdapter(
- senderId,
- messageHolders,
- ImageLoader { imageView, url, payload ->
- val draweeController = Fresco.newDraweeControllerBuilder()
- .setImageRequest(DisplayUtils.getImageRequestForUrl(url, conversationUser))
- .setControllerListener(DisplayUtils.getImageControllerListener(imageView))
- .setOldController(imageView.controller)
- .setAutoPlayAnimations(true)
- .build()
- imageView.controller = draweeController
- },
- this
- )
- } else {
- binding.messagesListView.visibility = View.VISIBLE
- }
- binding.messagesListView.setAdapter(adapter)
- adapter?.setLoadMoreListener(this)
- adapter?.setDateHeadersFormatter { format(it) }
- adapter?.setOnMessageViewLongClickListener { view, message -> onMessageViewLongClick(view, message) }
- adapter?.registerViewClickListener(
- R.id.playPauseBtn
- ) { view, message ->
- val filename = message.selectedIndividualHashMap!!["name"]
- val file = File(context!!.cacheDir, filename!!)
- if (file.exists()) {
- if (message.isPlayingVoiceMessage) {
- pausePlayback(message)
- } else {
- startPlayback(message)
- }
- } else {
- downloadFileToCache(message)
- }
- }
- if (context != null && hasChatPermission && !isReadOnlyConversation()) {
- val messageSwipeController = MessageSwipeCallback(
- activity!!,
- object : MessageSwipeActions {
- override fun showReplyUI(position: Int) {
- val chatMessage = adapter?.items?.get(position)?.item as ChatMessage?
- replyToMessage(chatMessage)
- }
- }
- )
- val itemTouchHelper = ItemTouchHelper(messageSwipeController)
- itemTouchHelper.attachToRecyclerView(binding.messagesListView)
- }
- layoutManager = binding.messagesListView.layoutManager as LinearLayoutManager?
- binding.popupBubbleView.setRecyclerView(binding.messagesListView)
- binding.popupBubbleView.setPopupBubbleListener { context ->
- if (newMessagesCount != 0) {
- val scrollPosition: Int
- if (newMessagesCount - 1 < 0) {
- scrollPosition = 0
- } else {
- scrollPosition = newMessagesCount - 1
- }
- Handler().postDelayed(
- {
- binding.messagesListView.smoothScrollToPosition(scrollPosition)
- },
- NEW_MESSAGES_POPUP_BUBBLE_DELAY
- )
- }
- }
- binding.messageInputView.setPadding(0, 0, 0, 0)
- binding.messagesListView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
- override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
- super.onScrollStateChanged(recyclerView, newState)
- if (newState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE) {
- if (newMessagesCount != 0 && layoutManager != null) {
- if (layoutManager!!.findFirstCompletelyVisibleItemPosition() < newMessagesCount) {
- newMessagesCount = 0
- if (binding.popupBubbleView.isShown) {
- binding.popupBubbleView.hide()
- }
- }
- }
- }
- }
- })
- val filters = arrayOfNulls<InputFilter>(1)
- val lengthFilter = CapabilitiesUtil.getMessageMaxLength(conversationUser) ?: MESSAGE_MAX_LENGTH
- filters[0] = InputFilter.LengthFilter(lengthFilter)
- binding.messageInputView.inputEditText?.filters = filters
- binding.messageInputView.inputEditText?.addTextChangedListener(object : TextWatcher {
- override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {
- // unused atm
- }
- @Suppress("Detekt.TooGenericExceptionCaught")
- override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
- try {
- if (s.length >= lengthFilter) {
- binding.messageInputView.inputEditText?.error = String.format(
- Objects.requireNonNull<Resources>(resources).getString(R.string.nc_limit_hit),
- Integer.toString(lengthFilter)
- )
- } else {
- binding.messageInputView.inputEditText?.error = null
- }
- val editable = binding.messageInputView.inputEditText?.editableText
- if (editable != null && binding.messageInputView.inputEditText != null) {
- val mentionSpans = editable.getSpans(
- 0, binding.messageInputView.inputEditText!!.length(),
- Spans.MentionChipSpan::class.java
- )
- var mentionSpan: Spans.MentionChipSpan
- for (i in mentionSpans.indices) {
- mentionSpan = mentionSpans[i]
- if (start >= editable.getSpanStart(mentionSpan) &&
- start < editable.getSpanEnd(mentionSpan)
- ) {
- if (editable.subSequence(
- editable.getSpanStart(mentionSpan),
- editable.getSpanEnd(mentionSpan)
- ).toString().trim { it <= ' ' } != mentionSpan.label
- ) {
- editable.removeSpan(mentionSpan)
- }
- }
- }
- }
- } catch (npe: NullPointerException) {
- // view binding can be null
- // since this is called asynchronously and UI might have been destroyed in the meantime
- Log.i(TAG, "UI destroyed - view binding already gone")
- }
- }
- override fun afterTextChanged(s: Editable) {
- // unused atm
- }
- })
- // Image keyboard support
- // See: https://developer.android.com/guide/topics/text/image-keyboard
- (binding.messageInputView.inputEditText as ImageEmojiEditText).onCommitContentListener = {
- uploadFiles(mutableListOf(it.toString()), false)
- }
- showMicrophoneButton(true)
- binding.messageInputView.messageInput.doAfterTextChanged {
- try {
- if (binding.messageInputView.messageInput.text.isEmpty()) {
- showMicrophoneButton(true)
- } else {
- showMicrophoneButton(false)
- }
- } catch (npe: NullPointerException) {
- // view binding can be null
- // since this is called asynchronously and UI might have been destroyed in the meantime
- Log.i(TAG, "UI destroyed - view binding already gone")
- }
- }
- var sliderInitX = 0F
- var downX = 0f
- var deltaX = 0f
- var voiceRecordStartTime = 0L
- var voiceRecordEndTime = 0L
- binding.messageInputView.recordAudioButton.setOnTouchListener(object : View.OnTouchListener {
- override fun onTouch(v: View?, event: MotionEvent?): Boolean {
- view.performClick()
- when (event?.action) {
- MotionEvent.ACTION_DOWN -> {
- if (!isRecordAudioPermissionGranted()) {
- requestRecordAudioPermissions()
- return true
- }
- if (!UploadAndShareFilesWorker.isStoragePermissionGranted(context!!)) {
- UploadAndShareFilesWorker.requestStoragePermission(this@ChatController)
- return true
- }
- voiceRecordStartTime = System.currentTimeMillis()
- setVoiceRecordFileName()
- startAudioRecording(currentVoiceRecordFile)
- downX = event.x
- showRecordAudioUi(true)
- }
- MotionEvent.ACTION_CANCEL -> {
- Log.d(TAG, "ACTION_CANCEL. same as for UP")
- if (!isVoiceRecordingInProgress || !isRecordAudioPermissionGranted()) {
- return true
- }
- stopAndDiscardAudioRecording()
- showRecordAudioUi(false)
- binding.messageInputView.slideToCancelDescription.x = sliderInitX
- }
- MotionEvent.ACTION_UP -> {
- Log.d(TAG, "ACTION_UP. stop recording??")
- if (!isVoiceRecordingInProgress || !isRecordAudioPermissionGranted()) {
- return true
- }
- showRecordAudioUi(false)
- voiceRecordEndTime = System.currentTimeMillis()
- val voiceRecordDuration = voiceRecordEndTime - voiceRecordStartTime
- if (voiceRecordDuration < MINIMUM_VOICE_RECORD_DURATION) {
- Log.d(TAG, "voiceRecordDuration: " + voiceRecordDuration)
- Toast.makeText(
- context,
- context!!.getString(R.string.nc_voice_message_hold_to_record_info),
- Toast.LENGTH_SHORT
- ).show()
- stopAndDiscardAudioRecording()
- return true
- } else {
- voiceRecordStartTime = 0L
- voiceRecordEndTime = 0L
- stopAndSendAudioRecording()
- }
- binding.messageInputView.slideToCancelDescription.x = sliderInitX
- }
- MotionEvent.ACTION_MOVE -> {
- Log.d(TAG, "ACTION_MOVE.")
- if (!isVoiceRecordingInProgress || !isRecordAudioPermissionGranted()) {
- return true
- }
- showRecordAudioUi(true)
- if (sliderInitX == 0.0F) {
- sliderInitX = binding.messageInputView.slideToCancelDescription.x
- }
- val movedX: Float = event.x
- deltaX = movedX - downX
- // only allow slide to left
- if (binding.messageInputView.slideToCancelDescription.x > sliderInitX) {
- binding.messageInputView.slideToCancelDescription.x = sliderInitX
- }
- if (binding.messageInputView.slideToCancelDescription.x < VOICE_RECORD_CANCEL_SLIDER_X) {
- Log.d(TAG, "stopping recording because slider was moved to left")
- stopAndDiscardAudioRecording()
- showRecordAudioUi(false)
- binding.messageInputView.slideToCancelDescription.x = sliderInitX
- return true
- } else {
- binding.messageInputView.slideToCancelDescription.x = binding.messageInputView
- .slideToCancelDescription.x + deltaX
- downX = movedX
- }
- }
- }
- return v?.onTouchEvent(event) ?: true
- }
- })
- binding.messageInputView.inputEditText?.setText(sharedText)
- binding.messageInputView.setAttachmentsListener {
- activity?.let { AttachmentDialog(it, this).show() }
- }
- binding.messageInputView.button.setOnClickListener { submitMessage(false) }
- if (CapabilitiesUtil.hasSpreedFeatureCapability(conversationUser, "silent-send")) {
- binding.messageInputView.button.setOnLongClickListener {
- showSendButtonMenu()
- true
- }
- }
- binding.messageInputView.button.contentDescription = resources?.getString(
- R.string
- .nc_description_send_message_button
- )
- if (currentConversation != null && currentConversation?.roomId != null) {
- loadAvatarForStatusBar()
- setTitle()
- }
- if (adapterWasNull) {
- // we're starting
- if (TextUtils.isEmpty(roomToken)) {
- handleFromNotification()
- } else {
- getRoomInfo()
- }
- }
- super.onViewBound(view)
- }
- private fun showSendButtonMenu() {
- val popupMenu = PopupMenu(
- ContextThemeWrapper(view?.context, R.style.ChatSendButtonMenu),
- binding.messageInputView.button,
- Gravity.END
- )
- popupMenu.inflate(R.menu.chat_send_menu)
- popupMenu.setOnMenuItemClickListener { item: MenuItem ->
- when (item.itemId) {
- R.id.send_without_notification -> submitMessage(true)
- }
- true
- }
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
- popupMenu.setForceShowIcon(true)
- }
- popupMenu.show()
- }
- private fun showCallButtonMenu(isVoiceOnlyCall: Boolean) {
- val anchor: View? = if (isVoiceOnlyCall) {
- activity?.findViewById(R.id.conversation_voice_call)
- } else {
- activity?.findViewById(R.id.conversation_video_call)
- }
- if (anchor != null) {
- val popupMenu = PopupMenu(
- ContextThemeWrapper(view?.context, R.style.CallButtonMenu),
- anchor,
- Gravity.END
- )
- popupMenu.inflate(R.menu.chat_call_menu)
- popupMenu.setOnMenuItemClickListener { item: MenuItem ->
- when (item.itemId) {
- R.id.call_without_notification -> startACall(isVoiceOnlyCall, true)
- }
- true
- }
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
- popupMenu.setForceShowIcon(true)
- }
- popupMenu.show()
- }
- }
- private fun startPlayback(message: ChatMessage) {
- if (!this.isAttached) {
- // don't begin to play voice message if screen is not visible anymore.
- // this situation might happen if file is downloading but user already left the chatview.
- // If user returns to chatview, the old chatview instance is not attached anymore
- // and he has to click the play button again (which is considered to be okay)
- return
- }
- initMediaPlayer(message)
- if (!mediaPlayer!!.isPlaying) {
- mediaPlayer!!.start()
- }
- mediaPlayerHandler = Handler()
- activity?.runOnUiThread(object : Runnable {
- override fun run() {
- if (mediaPlayer != null) {
- val currentPosition: Int = mediaPlayer!!.currentPosition / VOICE_MESSAGE_SEEKBAR_BASE
- message.voiceMessagePlayedSeconds = currentPosition
- adapter?.update(message)
- }
- mediaPlayerHandler.postDelayed(this, SECOND)
- }
- })
- message.isDownloadingVoiceMessage = false
- message.isPlayingVoiceMessage = true
- adapter?.update(message)
- }
- private fun pausePlayback(message: ChatMessage) {
- if (mediaPlayer!!.isPlaying) {
- mediaPlayer!!.pause()
- }
- message.isPlayingVoiceMessage = false
- adapter?.update(message)
- }
- private fun initMediaPlayer(message: ChatMessage) {
- if (message != currentlyPlayedVoiceMessage) {
- currentlyPlayedVoiceMessage?.let { stopMediaPlayer(it) }
- }
- if (mediaPlayer == null) {
- val fileName = message.selectedIndividualHashMap!!["name"]
- val absolutePath = context!!.cacheDir.absolutePath + "/" + fileName
- mediaPlayer = MediaPlayer().apply {
- setDataSource(absolutePath)
- prepare()
- }
- currentlyPlayedVoiceMessage = message
- message.voiceMessageDuration = mediaPlayer!!.duration / VOICE_MESSAGE_SEEKBAR_BASE
- mediaPlayer!!.setOnCompletionListener {
- stopMediaPlayer(message)
- }
- } else {
- Log.e(TAG, "mediaPlayer was not null. This should not happen!")
- }
- }
- private fun stopMediaPlayer(message: ChatMessage) {
- message.isPlayingVoiceMessage = false
- message.resetVoiceMessage = true
- adapter?.update(message)
- currentlyPlayedVoiceMessage = null
- mediaPlayerHandler.removeCallbacksAndMessages(null)
- mediaPlayer?.stop()
- mediaPlayer?.release()
- mediaPlayer = null
- }
- override fun updateMediaPlayerProgressBySlider(messageWithSlidedProgress: ChatMessage, progress: Int) {
- if (mediaPlayer != null) {
- if (messageWithSlidedProgress == currentlyPlayedVoiceMessage) {
- mediaPlayer!!.seekTo(progress * VOICE_MESSAGE_SEEKBAR_BASE)
- }
- }
- }
- @SuppressLint("LongLogTag")
- private fun downloadFileToCache(message: ChatMessage) {
- message.isDownloadingVoiceMessage = true
- adapter?.update(message)
- val baseUrl = message.activeUser!!.baseUrl
- val userId = message.activeUser!!.userId
- val attachmentFolder = CapabilitiesUtil.getAttachmentFolder(message.activeUser)
- val fileName = message.selectedIndividualHashMap!!["name"]
- var size = message.selectedIndividualHashMap!!["size"]
- if (size == null) {
- size = "-1"
- }
- val fileSize = size.toLong()
- val fileId = message.selectedIndividualHashMap!!["id"]
- val path = message.selectedIndividualHashMap!!["path"]
- // check if download worker is already running
- val workers = WorkManager.getInstance(
- context!!
- ).getWorkInfosByTag(fileId!!)
- try {
- for (workInfo in workers.get()) {
- if (workInfo.state == WorkInfo.State.RUNNING || workInfo.state == WorkInfo.State.ENQUEUED) {
- Log.d(TAG, "Download worker for " + fileId + " is already running or scheduled")
- return
- }
- }
- } catch (e: ExecutionException) {
- Log.e(TAG, "Error when checking if worker already exists", e)
- } catch (e: InterruptedException) {
- Log.e(TAG, "Error when checking if worker already exists", e)
- }
- val data: Data = Data.Builder()
- .putString(DownloadFileToCacheWorker.KEY_BASE_URL, baseUrl)
- .putString(DownloadFileToCacheWorker.KEY_USER_ID, userId)
- .putString(DownloadFileToCacheWorker.KEY_ATTACHMENT_FOLDER, attachmentFolder)
- .putString(DownloadFileToCacheWorker.KEY_FILE_NAME, fileName)
- .putString(DownloadFileToCacheWorker.KEY_FILE_PATH, path)
- .putLong(DownloadFileToCacheWorker.KEY_FILE_SIZE, fileSize)
- .build()
- val downloadWorker: OneTimeWorkRequest = OneTimeWorkRequest.Builder(DownloadFileToCacheWorker::class.java)
- .setInputData(data)
- .addTag(fileId)
- .build()
- WorkManager.getInstance().enqueue(downloadWorker)
- WorkManager.getInstance(context!!).getWorkInfoByIdLiveData(downloadWorker.id)
- .observeForever { workInfo: WorkInfo ->
- if (workInfo.state == WorkInfo.State.SUCCEEDED) {
- startPlayback(message)
- }
- }
- }
- @SuppressLint("SimpleDateFormat")
- private fun setVoiceRecordFileName() {
- val pattern = "yyyy-MM-dd HH-mm-ss"
- val simpleDateFormat = SimpleDateFormat(pattern)
- val date: String = simpleDateFormat.format(Date())
- val fileNameWithoutSuffix = String.format(
- context!!.resources.getString(R.string.nc_voice_message_filename),
- date, currentConversation!!.displayName
- )
- val fileName = fileNameWithoutSuffix + VOICE_MESSAGE_FILE_SUFFIX
- currentVoiceRecordFile = "${context!!.cacheDir.absolutePath}/$fileName"
- }
- private fun showRecordAudioUi(show: Boolean) {
- if (show) {
- binding.messageInputView.microphoneEnabledInfo.visibility = View.VISIBLE
- binding.messageInputView.microphoneEnabledInfoBackground.visibility = View.VISIBLE
- binding.messageInputView.audioRecordDuration.visibility = View.VISIBLE
- binding.messageInputView.slideToCancelDescription.visibility = View.VISIBLE
- binding.messageInputView.attachmentButton.visibility = View.GONE
- binding.messageInputView.smileyButton.visibility = View.GONE
- binding.messageInputView.messageInput.visibility = View.GONE
- binding.messageInputView.messageInput.hint = ""
- } else {
- binding.messageInputView.microphoneEnabledInfo.visibility = View.GONE
- binding.messageInputView.microphoneEnabledInfoBackground.visibility = View.GONE
- binding.messageInputView.audioRecordDuration.visibility = View.GONE
- binding.messageInputView.slideToCancelDescription.visibility = View.GONE
- binding.messageInputView.attachmentButton.visibility = View.VISIBLE
- binding.messageInputView.smileyButton.visibility = View.VISIBLE
- binding.messageInputView.messageInput.visibility = View.VISIBLE
- binding.messageInputView.messageInput.hint =
- context?.resources?.getString(R.string.nc_hint_enter_a_message)
- }
- }
- private fun isRecordAudioPermissionGranted(): Boolean {
- return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
- return PermissionChecker.checkSelfPermission(
- context!!,
- Manifest.permission.RECORD_AUDIO
- ) == PermissionChecker.PERMISSION_GRANTED
- } else {
- true
- }
- }
- private fun isCameraPermissionGranted(): Boolean {
- return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
- return PermissionChecker.checkSelfPermission(
- context!!,
- Manifest.permission.CAMERA
- ) == PermissionChecker.PERMISSION_GRANTED
- } else {
- true
- }
- }
- private fun startAudioRecording(file: String) {
- binding.messageInputView.audioRecordDuration.base = SystemClock.elapsedRealtime()
- binding.messageInputView.audioRecordDuration.start()
- val animation: Animation = AlphaAnimation(1.0f, 0.0f)
- animation.duration = ANIMATION_DURATION
- animation.interpolator = LinearInterpolator()
- animation.repeatCount = Animation.INFINITE
- animation.repeatMode = Animation.REVERSE
- binding.messageInputView.microphoneEnabledInfo.startAnimation(animation)
- recorder = MediaRecorder().apply {
- setAudioSource(MediaRecorder.AudioSource.MIC)
- setOutputFile(file)
- setOutputFormat(MediaRecorder.OutputFormat.MPEG_4)
- setAudioEncoder(MediaRecorder.AudioEncoder.AAC)
- try {
- prepare()
- } catch (e: IOException) {
- Log.e(TAG, "prepare for audio recording failed")
- }
- try {
- start()
- isVoiceRecordingInProgress = true
- } catch (e: IllegalStateException) {
- Log.e(TAG, "start for audio recording failed")
- }
- vibrate()
- }
- }
- private fun stopAndSendAudioRecording() {
- stopAudioRecording()
- val uri = Uri.fromFile(File(currentVoiceRecordFile))
- uploadFiles(mutableListOf(uri.toString()), true)
- }
- private fun stopAndDiscardAudioRecording() {
- stopAudioRecording()
- val cachedFile = File(currentVoiceRecordFile)
- cachedFile.delete()
- }
- @Suppress("Detekt.TooGenericExceptionCaught")
- private fun stopAudioRecording() {
- binding.messageInputView.audioRecordDuration.stop()
- binding.messageInputView.microphoneEnabledInfo.clearAnimation()
- if (isVoiceRecordingInProgress) {
- recorder?.apply {
- try {
- stop()
- release()
- isVoiceRecordingInProgress = false
- Log.d(TAG, "stopped recorder. isVoiceRecordingInProgress = false")
- } catch (e: RuntimeException) {
- Log.w(TAG, "error while stopping recorder!")
- }
- vibrate()
- }
- recorder = null
- } else {
- Log.e(TAG, "tried to stop audio recorder but it was not recording")
- }
- }
- fun vibrate() {
- val vibrator = context?.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
- if (Build.VERSION.SDK_INT >= O) {
- vibrator.vibrate(VibrationEffect.createOneShot(SHORT_VIBRATE, VibrationEffect.DEFAULT_AMPLITUDE))
- } else {
- vibrator.vibrate(SHORT_VIBRATE)
- }
- }
- private fun requestRecordAudioPermissions() {
- requestPermissions(
- arrayOf(
- Manifest.permission.RECORD_AUDIO
- ),
- REQUEST_RECORD_AUDIO_PERMISSION
- )
- }
- private fun requestCameraPermissions() {
- requestPermissions(
- arrayOf(
- Manifest.permission.CAMERA
- ),
- REQUEST_CAMERA_PERMISSION
- )
- }
- private fun requestReadContacts() {
- requestPermissions(
- arrayOf(
- Manifest.permission.READ_CONTACTS
- ),
- REQUEST_READ_CONTACT_PERMISSION
- )
- }
- private fun checkShowCallButtons() {
- if (isAlive()) {
- if (isReadOnlyConversation() || shouldShowLobby()) {
- disableCallButtons()
- } else {
- enableCallButtons()
- }
- }
- }
- private fun checkShowMessageInputView() {
- if (isAlive()) {
- if (isReadOnlyConversation() ||
- shouldShowLobby() ||
- !hasChatPermission
- ) {
- binding.messageInputView.visibility = View.GONE
- } else {
- binding.messageInputView.visibility = View.VISIBLE
- }
- }
- }
- private fun shouldShowLobby(): Boolean {
- if (currentConversation != null) {
- return currentConversation?.shouldShowLobby(conversationUser!!) == true
- }
- return false
- }
- private fun disableCallButtons() {
- if (CapabilitiesUtil.isAbleToCall(conversationUser)) {
- if (conversationVoiceCallMenuItem != null && conversationVideoMenuItem != null) {
- conversationVoiceCallMenuItem?.icon?.alpha = SEMI_TRANSPARENT_INT
- conversationVideoMenuItem?.icon?.alpha = SEMI_TRANSPARENT_INT
- conversationVoiceCallMenuItem?.isEnabled = false
- conversationVideoMenuItem?.isEnabled = false
- } else {
- Log.e(TAG, "call buttons were null when trying to disable them")
- }
- }
- }
- private fun enableCallButtons() {
- if (CapabilitiesUtil.isAbleToCall(conversationUser)) {
- if (conversationVoiceCallMenuItem != null && conversationVideoMenuItem != null) {
- conversationVoiceCallMenuItem?.icon?.alpha = FULLY_OPAQUE_INT
- conversationVideoMenuItem?.icon?.alpha = FULLY_OPAQUE_INT
- conversationVoiceCallMenuItem?.isEnabled = true
- conversationVideoMenuItem?.isEnabled = true
- } else {
- Log.e(TAG, "call buttons were null when trying to enable them")
- }
- }
- }
- private fun isReadOnlyConversation(): Boolean {
- return currentConversation?.conversationReadOnlyState != null &&
- currentConversation?.conversationReadOnlyState ==
- Conversation.ConversationReadOnlyState.CONVERSATION_READ_ONLY
- }
- private fun checkLobbyState() {
- if (currentConversation != null &&
- currentConversation?.isLobbyViewApplicable(conversationUser!!) ?: false &&
- isAlive()
- ) {
- if (!checkingLobbyStatus) {
- getRoomInfo()
- }
- if (currentConversation?.shouldShowLobby(conversationUser!!) ?: false) {
- binding.lobby.lobbyView.visibility = View.VISIBLE
- binding.messagesListView.visibility = View.GONE
- binding.messageInputView.visibility = View.GONE
- binding.progressBar.visibility = View.GONE
- val sb = StringBuilder()
- sb.append(resources!!.getText(R.string.nc_lobby_waiting))
- .append("\n\n")
- if (currentConversation?.lobbyTimer != null && currentConversation?.lobbyTimer !=
- 0L
- ) {
- val timestamp = currentConversation?.lobbyTimer ?: 0
- val stringWithStartDate = String.format(
- resources!!.getString(R.string.nc_lobby_start_date),
- DateUtils.getLocalDateStringFromTimestampForLobby(timestamp)
- )
- val relativeTime = DateUtils.relativeStartTimeForLobby(timestamp, resources!!)
- sb.append("$stringWithStartDate - $relativeTime")
- .append("\n\n")
- }
- sb.append(currentConversation!!.description)
- binding.lobby.lobbyTextView.text = sb.toString()
- } else {
- binding.lobby.lobbyView.visibility = View.GONE
- binding.messagesListView.visibility = View.VISIBLE
- binding.messageInputView.inputEditText?.visibility = View.VISIBLE
- if (isFirstMessagesProcessing && pastPreconditionFailed) {
- pastPreconditionFailed = false
- pullChatMessages(0)
- } else if (futurePreconditionFailed) {
- futurePreconditionFailed = false
- pullChatMessages(1)
- }
- }
- } else {
- binding.lobby.lobbyView.visibility = View.GONE
- binding.messagesListView.visibility = View.VISIBLE
- binding.messageInputView.inputEditText?.visibility = View.VISIBLE
- }
- }
- override fun onActivityResult(requestCode: Int, resultCode: Int, intent: Intent?) {
- if (resultCode != RESULT_OK && (requestCode != REQUEST_CODE_MESSAGE_SEARCH)) {
- Log.e(TAG, "resultCode for received intent was != ok")
- return
- }
- when (requestCode) {
- REQUEST_CODE_CHOOSE_FILE -> {
- try {
- checkNotNull(intent)
- filesToUpload.clear()
- intent.clipData?.let {
- for (index in 0 until it.itemCount) {
- filesToUpload.add(it.getItemAt(index).uri.toString())
- }
- } ?: run {
- checkNotNull(intent.data)
- intent.data.let {
- filesToUpload.add(intent.data.toString())
- }
- }
- require(filesToUpload.isNotEmpty())
- val filenamesWithLinebreaks = StringBuilder("\n")
- for (file in filesToUpload) {
- val filename = UriUtils.getFileName(Uri.parse(file), context)
- filenamesWithLinebreaks.append(filename).append("\n")
- }
- val confirmationQuestion = when (filesToUpload.size) {
- 1 -> context?.resources?.getString(R.string.nc_upload_confirm_send_single)?.let {
- String.format(it, title)
- }
- else -> context?.resources?.getString(R.string.nc_upload_confirm_send_multiple)?.let {
- String.format(it, title)
- }
- }
- LovelyStandardDialog(activity)
- .setPositiveButtonColorRes(R.color.nc_darkGreen)
- .setTitle(confirmationQuestion)
- .setMessage(filenamesWithLinebreaks.toString())
- .setPositiveButton(R.string.nc_yes) { v ->
- if (UploadAndShareFilesWorker.isStoragePermissionGranted(context!!)) {
- uploadFiles(filesToUpload, false)
- } else {
- UploadAndShareFilesWorker.requestStoragePermission(this)
- }
- }
- .setNegativeButton(R.string.nc_no) {
- // unused atm
- }
- .show()
- } catch (e: IllegalStateException) {
- Toast.makeText(context, context?.resources?.getString(R.string.nc_upload_failed), Toast.LENGTH_LONG)
- .show()
- Log.e(javaClass.simpleName, "Something went wrong when trying to upload file", e)
- } catch (e: IllegalArgumentException) {
- Toast.makeText(context, context?.resources?.getString(R.string.nc_upload_failed), Toast.LENGTH_LONG)
- .show()
- Log.e(javaClass.simpleName, "Something went wrong when trying to upload file", e)
- }
- }
- REQUEST_CODE_SELECT_CONTACT -> {
- val contactUri = intent?.data ?: return
- val cursor: Cursor? = activity?.contentResolver!!.query(contactUri, null, null, null, null)
- if (cursor != null && cursor.moveToFirst()) {
- val id = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.Contacts._ID))
- val fileName = ContactUtils.getDisplayNameFromDeviceContact(context!!, id) + ".vcf"
- val file = File(context?.cacheDir, fileName)
- writeContactToVcfFile(cursor, file)
- val shareUri = FileProvider.getUriForFile(
- activity!!,
- BuildConfig.APPLICATION_ID,
- File(file.absolutePath)
- )
- uploadFiles(mutableListOf(shareUri.toString()), false)
- }
- cursor?.close()
- }
- REQUEST_CODE_PICK_CAMERA -> {
- if (resultCode == RESULT_OK) {
- try {
- checkNotNull(intent)
- filesToUpload.clear()
- run {
- checkNotNull(intent.data)
- intent.data.let {
- filesToUpload.add(intent.data.toString())
- }
- }
- require(filesToUpload.isNotEmpty())
- if (UploadAndShareFilesWorker.isStoragePermissionGranted(context!!)) {
- uploadFiles(filesToUpload, false)
- } else {
- UploadAndShareFilesWorker.requestStoragePermission(this)
- }
- } catch (e: IllegalStateException) {
- Toast.makeText(
- context,
- context?.resources?.getString(R.string.nc_upload_failed),
- Toast.LENGTH_LONG
- )
- .show()
- Log.e(javaClass.simpleName, "Something went wrong when trying to upload file", e)
- } catch (e: IllegalArgumentException) {
- Toast.makeText(
- context,
- context?.resources?.getString(R.string.nc_upload_failed),
- Toast.LENGTH_LONG
- )
- .show()
- Log.e(javaClass.simpleName, "Something went wrong when trying to upload file", e)
- }
- }
- }
- REQUEST_CODE_MESSAGE_SEARCH -> {
- val messageId = intent?.getStringExtra(MessageSearchActivity.RESULT_KEY_MESSAGE_ID)
- messageId?.let { id ->
- scrollToMessageWithId(id)
- }
- }
- }
- }
- private fun scrollToMessageWithId(messageId: String) {
- val position = adapter?.items?.indexOfFirst {
- it.item is ChatMessage && (it.item as ChatMessage).id == messageId
- }
- if (position != null && position >= 0) {
- binding.messagesListView.smoothScrollToPosition(position)
- } else {
- // TODO show error that we don't have that message?
- }
- }
- private fun writeContactToVcfFile(cursor: Cursor, file: File) {
- val lookupKey = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.Contacts.LOOKUP_KEY))
- val uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_VCARD_URI, lookupKey)
- val fd: AssetFileDescriptor = activity?.contentResolver!!.openAssetFileDescriptor(uri, "r")!!
- val fis = fd.createInputStream()
- file.createNewFile()
- fis.use { input ->
- file.outputStream().use { output ->
- input.copyTo(output)
- }
- }
- }
- override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
- if (requestCode == UploadAndShareFilesWorker.REQUEST_PERMISSION) {
- if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
- Log.d(ConversationsListController.TAG, "upload starting after permissions were granted")
- if (filesToUpload.isNotEmpty()) {
- uploadFiles(filesToUpload, false)
- }
- } else {
- Toast
- .makeText(context, context?.getString(R.string.read_storage_no_permission), Toast.LENGTH_LONG)
- .show()
- }
- } else if (requestCode == REQUEST_RECORD_AUDIO_PERMISSION) {
- if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
- // do nothing. user will tap on the microphone again if he wants to record audio..
- } else {
- Toast.makeText(
- context,
- context!!.getString(R.string.nc_voice_message_missing_audio_permission),
- Toast.LENGTH_LONG
- ).show()
- }
- } else if (requestCode == REQUEST_READ_CONTACT_PERMISSION) {
- if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
- val intent = Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI)
- startActivityForResult(intent, REQUEST_CODE_SELECT_CONTACT)
- } else {
- Toast.makeText(
- context,
- context!!.getString(R.string.nc_share_contact_permission),
- Toast.LENGTH_LONG
- ).show()
- }
- } else if (requestCode == REQUEST_CAMERA_PERMISSION) {
- if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
- Log.d(TAG, "launch cam activity since permission for cam has been granted")
- startActivityForResult(TakePhotoActivity.createIntent(context!!), REQUEST_CODE_PICK_CAMERA)
- } else {
- Toast
- .makeText(context, context?.getString(R.string.take_photo_permission), Toast.LENGTH_LONG)
- .show()
- }
- }
- }
- private fun uploadFiles(files: MutableList<String>, isVoiceMessage: Boolean) {
- var metaData = ""
- if (!hasChatPermission) {
- Log.w(TAG, "uploading file(s) is forbidden because of missing attendee permissions")
- return
- }
- if (isVoiceMessage) {
- metaData = VOICE_MESSAGE_META_DATA
- }
- try {
- require(files.isNotEmpty())
- val data: Data = Data.Builder()
- .putStringArray(UploadAndShareFilesWorker.DEVICE_SOURCEFILES, files.toTypedArray())
- .putString(
- UploadAndShareFilesWorker.NC_TARGETPATH,
- CapabilitiesUtil.getAttachmentFolder(conversationUser)
- )
- .putString(UploadAndShareFilesWorker.ROOM_TOKEN, roomToken)
- .putString(UploadAndShareFilesWorker.META_DATA, metaData)
- .build()
- val uploadWorker: OneTimeWorkRequest = OneTimeWorkRequest.Builder(UploadAndShareFilesWorker::class.java)
- .setInputData(data)
- .build()
- WorkManager.getInstance().enqueue(uploadWorker)
- if (!isVoiceMessage) {
- Toast.makeText(
- context, context?.getString(R.string.nc_upload_in_progess),
- Toast.LENGTH_LONG
- ).show()
- }
- } catch (e: IllegalArgumentException) {
- Toast.makeText(context, context?.resources?.getString(R.string.nc_upload_failed), Toast.LENGTH_LONG).show()
- Log.e(javaClass.simpleName, "Something went wrong when trying to upload file", e)
- }
- }
- fun sendSelectLocalFileIntent() {
- val action = Intent(Intent.ACTION_OPEN_DOCUMENT).apply {
- type = "*/*"
- addCategory(Intent.CATEGORY_OPENABLE)
- putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true)
- }
- startActivityForResult(
- Intent.createChooser(
- action,
- context?.resources?.getString(
- R.string.nc_upload_choose_local_files
- )
- ),
- REQUEST_CODE_CHOOSE_FILE
- )
- }
- fun sendChooseContactIntent() {
- requestReadContacts()
- }
- fun showBrowserScreen(browserType: BrowserController.BrowserType) {
- val bundle = Bundle()
- bundle.putParcelable(BundleKeys.KEY_BROWSER_TYPE, Parcels.wrap<BrowserController.BrowserType>(browserType))
- bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, Parcels.wrap<UserEntity>(conversationUser))
- bundle.putString(KEY_ROOM_TOKEN, roomToken)
- router.pushController(
- RouterTransaction.with(BrowserForSharingController(bundle))
- .pushChangeHandler(VerticalChangeHandler())
- .popChangeHandler(VerticalChangeHandler())
- )
- }
- fun showShareLocationScreen() {
- Log.d(TAG, "showShareLocationScreen")
- val bundle = Bundle()
- bundle.putString(KEY_ROOM_TOKEN, roomToken)
- router.pushController(
- RouterTransaction.with(LocationPickerController(bundle))
- .pushChangeHandler(HorizontalChangeHandler())
- .popChangeHandler(HorizontalChangeHandler())
- )
- }
- private fun showConversationInfoScreen() {
- val bundle = Bundle()
- bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, conversationUser)
- bundle.putString(KEY_ROOM_TOKEN, roomToken)
- bundle.putBoolean(BundleKeys.KEY_ROOM_ONE_TO_ONE, inOneToOneCall())
- router.pushController(
- RouterTransaction.with(ConversationInfoController(bundle))
- .pushChangeHandler(HorizontalChangeHandler())
- .popChangeHandler(HorizontalChangeHandler())
- )
- }
- private fun setupMentionAutocomplete() {
- if (isAlive()) {
- val elevation = MENTION_AUTO_COMPLETE_ELEVATION
- resources?.let {
- val backgroundDrawable = ColorDrawable(it.getColor(R.color.bg_default))
- val presenter = MentionAutocompletePresenter(activity, roomToken)
- val callback = MentionAutocompleteCallback(
- activity,
- conversationUser,
- binding.messageInputView.inputEditText
- )
- if (mentionAutocomplete == null && binding.messageInputView.inputEditText != null) {
- mentionAutocomplete = Autocomplete.on<Mention>(binding.messageInputView.inputEditText)
- .with(elevation)
- .with(backgroundDrawable)
- .with(MagicCharPolicy('@'))
- .with(presenter)
- .with(callback)
- .build()
- }
- }
- }
- }
- private fun validSessionId(): Boolean {
- return currentConversation != null &&
- !TextUtils.isEmpty(currentConversation?.sessionId) &&
- currentConversation?.sessionId != "0"
- }
- override fun onAttach(view: View) {
- super.onAttach(view)
- Log.d(
- TAG,
- "onAttach: Controller: " + System.identityHashCode(this).toString() +
- " Activity: " + System.identityHashCode(activity).toString()
- )
- eventBus?.register(this)
- if (conversationUser?.userId != "?" &&
- CapabilitiesUtil.hasSpreedFeatureCapability(conversationUser, "mention-flag") ?: false &&
- activity != null
- ) {
- activity?.findViewById<View>(R.id.toolbar)?.setOnClickListener { v -> showConversationInfoScreen() }
- }
- ApplicationWideCurrentRoomHolder.getInstance().currentRoomId = roomId
- ApplicationWideCurrentRoomHolder.getInstance().currentRoomToken = roomToken
- ApplicationWideCurrentRoomHolder.getInstance().userInRoom = conversationUser
- val smileyButton = binding.messageInputView.findViewById<ImageButton>(R.id.smileyButton)
- emojiPopup = binding.messageInputView.inputEditText?.let {
- EmojiPopup(
- rootView = view,
- editText = it,
- onEmojiPopupShownListener = {
- if (resources != null) {
- smileyButton?.setImageDrawable(
- ContextCompat.getDrawable(context!!, R.drawable.ic_baseline_keyboard_24)
- )
- }
- },
- onEmojiPopupDismissListener = {
- smileyButton?.setImageDrawable(
- ContextCompat.getDrawable(context!!, R.drawable.ic_insert_emoticon_black_24dp)
- )
- },
- onEmojiClickListener = {
- binding.messageInputView.inputEditText?.editableText?.append(" ")
- }
- )
- }
- smileyButton?.setOnClickListener {
- emojiPopup?.toggle()
- }
- binding.messageInputView.findViewById<ImageButton>(R.id.cancelReplyButton)?.setOnClickListener {
- cancelReply()
- }
- cancelNotificationsForCurrentConversation()
- Log.d(TAG, "onAttach inConversation: " + inConversation.toString())
- if (inConversation) {
- Log.d(TAG, "execute joinRoomWithPassword in onAttach")
- joinRoomWithPassword()
- }
- }
- private fun cancelReply() {
- binding.messageInputView.findViewById<RelativeLayout>(R.id.quotedChatMessageView)?.visibility = View.GONE
- binding.messageInputView.findViewById<ImageButton>(R.id.attachmentButton)?.visibility = View.VISIBLE
- }
- @Suppress("Detekt.TooGenericExceptionCaught")
- private fun cancelNotificationsForCurrentConversation() {
- if (conversationUser != null) {
- if (!TextUtils.isEmpty(roomToken)) {
- try {
- NotificationUtils.cancelExistingNotificationsForRoom(
- applicationContext,
- conversationUser,
- roomToken!!
- )
- } catch (e: RuntimeException) {
- Log.w(TAG, "Cancel notifications for current conversation results with an error.", e)
- }
- }
- }
- }
- override fun onDetach(view: View) {
- super.onDetach(view)
- Log.d(
- TAG,
- "onDetach: Controller: " + System.identityHashCode(this).toString() +
- " Activity: " + System.identityHashCode(activity).toString()
- )
- eventBus?.unregister(this)
- if (activity != null) {
- activity?.findViewById<View>(R.id.toolbar)?.setOnClickListener(null)
- }
- if (conversationUser != null && isActivityNotChangingConfigurations() && isNotInCall()) {
- ApplicationWideCurrentRoomHolder.getInstance().clear()
- if (inConversation && validSessionId()) {
- leaveRoom()
- }
- }
- if (mentionAutocomplete != null && mentionAutocomplete!!.isPopupShowing) {
- mentionAutocomplete?.dismissPopup()
- }
- }
- private fun isActivityNotChangingConfigurations(): Boolean {
- return activity != null && !activity?.isChangingConfigurations!!
- }
- private fun isNotInCall(): Boolean {
- return !ApplicationWideCurrentRoomHolder.getInstance().isInCall &&
- !ApplicationWideCurrentRoomHolder.getInstance().isDialing
- }
- override val title: String
- get() =
- if (currentConversation?.displayName != null) {
- try {
- " " + EmojiCompat.get().process(currentConversation?.displayName as CharSequence).toString()
- } catch (e: IllegalStateException) {
- " " + currentConversation?.displayName
- }
- } else {
- ""
- }
- public override fun onDestroy() {
- super.onDestroy()
- if (activity != null) {
- activity?.findViewById<View>(R.id.toolbar)?.setOnClickListener(null)
- }
- if (actionBar != null) {
- actionBar?.setIcon(null)
- }
- currentlyPlayedVoiceMessage?.let { stopMediaPlayer(it) }
- adapter = null
- inConversation = false
- }
- private fun dispose() {
- for (disposable in disposableList) {
- if (!disposable.isDisposed()) {
- disposable.dispose()
- }
- }
- }
- private fun joinRoomWithPassword() {
- Log.d(
- TAG,
- "joinRoomWithPassword start: " + (currentConversation == null).toString() +
- " sessionId: " + currentConversation?.sessionId
- )
- if (!validSessionId()) {
- var apiVersion = 1
- // FIXME Fix API checking with guests?
- if (conversationUser != null) {
- apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(ApiUtils.APIv4, 1))
- }
- val startNanoTime = System.nanoTime()
- Log.d(TAG, "joinRoomWithPassword - joinRoom - calling: " + startNanoTime)
- ncApi?.joinRoom(
- credentials,
- ApiUtils.getUrlForParticipantsActive(apiVersion, conversationUser?.baseUrl, roomToken),
- roomPassword
- )
- ?.subscribeOn(Schedulers.io())
- ?.observeOn(AndroidSchedulers.mainThread())
- ?.retry(RETRIES)
- ?.subscribe(object : Observer<RoomOverall> {
- override fun onSubscribe(d: Disposable) {
- disposableList.add(d)
- }
- @Suppress("Detekt.TooGenericExceptionCaught")
- override fun onNext(roomOverall: RoomOverall) {
- Log.d(TAG, "joinRoomWithPassword - joinRoom - got response: " + startNanoTime)
- inConversation = true
- currentConversation?.sessionId = roomOverall.ocs!!.data!!.sessionId
- Log.d(TAG, "joinRoomWithPassword - sessionId: " + currentConversation?.sessionId)
- ApplicationWideCurrentRoomHolder.getInstance().session =
- currentConversation?.sessionId
- setupWebsocket()
- try {
- checkLobbyState()
- } catch (npe: NullPointerException) {
- // view binding can be null
- // since this is called asynchrously and UI might have been destroyed in the meantime
- Log.i(TAG, "UI destroyed - view binding already gone")
- }
- if (isFirstMessagesProcessing) {
- pullChatMessages(0)
- } else {
- pullChatMessages(1, 0)
- }
- if (magicWebSocketInstance != null) {
- magicWebSocketInstance?.joinRoomWithRoomTokenAndSession(
- roomToken,
- currentConversation?.sessionId
- )
- }
- if (startCallFromNotification != null && startCallFromNotification ?: false) {
- startCallFromNotification = false
- startACall(voiceOnly, false)
- }
- }
- override fun onError(e: Throwable) {
- Log.e(TAG, "joinRoomWithPassword - joinRoom - ERROR", e)
- }
- override fun onComplete() {
- // unused atm
- }
- })
- } else {
- inConversation = true
- ApplicationWideCurrentRoomHolder.getInstance().session = currentConversation?.sessionId
- if (magicWebSocketInstance != null) {
- magicWebSocketInstance?.joinRoomWithRoomTokenAndSession(
- roomToken,
- currentConversation?.sessionId
- )
- }
- if (isFirstMessagesProcessing) {
- pullChatMessages(0)
- } else {
- pullChatMessages(1)
- }
- }
- }
- private fun leaveRoom() {
- Log.d(TAG, "leaveRoom")
- var apiVersion = 1
- // FIXME Fix API checking with guests?
- if (conversationUser != null) {
- apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(ApiUtils.APIv4, 1))
- }
- val startNanoTime = System.nanoTime()
- Log.d(TAG, "leaveRoom - leaveRoom - calling: " + startNanoTime)
- ncApi?.leaveRoom(
- credentials,
- ApiUtils.getUrlForParticipantsActive(
- apiVersion,
- conversationUser?.baseUrl,
- roomToken
- )
- )
- ?.subscribeOn(Schedulers.io())
- ?.observeOn(AndroidSchedulers.mainThread())
- ?.subscribe(object : Observer<GenericOverall> {
- override fun onSubscribe(d: Disposable) {
- disposableList.add(d)
- }
- override fun onNext(genericOverall: GenericOverall) {
- Log.d(TAG, "leaveRoom - leaveRoom - got response: " + startNanoTime)
- checkingLobbyStatus = false
- if (lobbyTimerHandler != null) {
- lobbyTimerHandler?.removeCallbacksAndMessages(null)
- }
- if (magicWebSocketInstance != null && currentConversation != null) {
- magicWebSocketInstance?.joinRoomWithRoomTokenAndSession(
- "",
- currentConversation?.sessionId
- )
- } else {
- Log.e(TAG, "magicWebSocketInstance or currentConversation were null! Failed to leave the room!")
- }
- currentConversation?.sessionId = "0"
- }
- override fun onError(e: Throwable) {
- Log.e(TAG, "leaveRoom - leaveRoom - ERROR", e)
- }
- override fun onComplete() {
- Log.d(TAG, "leaveRoom - leaveRoom - completed: " + startNanoTime)
- dispose()
- }
- })
- }
- private fun submitMessage(sendWithoutNotification: Boolean) {
- if (binding.messageInputView.inputEditText != null) {
- val editable = binding.messageInputView.inputEditText!!.editableText
- val mentionSpans = editable.getSpans(
- 0, editable.length,
- Spans.MentionChipSpan::class.java
- )
- var mentionSpan: Spans.MentionChipSpan
- for (i in mentionSpans.indices) {
- mentionSpan = mentionSpans[i]
- var mentionId = mentionSpan.id
- if (mentionId.contains(" ") || mentionId.startsWith("guest/")) {
- mentionId = "\"" + mentionId + "\""
- }
- editable.replace(editable.getSpanStart(mentionSpan), editable.getSpanEnd(mentionSpan), "@$mentionId")
- }
- binding.messageInputView.inputEditText?.setText("")
- val replyMessageId: Int? = view?.findViewById<RelativeLayout>(R.id.quotedChatMessageView)?.tag as Int?
- sendMessage(
- editable,
- if (
- view
- ?.findViewById<RelativeLayout>(R.id.quotedChatMessageView)
- ?.visibility == View.VISIBLE
- ) replyMessageId else null,
- sendWithoutNotification
- )
- cancelReply()
- }
- }
- private fun sendMessage(message: CharSequence, replyTo: Int?, sendWithoutNotification: Boolean) {
- if (conversationUser != null) {
- val apiVersion = ApiUtils.getChatApiVersion(conversationUser, intArrayOf(1))
- ncApi!!.sendChatMessage(
- credentials,
- ApiUtils.getUrlForChat(apiVersion, conversationUser.baseUrl, roomToken),
- message,
- conversationUser.displayName,
- replyTo,
- sendWithoutNotification
- )
- ?.subscribeOn(Schedulers.io())
- ?.observeOn(AndroidSchedulers.mainThread())
- ?.subscribe(object : Observer<GenericOverall> {
- override fun onSubscribe(d: Disposable) {
- // unused atm
- }
- @Suppress("Detekt.TooGenericExceptionCaught")
- override fun onNext(genericOverall: GenericOverall) {
- myFirstMessage = message
- try {
- if (binding.popupBubbleView.isShown == true) {
- binding.popupBubbleView.hide()
- }
- binding.messagesListView.smoothScrollToPosition(0)
- } catch (npe: NullPointerException) {
- // view binding can be null
- // since this is called asynchrously and UI might have been destroyed in the meantime
- Log.i(TAG, "UI destroyed - view binding already gone")
- }
- }
- override fun onError(e: Throwable) {
- if (e is HttpException) {
- val code = e.code()
- if (Integer.toString(code).startsWith("2")) {
- myFirstMessage = message
- if (binding.popupBubbleView.isShown == true) {
- binding.popupBubbleView.hide()
- }
- binding.messagesListView.smoothScrollToPosition(0)
- }
- }
- }
- override fun onComplete() {
- // unused atm
- }
- })
- }
- showMicrophoneButton(true)
- }
- private fun setupWebsocket() {
- if (conversationUser != null) {
- if (WebSocketConnectionHelper.getMagicWebSocketInstanceForUserId(conversationUser.id) != null) {
- magicWebSocketInstance =
- WebSocketConnectionHelper.getMagicWebSocketInstanceForUserId(conversationUser.id)
- } else {
- Log.d(TAG, "magicWebSocketInstance became null")
- magicWebSocketInstance = null
- }
- }
- }
- fun pullChatMessages(lookIntoFuture: Int, setReadMarker: Int = 1, xChatLastCommonRead: Int? = null) {
- if (!inConversation) {
- return
- }
- if (pullChatMessagesPending) {
- // Sometimes pullChatMessages may be called before response to a previous call is received.
- // In such cases just ignore the second call. Message processing will continue when response to the
- // earlier call is received.
- // More details: https://github.com/nextcloud/talk-android/pull/1766
- Log.d(TAG, "pullChatMessages - pullChatMessagesPending is true, exiting")
- return
- }
- pullChatMessagesPending = true
- if (currentConversation != null && currentConversation!!.shouldShowLobby(conversationUser!!)) {
- // return
- }
- val fieldMap = HashMap<String, Int>()
- fieldMap["includeLastKnown"] = 0
- if (lookIntoFuture > 0) {
- lookingIntoFuture = true
- } else if (isFirstMessagesProcessing) {
- if (currentConversation != null) {
- globalLastKnownFutureMessageId = currentConversation!!.lastReadMessage
- globalLastKnownPastMessageId = currentConversation!!.lastReadMessage
- fieldMap["includeLastKnown"] = 1
- }
- }
- val timeout = if (lookingIntoFuture) {
- LOOKING_INTO_FUTURE_TIMEOUT
- } else {
- 0
- }
- fieldMap["timeout"] = timeout
- fieldMap["lookIntoFuture"] = lookIntoFuture
- fieldMap["limit"] = MESSAGE_PULL_LIMIT
- fieldMap["setReadMarker"] = setReadMarker
- val lastKnown: Int
- if (lookIntoFuture > 0) {
- lastKnown = globalLastKnownFutureMessageId
- } else {
- lastKnown = globalLastKnownPastMessageId
- }
- fieldMap["lastKnownMessageId"] = lastKnown
- xChatLastCommonRead?.let {
- fieldMap["lastCommonReadId"] = it
- }
- var apiVersion = 1
- // FIXME this is a best guess, guests would need to get the capabilities themselves
- if (conversationUser != null) {
- apiVersion = ApiUtils.getChatApiVersion(conversationUser, intArrayOf(1))
- }
- if (lookIntoFuture > 0) {
- val finalTimeout = timeout
- Log.d(TAG, "pullChatMessages - pullChatMessages[lookIntoFuture > 0] - calling")
- ncApi?.pullChatMessages(
- credentials,
- ApiUtils.getUrlForChat(apiVersion, conversationUser?.baseUrl, roomToken), fieldMap
- )
- ?.subscribeOn(Schedulers.io())
- ?.observeOn(AndroidSchedulers.mainThread())
- ?.subscribe(object : Observer<Response<*>> {
- override fun onSubscribe(d: Disposable) {
- disposableList.add(d)
- }
- @Suppress("Detekt.TooGenericExceptionCaught")
- override fun onNext(response: Response<*>) {
- Log.d(TAG, "pullChatMessages - pullChatMessages[lookIntoFuture > 0] - got response")
- pullChatMessagesPending = false
- try {
- if (response.code() == HTTP_CODE_NOT_MODIFIED) {
- Log.d(TAG, "pullChatMessages - quasi recursive call to pullChatMessages")
- pullChatMessages(1, setReadMarker, xChatLastCommonRead)
- } else if (response.code() == HTTP_CODE_PRECONDITION_FAILED) {
- futurePreconditionFailed = true
- } else {
- processMessages(response, true, finalTimeout)
- }
- } catch (npe: NullPointerException) {
- // view binding can be null
- // since this is called asynchrously and UI might have been destroyed in the meantime
- Log.i(TAG, "UI destroyed - view binding already gone")
- }
- }
- override fun onError(e: Throwable) {
- Log.e(TAG, "pullChatMessages - pullChatMessages[lookIntoFuture > 0] - ERROR", e)
- pullChatMessagesPending = false
- }
- override fun onComplete() {
- pullChatMessagesPending = false
- }
- })
- } else {
- Log.d(TAG, "pullChatMessages - pullChatMessages[lookIntoFuture <= 0] - calling")
- ncApi?.pullChatMessages(
- credentials,
- ApiUtils.getUrlForChat(apiVersion, conversationUser?.baseUrl, roomToken), fieldMap
- )
- ?.subscribeOn(Schedulers.io())
- ?.observeOn(AndroidSchedulers.mainThread())
- ?.subscribe(object : Observer<Response<*>> {
- override fun onSubscribe(d: Disposable) {
- disposableList.add(d)
- }
- @Suppress("Detekt.TooGenericExceptionCaught")
- override fun onNext(response: Response<*>) {
- Log.d(TAG, "pullChatMessages - pullChatMessages[lookIntoFuture <= 0] - got response")
- pullChatMessagesPending = false
- try {
- if (response.code() == HTTP_CODE_PRECONDITION_FAILED) {
- pastPreconditionFailed = true
- } else {
- processMessages(response, false, 0)
- }
- } catch (e: NullPointerException) {
- // view binding can be null
- // since this is called asynchrously and UI might have been destroyed in the meantime
- Log.i(TAG, "UI destroyed - view binding already gone", e)
- }
- }
- override fun onError(e: Throwable) {
- Log.e(TAG, "pullChatMessages - pullChatMessages[lookIntoFuture <= 0] - ERROR", e)
- pullChatMessagesPending = false
- }
- override fun onComplete() {
- pullChatMessagesPending = false
- }
- })
- }
- }
- private fun processMessages(response: Response<*>, isFromTheFuture: Boolean, timeout: Int) {
- val xChatLastGivenHeader: String? = response.headers().get("X-Chat-Last-Given")
- val xChatLastCommonRead = response.headers().get("X-Chat-Last-Common-Read")?.let {
- Integer.parseInt(it)
- }
- if (response.headers().size > 0 && !TextUtils.isEmpty(xChatLastGivenHeader)) {
- val header = Integer.parseInt(xChatLastGivenHeader!!)
- if (header > 0) {
- if (isFromTheFuture) {
- globalLastKnownFutureMessageId = header
- } else {
- if (globalLastKnownFutureMessageId == -1) {
- globalLastKnownFutureMessageId = header
- }
- globalLastKnownPastMessageId = header
- }
- }
- }
- if (response.code() == HTTP_CODE_OK) {
- val chatOverall = response.body() as ChatOverall?
- val chatMessageList = handleSystemMessages(chatOverall?.ocs!!.data!!)
- if (chatMessageList.isNotEmpty() &&
- ChatMessage.SystemMessageType.CLEARED_CHAT == chatMessageList[0].systemMessageType
- ) {
- adapter?.clear()
- adapter?.notifyDataSetChanged()
- }
- if (isFirstMessagesProcessing) {
- cancelNotificationsForCurrentConversation()
- isFirstMessagesProcessing = false
- binding.progressBar.visibility = View.GONE
- binding.messagesListView.visibility = View.VISIBLE
- }
- var countGroupedMessages = 0
- if (!isFromTheFuture) {
- var previousMessageId = NO_PREVIOUS_MESSAGE_ID
- for (i in chatMessageList.indices.reversed()) {
- val chatMessage = chatMessageList[i]
- if (previousMessageId > NO_PREVIOUS_MESSAGE_ID) {
- chatMessage.previousMessageId = previousMessageId
- } else if (adapter?.isEmpty != true) {
- if (adapter!!.items[0].item is ChatMessage) {
- chatMessage.previousMessageId = (adapter!!.items[0].item as ChatMessage).jsonMessageId
- } else if (adapter!!.items.size > 1 && adapter!!.items[1].item is ChatMessage) {
- chatMessage.previousMessageId = (adapter!!.items[1].item as ChatMessage).jsonMessageId
- }
- }
- previousMessageId = chatMessage.jsonMessageId
- }
- for (i in chatMessageList.indices) {
- if (chatMessageList.size > i + 1) {
- if (isSameDayNonSystemMessages(chatMessageList[i], chatMessageList[i + 1]) &&
- chatMessageList[i + 1].actorId == chatMessageList[i].actorId &&
- countGroupedMessages < GROUPED_MESSAGES_THRESHOLD
- ) {
- chatMessageList[i].isGrouped = true
- countGroupedMessages++
- } else {
- countGroupedMessages = 0
- }
- }
- val chatMessage = chatMessageList[i]
- chatMessage.isOneToOneConversation =
- currentConversation?.type == Conversation.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL
- chatMessage.activeUser = conversationUser
- }
- if (adapter != null) {
- adapter?.addToEnd(chatMessageList, false)
- }
- scrollToRequestedMessageIfNeeded()
- } else {
- var chatMessage: ChatMessage
- val shouldAddNewMessagesNotice = timeout == 0 && adapter?.itemCount ?: 0 > 0 && chatMessageList.size > 0
- if (shouldAddNewMessagesNotice) {
- val unreadChatMessage = ChatMessage()
- unreadChatMessage.jsonMessageId = -1
- unreadChatMessage.actorId = "-1"
- unreadChatMessage.timestamp = chatMessageList[0].timestamp
- unreadChatMessage.message = context?.getString(R.string.nc_new_messages)
- adapter?.addToStart(unreadChatMessage, false)
- }
- val isThereANewNotice =
- shouldAddNewMessagesNotice || adapter?.getMessagePositionByIdInReverse("-1") != -1
- var previousMessageId = NO_PREVIOUS_MESSAGE_ID
- for (i in chatMessageList.indices.reversed()) {
- val chatMessageItem = chatMessageList[i]
- if (previousMessageId > NO_PREVIOUS_MESSAGE_ID) {
- chatMessageItem.previousMessageId = previousMessageId
- } else if (adapter?.isEmpty != true) {
- if (adapter!!.items[0].item is ChatMessage) {
- chatMessageItem.previousMessageId = (adapter!!.items[0].item as ChatMessage).jsonMessageId
- } else if (adapter!!.items.size > 1 && adapter!!.items[1].item is ChatMessage) {
- chatMessageItem.previousMessageId = (adapter!!.items[1].item as ChatMessage).jsonMessageId
- }
- }
- previousMessageId = chatMessageItem.jsonMessageId
- }
- for (i in chatMessageList.indices) {
- chatMessage = chatMessageList[i]
- chatMessage.activeUser = conversationUser
- val shouldScroll =
- !isThereANewNotice &&
- !shouldAddNewMessagesNotice &&
- layoutManager?.findFirstVisibleItemPosition() == 0 ||
- adapter != null &&
- adapter?.itemCount == 0
- if (!shouldAddNewMessagesNotice && !shouldScroll) {
- if (!binding.popupBubbleView.isShown) {
- newMessagesCount = 1
- binding.popupBubbleView.show()
- } else if (binding.popupBubbleView.isShown == true) {
- newMessagesCount++
- }
- } else {
- newMessagesCount = 0
- }
- if (adapter != null) {
- chatMessage.isGrouped = (
- adapter!!.isPreviousSameAuthor(
- chatMessage.actorId,
- -1
- ) && adapter!!.getSameAuthorLastMessagesCount(chatMessage.actorId) %
- GROUPED_MESSAGES_SAME_AUTHOR_THRESHOLD > 0
- )
- chatMessage.isOneToOneConversation =
- (currentConversation?.type == Conversation.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL)
- adapter?.addToStart(chatMessage, shouldScroll)
- }
- }
- if (shouldAddNewMessagesNotice && adapter != null) {
- layoutManager?.scrollToPositionWithOffset(
- adapter!!.getMessagePositionByIdInReverse("-1"),
- binding.messagesListView.height / 2
- )
- }
- }
- // update read status of all messages
- for (message in adapter!!.items) {
- xChatLastCommonRead?.let {
- if (message.item is ChatMessage) {
- val chatMessage = message.item as ChatMessage
- if (chatMessage.jsonMessageId <= it) {
- chatMessage.readStatus = ReadStatus.READ
- } else {
- chatMessage.readStatus = ReadStatus.SENT
- }
- }
- }
- }
- adapter?.notifyDataSetChanged()
- if (inConversation) {
- pullChatMessages(1, 1, xChatLastCommonRead)
- }
- } else if (response.code() == HTTP_CODE_NOT_MODIFIED && !isFromTheFuture) {
- if (isFirstMessagesProcessing) {
- cancelNotificationsForCurrentConversation()
- isFirstMessagesProcessing = false
- binding.progressBar.visibility = View.GONE
- }
- historyRead = true
- if (!lookingIntoFuture && inConversation) {
- pullChatMessages(1)
- }
- }
- }
- private fun scrollToRequestedMessageIfNeeded() {
- args.getString(BundleKeys.KEY_MESSAGE_ID)?.let {
- scrollToMessageWithId(it)
- }
- }
- private fun isSameDayNonSystemMessages(messageLeft: ChatMessage, messageRight: ChatMessage): Boolean {
- return TextUtils.isEmpty(messageLeft.systemMessage) &&
- TextUtils.isEmpty(messageRight.systemMessage) &&
- DateFormatter.isSameDay(messageLeft.createdAt, messageRight.createdAt)
- }
- override fun onLoadMore(page: Int, totalItemsCount: Int) {
- if (!historyRead && inConversation) {
- pullChatMessages(0)
- }
- }
- override fun format(date: Date): String {
- return if (DateFormatter.isToday(date)) {
- resources!!.getString(R.string.nc_date_header_today)
- } else if (DateFormatter.isYesterday(date)) {
- resources!!.getString(R.string.nc_date_header_yesterday)
- } else {
- DateFormatter.format(date, DateFormatter.Template.STRING_DAY_MONTH_YEAR)
- }
- }
- override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
- super.onCreateOptionsMenu(menu, inflater)
- inflater.inflate(R.menu.menu_conversation, menu)
- if (conversationUser?.userId == "?") {
- menu.removeItem(R.id.conversation_info)
- } else {
- conversationInfoMenuItem = menu.findItem(R.id.conversation_info)
- if (CapabilitiesUtil.hasSpreedFeatureCapability(conversationUser, "rich-object-list-media")) {
- conversationSharedItemsItem = menu.findItem(R.id.shared_items)
- } else {
- menu.removeItem(R.id.shared_items)
- }
- loadAvatarForStatusBar()
- }
- if (CapabilitiesUtil.isAbleToCall(conversationUser)) {
- conversationVoiceCallMenuItem = menu.findItem(R.id.conversation_voice_call)
- conversationVideoMenuItem = menu.findItem(R.id.conversation_video_call)
- if (CapabilitiesUtil.hasSpreedFeatureCapability(conversationUser, "silent-call")) {
- Handler().post {
- activity?.findViewById<View?>(R.id.conversation_voice_call)?.setOnLongClickListener {
- showCallButtonMenu(true)
- true
- }
- }
- Handler().post {
- activity?.findViewById<View?>(R.id.conversation_video_call)?.setOnLongClickListener {
- showCallButtonMenu(false)
- true
- }
- }
- }
- } else {
- menu.removeItem(R.id.conversation_video_call)
- menu.removeItem(R.id.conversation_voice_call)
- }
- }
- override fun onPrepareOptionsMenu(menu: Menu) {
- super.onPrepareOptionsMenu(menu)
- conversationUser?.let {
- if (CapabilitiesUtil.hasSpreedFeatureCapability(it, "read-only-rooms")) {
- checkShowCallButtons()
- }
- }
- }
- override fun onOptionsItemSelected(item: MenuItem): Boolean {
- return when (item.itemId) {
- android.R.id.home -> {
- (activity as MainActivity).resetConversationsList()
- true
- }
- R.id.conversation_video_call -> {
- startACall(false, false)
- true
- }
- R.id.conversation_voice_call -> {
- startACall(true, false)
- true
- }
- R.id.conversation_info -> {
- showConversationInfoScreen()
- true
- }
- R.id.shared_items -> {
- showSharedItems()
- true
- }
- R.id.conversation_search -> {
- startMessageSearch()
- true
- }
- else -> super.onOptionsItemSelected(item)
- }
- }
- private fun showSharedItems() {
- val intent = Intent(activity, SharedItemsActivity::class.java)
- intent.putExtra(KEY_CONVERSATION_NAME, currentConversation?.displayName)
- intent.putExtra(KEY_ROOM_TOKEN, roomToken)
- intent.putExtra(KEY_USER_ENTITY, conversationUser as Parcelable)
- activity!!.startActivity(intent)
- }
- private fun startMessageSearch() {
- val intent = Intent(activity, MessageSearchActivity::class.java)
- intent.putExtra(KEY_CONVERSATION_NAME, currentConversation?.displayName)
- intent.putExtra(KEY_ROOM_TOKEN, roomToken)
- startActivityForResult(intent, REQUEST_CODE_MESSAGE_SEARCH)
- }
- private fun handleSystemMessages(chatMessageList: List<ChatMessage>): List<ChatMessage> {
- val chatMessageMap = chatMessageList.map { it.id to it }.toMap().toMutableMap()
- val chatMessageIterator = chatMessageMap.iterator()
- while (chatMessageIterator.hasNext()) {
- val currentMessage = chatMessageIterator.next()
- // setDeletionFlagsAndRemoveInfomessages
- if (isInfoMessageAboutDeletion(currentMessage)) {
- if (!chatMessageMap.containsKey(currentMessage.value.parentMessage!!.id)) {
- // if chatMessageMap doesn't contain message to delete (this happens when lookingIntoFuture),
- // the message to delete has to be modified directly inside the adapter
- setMessageAsDeleted(currentMessage.value.parentMessage)
- } else {
- chatMessageMap[currentMessage.value.parentMessage!!.id]!!.isDeleted = true
- }
- chatMessageIterator.remove()
- }
- // delete reactions system messages
- else if (isReactionsMessage(currentMessage)) {
- if (!chatMessageMap.containsKey(currentMessage.value.parentMessage!!.id)) {
- updateAdapterForReaction(currentMessage.value.parentMessage)
- }
- chatMessageIterator.remove()
- }
- }
- return chatMessageMap.values.toList()
- }
- private fun isInfoMessageAboutDeletion(currentMessage: MutableMap.MutableEntry<String, ChatMessage>): Boolean {
- return currentMessage.value.parentMessage != null && currentMessage.value.systemMessageType == ChatMessage
- .SystemMessageType.MESSAGE_DELETED
- }
- private fun isReactionsMessage(currentMessage: MutableMap.MutableEntry<String, ChatMessage>): Boolean {
- return currentMessage.value.systemMessageType == ChatMessage.SystemMessageType.REACTION ||
- currentMessage.value.systemMessageType == ChatMessage.SystemMessageType.REACTION_DELETED ||
- currentMessage.value.systemMessageType == ChatMessage.SystemMessageType.REACTION_REVOKED
- }
- private fun startACall(isVoiceOnlyCall: Boolean, callWithoutNotification: Boolean) {
- if (currentConversation?.canStartCall == false && currentConversation?.hasCall == false) {
- Toast.makeText(context, R.string.startCallForbidden, Toast.LENGTH_LONG).show()
- } else {
- ApplicationWideCurrentRoomHolder.getInstance().isDialing = true
- val callIntent = getIntentForCall(isVoiceOnlyCall, callWithoutNotification)
- if (callIntent != null) {
- startActivity(callIntent)
- }
- }
- }
- private fun getIntentForCall(isVoiceOnlyCall: Boolean, callWithoutNotification: Boolean): Intent? {
- currentConversation?.let {
- val bundle = Bundle()
- bundle.putString(KEY_ROOM_TOKEN, roomToken)
- bundle.putString(KEY_ROOM_ID, roomId)
- bundle.putParcelable(KEY_USER_ENTITY, conversationUser)
- bundle.putString(BundleKeys.KEY_CONVERSATION_PASSWORD, roomPassword)
- bundle.putString(BundleKeys.KEY_MODIFIED_BASE_URL, conversationUser?.baseUrl)
- bundle.putString(KEY_CONVERSATION_NAME, it.displayName)
- if (isVoiceOnlyCall) {
- bundle.putBoolean(BundleKeys.KEY_CALL_VOICE_ONLY, true)
- }
- if (callWithoutNotification) {
- bundle.putBoolean(BundleKeys.KEY_CALL_WITHOUT_NOTIFICATION, true)
- }
- return if (activity != null) {
- val callIntent = Intent(activity, CallActivity::class.java)
- callIntent.putExtras(bundle)
- callIntent
- } else {
- null
- }
- } ?: run {
- return null
- }
- }
- override fun onClickReactions(chatMessage: ChatMessage) {
- activity?.let {
- ShowReactionsDialog(
- activity!!,
- currentConversation,
- chatMessage,
- conversationUser,
- hasChatPermission,
- ncApi!!
- ).show()
- }
- }
- override fun onLongClickReactions(chatMessage: ChatMessage) {
- openMessageActionsDialog(chatMessage)
- }
- override fun onMessageViewLongClick(view: View?, message: IMessage?) {
- openMessageActionsDialog(message)
- }
- override fun onPreviewMessageLongClick(chatMessage: ChatMessage) {
- openMessageActionsDialog(chatMessage)
- }
- private fun openMessageActionsDialog(iMessage: IMessage?) {
- val message = iMessage as ChatMessage
- if (hasVisibleItems(message) && !isSystemMessage(message)) {
- activity?.let {
- MessageActionsDialog(
- this,
- message,
- conversationUser,
- currentConversation,
- isShowMessageDeletionButton(message),
- hasChatPermission,
- ncApi!!
- ).show()
- }
- }
- }
- private fun isSystemMessage(message: ChatMessage): Boolean {
- return ChatMessage.MessageType.SYSTEM_MESSAGE == message.getCalculateMessageType()
- }
- fun deleteMessage(message: IMessage?) {
- if (!hasChatPermission) {
- Log.w(
- TAG,
- "Deletion of message is skipped because of restrictions by permissions. " +
- "This method should not have been called!"
- )
- Toast.makeText(context, R.string.nc_common_error_sorry, Toast.LENGTH_LONG).show()
- } else {
- var apiVersion = 1
- // FIXME Fix API checking with guests?
- if (conversationUser != null) {
- apiVersion = ApiUtils.getChatApiVersion(conversationUser, intArrayOf(1))
- }
- ncApi?.deleteChatMessage(
- credentials,
- ApiUtils.getUrlForChatMessage(
- apiVersion,
- conversationUser?.baseUrl,
- roomToken,
- message?.id
- )
- )?.subscribeOn(Schedulers.io())
- ?.observeOn(AndroidSchedulers.mainThread())
- ?.subscribe(object : Observer<ChatOverallSingleMessage> {
- override fun onSubscribe(d: Disposable) {
- // unused atm
- }
- override fun onNext(t: ChatOverallSingleMessage) {
- if (t.ocs!!.meta!!.statusCode == HttpURLConnection.HTTP_ACCEPTED) {
- Toast.makeText(
- context, R.string.nc_delete_message_leaked_to_matterbridge,
- Toast.LENGTH_LONG
- ).show()
- }
- }
- override fun onError(e: Throwable) {
- Log.e(
- TAG,
- "Something went wrong when trying to delete message with id " +
- message?.id,
- e
- )
- Toast.makeText(context, R.string.nc_common_error_sorry, Toast.LENGTH_LONG).show()
- }
- override fun onComplete() {
- // unused atm
- }
- })
- }
- }
- fun replyPrivately(message: IMessage?) {
- val apiVersion =
- ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(ApiUtils.APIv4, 1))
- val retrofitBucket = ApiUtils.getRetrofitBucketForCreateRoom(
- apiVersion,
- conversationUser?.baseUrl,
- "1",
- null,
- message?.user?.id?.substring(INVITE_LENGTH),
- null
- )
- ncApi!!.createRoom(
- credentials,
- retrofitBucket.url, retrofitBucket.queryMap
- )
- .subscribeOn(Schedulers.io())
- .observeOn(AndroidSchedulers.mainThread())
- .subscribe(object : Observer<RoomOverall> {
- override fun onSubscribe(d: Disposable) {
- // unused atm
- }
- override fun onNext(roomOverall: RoomOverall) {
- val bundle = Bundle()
- bundle.putParcelable(KEY_USER_ENTITY, conversationUser)
- bundle.putString(KEY_ROOM_TOKEN, roomOverall.ocs!!.data!!.token)
- bundle.putString(KEY_ROOM_ID, roomOverall.ocs!!.data!!.roomId)
- // FIXME once APIv2+ is used only, the createRoom already returns all the data
- ncApi!!.getRoom(
- credentials,
- ApiUtils.getUrlForRoom(
- apiVersion, conversationUser?.baseUrl,
- roomOverall.ocs!!.data!!.token
- )
- )
- .subscribeOn(Schedulers.io())
- .observeOn(AndroidSchedulers.mainThread())
- .subscribe(object : Observer<RoomOverall> {
- override fun onSubscribe(d: Disposable) {
- // unused atm
- }
- override fun onNext(roomOverall: RoomOverall) {
- bundle.putParcelable(
- KEY_ACTIVE_CONVERSATION,
- Parcels.wrap(roomOverall.ocs!!.data!!)
- )
- remapChatController(
- router, conversationUser!!.id,
- roomOverall.ocs!!.data!!.token!!, bundle, true
- )
- }
- override fun onError(e: Throwable) {
- Log.e(TAG, e.message, e)
- }
- override fun onComplete() {
- // unused atm
- }
- })
- }
- override fun onError(e: Throwable) {
- Log.e(TAG, e.message, e)
- }
- override fun onComplete() {
- // unused atm
- }
- })
- }
- fun forwardMessage(message: IMessage?) {
- val bundle = Bundle()
- bundle.putBoolean(BundleKeys.KEY_FORWARD_MSG_FLAG, true)
- bundle.putString(BundleKeys.KEY_FORWARD_MSG_TEXT, message?.text)
- bundle.putString(BundleKeys.KEY_FORWARD_HIDE_SOURCE_ROOM, roomId)
- router.pushController(
- RouterTransaction.with(ConversationsListController(bundle))
- .pushChangeHandler(HorizontalChangeHandler())
- .popChangeHandler(HorizontalChangeHandler())
- )
- }
- fun markAsUnread(message: IMessage?) {
- val chatMessage = message as ChatMessage?
- if (chatMessage!!.previousMessageId > NO_PREVIOUS_MESSAGE_ID) {
- ncApi!!.setChatReadMarker(
- credentials,
- ApiUtils.getUrlForSetChatReadMarker(
- ApiUtils.getChatApiVersion(conversationUser, intArrayOf(ApiUtils.APIv1)),
- conversationUser?.baseUrl,
- roomToken
- ),
- chatMessage.previousMessageId
- )
- .subscribeOn(Schedulers.io())
- .observeOn(AndroidSchedulers.mainThread())
- .subscribe(object : Observer<GenericOverall> {
- override fun onSubscribe(d: Disposable) {
- // unused atm
- }
- override fun onNext(t: GenericOverall) {
- // unused atm
- }
- override fun onError(e: Throwable) {
- Log.e(TAG, e.message, e)
- }
- override fun onComplete() {
- // unused atm
- }
- })
- }
- }
- fun copyMessage(message: IMessage?) {
- val clipboardManager =
- activity?.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
- val clipData = ClipData.newPlainText(
- resources?.getString(R.string.nc_app_product_name),
- message?.text
- )
- clipboardManager.setPrimaryClip(clipData)
- }
- private fun hasVisibleItems(message: ChatMessage): Boolean {
- return !message.isDeleted || // copy message
- message.replyable || // reply to
- message.replyable && // reply privately
- conversationUser?.userId?.isNotEmpty() == true && conversationUser?.userId != "?" &&
- message.user.id.startsWith("users/") &&
- message.user.id.substring(ACTOR_LENGTH) != currentConversation?.actorId &&
- currentConversation?.type != Conversation.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL ||
- isShowMessageDeletionButton(message) || // delete
- ChatMessage.MessageType.REGULAR_TEXT_MESSAGE == message.getCalculateMessageType() || // forward
- message.previousMessageId > NO_PREVIOUS_MESSAGE_ID && // mark as unread
- ChatMessage.MessageType.SYSTEM_MESSAGE != message.getCalculateMessageType() &&
- BuildConfig.DEBUG
- }
- fun replyToMessage(message: IMessage?) {
- val chatMessage = message as ChatMessage?
- chatMessage?.let {
- binding.messageInputView.findViewById<ImageButton>(R.id.attachmentButton)?.visibility =
- View.GONE
- binding.messageInputView.findViewById<ImageButton>(R.id.cancelReplyButton)?.visibility =
- View.VISIBLE
- val quotedMessage = binding
- .messageInputView
- .findViewById<EmojiTextView>(R.id.quotedMessage)
- quotedMessage?.maxLines = 2
- quotedMessage?.ellipsize = TextUtils.TruncateAt.END
- quotedMessage?.text = it.text
- binding.messageInputView.findViewById<EmojiTextView>(R.id.quotedMessageAuthor)?.text =
- it.actorDisplayName ?: context!!.getText(R.string.nc_nick_guest)
- conversationUser?.let { currentUser ->
- val quotedMessageImage = binding
- .messageInputView
- .findViewById<ImageView>(R.id.quotedMessageImage)
- chatMessage.imageUrl?.let { previewImageUrl ->
- quotedMessageImage?.visibility = View.VISIBLE
- val px = TypedValue.applyDimension(
- TypedValue.COMPLEX_UNIT_DIP,
- QUOTED_MESSAGE_IMAGE_MAX_HEIGHT,
- resources?.displayMetrics
- )
- quotedMessageImage?.maxHeight = px.toInt()
- val layoutParams = quotedMessageImage?.layoutParams as FlexboxLayout.LayoutParams
- layoutParams.flexGrow = 0f
- quotedMessageImage.layoutParams = layoutParams
- quotedMessageImage.load(previewImageUrl) {
- addHeader("Authorization", credentials!!)
- }
- } ?: run {
- binding
- .messageInputView
- .findViewById<ImageView>(R.id.quotedMessageImage)
- ?.visibility = View.GONE
- }
- }
- val quotedChatMessageView = binding
- .messageInputView
- .findViewById<RelativeLayout>(R.id.quotedChatMessageView)
- quotedChatMessageView?.tag = message?.jsonMessageId
- quotedChatMessageView?.visibility = View.VISIBLE
- }
- }
- private fun showMicrophoneButton(show: Boolean) {
- if (show && CapabilitiesUtil.hasSpreedFeatureCapability(conversationUser, "voice-message-sharing")) {
- binding.messageInputView.messageSendButton.visibility = View.GONE
- binding.messageInputView.recordAudioButton.visibility = View.VISIBLE
- } else {
- binding.messageInputView.messageSendButton.visibility = View.VISIBLE
- binding.messageInputView.recordAudioButton.visibility = View.GONE
- }
- }
- private fun setMessageAsDeleted(message: IMessage?) {
- val messageTemp = message as ChatMessage
- messageTemp.isDeleted = true
- messageTemp.isOneToOneConversation =
- currentConversation?.type == Conversation.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL
- messageTemp.activeUser = conversationUser
- adapter?.update(messageTemp)
- }
- private fun updateAdapterForReaction(message: IMessage?) {
- val messageTemp = message as ChatMessage
- messageTemp.isOneToOneConversation =
- currentConversation?.type == Conversation.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL
- messageTemp.activeUser = conversationUser
- adapter?.update(messageTemp)
- }
- fun updateAdapterAfterSendReaction(message: ChatMessage, emoji: String) {
- if (message.reactions == null) {
- message.reactions = LinkedHashMap()
- }
- if (message.reactionsSelf == null) {
- message.reactionsSelf = ArrayList<String>()
- }
- var amount = message.reactions!![emoji]
- if (amount == null) {
- amount = 0
- }
- message.reactions!![emoji] = amount + 1
- message.reactionsSelf!!.add(emoji)
- adapter?.update(message)
- }
- private fun isShowMessageDeletionButton(message: ChatMessage): Boolean {
- if (conversationUser == null) return false
- val isUserAllowedByPrivileges = if (message.actorId == conversationUser.userId) {
- true
- } else {
- currentConversation!!.canModerate(conversationUser)
- }
- val isOlderThanSixHours = message
- .createdAt
- ?.before(Date(System.currentTimeMillis() - AGE_THREHOLD_FOR_DELETE_MESSAGE)) == true
- return when {
- !isUserAllowedByPrivileges -> false
- isOlderThanSixHours -> false
- message.systemMessageType != ChatMessage.SystemMessageType.DUMMY -> false
- message.isDeleted -> false
- message.hasFileAttachment() -> false
- OBJECT_MESSAGE == message.message -> false
- !CapabilitiesUtil.hasSpreedFeatureCapability(conversationUser, "delete-messages") -> false
- !hasChatPermission -> false
- else -> true
- }
- }
- override fun hasContentFor(message: ChatMessage, type: Byte): Boolean {
- return when (type) {
- CONTENT_TYPE_LOCATION -> message.hasGeoLocation()
- CONTENT_TYPE_VOICE_MESSAGE -> message.isVoiceMessage
- CONTENT_TYPE_SYSTEM_MESSAGE -> !TextUtils.isEmpty(message.systemMessage)
- CONTENT_TYPE_UNREAD_NOTICE_MESSAGE -> message.id == "-1"
- else -> false
- }
- }
- @Subscribe(threadMode = ThreadMode.BACKGROUND)
- fun onMessageEvent(webSocketCommunicationEvent: WebSocketCommunicationEvent) {
- /*
- switch (webSocketCommunicationEvent.getType()) {
- case "refreshChat":
- if (
- webSocketCommunicationEvent
- .getHashMap().get(BundleKeys.KEY_INTERNAL_USER_ID)
- .equals(Long.toString(conversationUser.getId()))
- ) {
- if (roomToken.equals(webSocketCommunicationEvent.getHashMap().get(BundleKeys.KEY_ROOM_TOKEN))) {
- pullChatMessages(2);
- }
- }
- break;
- default:
- }*/
- }
- @Subscribe(threadMode = ThreadMode.BACKGROUND)
- fun onMessageEvent(userMentionClickEvent: UserMentionClickEvent) {
- if (currentConversation?.type != Conversation.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL ||
- currentConversation?.name != userMentionClickEvent.userId
- ) {
- var apiVersion = 1
- // FIXME Fix API checking with guests?
- if (conversationUser != null) {
- apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(ApiUtils.APIv4, 1))
- }
- val retrofitBucket = ApiUtils.getRetrofitBucketForCreateRoom(
- apiVersion,
- conversationUser?.baseUrl,
- "1",
- null,
- userMentionClickEvent.userId,
- null
- )
- ncApi?.createRoom(
- credentials,
- retrofitBucket.url, retrofitBucket.queryMap
- )
- ?.subscribeOn(Schedulers.io())
- ?.observeOn(AndroidSchedulers.mainThread())
- ?.subscribe(object : Observer<RoomOverall> {
- override fun onSubscribe(d: Disposable) {
- // unused atm
- }
- override fun onNext(roomOverall: RoomOverall) {
- val conversationIntent = Intent(activity, CallActivity::class.java)
- val bundle = Bundle()
- bundle.putParcelable(KEY_USER_ENTITY, conversationUser)
- bundle.putString(KEY_ROOM_TOKEN, roomOverall.ocs!!.data!!.token)
- bundle.putString(KEY_ROOM_ID, roomOverall.ocs!!.data!!.roomId)
- if (conversationUser != null) {
- bundle.putParcelable(
- KEY_ACTIVE_CONVERSATION,
- Parcels.wrap(roomOverall.ocs!!.data)
- )
- conversationIntent.putExtras(bundle)
- ConductorRemapping.remapChatController(
- router, conversationUser.id,
- roomOverall.ocs!!.data!!.token!!, bundle, false
- )
- } else {
- conversationIntent.putExtras(bundle)
- startActivity(conversationIntent)
- Handler().postDelayed(
- {
- if (!isDestroyed && !isBeingDestroyed) {
- router.popCurrentController()
- }
- },
- POP_CURRENT_CONTROLLER_DELAY
- )
- }
- }
- override fun onError(e: Throwable) {
- // unused atm
- }
- override fun onComplete() {
- // unused atm
- }
- })
- }
- }
- fun sendPictureFromCamIntent() {
- if (!isCameraPermissionGranted()) {
- requestCameraPermissions()
- } else {
- startActivityForResult(TakePhotoActivity.createIntent(context!!), REQUEST_CODE_PICK_CAMERA)
- }
- }
- companion object {
- private const val TAG = "ChatController"
- private const val CONTENT_TYPE_SYSTEM_MESSAGE: Byte = 1
- private const val CONTENT_TYPE_UNREAD_NOTICE_MESSAGE: Byte = 2
- private const val CONTENT_TYPE_LOCATION: Byte = 3
- private const val CONTENT_TYPE_VOICE_MESSAGE: Byte = 4
- private const val NEW_MESSAGES_POPUP_BUBBLE_DELAY: Long = 200
- private const val POP_CURRENT_CONTROLLER_DELAY: Long = 100
- private const val LOBBY_TIMER_DELAY: Long = 5000
- private const val HTTP_CODE_OK: Int = 200
- private const val MESSAGE_MAX_LENGTH: Int = 1000
- private const val AGE_THREHOLD_FOR_DELETE_MESSAGE: Int = 21600000 // (6 hours in millis = 6 * 3600 * 1000)
- private const val REQUEST_CODE_CHOOSE_FILE: Int = 555
- private const val REQUEST_CODE_SELECT_CONTACT: Int = 666
- private const val REQUEST_CODE_MESSAGE_SEARCH: Int = 777
- private const val REQUEST_RECORD_AUDIO_PERMISSION = 222
- private const val REQUEST_READ_CONTACT_PERMISSION = 234
- private const val REQUEST_CAMERA_PERMISSION = 223
- private const val REQUEST_CODE_PICK_CAMERA: Int = 333
- private const val OBJECT_MESSAGE: String = "{object}"
- private const val MINIMUM_VOICE_RECORD_DURATION: Int = 1000
- private const val VOICE_RECORD_CANCEL_SLIDER_X: Int = -50
- private const val VOICE_MESSAGE_META_DATA = "{\"messageType\":\"voice-message\"}"
- private const val VOICE_MESSAGE_FILE_SUFFIX = ".mp3"
- private const val SHORT_VIBRATE: Long = 20
- private const val FULLY_OPAQUE_INT: Int = 255
- private const val SEMI_TRANSPARENT_INT: Int = 99
- private const val VOICE_MESSAGE_SEEKBAR_BASE: Int = 1000
- private const val SECOND: Long = 1000
- private const val NO_PREVIOUS_MESSAGE_ID: Int = -1
- private const val GROUPED_MESSAGES_THRESHOLD = 4
- private const val GROUPED_MESSAGES_SAME_AUTHOR_THRESHOLD = 5
- private const val TOOLBAR_AVATAR_RATIO = 1.5
- private const val HTTP_CODE_NOT_MODIFIED = 304
- private const val HTTP_CODE_PRECONDITION_FAILED = 412
- private const val QUOTED_MESSAGE_IMAGE_MAX_HEIGHT = 96f
- private const val MENTION_AUTO_COMPLETE_ELEVATION = 6f
- private const val MESSAGE_PULL_LIMIT = 100
- private const val INVITE_LENGTH = 6
- private const val ACTOR_LENGTH = 6
- private const val ANIMATION_DURATION: Long = 750
- private const val RETRIES: Long = 3
- private const val LOOKING_INTO_FUTURE_TIMEOUT = 30
- }
- }
|