Fix message that remain in drafts

This commit is contained in:
Thomas 2022-10-08 17:21:43 +02:00
parent eea7e83f85
commit 116f5a01a1
2 changed files with 20 additions and 15 deletions

View File

@ -179,7 +179,7 @@ public class StatusCache {
* @return int - 0 if updated 1 if inserted
* @throws DBException exception with database
*/
public int insertOrUpdate(StatusCache statusCache, String slug) throws DBException {
public synchronized int insertOrUpdate(StatusCache statusCache, String slug) throws DBException {
if (db == null) {
throw new DBException("db is null. Wrong initialization.");
}

View File

@ -234,8 +234,11 @@ public class ComposeWorker extends Worker {
if (statusReply != null) {
in_reply_to_status = statusReply.id;
dataPost.statusDraft.state.posts_successfully_sent = i;
dataPost.statusDraft.state.posts.get(i).id = statusReply.id;
dataPost.statusDraft.state.posts.get(i).in_reply_to_id = statusReply.in_reply_to_id;
if (dataPost.statusDraft.state.posts.size() > i + 1) {
dataPost.statusDraft.state.posts.get(i + 1).id = statusReply.id;
dataPost.statusDraft.state.posts.get(i + 1).in_reply_to_id = statusReply.in_reply_to_id;
}
try {
new StatusDraft(context.getApplicationContext()).updatePostState(dataPost.statusDraft);
} catch (DBException e) {
@ -284,23 +287,15 @@ public class ComposeWorker extends Worker {
if (statusReply != null) {
in_reply_to_status = statusReply.id;
dataPost.statusDraft.state.posts_successfully_sent = i;
dataPost.statusDraft.state.posts.get(i).id = statusReply.id;
dataPost.statusDraft.state.posts.get(i).in_reply_to_id = statusReply.params.in_reply_to_id;
if (dataPost.statusDraft.state.posts.size() > i + 1) {
dataPost.statusDraft.state.posts.get(i + 1).id = statusReply.id;
dataPost.statusDraft.state.posts.get(i + 1).in_reply_to_id = statusReply.params.in_reply_to_id;
}
try {
new StatusDraft(context.getApplicationContext()).updatePostState(dataPost.statusDraft);
} catch (DBException e) {
e.printStackTrace();
}
if (i >= dataPost.statusDraft.statusDraftList.size()) {
try {
new StatusDraft(context).removeDraft(dataPost.statusDraft);
} catch (DBException e) {
e.printStackTrace();
}
if (dataPost.service != null) {
dataPost.service.stopSelf();
}
}
}
}
} catch (IOException e) {
@ -312,6 +307,16 @@ public class ComposeWorker extends Worker {
if (dataPost.messageSent > dataPost.messageToSend) {
dataPost.messageSent = dataPost.messageToSend;
}
if (i >= (statuses.size() - 1)) {
try {
new StatusDraft(context).removeDraft(dataPost.statusDraft);
} catch (DBException e) {
e.printStackTrace();
}
if (dataPost.service != null) {
dataPost.service.stopSelf();
}
}
}
}