supports conversation name change event
This commit is contained in:
parent
bb4df20d02
commit
39d77df300
|
@ -34,6 +34,7 @@ import org.mariotaku.microblog.library.twitter.model.util.ParcelMapBagger;
|
|||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
|
@ -126,6 +127,8 @@ public class DMResponse implements Parcelable {
|
|||
Message participantsLeave;
|
||||
@JsonField(name = "participants_join")
|
||||
Message participantsJoin;
|
||||
@JsonField(name = "conversation_name_update")
|
||||
Message conversationNameUpdate;
|
||||
|
||||
public Message getJoinConversation() {
|
||||
return joinConversation;
|
||||
|
@ -147,6 +150,10 @@ public class DMResponse implements Parcelable {
|
|||
return participantsJoin;
|
||||
}
|
||||
|
||||
public Message getConversationNameUpdate() {
|
||||
return conversationNameUpdate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Entry{" +
|
||||
|
@ -154,6 +161,8 @@ public class DMResponse implements Parcelable {
|
|||
", joinConversation=" + joinConversation +
|
||||
", message=" + message +
|
||||
", participantsLeave=" + participantsLeave +
|
||||
", participantsJoin=" + participantsJoin +
|
||||
", conversationNameUpdate=" + conversationNameUpdate +
|
||||
'}';
|
||||
}
|
||||
|
||||
|
@ -173,12 +182,18 @@ public class DMResponse implements Parcelable {
|
|||
@JsonField(name = "conversation_id")
|
||||
String conversationId;
|
||||
|
||||
@JsonField(name = "conversation_name")
|
||||
String conversationName;
|
||||
|
||||
@JsonField(name = "request_id")
|
||||
String requestId;
|
||||
|
||||
@JsonField(name = "sender_id")
|
||||
String senderId;
|
||||
|
||||
@JsonField(name = "by_user_id")
|
||||
String byUserId;
|
||||
|
||||
@JsonField(name = "message_data")
|
||||
Data messageData;
|
||||
|
||||
|
@ -217,6 +232,14 @@ public class DMResponse implements Parcelable {
|
|||
return participants;
|
||||
}
|
||||
|
||||
public String getConversationName() {
|
||||
return conversationName;
|
||||
}
|
||||
|
||||
public String getByUserId() {
|
||||
return byUserId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Message{" +
|
||||
|
@ -224,7 +247,12 @@ public class DMResponse implements Parcelable {
|
|||
", id=" + id +
|
||||
", time=" + time +
|
||||
", conversationId='" + conversationId + '\'' +
|
||||
", conversationName='" + conversationName + '\'' +
|
||||
", requestId='" + requestId + '\'' +
|
||||
", senderId='" + senderId + '\'' +
|
||||
", byUserId='" + byUserId + '\'' +
|
||||
", messageData=" + messageData +
|
||||
", participants=" + Arrays.toString(participants) +
|
||||
'}';
|
||||
}
|
||||
|
||||
|
@ -449,6 +477,15 @@ public class DMResponse implements Parcelable {
|
|||
@Type
|
||||
String type;
|
||||
|
||||
@JsonField(name = "created_by_user_id")
|
||||
String createdByUserId;
|
||||
|
||||
@JsonField(name = "created_time")
|
||||
String createdTime;
|
||||
|
||||
@JsonField(name = "name")
|
||||
String name;
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
@ -493,6 +530,18 @@ public class DMResponse implements Parcelable {
|
|||
return notificationsDisabled;
|
||||
}
|
||||
|
||||
public String getCreatedByUserId() {
|
||||
return createdByUserId;
|
||||
}
|
||||
|
||||
public String getCreatedTime() {
|
||||
return createdTime;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@StringDef({Type.ONE_TO_ONE, Type.GROUP_DM})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface Type {
|
||||
|
|
|
@ -158,6 +158,7 @@ public class ParcelableMessage {
|
|||
String JOIN_CONVERSATION = "join_conversation";
|
||||
String PARTICIPANTS_LEAVE = "participants_leave";
|
||||
String PARTICIPANTS_JOIN = "participants_join";
|
||||
String CONVERSATION_NAME_UPDATE = "conversation_name_update";
|
||||
String TEXT = "text";
|
||||
String STICKER = "sticker";
|
||||
}
|
||||
|
|
|
@ -63,6 +63,10 @@ public class ParcelableMessageConversation {
|
|||
@CursorField(Conversations.CONVERSATION_TYPE)
|
||||
public String conversation_type;
|
||||
|
||||
@JsonField(name = "conversation_name")
|
||||
@CursorField(Conversations.CONVERSATION_NAME)
|
||||
public String conversation_name;
|
||||
|
||||
@ParcelableMessage.MessageType
|
||||
@JsonField(name = "message_type")
|
||||
@CursorField(Conversations.MESSAGE_TYPE)
|
||||
|
@ -128,6 +132,7 @@ public class ParcelableMessageConversation {
|
|||
", account_color=" + account_color +
|
||||
", id='" + id + '\'' +
|
||||
", conversation_type='" + conversation_type + '\'' +
|
||||
", conversation_name='" + conversation_name + '\'' +
|
||||
", message_type='" + message_type + '\'' +
|
||||
", message_timestamp=" + message_timestamp +
|
||||
", local_timestamp=" + local_timestamp +
|
||||
|
|
|
@ -44,6 +44,8 @@ public abstract class MessageExtras implements Parcelable {
|
|||
case MessageType.PARTICIPANTS_LEAVE:
|
||||
case MessageType.PARTICIPANTS_JOIN:
|
||||
return LoganSquare.parse(json, UserArrayExtras.class);
|
||||
case MessageType.CONVERSATION_NAME_UPDATE:
|
||||
return LoganSquare.parse(json, NameUpdatedExtras.class);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* Twidere - Twitter client for Android
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.mariotaku.twidere.model.message;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import com.bluelinelabs.logansquare.annotation.JsonField;
|
||||
import com.bluelinelabs.logansquare.annotation.JsonObject;
|
||||
import com.hannesdorfmann.parcelableplease.annotation.ParcelablePlease;
|
||||
|
||||
import org.mariotaku.twidere.model.ParcelableUser;
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 2017/2/12.
|
||||
*/
|
||||
|
||||
@ParcelablePlease
|
||||
@JsonObject
|
||||
public class NameUpdatedExtras extends MessageExtras implements Parcelable {
|
||||
@JsonField(name = "user")
|
||||
ParcelableUser user;
|
||||
@JsonField(name = "name")
|
||||
String name;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setUser(final ParcelableUser user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public ParcelableUser getUser() {
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
NameUpdatedExtrasParcelablePlease.writeToParcel(this, dest, flags);
|
||||
}
|
||||
|
||||
public static final Creator<NameUpdatedExtras> CREATOR = new Creator<NameUpdatedExtras>() {
|
||||
public NameUpdatedExtras createFromParcel(Parcel source) {
|
||||
NameUpdatedExtras target = new NameUpdatedExtras();
|
||||
NameUpdatedExtrasParcelablePlease.readFromParcel(target, source);
|
||||
return target;
|
||||
}
|
||||
|
||||
public NameUpdatedExtras[] newArray(int size) {
|
||||
return new NameUpdatedExtras[size];
|
||||
}
|
||||
};
|
||||
}
|
|
@ -383,6 +383,7 @@ public interface TwidereDataStore {
|
|||
String ACCOUNT_COLOR = "account_color";
|
||||
String CONVERSATION_ID = "conversation_id";
|
||||
String CONVERSATION_TYPE = "conversation_type";
|
||||
String CONVERSATION_NAME = "conversation_name";
|
||||
String MESSAGE_TYPE = "message_type";
|
||||
String MESSAGE_TIMESTAMP = "message_timestamp";
|
||||
String SORT_ID = "sort_id";
|
||||
|
|
|
@ -34,7 +34,7 @@ import static org.mariotaku.twidere.annotation.PreferenceType.STRING;
|
|||
public interface Constants extends TwidereConstants {
|
||||
|
||||
String DATABASES_NAME = "twidere.sqlite";
|
||||
int DATABASES_VERSION = 170;
|
||||
int DATABASES_VERSION = 171;
|
||||
|
||||
int EXTRA_FEATURES_NOTICE_VERSION = 0;
|
||||
|
||||
|
|
|
@ -737,7 +737,7 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
|||
}
|
||||
|
||||
override fun handleKeyboardShortcutRepeat(handler: KeyboardShortcutsHandler, keyCode: Int,
|
||||
repeatCount: Int, event: KeyEvent, metaState: Int): Boolean {
|
||||
repeatCount: Int, event: KeyEvent, metaState: Int): Boolean {
|
||||
return super.handleKeyboardShortcutRepeat(handler, keyCode, repeatCount, event, metaState)
|
||||
}
|
||||
|
||||
|
@ -1047,7 +1047,7 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
|||
}
|
||||
|
||||
private fun handleReplyMultipleIntent(screenNames: Array<String>?, accountId: UserKey?,
|
||||
inReplyToStatus: ParcelableStatus): Boolean {
|
||||
inReplyToStatus: ParcelableStatus): Boolean {
|
||||
if (screenNames == null || screenNames.isEmpty() || accountId == null) return false
|
||||
val myScreenName = DataStoreUtils.getAccountScreenName(this, accountId)
|
||||
if (TextUtils.isEmpty(myScreenName)) return false
|
||||
|
@ -1785,7 +1785,7 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
|||
}
|
||||
|
||||
fun displayMedia(adapter: MediaPreviewAdapter, media: ParcelableMediaUpdate) {
|
||||
adapter.mediaLoader.displayPreviewImage(imageView, media.uri)
|
||||
adapter.mediaLoader.displayPreviewImage(imageView, media.uri, true)
|
||||
videoIndicatorView.visibility = if (media.type == ParcelableMedia.Type.VIDEO) {
|
||||
View.VISIBLE
|
||||
} else {
|
||||
|
|
|
@ -67,8 +67,7 @@ class MessagesConversationAdapter(context: Context) : LoadMoreSupportAdapter<Rec
|
|||
val view = inflater.inflate(StickerMessageViewHolder.layoutResource, parent, false)
|
||||
return StickerMessageViewHolder(view, this)
|
||||
}
|
||||
ITEM_TYPE_CONVERSATION_CREATE, ITEM_TYPE_JOIN_CONVERSATION,
|
||||
ITEM_TYPE_PARTICIPANTS_LEAVE, ITEM_TYPE_PARTICIPANTS_JOIN -> {
|
||||
ITEM_TYPE_NOTICE_MESSAGE -> {
|
||||
val view = inflater.inflate(NoticeSummaryEventViewHolder.layoutResource, parent, false)
|
||||
return NoticeSummaryEventViewHolder(view, this)
|
||||
}
|
||||
|
@ -78,8 +77,7 @@ class MessagesConversationAdapter(context: Context) : LoadMoreSupportAdapter<Rec
|
|||
|
||||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
|
||||
when (holder.itemViewType) {
|
||||
ITEM_TYPE_TEXT_MESSAGE, ITEM_TYPE_STICKER_MESSAGE, ITEM_TYPE_CONVERSATION_CREATE,
|
||||
ITEM_TYPE_JOIN_CONVERSATION, ITEM_TYPE_PARTICIPANTS_LEAVE, ITEM_TYPE_PARTICIPANTS_JOIN -> {
|
||||
ITEM_TYPE_TEXT_MESSAGE, ITEM_TYPE_STICKER_MESSAGE, ITEM_TYPE_NOTICE_MESSAGE -> {
|
||||
val message = getMessage(position)!!
|
||||
// Display date for oldest item
|
||||
var showDate = true
|
||||
|
@ -108,17 +106,10 @@ class MessagesConversationAdapter(context: Context) : LoadMoreSupportAdapter<Rec
|
|||
MessageType.STICKER -> {
|
||||
return ITEM_TYPE_STICKER_MESSAGE
|
||||
}
|
||||
MessageType.CONVERSATION_CREATE -> {
|
||||
return ITEM_TYPE_CONVERSATION_CREATE
|
||||
}
|
||||
MessageType.JOIN_CONVERSATION -> {
|
||||
return ITEM_TYPE_JOIN_CONVERSATION
|
||||
}
|
||||
MessageType.PARTICIPANTS_LEAVE -> {
|
||||
return ITEM_TYPE_PARTICIPANTS_LEAVE
|
||||
}
|
||||
MessageType.PARTICIPANTS_JOIN -> {
|
||||
return ITEM_TYPE_PARTICIPANTS_JOIN
|
||||
MessageType.CONVERSATION_CREATE, MessageType.JOIN_CONVERSATION,
|
||||
MessageType.PARTICIPANTS_LEAVE, MessageType.PARTICIPANTS_JOIN,
|
||||
MessageType.CONVERSATION_NAME_UPDATE -> {
|
||||
return ITEM_TYPE_NOTICE_MESSAGE
|
||||
}
|
||||
else -> return ITEM_TYPE_TEXT_MESSAGE
|
||||
}
|
||||
|
@ -146,10 +137,7 @@ class MessagesConversationAdapter(context: Context) : LoadMoreSupportAdapter<Rec
|
|||
|
||||
const val ITEM_TYPE_TEXT_MESSAGE = 1
|
||||
const val ITEM_TYPE_STICKER_MESSAGE = 2
|
||||
const val ITEM_TYPE_CONVERSATION_CREATE = 3
|
||||
const val ITEM_TYPE_JOIN_CONVERSATION = 4
|
||||
const val ITEM_TYPE_PARTICIPANTS_LEAVE = 5
|
||||
const val ITEM_TYPE_PARTICIPANTS_JOIN = 6
|
||||
const val ITEM_TYPE_NOTICE_MESSAGE = 3
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import org.mariotaku.twidere.model.ParcelableMessage.MessageType
|
|||
import org.mariotaku.twidere.model.ParcelableMessageConversation
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.model.message.MessageExtras
|
||||
import org.mariotaku.twidere.model.message.NameUpdatedExtras
|
||||
import org.mariotaku.twidere.model.message.UserArrayExtras
|
||||
import org.mariotaku.twidere.util.UserColorNameManager
|
||||
|
||||
|
@ -63,6 +64,16 @@ internal fun getSummaryText(context: Context, manager: UserColorNameManager, nam
|
|||
return res.getString(R.string.message_format_participants_leave, usersName)
|
||||
}
|
||||
}
|
||||
MessageType.CONVERSATION_NAME_UPDATE -> {
|
||||
extras as NameUpdatedExtras
|
||||
val res = context.resources
|
||||
if (extras.user != null) {
|
||||
return res.getString(R.string.message_format_conversation_name_update_by_user,
|
||||
manager.getDisplayName(extras.user, nameFirst), extras.name)
|
||||
} else {
|
||||
return res.getString(R.string.message_format_conversation_name_update, extras.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
return text
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.mariotaku.twidere.model.util
|
||||
|
||||
import android.support.annotation.FloatRange
|
||||
import org.mariotaku.ktextension.convert
|
||||
import org.mariotaku.microblog.library.twitter.model.DMResponse
|
||||
import org.mariotaku.microblog.library.twitter.model.DirectMessage
|
||||
import org.mariotaku.microblog.library.twitter.model.User
|
||||
|
@ -9,6 +10,7 @@ import org.mariotaku.twidere.model.ParcelableMessage
|
|||
import org.mariotaku.twidere.model.ParcelableMessage.MessageType
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.model.message.MessageExtras
|
||||
import org.mariotaku.twidere.model.message.NameUpdatedExtras
|
||||
import org.mariotaku.twidere.model.message.StickerExtras
|
||||
import org.mariotaku.twidere.model.message.UserArrayExtras
|
||||
import org.mariotaku.twidere.util.InternalTwitterContentUtils
|
||||
|
@ -54,6 +56,11 @@ object ParcelableMessageUtils {
|
|||
applyUsersEvent(accountKey, entry.participantsJoin, users, MessageType.PARTICIPANTS_JOIN)
|
||||
}
|
||||
}
|
||||
entry.conversationNameUpdate != null -> {
|
||||
return ParcelableMessage().apply {
|
||||
applyNameUpdatedEvent(accountKey, entry.conversationNameUpdate, users)
|
||||
}
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
@ -98,6 +105,17 @@ object ParcelableMessageUtils {
|
|||
this.is_outgoing = false
|
||||
}
|
||||
|
||||
private fun ParcelableMessage.applyNameUpdatedEvent(accountKey: UserKey,
|
||||
message: DMResponse.Entry.Message, users: Map<String, User>) {
|
||||
this.commonEntry(accountKey, message)
|
||||
this.message_type = MessageType.CONVERSATION_NAME_UPDATE
|
||||
this.extras = NameUpdatedExtras().apply {
|
||||
this.name = message.conversationName
|
||||
this.user = users[message.byUserId]?.convert { ParcelableUserUtils.fromUser(it, accountKey) }
|
||||
}
|
||||
this.is_outgoing = false
|
||||
}
|
||||
|
||||
private fun ParcelableMessage.commonEntry(accountKey: UserKey, message: DMResponse.Entry.Message) {
|
||||
val data = message.messageData
|
||||
this.sender_key = run {
|
||||
|
|
|
@ -102,7 +102,9 @@ class GetMessagesTask(
|
|||
DMResponse.Conversation.Type.GROUP_DM -> ConversationType.GROUP
|
||||
else -> ConversationType.ONE_TO_ONE
|
||||
}
|
||||
conversations.addConversation(k, details, message, participants, conversationType)
|
||||
val conversation = conversations.addConversation(k, details, message, participants,
|
||||
conversationType)
|
||||
conversation.conversation_name = v.name
|
||||
}
|
||||
return GetMessagesData(conversations.values, messages)
|
||||
}
|
||||
|
|
|
@ -669,6 +669,16 @@
|
|||
<string name="message_direct_message_deleted">Direct message deleted.</string>
|
||||
<string name="message_direct_message_sent">Direct message sent.</string>
|
||||
<string name="message_error_invalid_account">Some account data are corrupted, Twidere will remove those accounts to prevent crash.</string>
|
||||
<string
|
||||
name="message_format_conversation_name_update">Conversation name changed to
|
||||
<xliff:g
|
||||
example="User" id="name">%1$s</xliff:g>
|
||||
</string>
|
||||
<string name="message_format_conversation_name_update_by_user">
|
||||
<xliff:g example="User"
|
||||
id="by_user">%1$s</xliff:g> changed conversation name to <xliff:g
|
||||
example="New name" id="name">%2$s</xliff:g>
|
||||
</string>
|
||||
<string name="message_format_participants_join">
|
||||
<xliff:g example="User" id="name">%1$s</xliff:g> joined</string>
|
||||
<string name="message_format_participants_join_added">
|
||||
|
|
Loading…
Reference in New Issue