improved new dm conversation
supports disable_notification
This commit is contained in:
parent
cfd4e471a7
commit
a6cdf3217c
|
@ -49,6 +49,8 @@ public class TwitterOfficialConversationExtras extends ConversationExtras implem
|
|||
public long maxEntryTimestamp;
|
||||
@JsonField(name = "read_only")
|
||||
public boolean readOnly;
|
||||
@JsonField(name = "notifications_disabled")
|
||||
public boolean notificationsDisabled;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
@ -58,6 +60,7 @@ public class TwitterOfficialConversationExtras extends ConversationExtras implem
|
|||
", status='" + status + '\'' +
|
||||
", maxEntryTimestamp=" + maxEntryTimestamp +
|
||||
", readOnly=" + readOnly +
|
||||
", notificationsDisabled=" + notificationsDisabled +
|
||||
"} " + super.toString();
|
||||
}
|
||||
|
||||
|
|
|
@ -64,3 +64,13 @@ val ParcelableMessageConversation.readOnly: Boolean
|
|||
}
|
||||
return false
|
||||
}
|
||||
|
||||
val ParcelableMessageConversation.notificationDisabled: Boolean
|
||||
get() {
|
||||
when (conversation_extras_type) {
|
||||
ExtrasType.TWITTER_OFFICIAL -> {
|
||||
return (conversation_extras as? TwitterOfficialConversationExtras)?.notificationsDisabled ?: false
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
|
@ -149,10 +149,9 @@ class MessageNewConversationFragment : BaseFragment(), LoaderCallbacks<List<Parc
|
|||
val displayName = userColorNameManager.getDisplayName(user, nameFirst)
|
||||
val span = ParticipantSpan(user, displayName, roundRadius, spanPadding)
|
||||
val start = text.length
|
||||
text.append(user.screen_name)
|
||||
val end = text.length
|
||||
text.append("${user.screen_name} ")
|
||||
val end = text.length - 1
|
||||
text.setSpan(span, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
|
||||
text.append(' ')
|
||||
} else {
|
||||
text.getSpans(0, text.length, ParticipantSpan::class.java).forEach { span ->
|
||||
if (user != span.user) {
|
||||
|
|
|
@ -58,9 +58,9 @@ class CacheUserSearchLoader(
|
|||
c.close()
|
||||
val collator = Collator.getInstance()
|
||||
list.sortWith(Comparator { l, r ->
|
||||
val compare = collator.compare(l.name, r.name)
|
||||
val compare = collator.compare(r.name, l.name)
|
||||
if (compare != 0) return@Comparator compare
|
||||
return@Comparator l.screen_name.compareTo(r.screen_name)
|
||||
return@Comparator r.screen_name.compareTo(l.screen_name)
|
||||
})
|
||||
}
|
||||
}
|
|
@ -19,9 +19,19 @@
|
|||
|
||||
package org.mariotaku.twidere.task.twitter.message
|
||||
|
||||
import android.accounts.AccountManager
|
||||
import android.content.Context
|
||||
import org.mariotaku.microblog.library.MicroBlog
|
||||
import org.mariotaku.microblog.library.MicroBlogException
|
||||
import org.mariotaku.sqliteqb.library.Expression
|
||||
import org.mariotaku.twidere.annotation.AccountType
|
||||
import org.mariotaku.twidere.extension.model.isOfficial
|
||||
import org.mariotaku.twidere.extension.model.newMicroBlogInstance
|
||||
import org.mariotaku.twidere.model.AccountDetails
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.model.util.AccountUtils
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Messages
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Messages.Conversations
|
||||
import org.mariotaku.twidere.task.ExceptionHandlingAbstractTask
|
||||
|
||||
/**
|
||||
|
@ -32,9 +42,35 @@ class DestroyConversationTask(
|
|||
context: Context,
|
||||
val accountKey: UserKey,
|
||||
val conversationId: String
|
||||
) : ExceptionHandlingAbstractTask<Unit?, Unit, MicroBlogException, Unit?>(context) {
|
||||
override fun onExecute(params: Unit?) {
|
||||
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
) : ExceptionHandlingAbstractTask<Unit?, Boolean, MicroBlogException, Unit?>(context) {
|
||||
override fun onExecute(params: Unit?): Boolean {
|
||||
val account = AccountUtils.getAccountDetails(AccountManager.get(context), accountKey, true) ?:
|
||||
throw MicroBlogException("No account")
|
||||
val microBlog = account.newMicroBlogInstance(context, cls = MicroBlog::class.java)
|
||||
if (!performDestroyConversation(microBlog, account)) {
|
||||
return false
|
||||
}
|
||||
|
||||
val deleteMessageWhere = Expression.and(Expression.equalsArgs(Messages.ACCOUNT_KEY),
|
||||
Expression.equalsArgs(Messages.CONVERSATION_ID)).sql
|
||||
val deleteMessageWhereArgs = arrayOf(accountKey.toString(), conversationId)
|
||||
context.contentResolver.delete(Messages.CONTENT_URI, deleteMessageWhere, deleteMessageWhereArgs)
|
||||
val deleteConversationWhere = Expression.and(Expression.equalsArgs(Conversations.ACCOUNT_KEY),
|
||||
Expression.equalsArgs(Conversations.CONVERSATION_ID)).sql
|
||||
val deleteConversationWhereArgs = arrayOf(accountKey.toString(), conversationId)
|
||||
context.contentResolver.delete(Conversations.CONTENT_URI, deleteConversationWhere, deleteConversationWhereArgs)
|
||||
return true
|
||||
}
|
||||
|
||||
private fun performDestroyConversation(microBlog: MicroBlog, account: AccountDetails): Boolean {
|
||||
when (account.type) {
|
||||
AccountType.TWITTER -> {
|
||||
if (account.isOfficial(context)) {
|
||||
return microBlog.deleteDmConversation(conversationId).isSuccessful
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -414,6 +414,7 @@ class GetMessagesTask(
|
|||
this.maxEntryId = v.maxEntryId
|
||||
this.status = v.status
|
||||
this.readOnly = v.isReadOnly
|
||||
this.notificationsDisabled = v.isNotificationsDisabled
|
||||
val maxEntryTimestamp = messagesMap.findLastReadTimestamp(k, maxEntryId)
|
||||
if (maxEntryTimestamp > 0) {
|
||||
this.maxEntryTimestamp = maxEntryTimestamp
|
||||
|
@ -509,6 +510,7 @@ class GetMessagesTask(
|
|||
this.participants = participants + ParcelableUserUtils.fromUser(user, accountKey)
|
||||
}
|
||||
}
|
||||
participants.sortBy(ParcelableUser::screen_name)
|
||||
}
|
||||
|
||||
private fun Map<String, List<ParcelableMessage>>.findLastReadTimestamp(conversationId: String, lastReadEventId: String?): Long {
|
||||
|
|
|
@ -43,6 +43,7 @@ import org.mariotaku.twidere.constant.iWantMyStarsBackKey
|
|||
import org.mariotaku.twidere.constant.nameFirstKey
|
||||
import org.mariotaku.twidere.extension.model.getConversationName
|
||||
import org.mariotaku.twidere.extension.model.getSummaryText
|
||||
import org.mariotaku.twidere.extension.model.notificationDisabled
|
||||
import org.mariotaku.twidere.extension.rawQuery
|
||||
import org.mariotaku.twidere.model.*
|
||||
import org.mariotaku.twidere.model.util.ParcelableActivityUtils
|
||||
|
@ -294,6 +295,7 @@ class ContentNotificationManager(
|
|||
builder.setContentTitle(notificationTitle)
|
||||
val remaining = cur.forEachRow(5) { cur, pos ->
|
||||
val conversation = indices.newObject(cur)
|
||||
if (conversation.notificationDisabled) return@forEachRow false
|
||||
val title = conversation.getConversationName(context, userColorNameManager, nameFirst)
|
||||
val summary = conversation.getSummaryText(context, userColorNameManager, nameFirst)
|
||||
val line = SpanFormatter.format(context.getString(R.string.title_summary_line_format),
|
||||
|
@ -304,6 +306,7 @@ class ContentNotificationManager(
|
|||
style.addLine(line)
|
||||
return@forEachRow true
|
||||
}
|
||||
if (remaining < 0) return
|
||||
if (remaining > 0) {
|
||||
style.addLine(context.getString(R.string.and_N_more, remaining))
|
||||
}
|
||||
|
@ -323,7 +326,7 @@ class ContentNotificationManager(
|
|||
var current = 0
|
||||
while (!isAfterLast) {
|
||||
if (limit >= 0 && current >= limit) break
|
||||
if (action(this, position)) {
|
||||
if (action(this, current)) {
|
||||
current++
|
||||
}
|
||||
moveToNext()
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Twidere - Twitter client for Android
|
||||
~
|
||||
~ Copyright (C) 2012-2017 Mariotaku Lee <mariotaku.lee@gmail.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/>.
|
||||
-->
|
||||
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
</menu>
|
Loading…
Reference in New Issue