implemented new dm conversation

This commit is contained in:
Mariotaku Lee 2017-02-16 02:02:59 +08:00
parent 9c7a62f447
commit bb05d46c69
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
4 changed files with 31 additions and 6 deletions

View File

@ -38,7 +38,7 @@ public class NewDm extends SimpleValueMap {
}
public void setRecipientIds(String[] recipientIds) {
put("conversation_ids", InternalArrayUtil.join(recipientIds, ","));
put("recipient_ids", InternalArrayUtil.join(recipientIds, ","));
}
public void setMediaId(String mediaId) {

View File

@ -54,6 +54,7 @@ import org.mariotaku.twidere.provider.TwidereDataStore.Messages.Conversations
import org.mariotaku.twidere.text.MarkForDeleteSpan
import org.mariotaku.twidere.util.IntentUtils
import org.mariotaku.twidere.util.view.SimpleTextWatcher
import java.lang.ref.WeakReference
/**
* Created by mariotaku on 2017/2/15.
@ -72,6 +73,7 @@ class MessageNewConversationFragment : BaseFragment(), LoaderCallbacks<List<Parc
}
private var loaderInitialized: Boolean = false
private var performSearchRequestRunnable: Runnable? = null
private lateinit var usersAdapter: SelectableUsersAdapter
@ -246,14 +248,15 @@ class MessageNewConversationFragment : BaseFragment(), LoaderCallbacks<List<Parc
activity?.supportInvalidateOptionsMenu()
}
private fun searchUser(query: String, fromCache: Boolean) {
private fun searchUser(query: String, fromType: Boolean) {
if (TextUtils.isEmpty(query)) {
return
}
val args = Bundle {
this[EXTRA_ACCOUNT_KEY] = accountKey
this[EXTRA_QUERY] = query
this[EXTRA_FROM_CACHE] = fromCache
this[EXTRA_FROM_CACHE] = fromType
}
if (loaderInitialized) {
loaderManager.initLoader(0, args, this)
@ -261,8 +264,23 @@ class MessageNewConversationFragment : BaseFragment(), LoaderCallbacks<List<Parc
} else {
loaderManager.restartLoader(0, args, this)
}
if (performSearchRequestRunnable != null) {
editParticipants.removeCallbacks(performSearchRequestRunnable)
}
if (fromType) {
performSearchRequestRunnable = PerformSearchRequestRunnable(query, this)
editParticipants.postDelayed(performSearchRequestRunnable, 1000L)
}
}
internal class PerformSearchRequestRunnable(val query: String, fragment: MessageNewConversationFragment) : Runnable {
val fragmentRef = WeakReference(fragment)
override fun run() {
val fragment = fragmentRef.get() ?: return
fragment.searchUser(query, false)
}
}
class PendingQuerySpan

View File

@ -257,7 +257,7 @@ class MessagesConversationFragment : AbsContentListRecyclerViewFragment<Messages
@Subscribe
fun onSendMessageTaskEvent(event: SendMessageTaskEvent) {
if (event.success || event.accountKey != accountKey || event.conversationId != conversationId) {
if (!event.success || event.accountKey != accountKey || event.conversationId != conversationId) {
return
}
val newConversationId = event.newConversationId ?: return
@ -291,10 +291,13 @@ class MessagesConversationFragment : AbsContentListRecyclerViewFragment<Messages
this.account = conversationAccount
this.media = mediaPreviewAdapter.asList().toTypedArray()
this.conversation_id = conversation.id
this.recipient_ids = conversation.participants?.map {
this.recipient_ids = conversation.participants?.filter {
it.key != accountKey
}?.map {
it.key.id
}?.toTypedArray()
this.text = text
this.is_temp_conversation = conversation.is_temp
}
LengthyOperationsService.sendMessageAsync(context, message)
editText.text = null

View File

@ -91,7 +91,7 @@ class SendMessageTask(
private fun sendTwitterOfficialDM(microBlog: MicroBlog, account: AccountDetails, message: ParcelableNewMessage): GetMessagesTask.DatabaseUpdateData {
var deleteOnSuccess: List<UpdateStatusTask.MediaDeletionItem>? = null
var deleteAlways: List<UpdateStatusTask.MediaDeletionItem>? = null
val response = try {
val sendResponse = try {
val conversationId = message.conversation_id
val tempConversation = message.is_temp_conversation
@ -116,6 +116,10 @@ class SendMessageTask(
deleteOnSuccess?.forEach { it.delete(context) }
}
deleteAlways?.forEach { it.delete(context) }
val conversationId = sendResponse.entries?.firstOrNull {
it.message != null
}?.message?.conversationId
val response = microBlog.getDmConversation(conversationId, null).conversationTimeline
response.fixMedia(microBlog)
return GetMessagesTask.createDatabaseUpdateData(context, account, response)
}