Offline messages for MUCs

fixes #187
This commit is contained in:
fiaxh 2017-10-22 02:43:04 +02:00
parent e49fc134dd
commit 555187deb9
3 changed files with 19 additions and 14 deletions

View file

@ -253,11 +253,14 @@ public class Database : Qlite.Database {
return ret; return ret;
} }
public Gee.List<Message> get_unsend_messages(Account account) { public Gee.List<Message> get_unsend_messages(Account account, Jid? jid = null) {
Gee.List<Message> ret = new ArrayList<Message>(); Gee.List<Message> ret = new ArrayList<Message>();
var select = message.select() var select = message.select()
.with(message.account_id, "=", account.id) .with(message.account_id, "=", account.id)
.with(message.marked, "=", (int) Message.Marked.UNSENT); .with(message.marked, "=", (int) Message.Marked.UNSENT);
if (jid != null) {
select.with(message.counterpart_id, "=", get_jid_id(jid));
}
foreach (Row row in select) { foreach (Row row in select) {
ret.add(new Message.from_row(this, row)); ret.add(new Message.from_row(this, row));
} }

View file

@ -40,6 +40,16 @@ public class MessageProcessor : StreamInteractionModule, Object {
message_sent(message, conversation); message_sent(message, conversation);
} }
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 on_account_added(Account account) { private void on_account_added(Account account) {
stream_interactor.module_manager.get_module(account, Xmpp.Message.Module.IDENTITY).received_message.connect( (stream, message) => { stream_interactor.module_manager.get_module(account, Xmpp.Message.Module.IDENTITY).received_message.connect( (stream, message) => {
on_message_received(account, message); on_message_received(account, message);
@ -50,16 +60,6 @@ public class MessageProcessor : StreamInteractionModule, Object {
}); });
} }
private void send_unsent_messages(Account account) {
Gee.List<Entities.Message> unsend_messages = db.get_unsend_messages(account);
foreach (Entities.Message message in unsend_messages) {
Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation(message.counterpart, account);
if (conversation != null) {
send_xmpp_message(message, conversation, true);
}
}
}
private void on_message_received(Account account, Xmpp.Message.Stanza message) { private void on_message_received(Account account, Xmpp.Message.Stanza message) {
if (message.body == null) return; if (message.body == null) return;
@ -168,7 +168,7 @@ public class MessageProcessor : StreamInteractionModule, Object {
message.direction = Entities.Message.DIRECTION_SENT; message.direction = Entities.Message.DIRECTION_SENT;
message.counterpart = conversation.counterpart; message.counterpart = conversation.counterpart;
if (conversation.type_ in new Conversation.Type[]{Conversation.Type.GROUPCHAT, Conversation.Type.GROUPCHAT_PM}) { if (conversation.type_ in new Conversation.Type[]{Conversation.Type.GROUPCHAT, Conversation.Type.GROUPCHAT_PM}) {
message.ourpart = stream_interactor.get_module(MucManager.IDENTITY).get_own_jid(conversation.counterpart, conversation.account); message.ourpart = stream_interactor.get_module(MucManager.IDENTITY).get_own_jid(conversation.counterpart, conversation.account) ?? conversation.account.bare_jid;
message.real_jid = conversation.account.bare_jid; message.real_jid = conversation.account.bare_jid;
} else { } else {
message.ourpart = new Jid.with_resource(conversation.account.bare_jid.to_string(), conversation.account.resourcepart); message.ourpart = new Jid.with_resource(conversation.account.bare_jid.to_string(), conversation.account.resourcepart);

View file

@ -207,8 +207,10 @@ public class MucManager : StreamInteractionModule, Object {
} }
private void on_account_added(Account account) { private void on_account_added(Account account) {
stream_interactor.module_manager.get_module(account, Xep.Muc.Module.IDENTITY).room_entered.connect( (stream, jid, nick) => { stream_interactor.module_manager.get_module(account, Xep.Muc.Module.IDENTITY).room_entered.connect( (stream, jid_string, nick) => {
joined(account, new Jid(jid), nick); Jid jid = new Jid(jid_string);
joined(account, jid, nick);
stream_interactor.get_module(MessageProcessor.IDENTITY).send_unsent_messages(account, jid);
}); });
stream_interactor.module_manager.get_module(account, Xep.Muc.Module.IDENTITY).room_enter_error.connect( (stream, jid, error) => { stream_interactor.module_manager.get_module(account, Xep.Muc.Module.IDENTITY).room_enter_error.connect( (stream, jid, error) => {
enter_errors[new Jid(jid)] = error; enter_errors[new Jid(jid)] = error;