From 21c984ff31f509f1216226ea02aafcddf34bab24 Mon Sep 17 00:00:00 2001 From: drcfts Date: Thu, 8 Nov 2018 10:10:25 -0200 Subject: [PATCH] Refactoring based on co-change dependency: Move Method refactoring of method fromContent: from class ContentDescription to class AbsContent --- .../actor/core/entity/ContentDescription.java | 63 ------------------ .../actor/core/entity/content/AbsContent.java | 65 +++++++++++++++++++ .../messaging/dialogs/DialogsActor.java | 7 +- .../modules/messaging/router/RouterActor.java | 3 +- 4 files changed, 69 insertions(+), 69 deletions(-) diff --git a/actor-sdk/sdk-core/core/core-shared/src/main/java/im/actor/core/entity/ContentDescription.java b/actor-sdk/sdk-core/core/core-shared/src/main/java/im/actor/core/entity/ContentDescription.java index aa1677b925..39e13d046f 100644 --- a/actor-sdk/sdk-core/core/core-shared/src/main/java/im/actor/core/entity/ContentDescription.java +++ b/actor-sdk/sdk-core/core/core-shared/src/main/java/im/actor/core/entity/ContentDescription.java @@ -43,69 +43,6 @@ public static ContentDescription fromBytes(byte[] data) throws IOException { return Bser.parse(new ContentDescription(), data); } - public static ContentDescription fromContent(AbsContent msg) { - if (msg instanceof TextContent) { - return new ContentDescription(ContentType.TEXT, - ((TextContent) msg).getText()); - } else if (msg instanceof PhotoContent) { - return new ContentDescription(ContentType.DOCUMENT_PHOTO); - } else if (msg instanceof VideoContent) { - return new ContentDescription(ContentType.DOCUMENT_VIDEO); - } else if (msg instanceof VoiceContent) { - return new ContentDescription(ContentType.DOCUMENT_AUDIO); - } else if (msg instanceof DocumentContent) { - return new ContentDescription(ContentType.DOCUMENT); - } else if (msg instanceof LocationContent) { - return new ContentDescription(ContentType.LOCATION); - } else if (msg instanceof ContactContent) { - return new ContentDescription(ContentType.CONTACT); - } else if (msg instanceof StickerContent) { - return new ContentDescription(ContentType.STICKER); - } else if (msg instanceof ServiceUserRegistered) { - return new ContentDescription(ContentType.SERVICE_REGISTERED); - } else if (msg instanceof ServiceCallEnded) { - return new ContentDescription(ContentType.SERVICE_CALL_ENDED); - } else if (msg instanceof ServiceCallMissed) { - return new ContentDescription(ContentType.SERVICE_CALL_MISSED); - } else if (msg instanceof ServiceGroupAvatarChanged) { - if (((ServiceGroupAvatarChanged) msg).getNewAvatar() == null) { - return new ContentDescription(ContentType.SERVICE_AVATAR_REMOVED); - } else { - return new ContentDescription(ContentType.SERVICE_AVATAR); - } - } else if (msg instanceof ServiceGroupTitleChanged) { - return new ContentDescription(ContentType.SERVICE_TITLE, - ((ServiceGroupTitleChanged) msg).getNewTitle()); - } else if (msg instanceof ServiceGroupTopicChanged) { - return new ContentDescription(ContentType.SERVICE_TOPIC, - ((ServiceGroupTopicChanged) msg).getNewTopic()); - } else if (msg instanceof ServiceGroupAboutChanged) { - return new ContentDescription(ContentType.SERVICE_ABOUT, - ((ServiceGroupAboutChanged) msg).getNewAbout()); - } else if (msg instanceof ServiceGroupCreated) { - return new ContentDescription(ContentType.SERVICE_CREATED); - } else if (msg instanceof ServiceGroupUserInvited) { - return new ContentDescription(ContentType.SERVICE_ADD, "", - ((ServiceGroupUserInvited) msg).getAddedUid(), false); - } else if (msg instanceof ServiceGroupUserKicked) { - return new ContentDescription(ContentType.SERVICE_KICK, "", - ((ServiceGroupUserKicked) msg).getKickedUid(), false); - } else if (msg instanceof ServiceGroupUserLeave) { - return new ContentDescription(ContentType.SERVICE_LEAVE, "", - 0, true); - } else if (msg instanceof ServiceGroupUserJoined) { - return new ContentDescription(ContentType.SERVICE_JOINED, "", - 0, false); - } else if (msg instanceof ServiceContent) { - return new ContentDescription(ContentType.SERVICE, - ((ServiceContent) msg).getCompatText(), 0, false); - } else if (msg instanceof JsonContent) { - return new ContentDescription(ContentType.TEXT, ((JsonContent) msg).getContentDescription()); - } else { - return new ContentDescription(ContentType.UNKNOWN_CONTENT); - } - } - @Property("readonly, nonatomic") private ContentType contentType; @Property("readonly, nonatomic") diff --git a/actor-sdk/sdk-core/core/core-shared/src/main/java/im/actor/core/entity/content/AbsContent.java b/actor-sdk/sdk-core/core/core-shared/src/main/java/im/actor/core/entity/content/AbsContent.java index a746ffd5c7..6274962939 100644 --- a/actor-sdk/sdk-core/core/core-shared/src/main/java/im/actor/core/entity/content/AbsContent.java +++ b/actor-sdk/sdk-core/core/core-shared/src/main/java/im/actor/core/entity/content/AbsContent.java @@ -29,6 +29,8 @@ import im.actor.core.api.ApiServiceMessage; import im.actor.core.api.ApiStickerMessage; import im.actor.core.api.ApiTextMessage; +import im.actor.core.entity.ContentDescription; +import im.actor.core.entity.ContentType; import im.actor.core.entity.content.internal.AbsContentContainer; import im.actor.core.entity.content.internal.AbsLocalContent; import im.actor.core.entity.content.internal.ContentLocalContainer; @@ -185,6 +187,69 @@ public AbsContent(ContentLocalContainer contentContainer) { this.contentContainer = contentContainer; } + public static ContentDescription fromContent(AbsContent msg) { + if (msg instanceof TextContent) { + return new ContentDescription(ContentType.TEXT, + ((TextContent) msg).getText()); + } else if (msg instanceof PhotoContent) { + return new ContentDescription(ContentType.DOCUMENT_PHOTO); + } else if (msg instanceof VideoContent) { + return new ContentDescription(ContentType.DOCUMENT_VIDEO); + } else if (msg instanceof VoiceContent) { + return new ContentDescription(ContentType.DOCUMENT_AUDIO); + } else if (msg instanceof DocumentContent) { + return new ContentDescription(ContentType.DOCUMENT); + } else if (msg instanceof LocationContent) { + return new ContentDescription(ContentType.LOCATION); + } else if (msg instanceof ContactContent) { + return new ContentDescription(ContentType.CONTACT); + } else if (msg instanceof StickerContent) { + return new ContentDescription(ContentType.STICKER); + } else if (msg instanceof ServiceUserRegistered) { + return new ContentDescription(ContentType.SERVICE_REGISTERED); + } else if (msg instanceof ServiceCallEnded) { + return new ContentDescription(ContentType.SERVICE_CALL_ENDED); + } else if (msg instanceof ServiceCallMissed) { + return new ContentDescription(ContentType.SERVICE_CALL_MISSED); + } else if (msg instanceof ServiceGroupAvatarChanged) { + if (((ServiceGroupAvatarChanged) msg).getNewAvatar() == null) { + return new ContentDescription(ContentType.SERVICE_AVATAR_REMOVED); + } else { + return new ContentDescription(ContentType.SERVICE_AVATAR); + } + } else if (msg instanceof ServiceGroupTitleChanged) { + return new ContentDescription(ContentType.SERVICE_TITLE, + ((ServiceGroupTitleChanged) msg).getNewTitle()); + } else if (msg instanceof ServiceGroupTopicChanged) { + return new ContentDescription(ContentType.SERVICE_TOPIC, + ((ServiceGroupTopicChanged) msg).getNewTopic()); + } else if (msg instanceof ServiceGroupAboutChanged) { + return new ContentDescription(ContentType.SERVICE_ABOUT, + ((ServiceGroupAboutChanged) msg).getNewAbout()); + } else if (msg instanceof ServiceGroupCreated) { + return new ContentDescription(ContentType.SERVICE_CREATED); + } else if (msg instanceof ServiceGroupUserInvited) { + return new ContentDescription(ContentType.SERVICE_ADD, "", + ((ServiceGroupUserInvited) msg).getAddedUid(), false); + } else if (msg instanceof ServiceGroupUserKicked) { + return new ContentDescription(ContentType.SERVICE_KICK, "", + ((ServiceGroupUserKicked) msg).getKickedUid(), false); + } else if (msg instanceof ServiceGroupUserLeave) { + return new ContentDescription(ContentType.SERVICE_LEAVE, "", + 0, true); + } else if (msg instanceof ServiceGroupUserJoined) { + return new ContentDescription(ContentType.SERVICE_JOINED, "", + 0, false); + } else if (msg instanceof ServiceContent) { + return new ContentDescription(ContentType.SERVICE, + ((ServiceContent) msg).getCompatText(), 0, false); + } else if (msg instanceof JsonContent) { + return new ContentDescription(ContentType.TEXT, ((JsonContent) msg).getContentDescription()); + } else { + return new ContentDescription(ContentType.UNKNOWN_CONTENT); + } + } + public AbsContentContainer getContentContainer() { return contentContainer; } diff --git a/actor-sdk/sdk-core/core/core-shared/src/main/java/im/actor/core/modules/messaging/dialogs/DialogsActor.java b/actor-sdk/sdk-core/core/core-shared/src/main/java/im/actor/core/modules/messaging/dialogs/DialogsActor.java index ef3e642582..be6ec4b2b8 100644 --- a/actor-sdk/sdk-core/core/core-shared/src/main/java/im/actor/core/modules/messaging/dialogs/DialogsActor.java +++ b/actor-sdk/sdk-core/core/core-shared/src/main/java/im/actor/core/modules/messaging/dialogs/DialogsActor.java @@ -33,7 +33,6 @@ import im.actor.core.modules.messaging.history.entity.DialogHistory; import im.actor.core.modules.ModuleActor; import im.actor.runtime.Log; -import im.actor.runtime.Runtime; import im.actor.runtime.actors.messages.Void; import im.actor.runtime.annotations.Verified; import im.actor.runtime.promise.Promise; @@ -79,7 +78,7 @@ private Promise onMessage(Peer peer, Message message, boolean forceWrite, } else { Dialog dialog = dialogs.getValue(peer.getUnuqueId()); - ContentDescription contentDescription = ContentDescription.fromContent(message.getContent()); + ContentDescription contentDescription = AbsContent.fromContent(message.getContent()); DialogBuilder builder = new DialogBuilder() .setRid(message.getRid()) @@ -238,7 +237,7 @@ private Promise onMessageContentChanged(Peer peer, long rid, AbsContent co // If message is on top if (dialog != null && dialog.getRid() == rid) { - ContentDescription description = ContentDescription.fromContent(content); + ContentDescription description = AbsContent.fromContent(content); addOrUpdateItem(new DialogBuilder(dialog) .setText(description.getText()) @@ -278,7 +277,7 @@ private Promise onHistoryLoaded(List history) { continue; } - ContentDescription description = ContentDescription.fromContent(dialogHistory.getContent()); + ContentDescription description = AbsContent.fromContent(dialogHistory.getContent()); DialogBuilder builder = new DialogBuilder() .setPeer(dialogHistory.getPeer()) diff --git a/actor-sdk/sdk-core/core/core-shared/src/main/java/im/actor/core/modules/messaging/router/RouterActor.java b/actor-sdk/sdk-core/core/core-shared/src/main/java/im/actor/core/modules/messaging/router/RouterActor.java index b711a0dfe2..a338d31c98 100644 --- a/actor-sdk/sdk-core/core/core-shared/src/main/java/im/actor/core/modules/messaging/router/RouterActor.java +++ b/actor-sdk/sdk-core/core/core-shared/src/main/java/im/actor/core/modules/messaging/router/RouterActor.java @@ -22,7 +22,6 @@ import im.actor.core.api.updates.UpdateMessageSent; import im.actor.core.api.updates.UpdateReactionsUpdate; import im.actor.core.entity.Avatar; -import im.actor.core.entity.ContentDescription; import im.actor.core.entity.ConversationState; import im.actor.core.entity.Group; import im.actor.core.entity.Message; @@ -329,7 +328,7 @@ private Promise onNewMessages(Peer peer, List messages) { peer, m.getSenderId(), m.getSortDate(), - ContentDescription.fromContent(m.getContent()), + AbsContent.fromContent(m.getContent()), hasCurrentMention, messagesCount, dialogsCount);