Improve MUC message resending

This commit is contained in:
fiaxh 2020-03-03 15:14:31 +01:00
parent 17acdd9f41
commit b8b3e1c6f5
4 changed files with 42 additions and 28 deletions

View file

@ -400,24 +400,6 @@ public class Database : Qlite.Database {
return ret;
}
public Gee.List<Message> get_unsend_messages(Account account, Jid? jid = null) {
Gee.List<Message> ret = new ArrayList<Message>();
var select = message.select()
.with(message.account_id, "=", account.id)
.with(message.marked, "=", (int) Message.Marked.UNSENT);
if (jid != null) {
select.with(message.counterpart_id, "=", get_jid_id(jid));
}
foreach (Row row in select) {
try {
ret.add(new Message.from_row(this, row));
} catch (InvalidJidError e) {
warning("Ignoring message with invalid Jid: %s", e.message);
}
}
return ret;
}
public Message? get_message_by_id(int id) {
Row? row = message.row_with(message.id, id).inner;
if (row != null) {

View file

@ -46,7 +46,7 @@ public class MessageProcessor : StreamInteractionModule, Object {
stream_interactor.account_added.connect(on_account_added);
stream_interactor.connection_manager.connection_state_changed.connect((account, state) => {
if (state == ConnectionManager.ConnectionState.CONNECTED) send_unsent_messages(account);
if (state == ConnectionManager.ConnectionState.CONNECTED) send_unsent_chat_messages(account);
});
stream_interactor.connection_manager.stream_opened.connect((account, stream) => {
@ -68,12 +68,32 @@ public class MessageProcessor : StreamInteractionModule, Object {
return message;
}
public void send_unsent_messages(Account account, Jid? jid = null) {
Gee.List<Entities.Message> unsend_messages = db.get_unsend_messages(account, jid);
foreach (Entities.Message message in unsend_messages) {
Conversation? msg_conv = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation(message.counterpart, account);
if (msg_conv != null) {
send_xmpp_message(message, msg_conv, true);
private void send_unsent_chat_messages(Account account) {
var select = db.message.select()
.with(db.message.account_id, "=", account.id)
.with(db.message.marked, "=", (int) Message.Marked.UNSENT)
.with(db.message.type_, "=", (int) Message.Type.CHAT);
send_unsent_messages(account, select);
}
public void send_unsent_muc_messages(Account account, Jid muc_jid) {
var select = db.message.select()
.with(db.message.account_id, "=", account.id)
.with(db.message.marked, "=", (int) Message.Marked.UNSENT)
.with(db.message.counterpart_id, "=", db.get_jid_id(muc_jid));
send_unsent_messages(account, select);
}
private void send_unsent_messages(Account account, QueryBuilder select) {
foreach (Row row in select) {
try {
Message message = new Message.from_row(db, row);
Conversation? msg_conv = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation(message.counterpart, account, Util.get_conversation_type_for_message(message));
if (msg_conv != null) {
send_xmpp_message(message, msg_conv, true);
}
} catch (InvalidJidError e) {
warning("Ignoring message with invalid Jid: %s", e.message);
}
}
}

View file

@ -58,7 +58,7 @@ public class MucManager : StreamInteractionModule, Object {
// Join completed
enter_errors.unset(jid);
set_autojoin(account, stream, jid, nick, password);
stream_interactor.get_module(MessageProcessor.IDENTITY).send_unsent_messages(account, jid);
stream_interactor.get_module(MessageProcessor.IDENTITY).send_unsent_muc_messages(account, jid);
Conversation joined_conversation = stream_interactor.get_module(ConversationManager.IDENTITY).create_conversation(jid, account, Conversation.Type.GROUPCHAT);
joined_conversation.nickname = nick;

View file

@ -3,7 +3,7 @@ using Dino.Entities;
namespace Dino {
public class Util {
public static Entities.Message.Type get_message_type_for_conversation(Conversation conversation) {
public static Message.Type get_message_type_for_conversation(Conversation conversation) {
switch (conversation.type_) {
case Conversation.Type.CHAT:
return Entities.Message.Type.CHAT;
@ -14,6 +14,18 @@ public class Util {
}
assert_not_reached();
}
public static Conversation.Type get_conversation_type_for_message(Message message) {
switch (message.type_) {
case Entities.Message.Type.CHAT:
return Conversation.Type.CHAT;
case Entities.Message.Type.GROUPCHAT:
return Conversation.Type.GROUPCHAT;
case Entities.Message.Type.GROUPCHAT_PM:
return Conversation.Type.GROUPCHAT_PM;
}
assert_not_reached();
}
}
}