Skip to content
This repository has been archived by the owner on Feb 17, 2023. It is now read-only.

Refactoring based on co-change dependency #1038

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -79,7 +78,7 @@ private Promise<Void> 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())
Expand Down Expand Up @@ -238,7 +237,7 @@ private Promise<Void> 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())
Expand Down Expand Up @@ -278,7 +277,7 @@ private Promise<Void> onHistoryLoaded(List<DialogHistory> history) {
continue;
}

ContentDescription description = ContentDescription.fromContent(dialogHistory.getContent());
ContentDescription description = AbsContent.fromContent(dialogHistory.getContent());

DialogBuilder builder = new DialogBuilder()
.setPeer(dialogHistory.getPeer())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -329,7 +328,7 @@ private Promise<Void> onNewMessages(Peer peer, List<Message> messages) {
peer,
m.getSenderId(),
m.getSortDate(),
ContentDescription.fromContent(m.getContent()),
AbsContent.fromContent(m.getContent()),
hasCurrentMention,
messagesCount,
dialogsCount);
Expand Down