use of com.sys1yagi.mastodon4j.api.exception.Mastodon4jRequestException in project twicalico by moko256.
the class MastodonTwitterImpl method search.
@Override
public QueryResult search(Query query) {
Pageable<com.sys1yagi.mastodon4j.api.entity.Status> pageable = null;
try {
pageable = new Public(client).getFederatedTag(query.getQuery(), MTRangeConverter.convert(query)).execute();
} catch (Mastodon4jRequestException e) {
e.printStackTrace();
}
long previous;
long next;
if (pageable == null)
return null;
if (pageable.getLink() != null) {
next = pageable.getLink().getMaxId();
previous = pageable.getLink().getSinceId();
} else {
next = -1;
previous = -1;
}
List<com.sys1yagi.mastodon4j.api.entity.Status> part = pageable.getPart();
Pageable<com.sys1yagi.mastodon4j.api.entity.Status> finalPageable = pageable;
return new QueryResult() {
@Override
public long getSinceId() {
return previous;
}
@Override
public long getMaxId() {
return next;
}
@Override
public String getRefreshURL() {
return null;
}
@Override
public int getCount() {
return part.size();
}
@Override
public double getCompletedIn() {
return 0;
}
@Override
public String getQuery() {
return query.getQuery();
}
@Override
public List<Status> getTweets() {
return MTResponseList.convert(finalPageable);
}
@Override
public Query nextQuery() {
return new Query(query.getQuery()).sinceId(next);
}
@Override
public boolean hasNext() {
return next != -1;
}
@Override
public RateLimitStatus getRateLimitStatus() {
return null;
}
@Override
public int getAccessLevel() {
return 0;
}
};
}
use of com.sys1yagi.mastodon4j.api.exception.Mastodon4jRequestException in project twicalico by moko256.
the class PostTweetModelImpl method postTweet.
@Override
public Single<Status> postTweet() {
return Single.create(subscriber -> {
try {
List<Long> ids = null;
if (uriList.size() > 0) {
ids = new ArrayList<>(uriList.size());
for (Uri uri : uriList) {
InputStream image = contentResolver.openInputStream(uri);
ByteArrayOutputStream bout = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
while (true) {
int len = image.read(buffer);
if (len < 0) {
break;
}
bout.write(buffer, 0, len);
}
Attachment attachment = new Media(((MastodonTwitterImpl) GlobalApplication.twitter).client).postMedia(MultipartBody.Part.createFormData("file", uri.getLastPathSegment(), RequestBody.create(MediaType.parse(contentResolver.getType(uri)), bout.toByteArray()))).execute();
ids.add(attachment.getId());
}
}
subscriber.onSuccess(new MTStatus(new Statuses(client).postStatus(tweetText, inReplyToStatusId == -1 ? null : inReplyToStatusId, ids, possiblySensitive, null, com.sys1yagi.mastodon4j.api.entity.Status.Visibility.Public).execute()));
} catch (IOException | Mastodon4jRequestException e) {
subscriber.onError(e);
}
});
}
Aggregations