Improve MUC message resending
This commit is contained in:
parent
17acdd9f41
commit
b8b3e1c6f5
|
@ -400,24 +400,6 @@ public class Database : Qlite.Database {
|
||||||
return ret;
|
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) {
|
public Message? get_message_by_id(int id) {
|
||||||
Row? row = message.row_with(message.id, id).inner;
|
Row? row = message.row_with(message.id, id).inner;
|
||||||
if (row != null) {
|
if (row != null) {
|
||||||
|
|
|
@ -46,7 +46,7 @@ public class MessageProcessor : StreamInteractionModule, Object {
|
||||||
stream_interactor.account_added.connect(on_account_added);
|
stream_interactor.account_added.connect(on_account_added);
|
||||||
|
|
||||||
stream_interactor.connection_manager.connection_state_changed.connect((account, state) => {
|
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) => {
|
stream_interactor.connection_manager.stream_opened.connect((account, stream) => {
|
||||||
|
@ -68,12 +68,32 @@ public class MessageProcessor : StreamInteractionModule, Object {
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void send_unsent_messages(Account account, Jid? jid = null) {
|
private void send_unsent_chat_messages(Account account) {
|
||||||
Gee.List<Entities.Message> unsend_messages = db.get_unsend_messages(account, jid);
|
var select = db.message.select()
|
||||||
foreach (Entities.Message message in unsend_messages) {
|
.with(db.message.account_id, "=", account.id)
|
||||||
Conversation? msg_conv = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation(message.counterpart, account);
|
.with(db.message.marked, "=", (int) Message.Marked.UNSENT)
|
||||||
if (msg_conv != null) {
|
.with(db.message.type_, "=", (int) Message.Type.CHAT);
|
||||||
send_xmpp_message(message, msg_conv, true);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ public class MucManager : StreamInteractionModule, Object {
|
||||||
// Join completed
|
// Join completed
|
||||||
enter_errors.unset(jid);
|
enter_errors.unset(jid);
|
||||||
set_autojoin(account, stream, jid, nick, password);
|
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);
|
Conversation joined_conversation = stream_interactor.get_module(ConversationManager.IDENTITY).create_conversation(jid, account, Conversation.Type.GROUPCHAT);
|
||||||
joined_conversation.nickname = nick;
|
joined_conversation.nickname = nick;
|
||||||
|
|
|
@ -3,7 +3,7 @@ using Dino.Entities;
|
||||||
namespace Dino {
|
namespace Dino {
|
||||||
|
|
||||||
public class Util {
|
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_) {
|
switch (conversation.type_) {
|
||||||
case Conversation.Type.CHAT:
|
case Conversation.Type.CHAT:
|
||||||
return Entities.Message.Type.CHAT;
|
return Entities.Message.Type.CHAT;
|
||||||
|
@ -14,6 +14,18 @@ public class Util {
|
||||||
}
|
}
|
||||||
assert_not_reached();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue