Search in sources :

Example 1 with Account

use of org.datatransferproject.transfer.mastodon.model.Account in project data-transfer-project by google.

the class MastodonActivityExport method export.

@Override
public ExportResult<SocialActivityContainerResource> export(UUID jobId, CookiesAndUrlAuthData authData, Optional<ExportInformation> exportInformation) throws Exception {
    checkState(authData.getCookies().size() == 1, "Exactly 1 cookie expected: %s", authData.getCookies());
    String maxId = null;
    if (exportInformation.isPresent()) {
        StringPaginationToken pageData = (StringPaginationToken) exportInformation.get().getPaginationData();
        if (!Strings.isNullOrEmpty(pageData.getToken())) {
            maxId = pageData.getToken();
        }
    }
    MastodonHttpUtilities utilities = new MastodonHttpUtilities(authData.getCookies().get(0), authData.getUrl());
    Account account = utilities.getAccount();
    Status[] statuses = utilities.getStatuses(maxId);
    List<SocialActivityModel> activityList = new ArrayList<>(statuses.length);
    SocialActivityActor actor = new SocialActivityActor("acct:" + account.getUsername() + "@" + utilities.getHostName(), account.getDisplayName(), account.getUrl());
    ContinuationData continuationData = null;
    if (statuses.length > 0) {
        String lastId = null;
        for (Status status : statuses) {
            activityList.add(statusToActivity(account, status, utilities));
            lastId = status.getId();
        }
        continuationData = new ContinuationData(new StringPaginationToken(lastId));
    }
    return new ExportResult<>(continuationData == null ? ResultType.END : ResultType.CONTINUE, new SocialActivityContainerResource(account.getId() + maxId, actor, activityList), continuationData);
}
Also used : Status(org.datatransferproject.transfer.mastodon.model.Status) Account(org.datatransferproject.transfer.mastodon.model.Account) SocialActivityContainerResource(org.datatransferproject.types.common.models.social.SocialActivityContainerResource) ArrayList(java.util.ArrayList) ContinuationData(org.datatransferproject.spi.transfer.types.ContinuationData) SocialActivityModel(org.datatransferproject.types.common.models.social.SocialActivityModel) StringPaginationToken(org.datatransferproject.types.common.StringPaginationToken) SocialActivityActor(org.datatransferproject.types.common.models.social.SocialActivityActor) ExportResult(org.datatransferproject.spi.transfer.provider.ExportResult)

Aggregations

ArrayList (java.util.ArrayList)1 ExportResult (org.datatransferproject.spi.transfer.provider.ExportResult)1 ContinuationData (org.datatransferproject.spi.transfer.types.ContinuationData)1 Account (org.datatransferproject.transfer.mastodon.model.Account)1 Status (org.datatransferproject.transfer.mastodon.model.Status)1 StringPaginationToken (org.datatransferproject.types.common.StringPaginationToken)1 SocialActivityActor (org.datatransferproject.types.common.models.social.SocialActivityActor)1 SocialActivityContainerResource (org.datatransferproject.types.common.models.social.SocialActivityContainerResource)1 SocialActivityModel (org.datatransferproject.types.common.models.social.SocialActivityModel)1