From 5052d1fc62809e7fa5aba5f256e0cd31c63f2c0c Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Wed, 8 Jan 2020 11:37:49 +0900 Subject: [PATCH] Removed private API usages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit > Hello, > > This is a policy violation notice from Twitter API Policy. Multiple applications registered to your account (or accounts) have been found in violation of the Developer Agreement and Policy: > > Developer Agreement: Section II.A.4 > > Developer Agreement: Section II.E > > Developer Policy: Section I.F.5.a > > To ensure continued API access you must do the following: > > Delete all applications associated with your service that are in violation of Twitter’s multi-key abuse policy > > Eliminate all functionality from your service that allows people to use Twitter client application credentials > > Eliminate all functionality from your service that allows people to access non-public API endpoints > > We look forward to hearing back from you on or before 17 JANUARY 2020. If we don’t receive a response by that time your API access will be permanently suspended. > > Regards, > > Twitter API Policy --- .../microblog/library/twitter/Twitter.java | 2 +- .../library/twitter/TwitterPrivate.java | 35 --- .../twitter/api/PrivateAccountResources.java | 37 --- .../twitter/api/PrivateActivityResources.java | 52 ---- .../api/PrivateDirectMessagesResources.java | 102 -------- .../api/PrivateFriendsFollowersResources.java | 43 ---- .../twitter/api/PrivateMutesResources.java | 42 ---- .../library/twitter/api/PrivateResources.java | 23 -- .../twitter/api/PrivateSearchResources.java | 38 --- .../twitter/api/PrivateTimelineResources.java | 39 --- .../twitter/api/PrivateTweetResources.java | 45 ---- .../twidere/model/ConsumerKeyType.java | 3 +- .../model/account/TwitterAccountExtras.java | 14 -- .../twidere/model/util/AccountUtils.java | 17 -- .../util/InternalTwitterContentUtils.java | 57 ----- .../twidere/util/MicroBlogAPIFactory.java | 15 -- .../twidere/activity/SignInActivity.kt | 15 +- .../model/AccountDetailsExtensions.kt | 21 -- .../extension/model/AccountExtensions.kt | 13 - .../extension/model/CredentialsExtensions.kt | 5 +- .../twidere/fragment/AbsActivitiesFragment.kt | 11 +- .../twidere/fragment/CustomTabsFragment.kt | 3 +- .../MessageConversationInfoFragment.kt | 72 ------ .../message/MessageNewConversationFragment.kt | 7 +- .../status/PinStatusDialogFragment.kt | 55 ---- .../twidere/fragment/status/StatusFragment.kt | 41 --- .../status/UnpinStatusDialogFragment.kt | 55 ---- .../users/IncomingFriendshipsFragment.kt | 3 - .../loader/statuses/ConversationLoader.kt | 6 - .../statuses/MediaStatusesSearchLoader.kt | 14 -- .../loader/statuses/MediaTimelineLoader.kt | 42 ++-- .../loader/statuses/TweetSearchLoader.kt | 13 - .../loader/statuses/UserMentionsLoader.kt | 4 - .../loader/users/StatusFavoritersLoader.kt | 5 +- .../tab/impl/InteractionsTabConfiguration.kt | 7 +- .../twidere/service/StreamingService.kt | 235 ------------------ .../twidere/task/AcceptFriendshipTask.kt | 5 +- .../twidere/task/DenyFriendshipTask.kt | 5 +- .../twidere/task/status/PinStatusTask.kt | 52 ---- .../twidere/task/status/UnpinStatusTask.kt | 52 ---- .../task/twitter/GetActivitiesAboutMeTask.kt | 23 -- .../twidere/task/twitter/GetStatusesTask.kt | 2 +- .../twitter/message/AddParticipantsTask.kt | 97 -------- .../message/DestroyConversationTask.kt | 4 - .../twitter/message/DestroyMessageTask.kt | 4 - .../task/twitter/message/GetMessagesTask.kt | 70 +----- .../twitter/message/MarkMessageReadTask.kt | 18 -- .../task/twitter/message/SendMessageTask.kt | 49 +--- ...SetConversationNotificationDisabledTask.kt | 19 -- .../twidere/util/AsyncTwitterWrapper.kt | 12 - .../mariotaku/twidere/util/DataStoreUtils.kt | 19 +- .../org/mariotaku/twidere/util/MenuUtils.kt | 9 +- .../holder/status/DetailStatusViewHolder.kt | 22 +- .../main/res/values/arrays_no_translate.xml | 51 ---- 54 files changed, 46 insertions(+), 1658 deletions(-) delete mode 100644 twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/TwitterPrivate.java delete mode 100644 twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/api/PrivateAccountResources.java delete mode 100644 twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/api/PrivateActivityResources.java delete mode 100644 twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/api/PrivateDirectMessagesResources.java delete mode 100644 twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/api/PrivateFriendsFollowersResources.java delete mode 100644 twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/api/PrivateMutesResources.java delete mode 100644 twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/api/PrivateResources.java delete mode 100644 twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/api/PrivateSearchResources.java delete mode 100644 twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/api/PrivateTimelineResources.java delete mode 100644 twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/api/PrivateTweetResources.java delete mode 100644 twidere/src/main/kotlin/org/mariotaku/twidere/fragment/status/PinStatusDialogFragment.kt delete mode 100644 twidere/src/main/kotlin/org/mariotaku/twidere/fragment/status/UnpinStatusDialogFragment.kt delete mode 100644 twidere/src/main/kotlin/org/mariotaku/twidere/task/status/PinStatusTask.kt delete mode 100644 twidere/src/main/kotlin/org/mariotaku/twidere/task/status/UnpinStatusTask.kt delete mode 100644 twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/message/AddParticipantsTask.kt diff --git a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/Twitter.java b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/Twitter.java index 94b11e67c..d3cc2c7dc 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/Twitter.java +++ b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/Twitter.java @@ -41,5 +41,5 @@ public interface Twitter extends SearchResources, TimelineResources, TweetResour ListResources, DirectMessagesResources, DirectMessagesEventResources, FriendsFollowersResources, FavoritesResources, SpamReportingResources, SavedSearchesResources, TrendsResources, PlacesGeoResources, - HelpResources, MutesResources, TwitterPrivate { + HelpResources, MutesResources { } diff --git a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/TwitterPrivate.java b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/TwitterPrivate.java deleted file mode 100644 index 4414f99be..000000000 --- a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/TwitterPrivate.java +++ /dev/null @@ -1,35 +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.twitter; - -import org.mariotaku.microblog.library.twitter.api.PrivateAccountResources; -import org.mariotaku.microblog.library.twitter.api.PrivateActivityResources; -import org.mariotaku.microblog.library.twitter.api.PrivateDirectMessagesResources; -import org.mariotaku.microblog.library.twitter.api.PrivateFriendsFollowersResources; -import org.mariotaku.microblog.library.twitter.api.PrivateSearchResources; -import org.mariotaku.microblog.library.twitter.api.PrivateTimelineResources; -import org.mariotaku.microblog.library.twitter.api.PrivateTweetResources; - -/** - * Created by mariotaku on 16/3/4. - */ -public interface TwitterPrivate extends PrivateActivityResources, PrivateTweetResources, - PrivateTimelineResources, PrivateFriendsFollowersResources, PrivateDirectMessagesResources, - PrivateSearchResources, PrivateAccountResources { -} diff --git a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/api/PrivateAccountResources.java b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/api/PrivateAccountResources.java deleted file mode 100644 index 9e6a699af..000000000 --- a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/api/PrivateAccountResources.java +++ /dev/null @@ -1,37 +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.twitter.api; - -import org.mariotaku.microblog.library.MicroBlogException; -import org.mariotaku.microblog.library.twitter.model.PinTweetResult; -import org.mariotaku.restfu.annotation.method.POST; -import org.mariotaku.restfu.annotation.param.Param; - -/** - * Created by mariotaku on 16/8/20. - */ -public interface PrivateAccountResources extends PrivateResources { - - @POST("/account/pin_tweet.json") - PinTweetResult pinTweet(@Param("id") String id) throws MicroBlogException; - - @POST("/account/unpin_tweet.json") - PinTweetResult unpinTweet(@Param("id") String id) throws MicroBlogException; - -} diff --git a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/api/PrivateActivityResources.java b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/api/PrivateActivityResources.java deleted file mode 100644 index 92e13c820..000000000 --- a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/api/PrivateActivityResources.java +++ /dev/null @@ -1,52 +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.twitter.api; - -import org.mariotaku.microblog.library.MicroBlogException; -import org.mariotaku.microblog.library.twitter.model.Activity; -import org.mariotaku.microblog.library.twitter.model.CursorTimestampResponse; -import org.mariotaku.microblog.library.twitter.model.Paging; -import org.mariotaku.microblog.library.twitter.model.ResponseList; -import org.mariotaku.microblog.library.twitter.template.StatusAnnotationTemplate; -import org.mariotaku.restfu.annotation.method.GET; -import org.mariotaku.restfu.annotation.method.POST; -import org.mariotaku.restfu.annotation.param.Param; -import org.mariotaku.restfu.annotation.param.Params; -import org.mariotaku.restfu.annotation.param.Queries; -import org.mariotaku.restfu.annotation.param.Query; -import org.mariotaku.restfu.http.BodyType; - -@SuppressWarnings("RedundantThrows") -@Params(template = StatusAnnotationTemplate.class) -public interface PrivateActivityResources extends PrivateResources { - - @GET("/activity/about_me.json") - ResponseList getActivitiesAboutMe(@Query Paging paging) throws MicroBlogException; - - @Queries({}) - @GET("/activity/about_me/unread.json") - CursorTimestampResponse getActivitiesAboutMeUnread(@Query("cursor") boolean cursor) throws MicroBlogException; - - @Queries({}) - @POST("/activity/about_me/unread.json") - @BodyType(BodyType.FORM) - CursorTimestampResponse setActivitiesAboutMeUnread(@Param("cursor") long cursor) throws MicroBlogException; - - -} diff --git a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/api/PrivateDirectMessagesResources.java b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/api/PrivateDirectMessagesResources.java deleted file mode 100644 index 8aedefa37..000000000 --- a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/api/PrivateDirectMessagesResources.java +++ /dev/null @@ -1,102 +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.twitter.api; - -import android.support.annotation.Nullable; - -import org.mariotaku.microblog.library.MicroBlogException; -import org.mariotaku.microblog.library.twitter.model.ConversationTimeline; -import org.mariotaku.microblog.library.twitter.model.DMResponse; -import org.mariotaku.microblog.library.twitter.model.NewDm; -import org.mariotaku.microblog.library.twitter.model.Paging; -import org.mariotaku.microblog.library.twitter.model.ResponseCode; -import org.mariotaku.microblog.library.twitter.model.UserEvents; -import org.mariotaku.microblog.library.twitter.model.UserInbox; -import org.mariotaku.microblog.library.twitter.template.DMAnnotationTemplate; -import org.mariotaku.restfu.annotation.method.GET; -import org.mariotaku.restfu.annotation.method.POST; -import org.mariotaku.restfu.annotation.param.Param; -import org.mariotaku.restfu.annotation.param.Params; -import org.mariotaku.restfu.annotation.param.Path; -import org.mariotaku.restfu.annotation.param.Query; -import org.mariotaku.restfu.http.BodyType; - -@Params(template = DMAnnotationTemplate.class) -public interface PrivateDirectMessagesResources extends PrivateResources { - - @POST("/dm/conversation/{conversation_id}/delete.json") - @BodyType(BodyType.FORM) - ResponseCode deleteDmConversation(@Path("conversation_id") String conversationId) - throws MicroBlogException; - - @POST("/dm/conversation/{conversation_id}/mark_read.json") - @BodyType(BodyType.FORM) - ResponseCode markDmRead(@Path("conversation_id") String conversationId, - @Param("last_read_event_id") String lastReadEventId) throws MicroBlogException; - - @POST("/dm/update_last_seen_event_id.json") - @BodyType(BodyType.FORM) - ResponseCode updateLastSeenEventId(@Param("last_seen_event_id") String lastSeenEventId) throws MicroBlogException; - - @POST("/dm/conversation/{conversation_id}/update_name.json") - @BodyType(BodyType.FORM) - ResponseCode updateDmConversationName(@Path("conversation_id") String conversationId, - @Param("name") String name) throws MicroBlogException; - - /** - * Update DM conversation avatar - * - * @param conversationId DM conversation ID - * @param avatarId Avatar media ID, null for removing avatar - * @return HTTP response code - */ - @POST("/dm/conversation/{conversation_id}/update_avatar.json") - @BodyType(BodyType.FORM) - ResponseCode updateDmConversationAvatar(@Path("conversation_id") String conversationId, - @Param(value = "avatar_id", ignoreOnNull = true) @Nullable String avatarId) throws MicroBlogException; - - @POST("/dm/conversation/{conversation_id}/disable_notifications.json") - ResponseCode disableDmConversations(@Path("conversation_id") String conversationId) - throws MicroBlogException; - - @POST("/dm/conversation/{conversation_id}/enable_notifications.json") - ResponseCode enableDmConversations(@Path("conversation_id") String conversationId) - throws MicroBlogException; - - @POST("/dm/new.json") - DMResponse sendDm(@Param NewDm newDm) throws MicroBlogException; - - @POST("/dm/conversation/{conversation_id}/add_participants.json") - DMResponse addParticipants(@Path("conversation_id") String conversationId, - @Param(value = "participant_ids", arrayDelimiter = ',') String[] participantIds) - throws MicroBlogException; - - @POST("/dm/destroy.json") - ResponseCode destroyDm(@Param("dm_id") String id) throws MicroBlogException; - - @GET("/dm/user_inbox.json") - UserInbox getUserInbox(@Query Paging paging) throws MicroBlogException; - - @GET("/dm/user_updates.json") - UserEvents getUserUpdates(@Query("cursor") String cursor) throws MicroBlogException; - - @GET("/dm/conversation/{conversation_id}.json") - ConversationTimeline getDmConversation(@Path("conversation_id") String conversationId, - @Query Paging paging) throws MicroBlogException; -} diff --git a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/api/PrivateFriendsFollowersResources.java b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/api/PrivateFriendsFollowersResources.java deleted file mode 100644 index 82cbedbd7..000000000 --- a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/api/PrivateFriendsFollowersResources.java +++ /dev/null @@ -1,43 +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.twitter.api; - -import org.mariotaku.microblog.library.MicroBlogException; -import org.mariotaku.microblog.library.twitter.model.User; -import org.mariotaku.restfu.annotation.method.POST; -import org.mariotaku.restfu.annotation.param.KeyValue; -import org.mariotaku.restfu.annotation.param.Param; -import org.mariotaku.restfu.annotation.param.Queries; - -@Queries({@KeyValue(key = "include_entities", valueKey = "include_entities")}) -public interface PrivateFriendsFollowersResources extends PrivateResources { - - @POST("/friendships/accept.json") - User acceptFriendship(@Param("user_id") String userId) throws MicroBlogException; - - @POST("/friendships/accept.json") - User acceptFriendshipByScreenName(@Param("screen_name") String screenName) throws MicroBlogException; - - @POST("/friendships/deny.json") - User denyFriendship(@Param("user_id") String userId) throws MicroBlogException; - - @POST("/friendships/deny.json") - User denyFriendshipByScreenName(@Param("screen_name") String screenName) throws MicroBlogException; - -} diff --git a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/api/PrivateMutesResources.java b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/api/PrivateMutesResources.java deleted file mode 100644 index deb4e98dc..000000000 --- a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/api/PrivateMutesResources.java +++ /dev/null @@ -1,42 +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.twitter.api; - -import org.mariotaku.microblog.library.MicroBlogException; -import org.mariotaku.microblog.library.twitter.model.IDs; -import org.mariotaku.microblog.library.twitter.model.MutedKeyword; -import org.mariotaku.microblog.library.twitter.model.PageableResponseList; -import org.mariotaku.microblog.library.twitter.model.Paging; -import org.mariotaku.microblog.library.twitter.template.UserAnnotationTemplate; -import org.mariotaku.restfu.annotation.method.GET; -import org.mariotaku.restfu.annotation.param.Params; -import org.mariotaku.restfu.annotation.param.Query; - -/** - * Created by mariotaku on 2017/3/26. - */ -@Params(template = UserAnnotationTemplate.class) -public interface PrivateMutesResources { - - @GET("/mutes/keywords/ids.json") - IDs getMutesKeywordsIDs(Paging paging) throws MicroBlogException; - - @GET("/mutes/keywords/list.json") - PageableResponseList getMutesKeywordsList(@Query Paging paging) throws MicroBlogException; -} diff --git a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/api/PrivateResources.java b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/api/PrivateResources.java deleted file mode 100644 index 03a6f8c98..000000000 --- a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/api/PrivateResources.java +++ /dev/null @@ -1,23 +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.twitter.api; - -public interface PrivateResources { - -} diff --git a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/api/PrivateSearchResources.java b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/api/PrivateSearchResources.java deleted file mode 100644 index 750fd4dac..000000000 --- a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/api/PrivateSearchResources.java +++ /dev/null @@ -1,38 +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.twitter.api; - -import org.mariotaku.microblog.library.MicroBlogException; -import org.mariotaku.microblog.library.twitter.model.UniversalSearchQuery; -import org.mariotaku.microblog.library.twitter.model.UniversalSearchResult; -import org.mariotaku.microblog.library.twitter.template.StatusAnnotationTemplate; -import org.mariotaku.restfu.annotation.method.GET; -import org.mariotaku.restfu.annotation.param.Params; -import org.mariotaku.restfu.annotation.param.Query; - -/** - * Created by mariotaku on 15/10/21. - */ -public interface PrivateSearchResources extends PrivateResources { - - @GET("/search/universal.json") - @Params(template = StatusAnnotationTemplate.class) - UniversalSearchResult universalSearch(@Query UniversalSearchQuery query) throws MicroBlogException; - -} diff --git a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/api/PrivateTimelineResources.java b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/api/PrivateTimelineResources.java deleted file mode 100644 index 3b589dac1..000000000 --- a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/api/PrivateTimelineResources.java +++ /dev/null @@ -1,39 +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.twitter.api; - -import org.mariotaku.microblog.library.MicroBlogException; -import org.mariotaku.microblog.library.twitter.model.Paging; -import org.mariotaku.microblog.library.twitter.model.ResponseList; -import org.mariotaku.microblog.library.twitter.model.Status; -import org.mariotaku.microblog.library.twitter.template.StatusAnnotationTemplate; -import org.mariotaku.restfu.annotation.method.GET; -import org.mariotaku.restfu.annotation.param.Params; -import org.mariotaku.restfu.annotation.param.Query; - -@SuppressWarnings("RedundantThrows") -@Params(template = StatusAnnotationTemplate.class) -public interface PrivateTimelineResources extends PrivateResources { - - @GET("/statuses/media_timeline.json") - ResponseList getMediaTimeline(@Query("user_id") String userId, @Query Paging paging) throws MicroBlogException; - - @GET("/statuses/media_timeline.json") - ResponseList getMediaTimelineByScreenName(@Query("screen_name") String screenName, @Query Paging paging) throws MicroBlogException; -} diff --git a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/api/PrivateTweetResources.java b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/api/PrivateTweetResources.java deleted file mode 100644 index de7a033d4..000000000 --- a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/api/PrivateTweetResources.java +++ /dev/null @@ -1,45 +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.twitter.api; - -import org.mariotaku.microblog.library.MicroBlogException; -import org.mariotaku.microblog.library.twitter.model.Paging; -import org.mariotaku.microblog.library.twitter.model.ResponseList; -import org.mariotaku.microblog.library.twitter.model.Status; -import org.mariotaku.microblog.library.twitter.model.StatusActivitySummary; -import org.mariotaku.microblog.library.twitter.model.TranslationResult; -import org.mariotaku.microblog.library.twitter.template.StatusAnnotationTemplate; -import org.mariotaku.restfu.annotation.method.GET; -import org.mariotaku.restfu.annotation.param.Params; -import org.mariotaku.restfu.annotation.param.Path; -import org.mariotaku.restfu.annotation.param.Query; - -@SuppressWarnings("RedundantThrows") -@Params(template = StatusAnnotationTemplate.class) -public interface PrivateTweetResources extends PrivateResources { - - @GET("/statuses/{id}/activity/summary.json") - StatusActivitySummary getStatusActivitySummary(@Path("id") String statusId) throws MicroBlogException; - - @GET("/conversation/show.json") - ResponseList showConversation(@Query("id") String statusId, @Query Paging paging) throws MicroBlogException; - - @GET("/translations/show.json") - TranslationResult showTranslation(@Query("id") String statusId, @Query("dest") String dest) throws MicroBlogException; -} diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ConsumerKeyType.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ConsumerKeyType.java index c0ba9fabb..79fd4cbd4 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ConsumerKeyType.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ConsumerKeyType.java @@ -24,8 +24,7 @@ import android.support.annotation.NonNull; * Created by mariotaku on 15/4/20. */ public enum ConsumerKeyType { - TWITTER_FOR_ANDROID, TWITTER_FOR_IPHONE, TWITTER_FOR_IPAD, TWITTER_FOR_MAC, - TWITTER_FOR_WINDOWS_PHONE, TWITTER_FOR_GOOGLE_TV, TWEETDECK, UNKNOWN; + UNKNOWN; @NonNull public static ConsumerKeyType parse(String type) { diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/account/TwitterAccountExtras.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/account/TwitterAccountExtras.java index 7eb204877..0e516b757 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/account/TwitterAccountExtras.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/account/TwitterAccountExtras.java @@ -21,10 +21,8 @@ package org.mariotaku.twidere.model.account; 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 com.hannesdorfmann.parcelableplease.annotation.ParcelableThisPlease; /** * Created by mariotaku on 16/2/26. @@ -47,17 +45,6 @@ public class TwitterAccountExtras implements Parcelable, AccountExtras { } }; - @JsonField(name = "official_credentials") - @ParcelableThisPlease - boolean officialCredentials; - - public boolean isOfficialCredentials() { - return officialCredentials; - } - - public void setIsOfficialCredentials(boolean officialCredentials) { - this.officialCredentials = officialCredentials; - } @Override public int describeContents() { @@ -72,7 +59,6 @@ public class TwitterAccountExtras implements Parcelable, AccountExtras { @Override public String toString() { return "TwitterAccountExtras{" + - "officialCredentials=" + officialCredentials + '}'; } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/util/AccountUtils.java b/twidere/src/main/java/org/mariotaku/twidere/model/util/AccountUtils.java index 77fac1afd..73ba5b7f1 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/model/util/AccountUtils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/model/util/AccountUtils.java @@ -129,23 +129,6 @@ public class AccountUtils { return null; } - public static boolean isOfficial(@NonNull final Context context, @NonNull final UserKey accountKey) { - AccountManager am = AccountManager.get(context); - Account account = AccountUtils.findByAccountKey(am, accountKey); - if (account == null) return false; - return AccountExtensionsKt.isOfficial(account, am, context); - } - - public static boolean hasOfficialKeyAccount(Context context) { - final AccountManager am = AccountManager.get(context); - for (Account account : getAccounts(am)) { - if (AccountExtensionsKt.isOfficial(account, am, context)) { - return true; - } - } - return false; - } - public static int getAccountTypeIcon(@Nullable String accountType) { if (accountType == null) return R.drawable.ic_account_logo_twitter; switch (accountType) { diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/InternalTwitterContentUtils.java b/twidere/src/main/java/org/mariotaku/twidere/util/InternalTwitterContentUtils.java index f7fcdc773..650b4c8cd 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/InternalTwitterContentUtils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/InternalTwitterContentUtils.java @@ -1,6 +1,5 @@ package org.mariotaku.twidere.util; -import android.content.Context; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.text.TextUtils; @@ -10,14 +9,9 @@ import org.mariotaku.microblog.library.twitter.model.DirectMessage; import org.mariotaku.microblog.library.twitter.model.MediaEntity; import org.mariotaku.microblog.library.twitter.model.UrlEntity; import org.mariotaku.microblog.library.twitter.model.User; -import org.mariotaku.twidere.R; import org.mariotaku.twidere.extension.model.api.StatusExtensionsKt; -import org.mariotaku.twidere.model.ConsumerKeyType; import org.mariotaku.twidere.model.SpanItem; -import java.nio.charset.Charset; -import java.util.zip.CRC32; - import kotlin.Pair; /** @@ -102,55 +96,4 @@ public class InternalTwitterContentUtils { } - public static boolean isOfficialKey(final Context context, final String consumerKey, - final String consumerSecret) { - if (context == null || consumerKey == null || consumerSecret == null) return false; - final String[] keySecrets = context.getResources().getStringArray(R.array.values_official_consumer_secret_crc32); - final CRC32 crc32 = new CRC32(); - final byte[] consumerSecretBytes = consumerSecret.getBytes(Charset.forName("UTF-8")); - crc32.update(consumerSecretBytes, 0, consumerSecretBytes.length); - final long value = crc32.getValue(); - crc32.reset(); - for (final String keySecret : keySecrets) { - if (Long.parseLong(keySecret, 16) == value) return true; - } - return false; - } - - public static String getOfficialKeyName(final Context context, final String consumerKey, - final String consumerSecret) { - if (context == null || consumerKey == null || consumerSecret == null) return null; - final String[] keySecrets = context.getResources().getStringArray(R.array.values_official_consumer_secret_crc32); - final String[] keyNames = context.getResources().getStringArray(R.array.names_official_consumer_secret); - final CRC32 crc32 = new CRC32(); - final byte[] consumerSecretBytes = consumerSecret.getBytes(Charset.forName("UTF-8")); - crc32.update(consumerSecretBytes, 0, consumerSecretBytes.length); - final long value = crc32.getValue(); - crc32.reset(); - for (int i = 0, j = keySecrets.length; i < j; i++) { - if (Long.parseLong(keySecrets[i], 16) == value) return keyNames[i]; - } - return null; - } - - @NonNull - public static ConsumerKeyType getOfficialKeyType(final Context context, final String consumerKey, - final String consumerSecret) { - if (context == null || consumerKey == null || consumerSecret == null) { - return ConsumerKeyType.UNKNOWN; - } - final String[] keySecrets = context.getResources().getStringArray(R.array.values_official_consumer_secret_crc32); - final String[] keyNames = context.getResources().getStringArray(R.array.types_official_consumer_secret); - final CRC32 crc32 = new CRC32(); - final byte[] consumerSecretBytes = consumerSecret.getBytes(Charset.forName("UTF-8")); - crc32.update(consumerSecretBytes, 0, consumerSecretBytes.length); - final long value = crc32.getValue(); - crc32.reset(); - for (int i = 0, j = keySecrets.length; i < j; i++) { - if (Long.parseLong(keySecrets[i], 16) == value) { - return ConsumerKeyType.parse(keyNames[i]); - } - } - return ConsumerKeyType.UNKNOWN; - } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/MicroBlogAPIFactory.java b/twidere/src/main/java/org/mariotaku/twidere/util/MicroBlogAPIFactory.java index dcbe816ec..7810024df 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/MicroBlogAPIFactory.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/MicroBlogAPIFactory.java @@ -169,21 +169,6 @@ public class MicroBlogAPIFactory implements TwidereConstants { @WorkerThread @Nullable public static ExtraHeaders getExtraHeaders(Context context, ConsumerKeyType type) { - switch (type) { - case TWITTER_FOR_ANDROID: { - return TwitterAndroidExtraHeaders.INSTANCE; - } - case TWITTER_FOR_IPHONE: - case TWITTER_FOR_IPAD: { - return new UserAgentExtraHeaders("Twitter/6.75.2 CFNetwork/811.4.18 Darwin/16.5.0"); - } - case TWITTER_FOR_MAC: { - return TwitterMacExtraHeaders.INSTANCE; - } - case TWEETDECK: { - return new UserAgentExtraHeaders(UserAgentUtils.getDefaultUserAgentStringSafe(context)); - } - } return null; } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/SignInActivity.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/SignInActivity.kt index d711a0dc3..e0c4ce5b0 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/SignInActivity.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/SignInActivity.kt @@ -70,7 +70,6 @@ import org.mariotaku.microblog.library.mastodon.annotation.AuthScope import org.mariotaku.microblog.library.twitter.TwitterOAuth import org.mariotaku.microblog.library.twitter.auth.BasicAuthorization import org.mariotaku.microblog.library.twitter.auth.EmptyAuthorization -import org.mariotaku.microblog.library.twitter.model.Paging import org.mariotaku.microblog.library.twitter.model.User import org.mariotaku.restfu.http.Endpoint import org.mariotaku.restfu.oauth.OAuthToken @@ -411,7 +410,7 @@ class SignInActivity : BaseActivity(), OnClickListener, TextWatcher, result.addAccount(am, preferences[randomizeAccountNameKey]) Analyzer.log(SignIn(true, accountType = result.type, credentialsType = apiConfig.credentialsType, - officialKey = result.extras?.official == true)) + officialKey = false)) finishSignIn() } } @@ -1221,17 +1220,7 @@ class SignInActivity : BaseActivity(), OnClickListener, TextWatcher, } private fun getTwitterAccountExtras(twitter: MicroBlog): TwitterAccountExtras { - val extras = TwitterAccountExtras() - try { - // Get Twitter official only resource - val paging = Paging() - paging.count(1) - twitter.getActivitiesAboutMe(paging) - extras.setIsOfficialCredentials(true) - } catch (e: MicroBlogException) { - // Ignore - } - return extras + return TwitterAccountExtras() } private fun getMastodonAccountExtras(mastodon: Mastodon): MastodonAccountExtras { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/AccountDetailsExtensions.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/AccountDetailsExtensions.kt index ed59385da..00ef776f2 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/AccountDetailsExtensions.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/AccountDetailsExtensions.kt @@ -16,27 +16,6 @@ import org.mariotaku.twidere.util.text.FanfouValidator import org.mariotaku.twidere.util.text.MastodonValidator import org.mariotaku.twidere.util.text.TwitterValidator -fun AccountDetails.isOfficial(context: Context): Boolean { - val extra = this.extras - if (extra is TwitterAccountExtras) { - return extra.isOfficialCredentials - } - val credentials = this.credentials - if (credentials is OAuthCredentials) { - return InternalTwitterContentUtils.isOfficialKey(context, - credentials.consumer_key, credentials.consumer_secret) - } - return false -} - -val AccountExtras.official: Boolean - get() { - if (this is TwitterAccountExtras) { - return isOfficialCredentials - } - return false - } - fun AccountDetails.newMicroBlogInstance(context: Context, cls: Class): T { return credentials.newMicroBlogInstance(context, type, cls) } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/AccountExtensions.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/AccountExtensions.kt index a15a0d0e1..7fdf1cdad 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/AccountExtensions.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/AccountExtensions.kt @@ -100,19 +100,6 @@ fun Account.setPosition(am: AccountManager, position: Int) { am.setUserData(this, ACCOUNT_USER_DATA_POSITION, position.toString()) } -fun Account.isOfficial(am: AccountManager, context: Context): Boolean { - val extras = getAccountExtras(am) - if (extras is TwitterAccountExtras) { - return extras.isOfficialCredentials - } - val credentials = getCredentials(am) - if (credentials is OAuthCredentials) { - return InternalTwitterContentUtils.isOfficialKey(context, credentials.consumer_key, - credentials.consumer_secret) - } - return false -} - fun AccountManager.hasInvalidAccount(): Boolean { val accounts = AccountUtils.getAccounts(this) if (accounts.isEmpty()) return false diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/CredentialsExtensions.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/CredentialsExtensions.kt index 3a4b864be..135c5e442 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/CredentialsExtensions.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/CredentialsExtensions.kt @@ -23,6 +23,7 @@ import org.mariotaku.restfu.oauth.OAuthToken import org.mariotaku.restfu.oauth2.OAuth2Authorization import org.mariotaku.twidere.TwidereConstants.DEFAULT_TWITTER_API_URL_FORMAT import org.mariotaku.twidere.annotation.AccountType +import org.mariotaku.twidere.model.ConsumerKeyType import org.mariotaku.twidere.model.account.cred.* import org.mariotaku.twidere.util.HttpClientFactory import org.mariotaku.twidere.util.InternalTwitterContentUtils @@ -148,9 +149,7 @@ fun newMicroBlogInstance(context: Context, endpoint: Endpoint, auth: Authori val factory = RestAPIFactory() val extraHeaders = run { if (auth !is OAuthAuthorization) return@run null - val officialKeyType = InternalTwitterContentUtils.getOfficialKeyType(context, - auth.consumerKey, auth.consumerSecret) - return@run MicroBlogAPIFactory.getExtraHeaders(context, officialKeyType) + return@run MicroBlogAPIFactory.getExtraHeaders(context, ConsumerKeyType.UNKNOWN) } ?: UserAgentExtraHeaders(MicroBlogAPIFactory.getTwidereUserAgent(context)) val holder = DependencyHolder.get(context) var extraRequestParams: Map? = null diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AbsActivitiesFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AbsActivitiesFragment.kt index 5d9d9c5fd..713080812 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AbsActivitiesFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AbsActivitiesFragment.kt @@ -304,13 +304,10 @@ abstract class AbsActivitiesFragment protected constructor() : override fun onGapClick(holder: GapViewHolder, position: Int) { val activity = adapter.getActivity(position) DebugLog.v(msg = "Load activity gap $activity") - if (!AccountUtils.isOfficial(context, activity.account_key)) { - // Skip if item is not a status - if (activity.action !in Activity.Action.MENTION_ACTIONS) { - adapter.removeGapLoadingId(ObjectId(activity.account_key, activity.id)) - adapter.notifyItemChanged(position) - return - } + if (activity.action !in Activity.Action.MENTION_ACTIONS) { + adapter.removeGapLoadingId(ObjectId(activity.account_key, activity.id)) + adapter.notifyItemChanged(position) + return } val accountKeys = arrayOf(activity.account_key) val pagination = arrayOf(SinceMaxPagination.maxId(activity.min_position, diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/CustomTabsFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/CustomTabsFragment.kt index ba5099d71..343f35c57 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/CustomTabsFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/CustomTabsFragment.kt @@ -60,7 +60,6 @@ import org.mariotaku.twidere.adapter.ArrayAdapter import org.mariotaku.twidere.annotation.CustomTabType import org.mariotaku.twidere.annotation.TabAccountFlags import org.mariotaku.twidere.extension.applyTheme -import org.mariotaku.twidere.extension.model.isOfficial import org.mariotaku.twidere.model.AccountDetails import org.mariotaku.twidere.model.Tab import org.mariotaku.twidere.model.tab.DrawableHolder @@ -290,7 +289,7 @@ class CustomTabsFragment : BaseFragment(), LoaderCallbacks, MultiChoice } val officialKeyOnly = arguments.getBoolean(EXTRA_OFFICIAL_KEY_ONLY, false) accountsAdapter.addAll(AccountUtils.getAllAccountDetails(AccountManager.get(context), true).filter { - if (officialKeyOnly && !it.isOfficial(context)) { + if (officialKeyOnly) { return@filter false } return@filter conf.checkAccountAvailability(it) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/message/MessageConversationInfoFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/message/MessageConversationInfoFragment.kt index 6e30b994e..4b6608ac7 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/message/MessageConversationInfoFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/message/MessageConversationInfoFragment.kt @@ -61,7 +61,6 @@ import org.mariotaku.ktextension.spannable import org.mariotaku.library.objectcursor.ObjectCursor import org.mariotaku.microblog.library.MicroBlog import org.mariotaku.microblog.library.MicroBlogException -import org.mariotaku.microblog.library.twitter.TwitterUpload import org.mariotaku.pickncrop.library.MediaPickerActivity import org.mariotaku.sqliteqb.library.Expression import org.mariotaku.twidere.R @@ -91,8 +90,6 @@ import org.mariotaku.twidere.model.ParcelableMessageConversation.ConversationTyp import org.mariotaku.twidere.model.ParcelableMessageConversation.ExtrasType import org.mariotaku.twidere.model.util.AccountUtils import org.mariotaku.twidere.provider.TwidereDataStore.Messages.Conversations -import org.mariotaku.twidere.task.twitter.UpdateStatusTask -import org.mariotaku.twidere.task.twitter.message.AddParticipantsTask import org.mariotaku.twidere.task.twitter.message.ClearMessagesTask import org.mariotaku.twidere.task.twitter.message.DestroyConversationTask import org.mariotaku.twidere.task.twitter.message.SetConversationNotificationDisabledTask @@ -186,12 +183,6 @@ class MessageConversationInfoFragment : BaseFragment(), IToolBarSupportFragment, override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { when (requestCode) { - REQUEST_CONVERSATION_ADD_USER -> { - if (resultCode == Activity.RESULT_OK && data != null) { - val user = data.getParcelableExtra(EXTRA_USER) - performAddParticipant(user) - } - } REQUEST_PICK_MEDIA -> { when (resultCode) { Activity.RESULT_OK -> { @@ -325,19 +316,6 @@ class MessageConversationInfoFragment : BaseFragment(), IToolBarSupportFragment, TaskStarter.execute(task) } - private fun performAddParticipant(user: ParcelableUser) { - ProgressDialogFragment.show(childFragmentManager, "add_participant_progress") - val weakThis = WeakReference(this) - val task = AddParticipantsTask(context, accountKey, conversationId, listOf(user)) - task.callback = callback@ { succeed -> - val f = weakThis.get() ?: return@callback - f.dismissDialogThen("add_participant_progress") { - loaderManager.restartLoader(0, null, this) - } - } - TaskStarter.execute(task) - } - private fun performSetNotificationDisabled(disabled: Boolean) { ProgressDialogFragment.show(childFragmentManager, "set_notifications_disabled_progress") val weakThis = WeakReference(this) @@ -379,9 +357,6 @@ class MessageConversationInfoFragment : BaseFragment(), IToolBarSupportFragment, val context = fragment.context when (account.type) { AccountType.TWITTER -> { - if (account.isOfficial(context)) { - return@updateAction microBlog.updateDmConversationName(conversationId, name).isSuccessful - } } } throw UnsupportedOperationException() @@ -391,53 +366,6 @@ class MessageConversationInfoFragment : BaseFragment(), IToolBarSupportFragment, } private fun performSetConversationAvatar(uri: Uri?) { - val conversationId = this.conversationId - performUpdateInfo("set_avatar_progress", updateAction = updateAction@ { fragment, account, microBlog -> - val context = fragment.context - when (account.type) { - AccountType.TWITTER -> { - if (account.isOfficial(context)) { - val upload = account.newMicroBlogInstance(context, cls = TwitterUpload::class.java) - if (uri == null) { - val result = microBlog.updateDmConversationAvatar(conversationId, null) - if (result.isSuccessful) { - val dmResponse = microBlog.getDmConversation(conversationId, null).conversationTimeline - return@updateAction dmResponse.conversations[conversationId]?.avatarImageHttps - } - throw MicroBlogException("Error ${result.responseCode}") - } - var deleteAlways: List? = null - try { - val media = arrayOf(ParcelableMediaUpdate().apply { - this.uri = uri.toString() - this.delete_always = true - }) - val uploadResult = UpdateStatusTask.uploadMicroBlogMediaShared(context, - upload, account, media, null, null, true, null) - deleteAlways = uploadResult.deleteAlways - val avatarId = uploadResult.ids.first() - val result = microBlog.updateDmConversationAvatar(conversationId, avatarId) - if (result.isSuccessful) { - uploadResult.deleteOnSuccess.forEach { it.delete(context) } - val dmResponse = microBlog.getDmConversation(conversationId, null).conversationTimeline - return@updateAction dmResponse.conversations[conversationId]?.avatarImageHttps - } - throw MicroBlogException("Error ${result.responseCode}") - } catch (e: UpdateStatusTask.UploadException) { - e.deleteAlways?.forEach { - it.delete(context) - } - throw e - } finally { - deleteAlways?.forEach { it.delete(context) } - } - } - } - } - throw UnsupportedOperationException() - }, successAction = { uri -> - put(Conversations.CONVERSATION_AVATAR, uri) - }) } private inline fun performUpdateInfo( diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/message/MessageNewConversationFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/message/MessageNewConversationFragment.kt index 403943d8d..d2890a406 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/message/MessageNewConversationFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/message/MessageNewConversationFragment.kt @@ -44,7 +44,6 @@ import org.mariotaku.twidere.R import org.mariotaku.twidere.adapter.SelectableUsersAdapter import org.mariotaku.twidere.constant.IntentConstants.* import org.mariotaku.twidere.constant.nameFirstKey -import org.mariotaku.twidere.extension.model.isOfficial import org.mariotaku.twidere.extension.queryOne import org.mariotaku.twidere.extension.text.appendCompat import org.mariotaku.twidere.fragment.BaseFragment @@ -238,11 +237,7 @@ class MessageNewConversationFragment : BaseFragment(), LoaderCallbacks maxParticipants) { editParticipants.error = getString(R.string.error_message_message_too_many_participants) return diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/status/PinStatusDialogFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/status/PinStatusDialogFragment.kt deleted file mode 100644 index 0657636ba..000000000 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/status/PinStatusDialogFragment.kt +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2017 Mariotaku Lee - * - * 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 . - */ - -package org.mariotaku.twidere.fragment.status - -import android.os.Bundle -import android.support.v4.app.FragmentManager -import org.mariotaku.abstask.library.TaskStarter -import org.mariotaku.twidere.R -import org.mariotaku.twidere.constant.IntentConstants.EXTRA_STATUS -import org.mariotaku.twidere.model.ParcelableStatus -import org.mariotaku.twidere.task.status.PinStatusTask - -class PinStatusDialogFragment : AbsSimpleStatusOperationDialogFragment() { - - override val title: String? - get() = getString(R.string.title_pin_status_confirm) - override val message: String - get() = getString(R.string.message_pin_status_confirm) - - override fun onPerformAction(status: ParcelableStatus) { - val task = PinStatusTask(context, status.account_key, status.id) - TaskStarter.execute(task) - } - - companion object { - - val FRAGMENT_TAG = "pin_status" - - fun show(fm: FragmentManager, status: ParcelableStatus): PinStatusDialogFragment { - val args = Bundle() - args.putParcelable(EXTRA_STATUS, status) - val f = PinStatusDialogFragment() - f.arguments = args - f.show(fm, FRAGMENT_TAG) - return f - } - } -} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/status/StatusFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/status/StatusFragment.kt index f3a86a7cc..3cd6855cb 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/status/StatusFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/status/StatusFragment.kt @@ -123,7 +123,6 @@ class StatusFragment : BaseFragment(), LoaderCallbacks - private var loadTranslationTask: LoadTranslationTask? = null // Data fields private var conversationLoaderInitialized: Boolean = false @@ -494,18 +493,9 @@ class StatusFragment : BaseFragment(), LoaderCallbacks?) { @@ -668,37 +658,6 @@ class StatusFragment : BaseFragment(), LoaderCallbacks(fragment.context, status.account_key) { - - private val weakFragment = WeakReference(fragment) - - override fun onExecute(account: AccountDetails, params: Any?): TranslationResult { - val twitter = account.newMicroBlogInstance(context, MicroBlog::class.java) - val prefDest = preferences.getString(KEY_TRANSLATION_DESTINATION, null).orEmpty() - val dest: String - if (TextUtils.isEmpty(prefDest)) { - dest = twitter.accountSettings.language - val editor = preferences.edit() - editor.putString(KEY_TRANSLATION_DESTINATION, dest) - editor.apply() - } else { - dest = prefDest - } - return twitter.showTranslation(status.originalId, dest) - } - - override fun onSucceed(callback: Any?, result: TranslationResult) { - val fragment = weakFragment.get() ?: return - fragment.displayTranslation(result) - } - - override fun onException(callback: Any?, exception: MicroBlogException) { - Toast.makeText(context, exception.getErrorMessage(context), Toast.LENGTH_SHORT).show() - } - } - - class StatusActivitySummaryLoader( context: Context, private val accountKey: UserKey, diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/status/UnpinStatusDialogFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/status/UnpinStatusDialogFragment.kt deleted file mode 100644 index 1d1190140..000000000 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/status/UnpinStatusDialogFragment.kt +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2017 Mariotaku Lee - * - * 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 . - */ - -package org.mariotaku.twidere.fragment.status - -import android.os.Bundle -import android.support.v4.app.FragmentManager -import org.mariotaku.abstask.library.TaskStarter -import org.mariotaku.twidere.R -import org.mariotaku.twidere.constant.IntentConstants.EXTRA_STATUS -import org.mariotaku.twidere.model.ParcelableStatus -import org.mariotaku.twidere.task.status.UnpinStatusTask - -class UnpinStatusDialogFragment : AbsSimpleStatusOperationDialogFragment() { - - override val title: String? - get() = getString(R.string.title_unpin_status_confirm) - override val message: String - get() = getString(R.string.message_unpin_status_confirm) - - override fun onPerformAction(status: ParcelableStatus) { - val task = UnpinStatusTask(context, status.account_key, status.id) - TaskStarter.execute(task) - } - - companion object { - - val FRAGMENT_TAG = "unpin_status" - - fun show(fm: FragmentManager, status: ParcelableStatus): UnpinStatusDialogFragment { - val args = Bundle() - args.putParcelable(EXTRA_STATUS, status) - val f = UnpinStatusDialogFragment() - f.arguments = args - f.show(fm, FRAGMENT_TAG) - return f - } - } -} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/users/IncomingFriendshipsFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/users/IncomingFriendshipsFragment.kt index 3e4a1879d..d269c428f 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/users/IncomingFriendshipsFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/users/IncomingFriendshipsFragment.kt @@ -32,7 +32,6 @@ import org.mariotaku.twidere.loader.users.AbsRequestUsersLoader import org.mariotaku.twidere.loader.users.IncomingFriendshipsLoader import org.mariotaku.twidere.model.UserKey import org.mariotaku.twidere.model.event.FriendshipTaskEvent -import org.mariotaku.twidere.model.util.AccountUtils import org.mariotaku.twidere.view.holder.UserViewHolder class IncomingFriendshipsFragment : ParcelableUsersFragment(), IUsersAdapter.RequestClickListener { @@ -49,8 +48,6 @@ class IncomingFriendshipsFragment : ParcelableUsersFragment(), IUsersAdapter.Req val accountKey = arguments.getParcelable(EXTRA_ACCOUNT_KEY) ?: return adapter if (USER_TYPE_FANFOU_COM == accountKey.host) { adapter.requestClickListener = this - } else if (AccountUtils.isOfficial(context, accountKey)) { - adapter.requestClickListener = this } return adapter } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/ConversationLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/ConversationLoader.kt index 301010a9e..481fe9d2c 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/ConversationLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/ConversationLoader.kt @@ -38,7 +38,6 @@ import org.mariotaku.twidere.extension.atto.filter import org.mariotaku.twidere.extension.atto.firstElementOrNull import org.mariotaku.twidere.extension.model.api.mastodon.toParcelable import org.mariotaku.twidere.extension.model.api.toParcelable -import org.mariotaku.twidere.extension.model.isOfficial import org.mariotaku.twidere.extension.model.makeOriginal import org.mariotaku.twidere.extension.model.newMicroBlogInstance import org.mariotaku.twidere.model.AccountDetails @@ -93,11 +92,6 @@ class ConversationLoader( // val isOfficial = account.isOfficial(context) val isOfficial = false canLoadAllReplies = isOfficial - if (isOfficial) { - return microBlog.showConversation(status.id, paging).mapMicroBlogToPaginated { - it.toParcelable(account, profileImageSize) - } - } return showConversationCompat(microBlog, account, status, true) } AccountType.STATUSNET -> { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/MediaStatusesSearchLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/MediaStatusesSearchLoader.kt index b200cec41..27ab15f68 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/MediaStatusesSearchLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/MediaStatusesSearchLoader.kt @@ -27,12 +27,10 @@ import org.mariotaku.microblog.library.MicroBlogException import org.mariotaku.microblog.library.twitter.model.Paging import org.mariotaku.microblog.library.twitter.model.SearchQuery import org.mariotaku.microblog.library.twitter.model.Status -import org.mariotaku.microblog.library.twitter.model.UniversalSearchQuery import org.mariotaku.twidere.annotation.AccountType import org.mariotaku.twidere.annotation.FilterScope import org.mariotaku.twidere.extension.model.api.toParcelable import org.mariotaku.twidere.extension.model.newMicroBlogInstance -import org.mariotaku.twidere.extension.model.official import org.mariotaku.twidere.model.AccountDetails import org.mariotaku.twidere.model.ParcelableStatus import org.mariotaku.twidere.model.UserKey @@ -78,9 +76,6 @@ open class MediaStatusesSearchLoader( protected open fun processQuery(details: AccountDetails, query: String): String { if (details.type == AccountType.TWITTER) { - if (details.extras?.official == true) { - return TweetSearchLoader.smQuery("$query filter:media", pagination) - } return "$query filter:media exclude:retweets" } return query @@ -92,15 +87,6 @@ open class MediaStatusesSearchLoader( val microBlog = account.newMicroBlogInstance(context, MicroBlog::class.java) when (account.type) { AccountType.TWITTER -> { - if (account.extras?.official == true) { - val universalQuery = UniversalSearchQuery(queryText) - universalQuery.setModules(UniversalSearchQuery.Module.TWEET) - universalQuery.setResultType(UniversalSearchQuery.ResultType.RECENT) - universalQuery.setPaging(paging) - val searchResult = microBlog.universalSearch(universalQuery) - return searchResult.modules.mapNotNull { it.status?.data } - } - val searchQuery = SearchQuery(queryText) searchQuery.paging(paging) return microBlog.search(searchQuery) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/MediaTimelineLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/MediaTimelineLoader.kt index 6ce6ad361..9abf6516d 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/MediaTimelineLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/MediaTimelineLoader.kt @@ -34,7 +34,6 @@ import org.mariotaku.twidere.extension.model.api.mastodon.mapToPaginated import org.mariotaku.twidere.extension.model.api.mastodon.toParcelable import org.mariotaku.twidere.extension.model.api.toParcelable import org.mariotaku.twidere.extension.model.api.updateFilterInfoForUserTimeline -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.ParcelableStatus @@ -90,32 +89,23 @@ class MediaTimelineLoader( val microBlog = account.newMicroBlogInstance(context, MicroBlog::class.java) when (account.type) { AccountType.TWITTER -> { - if (account.isOfficial(context)) { - if (userKey != null) { - return microBlog.getMediaTimeline(userKey.id, paging) - } - if (screenName != null) { - return microBlog.getMediaTimelineByScreenName(screenName, paging) - } - } else { - val screenName = this.screenName ?: run { - return@run this.user ?: run fetchUser@ { - if (userKey == null) throw MicroBlogException("Invalid parameters") - val user = microBlog.tryShowUser(userKey.id, null, account.type) - this.user = user - return@fetchUser user - }.screenName - } - val query = SearchQuery("from:$screenName filter:media exclude:retweets") - query.paging(paging) - val result = ResponseList() - microBlog.search(query).filterTo(result) { status -> - val user = status.user - return@filterTo user.id == userKey?.id - || user.screenName.equals(this.screenName, ignoreCase = true) - } - return result + val screenName = this.screenName ?: run { + return@run this.user ?: run fetchUser@ { + if (userKey == null) throw MicroBlogException("Invalid parameters") + val user = microBlog.tryShowUser(userKey.id, null, account.type) + this.user = user + return@fetchUser user + }.screenName } + val query = SearchQuery("from:$screenName filter:media exclude:retweets") + query.paging(paging) + val result = ResponseList() + microBlog.search(query).filterTo(result) { status -> + val user = status.user + return@filterTo user.id == userKey?.id + || user.screenName.equals(this.screenName, ignoreCase = true) + } + return result throw MicroBlogException("Wrong user") } AccountType.FANFOU -> { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/TweetSearchLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/TweetSearchLoader.kt index 262461063..080537e77 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/TweetSearchLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/TweetSearchLoader.kt @@ -34,7 +34,6 @@ import org.mariotaku.twidere.extension.model.api.mastodon.mapToPaginated import org.mariotaku.twidere.extension.model.api.mastodon.toParcelable import org.mariotaku.twidere.extension.model.api.toParcelable import org.mariotaku.twidere.extension.model.newMicroBlogInstance -import org.mariotaku.twidere.extension.model.official import org.mariotaku.twidere.model.AccountDetails import org.mariotaku.twidere.model.ParcelableStatus import org.mariotaku.twidere.model.UserKey @@ -76,9 +75,6 @@ open class TweetSearchLoader( protected open fun processQuery(details: AccountDetails, query: String): String { if (details.type == AccountType.TWITTER) { - if (details.extras?.official == true) { - return smQuery(query, pagination) - } return "$query exclude:retweets" } return query @@ -108,15 +104,6 @@ open class TweetSearchLoader( val queryText = processQuery(account, query) when (account.type) { AccountType.TWITTER -> { - if (account.extras?.official == true) { - val universalQuery = UniversalSearchQuery(queryText) - universalQuery.setModules(UniversalSearchQuery.Module.TWEET) - universalQuery.setResultType(UniversalSearchQuery.ResultType.RECENT) - universalQuery.setPaging(paging) - val searchResult = microBlog.universalSearch(universalQuery) - return searchResult.modules.mapNotNull { it.status?.data } - } - val searchQuery = SearchQuery(queryText) searchQuery.paging(paging) return microBlog.search(searchQuery) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/UserMentionsLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/UserMentionsLoader.kt index e8075a7f0..e716e559d 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/UserMentionsLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/UserMentionsLoader.kt @@ -21,7 +21,6 @@ package org.mariotaku.twidere.loader.statuses import android.content.Context import org.mariotaku.twidere.annotation.AccountType -import org.mariotaku.twidere.extension.model.official import org.mariotaku.twidere.model.AccountDetails import org.mariotaku.twidere.model.ParcelableStatus import org.mariotaku.twidere.model.UserKey @@ -43,9 +42,6 @@ class UserMentionsLoader( override fun processQuery(details: AccountDetails, query: String): String { val screenName = query.substringAfter("@") if (details.type == AccountType.TWITTER) { - if (details.extras?.official == true) { - return smQuery("to:$screenName", pagination) - } return "to:$screenName exclude:retweets" } return "@$screenName -RT" diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/StatusFavoritersLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/StatusFavoritersLoader.kt index 5054298b4..7e99ae2be 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/StatusFavoritersLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/StatusFavoritersLoader.kt @@ -36,7 +36,6 @@ import org.mariotaku.twidere.extension.api.lookupUsersMapPaginated import org.mariotaku.twidere.extension.model.api.mastodon.mapToPaginated import org.mariotaku.twidere.extension.model.api.mastodon.toParcelable import org.mariotaku.twidere.extension.model.api.toParcelable -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.ParcelableUser @@ -63,9 +62,7 @@ class StatusFavoritersLoader( } AccountType.TWITTER -> { val microBlog = details.newMicroBlogInstance(context, MicroBlog::class.java) - val ids = if (details.isOfficial(context)) { - microBlog.getStatusActivitySummary(statusId).favoriters - } else { + val ids = run { val web = details.newMicroBlogInstance(context, TwitterWeb::class.java) val htmlUsers = web.getFavoritedPopup(statusId).htmlUsers IDsAccessor.setIds(IDs(), parseUserIds(htmlUsers)) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/impl/InteractionsTabConfiguration.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/impl/InteractionsTabConfiguration.kt index 050e5158c..8c6890acd 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/impl/InteractionsTabConfiguration.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/impl/InteractionsTabConfiguration.kt @@ -29,7 +29,6 @@ import org.mariotaku.twidere.annotation.AccountType import org.mariotaku.twidere.annotation.TabAccountFlags import org.mariotaku.twidere.constant.IntentConstants.EXTRA_MENTIONS_ONLY import org.mariotaku.twidere.constant.IntentConstants.EXTRA_MY_FOLLOWING_ONLY -import org.mariotaku.twidere.extension.model.isOfficial import org.mariotaku.twidere.fragment.InteractionsTimelineFragment import org.mariotaku.twidere.model.AccountDetails import org.mariotaku.twidere.model.Tab @@ -105,11 +104,11 @@ class InteractionsTabConfiguration : TabConfiguration() { val am = AccountManager.get(context) val accounts = AccountUtils.getAllAccountDetails(am, false) interactionsAvailable = accounts.any { it.supportsInteractions } - requiresStreaming = accounts.all { it.requiresStreaming } + requiresStreaming = accounts.all { true } } else when (account.type) { AccountType.TWITTER -> { interactionsAvailable = true - requiresStreaming = !account.isOfficial(context) + requiresStreaming = true } AccountType.MASTODON -> { interactionsAvailable = true @@ -161,7 +160,7 @@ class InteractionsTabConfiguration : TabConfiguration() { get() = type == AccountType.TWITTER || type == AccountType.MASTODON private val AccountDetails.requiresStreaming: Boolean - get() = !isOfficial(context) + get() = true } } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/service/StreamingService.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/service/StreamingService.kt index 263984447..2d2ab5005 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/service/StreamingService.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/service/StreamingService.kt @@ -194,11 +194,6 @@ class StreamingService : BaseService() { } private fun newStreamingRunnable(account: AccountDetails, preferences: AccountPreferences): StreamingRunnable<*>? { - when (account.type) { - AccountType.TWITTER -> { - return TwitterStreamingRunnable(this, account, preferences) - } - } return null } @@ -237,236 +232,6 @@ class StreamingService : BaseService() { abstract fun onCancelled() } - internal inner class TwitterStreamingRunnable( - context: Context, - account: AccountDetails, - accountPreferences: AccountPreferences - ) : StreamingRunnable(context, account, accountPreferences) { - - private val profileImageSize = context.getString(R.string.profile_image_size) - private val isOfficial = account.isOfficial(context) - - private var canGetInteractions: Boolean = true - private var canGetMessages: Boolean = true - - private val interactionsTimeoutRunnable = Runnable { - canGetInteractions = true - } - - private val messagesTimeoutRunnable = Runnable { - canGetMessages = true - } - - val callback = object : TwitterTimelineStreamCallback(account.key.id) { - - private var lastStatusTimestamps = LongArray(2) - - private var homeInsertGap = false - private var interactionsInsertGap = false - - private var lastActivityAboutMe: ParcelableActivity? = null - - override fun onConnected(): Boolean { - homeInsertGap = true - interactionsInsertGap = true - return true - } - - override fun onHomeTimeline(status: Status): Boolean { - if (!accountPreferences.isStreamHomeTimelineEnabled) { - homeInsertGap = true - return false - } - val parcelableStatus = status.toParcelable(account, profileImageSize = profileImageSize) - parcelableStatus.is_gap = homeInsertGap - - val currentTimeMillis = System.currentTimeMillis() - if (lastStatusTimestamps[0] >= parcelableStatus.timestamp) { - val extraValue = (currentTimeMillis - lastStatusTimestamps[1]).coerceAtMost(499) - parcelableStatus.position_key = parcelableStatus.timestamp + extraValue - } else { - parcelableStatus.position_key = parcelableStatus.timestamp - } - parcelableStatus.inserted_date = currentTimeMillis - - lastStatusTimestamps[0] = parcelableStatus.position_key - lastStatusTimestamps[1] = parcelableStatus.inserted_date - - val values = ObjectCursor.valuesCreatorFrom(ParcelableStatus::class.java) - .create(parcelableStatus) - context.contentResolver.insert(Statuses.CONTENT_URI, values) - homeInsertGap = false - return true - } - - override fun onActivityAboutMe(activity: Activity): Boolean { - if (!accountPreferences.isStreamInteractionsEnabled) { - interactionsInsertGap = true - return false - } - if (isOfficial) { - // Wait for 30 seconds to avoid rate limit - if (canGetInteractions) { - handler.post { getInteractions() } - canGetInteractions = false - handler.postDelayed(interactionsTimeoutRunnable, TimeUnit.SECONDS.toMillis(30)) - } - } else { - val insertGap: Boolean - if (activity.action in Activity.Action.MENTION_ACTIONS) { - insertGap = interactionsInsertGap - interactionsInsertGap = false - } else { - insertGap = false - } - val curActivity = activity.toParcelable(account, insertGap, profileImageSize) - curActivity.account_color = account.color - curActivity.position_key = curActivity.timestamp - var updateId = -1L - if (curActivity.action !in Activity.Action.MENTION_ACTIONS) { - /* Merge two activities if: - * * Not mention/reply/quote - * * Same action - * * Same source or target or target object - */ - val lastActivity = this.lastActivityAboutMe - if (lastActivity != null && curActivity.action == lastActivity.action) { - if (curActivity.reachedCountLimit) { - // Skip if more than 10 sources/targets/target_objects - } else if (curActivity.isSameSources(lastActivity)) { - curActivity.prependTargets(lastActivity) - curActivity.prependTargetObjects(lastActivity) - updateId = lastActivity._id - } else if (curActivity.isSameTarget(lastActivity)) { - curActivity.prependSources(lastActivity) - curActivity.prependTargets(lastActivity) - updateId = lastActivity._id - } else if (curActivity.isSameTargetObject(lastActivity)) { - curActivity.prependSources(lastActivity) - curActivity.prependTargets(lastActivity) - updateId = lastActivity._id - } - if (updateId > 0) { - curActivity.min_position = lastActivity.min_position - curActivity.min_sort_position = lastActivity.min_sort_position - } - } - } - val values = ObjectCursor.valuesCreatorFrom(ParcelableActivity::class.java) - .create(curActivity) - val resolver = context.contentResolver - if (updateId > 0) { - val where = Expression.equals(Activities._ID, updateId).sql - resolver.update(Activities.AboutMe.CONTENT_URI, values, where, null) - curActivity._id = updateId - } else { - val uri = resolver.insert(Activities.AboutMe.CONTENT_URI, values) - if (uri != null) { - curActivity._id = uri.lastPathSegment.toLongOr(-1L) - } - } - lastActivityAboutMe = curActivity - } - return true - } - - @WorkerThread - override fun onDirectMessage(directMessage: DirectMessage): Boolean { - if (!accountPreferences.isStreamDirectMessagesEnabled) { - return false - } - if (canGetMessages) { - handler.post { getMessages() } - canGetMessages = false - val timeout = TimeUnit.SECONDS.toMillis(if (isOfficial) 30 else 90) - handler.postDelayed(messagesTimeoutRunnable, timeout) - } - return true - } - - override fun onAllStatus(status: Status) { - if (!accountPreferences.isStreamNotificationUsersEnabled) { - return - } - val user = status.user ?: return - val userKey = user.key - val where = Expression.and(Expression.equalsArgs(CachedRelationships.ACCOUNT_KEY), - Expression.equalsArgs(CachedRelationships.USER_KEY), - Expression.equals(CachedRelationships.NOTIFICATIONS_ENABLED, 1)).sql - val whereArgs = arrayOf(account.key.toString(), userKey.toString()) - if (context.contentResolver.queryCount(CachedRelationships.CONTENT_URI, - where, whereArgs) <= 0) return - - contentNotificationManager.showUserNotification(account.key, status, userKey) - } - - override fun onStatusDeleted(event: DeletionEvent): Boolean { - val deleteWhere = Expression.and(Expression.likeRaw(Columns.Column(Statuses.ACCOUNT_KEY), "'%@'||?"), - Expression.equalsArgs(Columns.Column(Statuses.ID))).sql - val deleteWhereArgs = arrayOf(account.key.host, event.id) - context.contentResolver.delete(Statuses.CONTENT_URI, deleteWhere, deleteWhereArgs) - return true - } - - override fun onDisconnectNotice(code: Int, reason: String?): Boolean { - disconnect() - return true - } - - override fun onException(ex: Throwable): Boolean { - DebugLog.w(LOGTAG, msg = "Exception for ${account.key}", tr = ex) - return true - } - - override fun onUnhandledEvent(obj: TwitterStreamObject, json: String) { - DebugLog.d(LOGTAG, msg = "Unhandled event ${obj.determine()} for ${account.key}: $json") - } - - @UiThread - private fun getInteractions() { - val task = GetActivitiesAboutMeTask(context) - task.params = object : RefreshTaskParam { - override val accountKeys: Array = arrayOf(account.key) - - override val pagination by lazy { - val keys = accountKeys.toNulls() - val sinceIds = DataStoreUtils.getRefreshNewestActivityMaxPositions(context, - Activities.AboutMe.CONTENT_URI, keys) - val sinceSortIds = DataStoreUtils.getRefreshNewestActivityMaxSortPositions(context, - Activities.AboutMe.CONTENT_URI, keys) - return@lazy Array(keys.size) { idx -> - SinceMaxPagination.sinceId(sinceIds[idx], sinceSortIds[idx]) - } - } - - } - TaskStarter.execute(task) - } - - @UiThread - private fun getMessages() { - val task = GetMessagesTask(context) - task.params = object : GetMessagesTask.RefreshMessagesTaskParam(context) { - override val accountKeys: Array = arrayOf(account.key) - } - TaskStarter.execute(task) - } - } - - override fun createStreamingInstance(): TwitterUserStream { - return account.newMicroBlogInstance(context, cls = TwitterUserStream::class.java) - } - - override fun TwitterUserStream.beginStreaming() { - getUserStream(StreamWith.USER, callback) - } - - override fun onCancelled() { - callback.disconnect() - } - - } - companion object { private val NOTIFICATION_SERVICE_STARTED = 1 diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/task/AcceptFriendshipTask.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/task/AcceptFriendshipTask.kt index 6202d9394..40580b5f7 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/task/AcceptFriendshipTask.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/task/AcceptFriendshipTask.kt @@ -15,6 +15,7 @@ import org.mariotaku.twidere.model.AccountDetails import org.mariotaku.twidere.model.ParcelableUser import org.mariotaku.twidere.model.event.FriendshipTaskEvent import org.mariotaku.twidere.util.Utils +import java.lang.UnsupportedOperationException /** * Created by mariotaku on 16/3/11. @@ -35,9 +36,7 @@ class AcceptFriendshipTask(context: Context) : AbsFriendshipOperationTask(contex return mastodon.getAccount(args.userKey.id).toParcelable(details) } else -> { - val twitter = details.newMicroBlogInstance(context, MicroBlog::class.java) - return twitter.acceptFriendship(args.userKey.id).toParcelable(details, - profileImageSize = profileImageSize) + throw UnsupportedOperationException() } } } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/task/DenyFriendshipTask.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/task/DenyFriendshipTask.kt index b7b8f2e2b..81e7492f4 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/task/DenyFriendshipTask.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/task/DenyFriendshipTask.kt @@ -15,6 +15,7 @@ import org.mariotaku.twidere.model.AccountDetails import org.mariotaku.twidere.model.ParcelableUser import org.mariotaku.twidere.model.event.FriendshipTaskEvent import org.mariotaku.twidere.util.Utils +import java.lang.UnsupportedOperationException /** * Created by mariotaku on 16/3/11. @@ -35,9 +36,7 @@ class DenyFriendshipTask(context: Context) : AbsFriendshipOperationTask(context, return mastodon.getAccount(args.userKey.id).toParcelable(details) } else -> { - val twitter = details.newMicroBlogInstance(context, MicroBlog::class.java) - return twitter.denyFriendship(args.userKey.id).toParcelable(details, - profileImageSize = profileImageSize) + throw UnsupportedOperationException() } } } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/task/status/PinStatusTask.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/task/status/PinStatusTask.kt deleted file mode 100644 index 49e1b2dcf..000000000 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/task/status/PinStatusTask.kt +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2017 Mariotaku Lee - * - * 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 . - */ - -package org.mariotaku.twidere.task.status - -import android.content.Context -import android.widget.Toast -import org.mariotaku.microblog.library.MicroBlog -import org.mariotaku.microblog.library.twitter.model.PinTweetResult -import org.mariotaku.twidere.R -import org.mariotaku.twidere.extension.model.newMicroBlogInstance -import org.mariotaku.twidere.model.AccountDetails -import org.mariotaku.twidere.model.UserKey -import org.mariotaku.twidere.model.event.StatusPinEvent -import org.mariotaku.twidere.task.AbsAccountRequestTask - -/** - * Created by mariotaku on 2017/4/28. - */ - -class PinStatusTask(context: Context, accountKey: UserKey, val id: String) : AbsAccountRequestTask(context, accountKey) { - - override fun onExecute(account: AccountDetails, params: Any?): PinTweetResult { - val twitter = account.newMicroBlogInstance(context, MicroBlog::class.java) - return twitter.pinTweet(id) - } - - override fun onSucceed(callback: Any?, result: PinTweetResult) { - super.onSucceed(callback, result) - Toast.makeText(context, R.string.message_toast_status_pinned, Toast.LENGTH_SHORT).show() - if (accountKey != null) { - bus.post(StatusPinEvent(accountKey, true)) - } - } -} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/task/status/UnpinStatusTask.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/task/status/UnpinStatusTask.kt deleted file mode 100644 index 0bcc94aa7..000000000 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/task/status/UnpinStatusTask.kt +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2017 Mariotaku Lee - * - * 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 . - */ - -package org.mariotaku.twidere.task.status - -import android.content.Context -import android.widget.Toast -import org.mariotaku.microblog.library.MicroBlog -import org.mariotaku.microblog.library.twitter.model.PinTweetResult -import org.mariotaku.twidere.R -import org.mariotaku.twidere.extension.model.newMicroBlogInstance -import org.mariotaku.twidere.model.AccountDetails -import org.mariotaku.twidere.model.UserKey -import org.mariotaku.twidere.model.event.StatusPinEvent -import org.mariotaku.twidere.task.AbsAccountRequestTask - -/** - * Created by mariotaku on 2017/4/28. - */ - -class UnpinStatusTask(context: Context, accountKey: UserKey, val id: String) : AbsAccountRequestTask(context, accountKey) { - - override fun onExecute(account: AccountDetails, params: Any?): PinTweetResult { - val twitter = account.newMicroBlogInstance(context, MicroBlog::class.java) - return twitter.unpinTweet(id) - } - - override fun onSucceed(callback: Any?, result: PinTweetResult) { - super.onSucceed(callback, result) - Toast.makeText(context, R.string.message_toast_status_unpinned, Toast.LENGTH_SHORT).show() - if (accountKey != null) { - bus.post(StatusPinEvent(accountKey, false)) - } - } -} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/GetActivitiesAboutMeTask.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/GetActivitiesAboutMeTask.kt index 41901ef6a..eead73e86 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/GetActivitiesAboutMeTask.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/GetActivitiesAboutMeTask.kt @@ -36,7 +36,6 @@ import org.mariotaku.twidere.extension.api.batchGetRelationships import org.mariotaku.twidere.extension.model.api.mastodon.toParcelable import org.mariotaku.twidere.extension.model.api.microblog.toParcelable import org.mariotaku.twidere.extension.model.extractFanfouHashtags -import org.mariotaku.twidere.extension.model.isOfficial import org.mariotaku.twidere.extension.model.newMicroBlogInstance import org.mariotaku.twidere.fragment.InteractionsTimelineFragment import org.mariotaku.twidere.model.AccountDetails @@ -82,28 +81,6 @@ class GetActivitiesAboutMeTask(context: Context) : GetActivitiesTask(context) { notification.status?.tags?.map { it.name }.orEmpty() }) } - AccountType.TWITTER -> { - val microBlog = account.newMicroBlogInstance(context, MicroBlog::class.java) - if (account.isOfficial(context)) { - val timeline = microBlog.getActivitiesAboutMe(paging) - val activities = timeline.map { - it.toParcelable(account, profileImageSize = profileImageSize) - } - - return GetTimelineResult(account, activities, activities.flatMap { - it.sources?.toList().orEmpty() - }, timeline.flatMapTo(HashSet()) { activity -> - val mapResult = mutableSetOf() - activity.targetStatuses?.flatMapTo(mapResult) { status -> - status.entities?.hashtags?.map { it.text }.orEmpty() - } - activity.targetObjectStatuses?.flatMapTo(mapResult) { status -> - status.entities?.hashtags?.map { it.text }.orEmpty() - } - return@flatMapTo mapResult - }) - } - } AccountType.FANFOU -> { val microBlog = account.newMicroBlogInstance(context, MicroBlog::class.java) val activities = microBlog.getMentions(paging).map { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/GetStatusesTask.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/GetStatusesTask.kt index 458c041c1..cb96ba1a6 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/GetStatusesTask.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/GetStatusesTask.kt @@ -244,7 +244,7 @@ abstract class GetStatusesTask( if (result == null) return@forEach val account = result.account val task = CacheTimelineResultTask(context, result, - account.type == AccountType.STATUSNET || account.isOfficial(context)) + account.type == AccountType.STATUSNET) TaskStarter.execute(task) } } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/message/AddParticipantsTask.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/message/AddParticipantsTask.kt deleted file mode 100644 index 8c8983e7f..000000000 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/message/AddParticipantsTask.kt +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2017 Mariotaku Lee - * - * 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 . - */ - -package org.mariotaku.twidere.task.twitter.message - -import android.accounts.AccountManager -import android.content.Context -import org.mariotaku.ktextension.mapToArray -import org.mariotaku.microblog.library.MicroBlog -import org.mariotaku.microblog.library.MicroBlogException -import org.mariotaku.twidere.R -import org.mariotaku.twidere.annotation.AccountType -import org.mariotaku.twidere.extension.model.addParticipants -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.ParcelableMessageConversation -import org.mariotaku.twidere.model.ParcelableUser -import org.mariotaku.twidere.model.UserKey -import org.mariotaku.twidere.model.util.AccountUtils -import org.mariotaku.twidere.task.ExceptionHandlingAbstractTask -import org.mariotaku.twidere.util.DataStoreUtils - -/** - * Created by mariotaku on 2017/2/25. - */ - -class AddParticipantsTask( - context: Context, - val accountKey: UserKey, - val conversationId: String, - val participants: Collection -) : ExceptionHandlingAbstractTask Unit)?>(context) { - - private val profileImageSize: String = context.getString(R.string.profile_image_size) - - override val exceptionClass = MicroBlogException::class.java - - override fun onExecute(params: Unit?): Boolean { - val account = AccountUtils.getAccountDetails(AccountManager.get(context), accountKey, true) ?: - throw MicroBlogException("No account") - val conversation = DataStoreUtils.findMessageConversation(context, accountKey, conversationId) - if (conversation != null && conversation.is_temp) { - val addData = GetMessagesTask.DatabaseUpdateData(listOf(conversation), emptyList()) - conversation.addParticipants(participants) - GetMessagesTask.storeMessages(context, addData, account, showNotification = false) - // Don't finish too fast - Thread.sleep(300L) - return true - } - val microBlog = account.newMicroBlogInstance(context, cls = MicroBlog::class.java) - val addData = requestAddParticipants(microBlog, account, conversation) - GetMessagesTask.storeMessages(context, addData, account, showNotification = false) - return true - } - - override fun afterExecute(callback: ((Boolean) -> Unit)?, result: Boolean?, exception: MicroBlogException?) { - callback?.invoke(result ?: false) - } - - private fun requestAddParticipants(microBlog: MicroBlog, account: AccountDetails, conversation: ParcelableMessageConversation?): - GetMessagesTask.DatabaseUpdateData { - when (account.type) { - AccountType.TWITTER -> { - if (account.isOfficial(context)) { - val ids = participants.mapToArray { it.key.id } - val response = microBlog.addParticipants(conversationId, ids) - if (conversation != null) { - conversation.addParticipants(participants) - return GetMessagesTask.DatabaseUpdateData(listOf(conversation), emptyList()) - } - return GetMessagesTask.createDatabaseUpdateData(context, account, response, - profileImageSize) - } - } - - } - throw MicroBlogException("Adding participants is not supported") - } - -} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/message/DestroyConversationTask.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/message/DestroyConversationTask.kt index 0dc989fe2..38975aee1 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/message/DestroyConversationTask.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/message/DestroyConversationTask.kt @@ -25,7 +25,6 @@ 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.ParcelableMessageConversation @@ -89,9 +88,6 @@ class DestroyConversationTask( private fun requestDestroyConversation(microBlog: MicroBlog, account: AccountDetails): Boolean { when (account.type) { AccountType.TWITTER -> { - if (account.isOfficial(context)) { - return microBlog.deleteDmConversation(conversationId).isSuccessful - } } } return false diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/message/DestroyMessageTask.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/message/DestroyMessageTask.kt index dd0779e6a..7c6fbeb4c 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/message/DestroyMessageTask.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/message/DestroyMessageTask.kt @@ -25,7 +25,6 @@ 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 @@ -75,9 +74,6 @@ class DestroyMessageTask( account: AccountDetails, messageId: String): Boolean { when (account.type) { AccountType.TWITTER -> { - if (account.isOfficial(context)) { - return microBlog.destroyDm(messageId).isSuccessful - } } } microBlog.destroyDirectMessage(messageId) 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 4d2b215a7..39fb4d195 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 @@ -99,27 +99,11 @@ class GetMessagesTask( // Use fanfou DM api, disabled since it's conversation api is not suitable for paging // return getFanfouMessages(microBlog, details, param, index) } - AccountType.TWITTER -> { - // Use official DM api - if (details.isOfficial(context)) { - return getTwitterOfficialMessages(microBlog, details, param, index) - } - } } // Use default method return getDefaultMessages(microBlog, details, param, index) } - private fun getTwitterOfficialMessages(microBlog: MicroBlog, details: AccountDetails, - param: RefreshMessagesTaskParam, index: Int): DatabaseUpdateData { - val conversationId = param.conversationId - if (conversationId == null) { - return getTwitterOfficialUserInbox(microBlog, details, param, index) - } else { - return getTwitterOfficialConversation(microBlog, details, conversationId, param, index) - } - } - private fun getFanfouMessages(microBlog: MicroBlog, details: AccountDetails, param: RefreshMessagesTaskParam, index: Int): DatabaseUpdateData { val conversationId = param.conversationId if (conversationId == null) { @@ -195,35 +179,6 @@ class GetMessagesTask( } - private fun getTwitterOfficialConversation(microBlog: MicroBlog, details: AccountDetails, - conversationId: String, param: RefreshMessagesTaskParam, index: Int): DatabaseUpdateData { - val maxId = (param.pagination?.get(index) as? SinceMaxPagination)?.maxId - ?: return DatabaseUpdateData(emptyList(), emptyList()) - val paging = Paging().apply { - maxId(maxId) - } - - val response = microBlog.getDmConversation(conversationId, paging).conversationTimeline - return createDatabaseUpdateData(context, details, response, profileImageSize) - } - - private fun getTwitterOfficialUserInbox(microBlog: MicroBlog, details: AccountDetails, - param: RefreshMessagesTaskParam, index: Int): DatabaseUpdateData { - val maxId = (param.pagination?.get(index) as? SinceMaxPagination)?.maxId - val cursor = (param.pagination?.get(index) as? CursorPagination)?.cursor - val response = if (cursor != null) { - microBlog.getUserUpdates(cursor).userEvents - } else { - microBlog.getUserInbox(Paging().apply { - if (maxId != null) { - maxId(maxId) - } - }).userInbox - } ?: throw MicroBlogException("Null response data") - return createDatabaseUpdateData(context, details, response, profileImageSize) - } - - private fun getFanfouConversations(microBlog: MicroBlog, details: AccountDetails, param: RefreshMessagesTaskParam, index: Int): DatabaseUpdateData { val accountKey = details.key @@ -275,16 +230,10 @@ class GetMessagesTask( defaultKeys, false) val outgoingIds = DataStoreUtils.getNewestMessageIds(context, Messages.CONTENT_URI, defaultKeys, true) - val cursors = DataStoreUtils.getNewestConversations(context, Conversations.CONTENT_URI, - twitterOfficialKeys).mapToArray { it?.request_cursor } accounts.forEachIndexed { index, details -> if (details == null) return@forEachIndexed - if (details.isOfficial(context)) { - result[index] = CursorPagination.valueOf(cursors[index]) - } else { - result[index] = SinceMaxPagination.sinceId(incomingIds[index], -1) - result[accounts.size + index] = SinceMaxPagination.sinceId(outgoingIds[index], -1) - } + result[index] = SinceMaxPagination.sinceId(incomingIds[index], -1) + result[accounts.size + index] = SinceMaxPagination.sinceId(outgoingIds[index], -1) } return@lazy result } @@ -301,7 +250,7 @@ class GetMessagesTask( val outgoingIds = DataStoreUtils.getOldestMessageIds(context, Messages.CONTENT_URI, defaultKeys, true) val oldestConversations = DataStoreUtils.getOldestConversations(context, - Conversations.CONTENT_URI, twitterOfficialKeys) + Conversations.CONTENT_URI, emptyArray()) oldestConversations.forEachIndexed { i, conversation -> val extras = conversation?.conversation_extras as? TwitterOfficialConversationExtras ?: return@forEachIndexed incomingIds[i] = extras.maxEntryId @@ -342,19 +291,6 @@ class GetMessagesTask( protected val defaultKeys: Array by lazy { return@lazy accounts.map { account -> account ?: return@map null - if (account.isOfficial(context)) { - return@map null - } - return@map account.key - }.toTypedArray() - } - - protected val twitterOfficialKeys: Array by lazy { - return@lazy accounts.map { account -> - account ?: return@map null - if (!account.isOfficial(context)) { - return@map null - } return@map account.key }.toTypedArray() } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/message/MarkMessageReadTask.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/message/MarkMessageReadTask.kt index 5cd678c6c..ff1d398a2 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/message/MarkMessageReadTask.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/message/MarkMessageReadTask.kt @@ -28,7 +28,6 @@ import org.mariotaku.microblog.library.MicroBlogException import org.mariotaku.sqliteqb.library.Expression import org.mariotaku.sqliteqb.library.OrderBy import org.mariotaku.twidere.annotation.AccountType -import org.mariotaku.twidere.extension.model.isOfficial import org.mariotaku.twidere.extension.model.newMicroBlogInstance import org.mariotaku.twidere.extension.model.timestamp import org.mariotaku.twidere.extension.queryOne @@ -81,23 +80,6 @@ class MarkMessageReadTask( internal fun performMarkRead(context: Context, microBlog: MicroBlog, account: AccountDetails, conversation: ParcelableMessageConversation): Pair? { val cr = context.contentResolver - when (account.type) { - AccountType.TWITTER -> { - if (account.isOfficial(context)) { - val event = (conversation.conversation_extras as? TwitterOfficialConversationExtras)?.maxReadEvent ?: run { - val message = cr.findRecentMessage(account.key, conversation.id) ?: return null - return@run Pair(message.id, message.timestamp) - } - if (conversation.last_read_timestamp > event.second) { - // Local is newer, ignore network request - return event - } - if (microBlog.markDmRead(conversation.id, event.first).isSuccessful) { - return event - } - } - } - } val message = cr.findRecentMessage(account.key, conversation.id) ?: return null return Pair(message.id, message.timestamp) } 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 9f9095913..e4f38be0b 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 @@ -31,7 +31,6 @@ import org.mariotaku.sqliteqb.library.Expression import org.mariotaku.twidere.R import org.mariotaku.twidere.annotation.AccountType import org.mariotaku.twidere.extension.model.api.* -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.ParcelableMedia @@ -42,7 +41,6 @@ import org.mariotaku.twidere.model.util.ParcelableMessageUtils import org.mariotaku.twidere.provider.TwidereDataStore.Messages.Conversations import org.mariotaku.twidere.task.ExceptionHandlingAbstractTask import org.mariotaku.twidere.task.twitter.UpdateStatusTask -import org.mariotaku.twidere.task.twitter.message.GetMessagesTask import org.mariotaku.twidere.task.twitter.message.GetMessagesTask.Companion.addConversation import org.mariotaku.twidere.task.twitter.message.GetMessagesTask.Companion.addLocalConversations @@ -86,11 +84,7 @@ class SendMessageTask( message: ParcelableNewMessage): GetMessagesTask.DatabaseUpdateData { when (account.type) { AccountType.TWITTER -> { - if (account.isOfficial(context)) { - return sendTwitterOfficialDM(microBlog, account, message) - } else { - return sendTwitterMessageEvent(microBlog, account, message) - } + return sendTwitterMessageEvent(microBlog, account, message) } AccountType.FANFOU -> { return sendFanfouDM(microBlog, account, message) @@ -99,47 +93,6 @@ class SendMessageTask( return sendDefaultDM(microBlog, account, message) } - private fun sendTwitterOfficialDM(microBlog: MicroBlog, account: AccountDetails, - message: ParcelableNewMessage): GetMessagesTask.DatabaseUpdateData { - var deleteOnSuccess: List? = null - var deleteAlways: List? = null - val sendResponse = try { - val conversationId = message.conversation_id - val tempConversation = message.is_temp_conversation - - val newDm = NewDm() - if (!tempConversation && conversationId != null) { - newDm.setConversationId(conversationId) - } else { - newDm.setRecipientIds(message.recipient_ids) - } - newDm.setText(message.text) - - if (message.media.isNotNullOrEmpty()) { - val upload = account.newMicroBlogInstance(context, cls = TwitterUpload::class.java) - val uploadResult = UpdateStatusTask.uploadMicroBlogMediaShared(context, - upload, account, message.media, null, null, true, null) - newDm.setMediaId(uploadResult.ids[0]) - deleteAlways = uploadResult.deleteAlways - deleteOnSuccess = uploadResult.deleteOnSuccess - } - microBlog.sendDm(newDm) - } catch (e: UpdateStatusTask.UploadException) { - e.deleteAlways?.forEach { - it.delete(context) - } - throw MicroBlogException(e) - } finally { - deleteAlways?.forEach { it.delete(context) } - } - deleteOnSuccess?.forEach { it.delete(context) } - val conversationId = sendResponse.entries?.firstOrNull { - it.message != null - }?.message?.conversationId - val response = microBlog.getDmConversation(conversationId, null).conversationTimeline - return GetMessagesTask.createDatabaseUpdateData(context, account, response, profileImageSize) - } - private fun sendTwitterMessageEvent(microBlog: MicroBlog, account: AccountDetails, message: ParcelableNewMessage): GetMessagesTask.DatabaseUpdateData { val recipientId = message.recipient_ids.singleOrNull() ?: throw MicroBlogException("No recipient") diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/message/SetConversationNotificationDisabledTask.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/message/SetConversationNotificationDisabledTask.kt index 0239b4c20..b8bbc7b85 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/message/SetConversationNotificationDisabledTask.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/message/SetConversationNotificationDisabledTask.kt @@ -24,7 +24,6 @@ import android.content.Context import org.mariotaku.microblog.library.MicroBlog import org.mariotaku.microblog.library.MicroBlogException import org.mariotaku.twidere.annotation.AccountType -import org.mariotaku.twidere.extension.model.isOfficial import org.mariotaku.twidere.extension.model.newMicroBlogInstance import org.mariotaku.twidere.extension.model.notificationDisabled import org.mariotaku.twidere.model.AccountDetails @@ -61,24 +60,6 @@ class SetConversationNotificationDisabledTask( private fun requestSetNotificationDisabled(microBlog: MicroBlog, account: AccountDetails): GetMessagesTask.DatabaseUpdateData { - when (account.type) { - AccountType.TWITTER -> { - if (account.isOfficial(context)) { - val response = if (notificationDisabled) { - microBlog.disableDmConversations(conversationId) - } else { - microBlog.enableDmConversations(conversationId) - } - val conversation = DataStoreUtils.findMessageConversation(context, accountKey, - conversationId) ?: return GetMessagesTask.DatabaseUpdateData(emptyList(), emptyList()) - if (response.isSuccessful) { - conversation.notificationDisabled = notificationDisabled - } - return GetMessagesTask.DatabaseUpdateData(listOf(conversation), emptyList()) - } - } - } - val conversation = DataStoreUtils.findMessageConversation(context, accountKey, conversationId) ?: return GetMessagesTask.DatabaseUpdateData(emptyList(), emptyList()) conversation.notificationDisabled = notificationDisabled diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/util/AsyncTwitterWrapper.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/util/AsyncTwitterWrapper.kt index 5d38d5134..740627656 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/util/AsyncTwitterWrapper.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/util/AsyncTwitterWrapper.kt @@ -377,18 +377,6 @@ class AsyncTwitterWrapper( } fun setActivitiesAboutMeUnreadAsync(accountKeys: Array, cursor: Long) { - val task = object : ExceptionHandlingAbstractTask(context) { - override val exceptionClass = MicroBlogException::class.java - - override fun onExecute(params: Any?) { - for (accountKey in accountKeys) { - val microBlog = MicroBlogAPIFactory.getInstance(context, accountKey) ?: continue - if (!AccountUtils.isOfficial(context, accountKey)) continue - microBlog.setActivitiesAboutMeUnread(cursor) - } - } - } - TaskStarter.execute(task) } fun addUpdatingRelationshipId(accountKey: UserKey, userKey: UserKey) { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/util/DataStoreUtils.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/util/DataStoreUtils.kt index 0c7407d0c..bf1f6635d 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/util/DataStoreUtils.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/util/DataStoreUtils.kt @@ -998,23 +998,8 @@ object DataStoreUtils { private fun getOfficialSeparatedIds(context: Context, getFromDatabase: (Array, Boolean) -> T, mergeResult: (T, T) -> T, accountKeys: Array): T { - val officialKeys = Array(accountKeys.size) { - val key = accountKeys[it] ?: return@Array null - if (AccountUtils.isOfficial(context, key)) { - return@Array key - } - return@Array null - } - val notOfficialKeys = Array(accountKeys.size) { - val key = accountKeys[it] ?: return@Array null - if (AccountUtils.isOfficial(context, key)) { - return@Array null - } - return@Array key - } - - val officialMaxPositions = getFromDatabase(officialKeys, true) - val notOfficialMaxPositions = getFromDatabase(notOfficialKeys, false) + val officialMaxPositions = getFromDatabase(emptyArray(), true) + val notOfficialMaxPositions = getFromDatabase(accountKeys, false) return mergeResult(officialMaxPositions, notOfficialMaxPositions) } } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/util/MenuUtils.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/util/MenuUtils.kt index acc6b9573..e267af7b5 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/util/MenuUtils.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/util/MenuUtils.kt @@ -54,7 +54,6 @@ import org.mariotaku.twidere.app.TwidereApplication import org.mariotaku.twidere.constant.favoriteConfirmationKey import org.mariotaku.twidere.constant.iWantMyStarsBackKey import org.mariotaku.twidere.constant.nameFirstKey -import org.mariotaku.twidere.extension.model.isOfficial import org.mariotaku.twidere.fragment.AbsStatusesFragment import org.mariotaku.twidere.fragment.AddStatusFilterDialogFragment import org.mariotaku.twidere.fragment.BaseFragment @@ -189,11 +188,7 @@ object MenuUtils { favorite.setTitle(if (isFavorite) R.string.action_undo_like else R.string.action_like) } } - val translate = menu.findItem(R.id.translate) - if (translate != null) { - val isOfficialKey = details.isOfficial(context) - menu.setItemAvailability(R.id.translate, isOfficialKey) - } + menu.setItemAvailability(R.id.translate, false) menu.removeGroup(MENU_GROUP_STATUS_EXTENSION) addIntentToMenuForExtension(context, menu, MENU_GROUP_STATUS_EXTENSION, INTENT_ACTION_EXTENSION_OPEN_STATUS, EXTRA_STATUS, EXTRA_STATUS_JSON, status) @@ -284,10 +279,8 @@ object MenuUtils { DestroyStatusDialogFragment.show(fm, status) } R.id.pin -> { - PinStatusDialogFragment.show(fm, status) } R.id.unpin -> { - UnpinStatusDialogFragment.show(fm, status) } R.id.add_to_filter -> { AddStatusFilterDialogFragment.show(fm, status) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/view/holder/status/DetailStatusViewHolder.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/view/holder/status/DetailStatusViewHolder.kt index c54078a4b..450a290af 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/view/holder/status/DetailStatusViewHolder.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/view/holder/status/DetailStatusViewHolder.kt @@ -339,26 +339,8 @@ class DetailStatusViewHolder( val lang = status.lang - if (CheckUtils.isValidLocale(lang) && account.isOfficial(context)) { - translateContainer.visibility = View.VISIBLE - if (translation != null) { - val locale = Locale(translation.translatedLang) - translateLabelView.text = context.getString(R.string.label_translated_to_language, - locale.displayLanguage) - translateResultView.visibility = View.VISIBLE - translateChangeLanguageView.visibility = View.VISIBLE - translateResultView.text = translation.text - } else { - val locale = Locale(lang) - translateLabelView.text = context.getString(R.string.label_translate_from_language, - locale.displayLanguage) - translateResultView.visibility = View.GONE - translateChangeLanguageView.visibility = View.GONE - } - } else { - translateLabelView.setText(R.string.unknown_language) - translateContainer.visibility = View.GONE - } + translateLabelView.setText(R.string.unknown_language) + translateContainer.visibility = View.GONE textView.setTextIsSelectable(true) translateResultView.setTextIsSelectable(true) diff --git a/twidere/src/main/res/values/arrays_no_translate.xml b/twidere/src/main/res/values/arrays_no_translate.xml index 70f30d522..c5a1030bc 100644 --- a/twidere/src/main/res/values/arrays_no_translate.xml +++ b/twidere/src/main/res/values/arrays_no_translate.xml @@ -25,40 +25,6 @@ true - - - Twitter for Android - - Twitter for iPhone - - Twitter for iPad - - Twitter for Mac - - Twitter for Windows Phone - - Twitter for Google TV - - TweetDeck - - - - - TWITTER_FOR_ANDROID - - TWITTER_FOR_IPHONE - - TWITTER_FOR_IPAD - - TWITTER_FOR_MAC - - TWITTER_FOR_WINDOWS_PHONE - - TWITTER_FOR_GOOGLE_TV - - TWEETDECK - - camera gallery @@ -99,23 +65,6 @@ mentions inbox - - - - 6ce85096 - - deffe9c7 - - 9f00e0cb - - df27640e - - 62bd0d33 - - 56d8f9ff - - ac602936 - round square