Remove Message.stanza field

This commit is contained in:
fiaxh 2019-05-21 21:42:39 +02:00
parent 32687d731f
commit 03f25e1f87
9 changed files with 51 additions and 48 deletions

View file

@ -102,27 +102,31 @@ public class Conversation : Object {
}
public NotifySetting get_notification_default_setting(StreamInteractor stream_interactor) {
Xmpp.XmppStream? stream = stream_interactor.get_stream(account);
if (!Application.get_default().settings.notifications) return NotifySetting.OFF;
if (type_ == Type.GROUPCHAT) {
Xmpp.Xep.Muc.Flag? flag = stream.get_flag(Xmpp.Xep.Muc.Flag.IDENTITY);
if (flag != null) {
bool members_only = flag.has_room_feature(counterpart.bare_jid, Xmpp.Xep.Muc.Feature.MEMBERS_ONLY);
return members_only ? NotifySetting.ON : NotifySetting.HIGHLIGHT;
if (stream_interactor.get_module(MucManager.IDENTITY).is_private_room(this.account, this.counterpart)) {
return NotifySetting.ON;
} else {
return NotifySetting.OFF;
return NotifySetting.HIGHLIGHT;
}
}
return NotifySetting.ON;
}
public Setting get_send_typing_setting() {
public Setting get_send_typing_setting(StreamInteractor stream_interactor) {
if (send_typing != Setting.DEFAULT) return send_typing;
if (stream_interactor.get_module(MucManager.IDENTITY).is_public_room(this.account, this.counterpart)) return Setting.OFF;
return Application.get_default().settings.send_typing ? Setting.ON : Setting.OFF;
}
public Setting get_send_marker_setting() {
public Setting get_send_marker_setting(StreamInteractor stream_interactor) {
if (send_marker != Setting.DEFAULT) return send_marker;
if (stream_interactor.get_module(MucManager.IDENTITY).is_public_room(this.account, this.counterpart)) return Setting.OFF;
return Application.get_default().settings.send_marker ? Setting.ON : Setting.OFF;
}

View file

@ -52,7 +52,6 @@ public class Message : Object {
marked_ = value;
}
}
public Xmpp.MessageStanza stanza { get; set; }
private Database? db;

View file

@ -95,10 +95,9 @@ public class ChatInteraction : StreamInteractionModule, Object {
private void check_send_read() {
if (selected_conversation == null || selected_conversation.type_ == Conversation.Type.GROUPCHAT) return;
Entities.Message? message = stream_interactor.get_module(MessageStorage.IDENTITY).get_last_message(selected_conversation);
if (message != null && message.direction == Entities.Message.DIRECTION_RECEIVED &&
message.stanza != null && !message.equals(selected_conversation.read_up_to)) {
if (message != null && message.direction == Entities.Message.DIRECTION_RECEIVED && !message.equals(selected_conversation.read_up_to)) {
selected_conversation.read_up_to = message;
send_chat_marker(selected_conversation, message, Xep.ChatMarkers.MARKER_DISPLAYED);
send_chat_marker(message, null, selected_conversation, Xep.ChatMarkers.MARKER_DISPLAYED);
}
}
@ -137,47 +136,52 @@ public class ChatInteraction : StreamInteractionModule, Object {
}
public override async bool run(Entities.Message message, Xmpp.MessageStanza stanza, Conversation conversation) {
if (Xep.MessageArchiveManagement.MessageFlag.get_flag(message.stanza) != null) return false;
if (Xep.MessageArchiveManagement.MessageFlag.get_flag(stanza) != null) return false;
ChatInteraction outer = stream_interactor.get_module(ChatInteraction.IDENTITY);
outer.send_delivery_receipt(conversation, message);
outer.send_delivery_receipt(message, stanza, conversation);
if (outer.is_active_focus(conversation)) {
outer.check_send_read();
conversation.read_up_to = message;
outer.send_chat_marker(conversation, message, Xep.ChatMarkers.MARKER_DISPLAYED);
outer.send_chat_marker(message, stanza, conversation, Xep.ChatMarkers.MARKER_DISPLAYED);
} else {
outer.send_chat_marker(conversation, message, Xep.ChatMarkers.MARKER_RECEIVED);
outer.send_chat_marker(message, stanza, conversation, Xep.ChatMarkers.MARKER_RECEIVED);
}
return false;
}
}
private void send_chat_marker(Conversation conversation, Entities.Message message, string marker) {
XmppStream stream = stream_interactor.get_stream(conversation.account);
if (stream != null &&
(marker == Xep.ChatMarkers.MARKER_RECEIVED || conversation.get_send_marker_setting() == Conversation.Setting.ON) &&
Xep.ChatMarkers.Module.requests_marking(message.stanza)) {
stream.get_module(Xep.ChatMarkers.Module.IDENTITY).send_marker(stream, message.stanza.from, message.stanza_id, message.get_type_string(), marker);
private void send_chat_marker(Entities.Message message, Xmpp.MessageStanza? stanza, Conversation conversation, string marker) {
XmppStream? stream = stream_interactor.get_stream(conversation.account);
if (stream == null) return;
switch (marker) {
case Xep.ChatMarkers.MARKER_RECEIVED:
if (stanza != null && Xep.ChatMarkers.Module.requests_marking(stanza)) {
stream.get_module(Xep.ChatMarkers.Module.IDENTITY).send_marker(stream, message.from, message.stanza_id, message.get_type_string(), Xep.ChatMarkers.MARKER_RECEIVED);
}
break;
case Xep.ChatMarkers.MARKER_DISPLAYED:
if (conversation.get_send_marker_setting(stream_interactor) == Conversation.Setting.ON) {
stream.get_module(Xep.ChatMarkers.Module.IDENTITY).send_marker(stream, message.from, message.stanza_id, message.get_type_string(), Xep.ChatMarkers.MARKER_DISPLAYED);
}
break;
}
}
private void send_delivery_receipt(Conversation conversation, Entities.Message message) {
XmppStream stream = stream_interactor.get_stream(conversation.account);
if (stream != null && Xep.MessageDeliveryReceipts.Module.requests_receipt(message.stanza)) {
private void send_delivery_receipt(Entities.Message message, Xmpp.MessageStanza stanza, Conversation conversation) {
XmppStream? stream = stream_interactor.get_stream(conversation.account);
if (stream != null && conversation.type_ != Conversation.Type.GROUPCHAT && Xep.MessageDeliveryReceipts.Module.requests_receipt(stanza)) {
stream.get_module(Xep.MessageDeliveryReceipts.Module.IDENTITY).send_received(stream, message.from, message.stanza_id);
}
}
private void send_chat_state_notification(Conversation conversation, string state) {
XmppStream stream = stream_interactor.get_stream(conversation.account);
if (stream != null && conversation.get_send_typing_setting() == Conversation.Setting.ON) {
if (conversation.type_ != Conversation.Type.GROUPCHAT) {
stream.get_module(Xep.ChatStateNotifications.Module.IDENTITY).send_state(stream, conversation.counterpart, Xmpp.MessageStanza.TYPE_CHAT, state);
}
if (stream_interactor.get_module(MucManager.IDENTITY).is_private_room(conversation.account, conversation.counterpart)) {
stream.get_module(Xep.ChatStateNotifications.Module.IDENTITY).send_state(stream, conversation.counterpart, Xmpp.MessageStanza.TYPE_GROUPCHAT, state);
}
XmppStream? stream = stream_interactor.get_stream(conversation.account);
if (stream != null && conversation.get_send_typing_setting(stream_interactor) == Conversation.Setting.ON) {
string message_type = conversation.type_ == Conversation.Type.GROUPCHAT ? Xmpp.MessageStanza.TYPE_GROUPCHAT : Xmpp.MessageStanza.TYPE_GROUPCHAT;
stream.get_module(Xep.ChatStateNotifications.Module.IDENTITY).send_state(stream, conversation.counterpart, message_type, state);
}
}
}

View file

@ -171,7 +171,7 @@ public class ConnectionManager : Object {
set_connection_error(account, new ConnectionError(ConnectionError.Source.TLS, null) { reconnect_recomendation=ConnectionError.Reconnect.NEVER});
});
stream.received_node.connect(() => {
connections[account].last_activity = new DateTime.now_utc();
connection.last_activity = new DateTime.now_utc();
});
connect_async.begin(account, stream);
stream_opened(account, stream);

View file

@ -27,7 +27,7 @@ public class ConversationManager : StreamInteractionModule, Object {
stream_interactor.add_module(this);
stream_interactor.account_added.connect(on_account_added);
stream_interactor.get_module(MessageProcessor.IDENTITY).received_pipeline.connect(new MessageListener(stream_interactor));
stream_interactor.get_module(MessageProcessor.IDENTITY).message_sent.connect(handle_new_message);
stream_interactor.get_module(MessageProcessor.IDENTITY).message_sent.connect(handle_sent_message);
}
public Conversation create_conversation(Jid jid, Account account, Conversation.Type? type = null) {
@ -133,8 +133,8 @@ public class ConversationManager : StreamInteractionModule, Object {
public override async bool run(Entities.Message message, Xmpp.MessageStanza stanza, Conversation conversation) {
conversation.last_active = message.time;
if (message.stanza != null) {
bool is_mam_message = Xep.MessageArchiveManagement.MessageFlag.get_flag(message.stanza) != null;
if (stanza != null) {
bool is_mam_message = Xep.MessageArchiveManagement.MessageFlag.get_flag(stanza) != null;
bool is_recent = message.local_time.compare(new DateTime.now_utc().add_hours(-24)) > 0;
if (is_mam_message && !is_recent) return false;
}
@ -143,16 +143,14 @@ public class ConversationManager : StreamInteractionModule, Object {
}
}
private void handle_new_message(Entities.Message message, Conversation conversation) {
private void handle_sent_message(Entities.Message message, Conversation conversation) {
conversation.last_active = message.time;
if (message.stanza != null) {
bool is_mam_message = Xep.MessageArchiveManagement.MessageFlag.get_flag(message.stanza) != null;
bool is_recent = message.local_time.compare(new DateTime.now_utc().add_hours(-24)) > 0;
if (is_mam_message && !is_recent) return;
}
if (is_recent) {
start_conversation(conversation);
}
}
private void add_conversation(Conversation conversation) {
conversations[conversation.account][conversation.counterpart] = conversation;

View file

@ -104,7 +104,6 @@ public class MessageProcessor : StreamInteractionModule, Object {
}
new_message.counterpart = counterpart_override ?? (new_message.direction == Entities.Message.DIRECTION_SENT ? message.to : message.from);
new_message.ourpart = new_message.direction == Entities.Message.DIRECTION_SENT ? message.from : message.to;
new_message.stanza = message;
Xep.MessageArchiveManagement.MessageFlag? mam_message_flag = Xep.MessageArchiveManagement.MessageFlag.get_flag(message);
if (mam_message_flag != null) new_message.local_time = mam_message_flag.server_time;
@ -271,7 +270,6 @@ public class MessageProcessor : StreamInteractionModule, Object {
}
stream.get_module(Xmpp.MessageModule.IDENTITY).send_message(stream, new_message);
message.stanza_id = new_message.id;
message.stanza = new_message;
} else {
message.marked = Entities.Message.Marked.UNSENT;
}

View file

@ -393,7 +393,7 @@ public class MucManager : StreamInteractionModule, Object {
if (conversation.type_ != Conversation.Type.GROUPCHAT) return false;
XmppStream stream = stream_interactor.get_stream(conversation.account);
if (stream == null) return false;
if (Xep.DelayedDelivery.MessageFlag.get_flag(message.stanza) == null) {
if (Xep.DelayedDelivery.MessageFlag.get_flag(stanza) == null) {
Jid? real_jid = stream.get_flag(Xep.Muc.Flag.IDENTITY).get_real_jid(message.counterpart);
if (real_jid != null && !real_jid.equals(message.counterpart)) {
message.real_jid = real_jid.bare_jid;

View file

@ -37,7 +37,7 @@ public class FileProvider : Dino.FileProvider, Object {
public override async bool run(Entities.Message message, Xmpp.MessageStanza stanza, Conversation conversation) {
if (outer.url_regex.match(message.body)) {
string? oob_url = Xmpp.Xep.OutOfBandData.get_url_from_message(message.stanza);
string? oob_url = Xmpp.Xep.OutOfBandData.get_url_from_message(stanza);
if (oob_url != null && oob_url == message.body) {
yield outer.on_file_message(message, conversation);
}

View file

@ -56,7 +56,7 @@ public class DeviceNotificationPopulator : NotificationPopulator, Object {
private void on_account_added(Account account) {
stream_interactor.module_manager.get_module(account, StreamModule.IDENTITY).bundle_fetched.connect_after((jid, device_id, bundle) => {
if (jid.equals(current_conversation.counterpart) && has_new_devices(current_conversation.counterpart)) {
if (current_conversation != null && jid.equals(current_conversation.counterpart) && has_new_devices(current_conversation.counterpart)) {
display_notification();
}
});