|
|
|
@ -14,6 +14,9 @@ package app.fedilab.android.services;
|
|
|
|
|
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
|
|
|
|
|
* see <http://www.gnu.org/licenses>. */
|
|
|
|
|
|
|
|
|
|
import static app.fedilab.android.helper.Helper.NotifType.TOOT;
|
|
|
|
|
import static app.fedilab.android.helper.Helper.notify_user;
|
|
|
|
|
|
|
|
|
|
import android.app.IntentService;
|
|
|
|
|
import android.app.Notification;
|
|
|
|
|
import android.app.NotificationChannel;
|
|
|
|
@ -23,6 +26,7 @@ import android.content.Intent;
|
|
|
|
|
import android.graphics.BitmapFactory;
|
|
|
|
|
import android.os.Build;
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
import android.text.Html;
|
|
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
@ -31,10 +35,13 @@ import androidx.core.app.NotificationCompat;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Locale;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
import app.fedilab.android.BaseMainActivity;
|
|
|
|
|
import app.fedilab.android.R;
|
|
|
|
|
import app.fedilab.android.activities.ContextActivity;
|
|
|
|
|
import app.fedilab.android.client.entities.Account;
|
|
|
|
|
import app.fedilab.android.client.entities.PostState;
|
|
|
|
|
import app.fedilab.android.client.entities.StatusDraft;
|
|
|
|
|
import app.fedilab.android.client.mastodon.MastodonStatusesService;
|
|
|
|
@ -136,6 +143,7 @@ public class PostMessageService extends IntentService {
|
|
|
|
|
}
|
|
|
|
|
MastodonStatusesService mastodonStatusesService = init(instance);
|
|
|
|
|
boolean error = false;
|
|
|
|
|
Status firstSendMessage = null;
|
|
|
|
|
if (statusDraft != null && statusDraft.statusDraftList != null && statusDraft.statusDraftList.size() > 0) {
|
|
|
|
|
//If state is null, it is created (typically when submitting the status the first time)
|
|
|
|
|
if (statusDraft.state == null) {
|
|
|
|
@ -156,8 +164,12 @@ public class PostMessageService extends IntentService {
|
|
|
|
|
}
|
|
|
|
|
startingPosition++;
|
|
|
|
|
}
|
|
|
|
|
String in_reply_to_status = null;
|
|
|
|
|
|
|
|
|
|
List<Status> statuses = statusDraft.statusDraftList;
|
|
|
|
|
String in_reply_to_status = null;
|
|
|
|
|
if (statusDraft.statusReplyList != null && statusDraft.statusReplyList.size() > 0) {
|
|
|
|
|
in_reply_to_status = statusDraft.statusReplyList.get(statusDraft.statusReplyList.size() - 1).id;
|
|
|
|
|
}
|
|
|
|
|
totalMediaSize = 0;
|
|
|
|
|
totalBitRead = 0;
|
|
|
|
|
for (int i = startingPosition; i < statuses.size(); i++) {
|
|
|
|
@ -221,6 +233,9 @@ public class PostMessageService extends IntentService {
|
|
|
|
|
|
|
|
|
|
if (statusResponse.isSuccessful()) {
|
|
|
|
|
Status statusReply = statusResponse.body();
|
|
|
|
|
if (firstSendMessage == null && statusReply != null) {
|
|
|
|
|
firstSendMessage = statusReply;
|
|
|
|
|
}
|
|
|
|
|
if (statusReply != null) {
|
|
|
|
|
in_reply_to_status = statusReply.id;
|
|
|
|
|
statusDraft.state.posts_successfully_sent = i;
|
|
|
|
@ -284,6 +299,31 @@ public class PostMessageService extends IntentService {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (scheduledDate == null && token != null) {
|
|
|
|
|
Account account = null;
|
|
|
|
|
try {
|
|
|
|
|
account = new Account(PostMessageService.this).getAccountByToken(token);
|
|
|
|
|
final Intent pendingIntent = new Intent(PostMessageService.this, ContextActivity.class);
|
|
|
|
|
pendingIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
|
pendingIntent.putExtra(Helper.ARG_STATUS, firstSendMessage);
|
|
|
|
|
pendingIntent.putExtra(Helper.PREF_INSTANCE, account.instance);
|
|
|
|
|
String text = firstSendMessage.content;
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
|
|
|
|
text = Html.fromHtml(text, Html.FROM_HTML_MODE_LEGACY).toString();
|
|
|
|
|
else
|
|
|
|
|
text = Html.fromHtml(text).toString();
|
|
|
|
|
if (text.length() > 255) {
|
|
|
|
|
text = text.substring(0, 254);
|
|
|
|
|
text = String.format(Locale.getDefault(), "%s…", text);
|
|
|
|
|
}
|
|
|
|
|
notify_user(PostMessageService.this, account, pendingIntent, BitmapFactory.decodeResource(getResources(),
|
|
|
|
|
R.mipmap.ic_launcher), TOOT, getString(R.string.message_has_been_sent), text);
|
|
|
|
|
} catch (DBException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|