diff --git a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/api/twitter/DirectMessagesEventResources.java b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/api/twitter/DirectMessagesEventResources.java index 23cdae09d..ed9e52fe0 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/api/twitter/DirectMessagesEventResources.java +++ b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/api/twitter/DirectMessagesEventResources.java @@ -19,10 +19,10 @@ package org.mariotaku.microblog.library.api.twitter; import org.mariotaku.microblog.library.MicroBlogException; -import org.mariotaku.microblog.library.model.microblog.DirectMessageEventObject; -import org.mariotaku.microblog.library.model.microblog.PageableResponseList; import org.mariotaku.microblog.library.model.Paging; import org.mariotaku.microblog.library.model.microblog.ResponseCode; +import org.mariotaku.microblog.library.model.twitter.dm.DirectMessageEventList; +import org.mariotaku.microblog.library.model.twitter.dm.DirectMessageEventObject; import org.mariotaku.microblog.library.template.twitter.DirectMessageAnnotationTemplate; import org.mariotaku.restfu.annotation.method.DELETE; import org.mariotaku.restfu.annotation.method.GET; @@ -38,8 +38,7 @@ public interface DirectMessagesEventResources { @GET("/direct_messages/events/list.json") @BodyType(BodyType.FORM) - PageableResponseList getDirectMessageEvents(@Query Paging paging) - throws MicroBlogException; + DirectMessageEventList getDirectMessageEvents(@Query Paging paging) throws MicroBlogException; @POST("/direct_messages/events/new.json") @BodyType(BodyType.RAW) diff --git a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/api/twitter/PrivateDirectMessagesResources.java b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/api/twitter/PrivateDirectMessagesResources.java index b0a82f43c..32b1051ba 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/api/twitter/PrivateDirectMessagesResources.java +++ b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/api/twitter/PrivateDirectMessagesResources.java @@ -23,7 +23,7 @@ import android.support.annotation.Nullable; import org.mariotaku.microblog.library.MicroBlogException; import org.mariotaku.microblog.library.model.microblog.ConversationTimeline; import org.mariotaku.microblog.library.model.microblog.DMResponse; -import org.mariotaku.microblog.library.model.twitter.NewDm; +import org.mariotaku.microblog.library.model.twitter.dm.NewDm; import org.mariotaku.microblog.library.model.Paging; import org.mariotaku.microblog.library.model.microblog.ResponseCode; import org.mariotaku.microblog.library.model.microblog.UserEvents; diff --git a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/model/microblog/DirectMessageEventObject.java b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/model/microblog/DirectMessageEventObject.java deleted file mode 100644 index dce59fb44..000000000 --- a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/model/microblog/DirectMessageEventObject.java +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Twidere - Twitter client for Android - * - * Copyright 2012-2017 Mariotaku Lee - * - * Licensed 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.microblog.library.model.microblog; - -import com.bluelinelabs.logansquare.annotation.JsonField; -import com.bluelinelabs.logansquare.annotation.JsonObject; - -/** - * Created by mariotaku on 2017/5/11. - */ -@JsonObject -public class DirectMessageEventObject { - @JsonField(name = "event") - Event event; - - public Event getEvent() { - return event; - } - - public void setEvent(Event event) { - this.event = event; - } - - @JsonObject - public static class Event { - @JsonField(name = "id") - String id; - - @JsonField(name = "type") - String type; - - @JsonField(name = "message_create") - MessageCreate messageCreate; - - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public MessageCreate getMessageCreate() { - return messageCreate; - } - - public void setMessageCreate(MessageCreate messageCreate) { - this.messageCreate = messageCreate; - } - - - public String getId() { - return id; - } - - - @JsonObject - public static class MessageCreate { - - @JsonField(name = "target") - Target target; - @JsonField(name = "message_data") - MessageData messageData; - - public Target getTarget() { - return target; - } - - public void setTarget(Target target) { - this.target = target; - } - - public MessageData getMessageData() { - return messageData; - } - - public void setMessageData(MessageData messageData) { - this.messageData = messageData; - } - - @JsonObject - public static class Target { - @JsonField(name = "recipient_id") - String recipientId; - - public String getRecipientId() { - return recipientId; - } - - public void setRecipientId(String recipientId) { - this.recipientId = recipientId; - } - } - - @JsonObject - public static class MessageData { - @JsonField(name = "text") - String text; - @JsonField(name = "attachment") - Attachment attachment; - - public String getText() { - return text; - } - - public void setText(String text) { - this.text = text; - } - - public Attachment getAttachment() { - return attachment; - } - - public void setAttachment(Attachment attachment) { - this.attachment = attachment; - } - - @JsonObject - public static class Attachment { - @JsonField(name = "type") - String type; - - @JsonField(name = "media") - Media media; - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public Media getMedia() { - return media; - } - - public void setMedia(Media media) { - this.media = media; - } - - @JsonObject - public static class Media { - @JsonField(name = "id") - String id; - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - } - } - } - - } - } -} diff --git a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/model/microblog/MediaEntity.java b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/model/microblog/MediaEntity.java index 629751ae8..b396f5e30 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/model/microblog/MediaEntity.java +++ b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/model/microblog/MediaEntity.java @@ -38,8 +38,8 @@ import java.util.Map; @ParcelablePlease @JsonObject public class MediaEntity extends UrlEntity implements Parcelable { - @JsonField(name = "id") - long id; + @JsonField(name = {"id_str", "id"}) + protected String id; @JsonField(name = "indices", typeConverter = IndicesConverter.class) Indices indices; @@ -125,7 +125,7 @@ public class MediaEntity extends UrlEntity implements Parcelable { return indices.getStart(); } - public long getId() { + public String getId() { return id; } diff --git a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/model/twitter/dm/App.java b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/model/twitter/dm/App.java new file mode 100644 index 000000000..aa5cc2886 --- /dev/null +++ b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/model/twitter/dm/App.java @@ -0,0 +1,44 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright 2012-2018 Mariotaku Lee + * + * Licensed 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.microblog.library.model.twitter.dm; + +import com.bluelinelabs.logansquare.annotation.JsonField; +import com.bluelinelabs.logansquare.annotation.JsonObject; + +@JsonObject +public class App { + @JsonField(name = "id") + String id; + @JsonField(name = "name") + String name; + @JsonField(name = "url") + String url; + + public String getId() { + return id; + } + + public String getName() { + return name; + } + + public String getUrl() { + return url; + } +} diff --git a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/model/twitter/dm/Attachment.java b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/model/twitter/dm/Attachment.java new file mode 100644 index 000000000..98a79cc3f --- /dev/null +++ b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/model/twitter/dm/Attachment.java @@ -0,0 +1,57 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright 2012-2018 Mariotaku Lee + * + * Licensed 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.microblog.library.model.twitter.dm; + +import com.bluelinelabs.logansquare.annotation.JsonField; +import com.bluelinelabs.logansquare.annotation.JsonObject; + +import org.mariotaku.microblog.library.model.microblog.MediaEntity; + +@JsonObject +public class Attachment { + @JsonField(name = "type") + String type; + + @JsonField(name = "media") + Media media; + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public Media getMedia() { + return media; + } + + public void setMedia(Media media) { + this.media = media; + } + + @JsonObject + public static class Media extends MediaEntity { + + public void setId(String id) { + this.id = id; + } + } +} diff --git a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/model/twitter/dm/DirectMessageEvent.java b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/model/twitter/dm/DirectMessageEvent.java new file mode 100644 index 000000000..3b00c1c2e --- /dev/null +++ b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/model/twitter/dm/DirectMessageEvent.java @@ -0,0 +1,142 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright 2012-2018 Mariotaku Lee + * + * Licensed 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.microblog.library.model.twitter.dm; + +import com.bluelinelabs.logansquare.annotation.JsonField; +import com.bluelinelabs.logansquare.annotation.JsonObject; + +import org.mariotaku.microblog.library.model.microblog.Entities; + +@JsonObject +public class DirectMessageEvent { + @JsonField(name = "id") + String id; + + @JsonField(name = "created_timestamp") + long created_timestamp; + + @JsonField(name = "type") + String type; + + @JsonField(name = "message_create") + MessageCreate messageCreate; + + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public MessageCreate getMessageCreate() { + return messageCreate; + } + + public void setMessageCreate(MessageCreate messageCreate) { + this.messageCreate = messageCreate; + } + + + public String getId() { + return id; + } + + + @JsonObject + public static class MessageCreate { + + @JsonField(name = "sender_id") + String senderId; + @JsonField(name = "source_app_id") + String sourceAppId; + @JsonField(name = "target") + MessageCreate.Target target; + @JsonField(name = "message_data") + MessageCreate.MessageData messageData; + + public String getSenderId() { + return senderId; + } + + public String getSourceAppId() { + return sourceAppId; + } + + public MessageCreate.Target getTarget() { + return target; + } + + public void setTarget(MessageCreate.Target target) { + this.target = target; + } + + public MessageCreate.MessageData getMessageData() { + return messageData; + } + + public void setMessageData(MessageCreate.MessageData messageData) { + this.messageData = messageData; + } + + @JsonObject + public static class Target { + @JsonField(name = "recipient_id") + String recipientId; + + public String getRecipientId() { + return recipientId; + } + + public void setRecipientId(String recipientId) { + this.recipientId = recipientId; + } + } + + @JsonObject + public static class MessageData { + @JsonField(name = "text") + String text; + @JsonField(name = "attachment") + Attachment attachment; + @JsonField(name = "attachment") + Entities entities; + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + + public Attachment getAttachment() { + return attachment; + } + + public void setAttachment(Attachment attachment) { + this.attachment = attachment; + } + + } + + } + +} diff --git a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/model/twitter/dm/DirectMessageEventList.java b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/model/twitter/dm/DirectMessageEventList.java new file mode 100644 index 000000000..080670d76 --- /dev/null +++ b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/model/twitter/dm/DirectMessageEventList.java @@ -0,0 +1,43 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright 2012-2018 Mariotaku Lee + * + * Licensed 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.microblog.library.model.twitter.dm; + +import com.bluelinelabs.logansquare.annotation.JsonField; +import com.bluelinelabs.logansquare.annotation.JsonObject; + +import org.mariotaku.microblog.library.model.microblog.MicroBlogResponseObject; + +import java.util.List; +import java.util.Map; + +@JsonObject +public class DirectMessageEventList extends MicroBlogResponseObject { + @JsonField(name = "apps") + Map apps; + @JsonField(name = "events") + List events; + + public Map getApps() { + return apps; + } + + public List getEvents() { + return events; + } +} diff --git a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/model/twitter/dm/DirectMessageEventObject.java b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/model/twitter/dm/DirectMessageEventObject.java new file mode 100644 index 000000000..3ffecfa63 --- /dev/null +++ b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/model/twitter/dm/DirectMessageEventObject.java @@ -0,0 +1,39 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright 2012-2018 Mariotaku Lee + * + * Licensed 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.microblog.library.model.twitter.dm; + +import com.bluelinelabs.logansquare.annotation.JsonField; +import com.bluelinelabs.logansquare.annotation.JsonObject; + +import org.mariotaku.microblog.library.model.microblog.MicroBlogResponseObject; + +@JsonObject +public class DirectMessageEventObject extends MicroBlogResponseObject { + @JsonField(name = "event") + DirectMessageEvent event; + + public DirectMessageEvent getEvent() { + return event; + } + + public void setEvent(DirectMessageEvent event) { + this.event = event; + } + +} diff --git a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/model/twitter/NewDm.java b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/model/twitter/dm/NewDm.java similarity index 89% rename from twidere.component.common/src/main/java/org/mariotaku/microblog/library/model/twitter/NewDm.java rename to twidere.component.common/src/main/java/org/mariotaku/microblog/library/model/twitter/dm/NewDm.java index 66ef10e7d..6bb3eb642 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/model/twitter/NewDm.java +++ b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/model/twitter/dm/NewDm.java @@ -1,7 +1,7 @@ /* * Twidere - Twitter client for Android * - * Copyright 2012-2017 Mariotaku Lee + * Copyright 2012-2018 Mariotaku Lee * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,14 +16,11 @@ * limitations under the License. */ -package org.mariotaku.microblog.library.model.twitter; +package org.mariotaku.microblog.library.model.twitter.dm; import org.mariotaku.microblog.library.util.InternalArrayUtil; import org.mariotaku.restfu.http.SimpleValueMap; -/** - * Created by mariotaku on 16/3/1. - */ public class NewDm extends SimpleValueMap { public void setText(String text) { diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableUser.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableUser.java index e9376e479..c0e7b9df7 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableUser.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableUser.java @@ -365,6 +365,9 @@ public class ParcelableUser implements Parcelable, Comparable { @JsonField(name = "pinned_status_ids") @ParcelableThisPlease public String[] pinned_status_ids; + @JsonField(name = "url_display") + @ParcelableThisPlease + public String url_display; @Override diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/ParcelableUserExtensions.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/ParcelableUserExtensions.kt index 1a1e3112f..88f921ecd 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/ParcelableUserExtensions.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/ParcelableUserExtensions.kt @@ -106,7 +106,8 @@ inline val ParcelableUser.originalProfileImage: String? ?: Utils.getOriginalTwitterProfileImage(profile_image_url) } -inline val ParcelableUser.urlPreferred: String? get() = url_expanded?.takeIf(String::isNotEmpty) ?: url +inline val ParcelableUser.urlFull: String? get() = url_expanded?.takeIf(String::isNotEmpty) ?: url +inline val ParcelableUser.urlDisplay: String? get() = extras?.url_display ?: urlFull inline val ParcelableUser.acct: String get() { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/DirectMessageEventObjectDsl.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/DirectMessageEventObjectDsl.kt index 53d96cd63..0fda3e36a 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/DirectMessageEventObjectDsl.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/DirectMessageEventObjectDsl.kt @@ -19,22 +19,20 @@ package org.mariotaku.twidere.extension.model.api -import org.mariotaku.microblog.library.model.microblog.DirectMessageEventObject -import org.mariotaku.microblog.library.model.microblog.DirectMessageEventObject.Event -import org.mariotaku.microblog.library.model.microblog.DirectMessageEventObject.Event.MessageCreate +import org.mariotaku.microblog.library.model.twitter.dm.DirectMessageEvent +import org.mariotaku.microblog.library.model.twitter.dm.DirectMessageEvent.MessageCreate +import org.mariotaku.microblog.library.model.twitter.dm.DirectMessageEventObject +import org.mariotaku.microblog.library.model.twitter.dm.Attachment -/** - * Created by mariotaku on 2017/5/11. - */ -fun DirectMessageEventObject(action: Event.() -> Unit): DirectMessageEventObject { +fun DirectMessageEventObject(action: DirectMessageEvent.() -> Unit): DirectMessageEventObject { val obj = DirectMessageEventObject() - val event = Event() + val event = DirectMessageEvent() action(event) obj.event = event return obj } -fun Event.messageCreate(action: MessageCreate.() -> Unit) { +fun DirectMessageEvent.messageCreate(action: MessageCreate.() -> Unit) { val messageCreate = MessageCreate() action(messageCreate) this.messageCreate = messageCreate @@ -52,14 +50,14 @@ fun MessageCreate.messageData(action: MessageCreate.MessageData.() -> Unit) { this.messageData = messageData } -fun MessageCreate.MessageData.attachment(action: MessageCreate.MessageData.Attachment.() -> Unit) { - val attachment = MessageCreate.MessageData.Attachment() +fun MessageCreate.MessageData.attachment(action: Attachment.() -> Unit) { + val attachment = Attachment() action(attachment) this.attachment = attachment } -fun MessageCreate.MessageData.Attachment.media(action: MessageCreate.MessageData.Attachment.Media.() -> Unit) { - val media = MessageCreate.MessageData.Attachment.Media() +fun Attachment.media(action: Attachment.Media.() -> Unit) { + val media = Attachment.Media() action(media) this.media = media } \ No newline at end of file diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/UserExtensions.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/UserExtensions.kt index d6212ac1e..7127908ac 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/UserExtensions.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/UserExtensions.kt @@ -20,7 +20,6 @@ package org.mariotaku.twidere.extension.model.api import android.text.TextUtils -import org.mariotaku.ktextension.isNotNullOrEmpty import org.mariotaku.microblog.library.model.microblog.User import org.mariotaku.twidere.TwidereConstants.USER_TYPE_FANFOU_COM import org.mariotaku.twidere.TwidereConstants.USER_TYPE_TWITTER_COM @@ -84,9 +83,8 @@ fun User.toParcelableInternal(accountKey: UserKey?, @AccountType accountType: St obj.profile_background_url = profileBackgroundImageUrl } obj.url = url - if (obj.url != null && urlEntities.isNotNullOrEmpty()) { - obj.url_expanded = urlEntities[0].expandedUrl - } + val urlEntity = urlEntities?.find { it.url == url } + obj.url_expanded = urlEntity?.expandedUrl obj.is_follow_request_sent = isFollowRequestSent == true obj.followers_count = followersCount obj.friends_count = friendsCount @@ -103,6 +101,7 @@ fun User.toParcelableInternal(accountKey: UserKey?, @AccountType accountType: St obj.is_basic = false val extras = ParcelableUser.Extras() + extras.url_display = urlEntity?.displayUrl extras.ostatus_uri = ostatusUri extras.blocking = isBlocking == true extras.blocked_by = isBlockedBy == true diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserFragment.kt index 042d0126d..1220b61a8 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserFragment.kt @@ -862,7 +862,7 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener, IntentUtils.openProfileEditor(context, accountKey) } R.id.url -> { - val uri = user.urlPreferred?.let(Uri::parse) ?: return + val uri = user.urlFull?.let(Uri::parse) ?: return OnLinkClickHandler.openLink(context, preferences, uri) } R.id.profileBirthdayBanner -> { @@ -1164,7 +1164,7 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener, location.spannable = user.location location.hideIfEmpty() - url.spannable = user.urlPreferred?.let { + url.spannable = user.urlDisplay?.let { val ssb = SpannableStringBuilder(it) ssb.setSpan(TwidereURLSpan(it, highlightStyle = linkHighlightOption), 0, ssb.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserProfileEditorFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserProfileEditorFragment.kt index eeb349226..0d7e0e33b 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserProfileEditorFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserProfileEditorFragment.kt @@ -44,7 +44,7 @@ import org.mariotaku.twidere.data.user.UserLiveData import org.mariotaku.twidere.extension.* import org.mariotaku.twidere.extension.data.observe import org.mariotaku.twidere.extension.model.expandedDescription -import org.mariotaku.twidere.extension.model.urlPreferred +import org.mariotaku.twidere.extension.model.urlFull import org.mariotaku.twidere.model.AccountDetails import org.mariotaku.twidere.model.ParcelableUser import org.mariotaku.twidere.model.UserKey @@ -103,7 +103,7 @@ class UserProfileEditorFragment : BaseFragment(), OnSizeChangedListener, editName.setText(savedInstanceState.getString(EXTRA_NAME, savedUser.name)) editLocation.setText(savedInstanceState.getString(EXTRA_LOCATION, savedUser.location)) editDescription.setText(savedInstanceState.getString(EXTRA_DESCRIPTION, savedUser.expandedDescription)) - editUrl.setText(savedInstanceState.getString(EXTRA_URL, savedUser.urlPreferred)) + editUrl.setText(savedInstanceState.getString(EXTRA_URL, savedUser.urlFull)) } else { getUserInfo(false) } @@ -251,7 +251,7 @@ class UserProfileEditorFragment : BaseFragment(), OnSizeChangedListener, editName.setText(user.name) editDescription.setText(user.expandedDescription) editLocation.setText(user.location) - editUrl.setText(user.urlPreferred) + editUrl.setText(user.urlFull) requestManager.loadProfileImage(activity, user, ImageShapeStyle.SHAPE_RECTANGLE).into(profileImage) @@ -303,7 +303,7 @@ class UserProfileEditorFragment : BaseFragment(), OnSizeChangedListener, if (user.name != editName.string) return true if (user.expandedDescription != editDescription.string) return true if (user.location != editLocation.string) return true - if (user.urlPreferred != editUrl.string) return true + if (user.urlFull != editUrl.string) return true return false } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/message/GetMessagesTask.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/message/GetMessagesTask.kt index 5336b6fe5..b88a2b2d4 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/message/GetMessagesTask.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/message/GetMessagesTask.kt @@ -35,6 +35,7 @@ import org.mariotaku.microblog.library.model.Paging import org.mariotaku.microblog.library.model.microblog.DMResponse import org.mariotaku.microblog.library.model.microblog.DMResponse.Conversation import org.mariotaku.microblog.library.model.microblog.DirectMessage +import org.mariotaku.microblog.library.model.twitter.dm.DirectMessageEvent import org.mariotaku.sqliteqb.library.Expression import org.mariotaku.twidere.R import org.mariotaku.twidere.TwidereConstants.QUERY_PARAM_SHOW_NOTIFICATION @@ -105,6 +106,7 @@ class GetMessagesTask( if (details.isOfficial(context)) { return getTwitterOfficialMessages(twitter, details, param, index) } +// getTwitterMessages(twitter, details, param, index) } } // Use default method @@ -140,34 +142,19 @@ class GetMessagesTask( val sincePagination = param.pagination?.get(accountsCount + index) as? SinceMaxPagination val firstFetch by lazy { - val noConversationsBefore = context.contentResolver.queryCount(Conversations.CONTENT_URI, + return@lazy context.contentResolver.queryCount(Conversations.CONTENT_URI, Expression.equalsArgs(Conversations.ACCOUNT_KEY).sql, arrayOf(accountKey.toString())) <= 0 - return@lazy noConversationsBefore } val updateLastRead = param.hasMaxIds || firstFetch val received = microBlog.getDirectMessages(Paging().apply { count(100) - val maxId = receivedPagination?.maxId - val sinceId = receivedPagination?.sinceId - if (maxId != null) { - maxId(maxId) - } - if (sinceId != null) { - sinceId(sinceId) - } + receivedPagination?.applyTo(this) }) val sent = microBlog.getSentDirectMessages(Paging().apply { count(100) - val maxId = sincePagination?.maxId - val sinceId = sincePagination?.sinceId - if (maxId != null) { - maxId(maxId) - } - if (sinceId != null) { - sinceId(sinceId) - } + sincePagination?.applyTo(this) }) @@ -197,6 +184,50 @@ class GetMessagesTask( } + private fun getTwitterMessages(twitter: Twitter, details: AccountDetails, + param: RefreshMessagesParam, index: Int): DatabaseUpdateData { + val accountKey = details.key + + val receivedPagination = param.pagination?.get(index) as? CursorPagination + + val firstFetch by lazy { + return@lazy context.contentResolver.queryCount(Conversations.CONTENT_URI, + Expression.equalsArgs(Conversations.ACCOUNT_KEY).sql, arrayOf(accountKey.toString())) <= 0 + } + + val updateLastRead = param.hasMaxIds || firstFetch + + val events = twitter.getDirectMessageEvents(Paging().apply { + count(50) + receivedPagination?.applyTo(this) + }).events + + + val insertMessages = arrayListOf() + val conversations = hashMapOf() + + val conversationIds = hashSetOf() + val users = twitter.lookupUsers(events.flatMap { + val mc = it.messageCreate ?: return@flatMap emptyList() + return@flatMap listOf(mc.senderId, mc.target.recipientId) + }.distinct().toTypedArray()) + + events.forEach { event -> + val msg = event.messageCreate + conversationIds.add(ParcelableMessageUtils.incomingConversationId(msg.senderId, msg.target.recipientId)) + } + + conversations.addLocalConversations(context, accountKey, conversationIds) + + events.forEachIndexed { i, dm -> + // addConversationMessage(insertMessages, conversations, details, dm, i, events.size, +// false, profileImageSize, updateLastRead) + } + + return DatabaseUpdateData(conversations.values, insertMessages) + } + + private fun getTwitterOfficialConversation(twitter: Twitter, details: AccountDetails, conversationId: String, param: RefreshMessagesParam, index: Int): DatabaseUpdateData { val maxId = (param.pagination?.get(index) as? SinceMaxPagination)?.maxId @@ -364,7 +395,6 @@ class GetMessagesTask( } companion object { - private const val KEY_FIRST_FETCH = "state_first_fetch_direct_messages" private val getMessageTasks = mutableSetOf() @@ -601,6 +631,25 @@ class GetMessagesTask( conversation.conversation_extras = DefaultConversationExtras() } } + + internal fun addConversationMessage(messages: MutableCollection, + conversations: MutableMap, + details: AccountDetails, dm: DirectMessageEvent.MessageCreate, index: Int, size: Int, + outgoing: Boolean, profileImageSize: String = "normal", updateLastRead: Boolean) { + val accountKey = details.key + val accountType = details.type +// val message = ParcelableMessageUtils.fromMessage(accountKey, dm, outgoing, +// 1.0 - (index.toDouble() / size)) +// messages.add(message) +// val sender = dm.sender.toParcelable(accountKey, accountType, profileImageSize = profileImageSize) +// val recipient = dm.recipient.toParcelable(accountKey, accountType, profileImageSize = profileImageSize) +// val conversation = conversations.addConversation(message.conversation_id, details, +// message, setOf(sender, recipient), updateLastRead = updateLastRead) ?: return +// conversation.conversation_extras_type = ParcelableMessageConversation.ExtrasType.DEFAULT +// if (conversation.conversation_extras == null) { +// conversation.conversation_extras = DefaultConversationExtras() +// } + } } } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/message/SendMessageTask.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/message/SendMessageTask.kt index ae1ff3456..deb364b4c 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/message/SendMessageTask.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/message/SendMessageTask.kt @@ -24,7 +24,7 @@ import org.mariotaku.ktextension.isNotNullOrEmpty import org.mariotaku.microblog.library.* import org.mariotaku.microblog.library.annotation.twitter.MediaCategory import org.mariotaku.microblog.library.model.microblog.DirectMessage -import org.mariotaku.microblog.library.model.twitter.NewDm +import org.mariotaku.microblog.library.model.twitter.dm.NewDm import org.mariotaku.sqliteqb.library.Expression import org.mariotaku.twidere.R import org.mariotaku.twidere.annotation.AccountType diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/view/holder/UserViewHolder.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/view/holder/UserViewHolder.kt index 87751560f..8466536c7 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/view/holder/UserViewHolder.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/view/holder/UserViewHolder.kt @@ -36,6 +36,7 @@ import org.mariotaku.twidere.adapter.iface.IUsersAdapter import org.mariotaku.twidere.adapter.iface.IUsersAdapter.* import org.mariotaku.twidere.extension.loadProfileImage import org.mariotaku.twidere.extension.model.hasSameHost +import org.mariotaku.twidere.extension.model.urlDisplay import org.mariotaku.twidere.extension.setVisible import org.mariotaku.twidere.model.ParcelableUser import org.mariotaku.twidere.model.placeholder.PlaceholderObject @@ -169,7 +170,7 @@ class UserViewHolder( descriptionView.hideIfEmpty() locationView.spannable = user.location locationView.hideIfEmpty() - urlView.spannable = user.url_expanded + urlView.spannable = user.urlDisplay urlView.hideIfEmpty() val locale = Locale.getDefault() statusesCountView.text = user.statuses_count.toString(locale)