From d2a5287effcf60a44084568a37c9c9091d336178 Mon Sep 17 00:00:00 2001 From: fiaxh Date: Thu, 31 Aug 2017 18:40:58 +0200 Subject: Use utc time everywhere --- libdino/src/entity/conversation.vala | 2 +- libdino/src/entity/file_transfer.vala | 4 ++-- libdino/src/entity/message.vala | 4 ++-- libdino/src/service/chat_interaction.vala | 8 ++++---- libdino/src/service/connection_manager.vala | 2 +- libdino/src/service/conversation_manager.vala | 2 +- libdino/src/service/message_processor.vala | 6 +++--- libdino/src/service/presence_manager.vala | 8 ++++---- main/src/ui/conversation_selector/conversation_row.vala | 4 ++-- main/src/ui/conversation_summary/conversation_view.vala | 4 ++-- main/src/ui/conversation_summary/file_populator.vala | 6 +++--- main/src/ui/util/helper.vala | 2 +- plugins/signal-protocol/src/context.vala | 4 ++-- plugins/signal-protocol/tests/session_builder.vala | 8 ++++---- 14 files changed, 32 insertions(+), 32 deletions(-) diff --git a/libdino/src/entity/conversation.vala b/libdino/src/entity/conversation.vala index a978cf10..83c5ac22 100644 --- a/libdino/src/entity/conversation.vala +++ b/libdino/src/entity/conversation.vala @@ -54,7 +54,7 @@ public class Conversation : Object { counterpart = resource != null ? new Jid.with_resource(jid, resource) : new Jid(jid); active = row[db.conversation.active]; int64? last_active = row[db.conversation.last_active]; - if (last_active != null) this.last_active = new DateTime.from_unix_local(last_active); + if (last_active != null) this.last_active = new DateTime.from_unix_utc(last_active); type_ = (Conversation.Type) row[db.conversation.type_]; encryption = (Encryption) row[db.conversation.encryption]; int? read_up_to = row[db.conversation.read_up_to]; diff --git a/libdino/src/entity/file_transfer.vala b/libdino/src/entity/file_transfer.vala index 7a752518..10fe99f5 100644 --- a/libdino/src/entity/file_transfer.vala +++ b/libdino/src/entity/file_transfer.vala @@ -52,8 +52,8 @@ public class FileTransfer : Object { ourpart = account.bare_jid; } direction = row[db.file_transfer.direction]; - time = new DateTime.from_unix_local(row[db.file_transfer.time]); - local_time = new DateTime.from_unix_local(row[db.file_transfer.time]); + time = new DateTime.from_unix_utc(row[db.file_transfer.time]); + local_time = new DateTime.from_unix_utc(row[db.file_transfer.time]); encryption = (Encryption) row[db.file_transfer.encryption]; file_name = row[db.file_transfer.file_name]; path = row[db.file_transfer.path]; diff --git a/libdino/src/entity/message.vala b/libdino/src/entity/message.vala index e5871f49..cd54b0a5 100644 --- a/libdino/src/entity/message.vala +++ b/libdino/src/entity/message.vala @@ -73,8 +73,8 @@ public class Message : Object { ourpart = account.bare_jid; } direction = row[db.message.direction]; - time = new DateTime.from_unix_local(row[db.message.time]); - local_time = new DateTime.from_unix_local(row[db.message.time]); + time = new DateTime.from_unix_utc(row[db.message.time]); + local_time = new DateTime.from_unix_utc(row[db.message.time]); body = row[db.message.body]; marked = (Message.Marked) row[db.message.marked]; encryption = (Encryption) row[db.message.encryption]; diff --git a/libdino/src/service/chat_interaction.vala b/libdino/src/service/chat_interaction.vala index 3e8f4b24..0aefc418 100644 --- a/libdino/src/service/chat_interaction.vala +++ b/libdino/src/service/chat_interaction.vala @@ -51,8 +51,8 @@ public class ChatInteraction : StreamInteractionModule, Object { if (!last_input_interaction.has_key(conversation)) { send_chat_state_notification(conversation, Xep.ChatStateNotifications.STATE_COMPOSING); } - last_input_interaction[conversation] = new DateTime.now_local(); - last_interface_interaction[conversation] = new DateTime.now_local(); + last_input_interaction[conversation] = new DateTime.now_utc(); + last_interface_interaction[conversation] = new DateTime.now_utc(); } public void on_message_cleared(Conversation? conversation) { @@ -106,7 +106,7 @@ public class ChatInteraction : StreamInteractionModule, Object { if (!iter.valid && iter.has_next()) iter.next(); Conversation conversation = iter.get_key(); if (last_input_interaction.has_key(conversation) && - (new DateTime.now_local()).difference(last_input_interaction[conversation]) >= 15 * TimeSpan.SECOND) { + (new DateTime.now_utc()).difference(last_input_interaction[conversation]) >= 15 * TimeSpan.SECOND) { iter.unset(); send_chat_state_notification(conversation, Xep.ChatStateNotifications.STATE_PAUSED); } @@ -115,7 +115,7 @@ public class ChatInteraction : StreamInteractionModule, Object { if (!iter.valid && iter.has_next()) iter.next(); Conversation conversation = iter.get_key(); if (last_interface_interaction.has_key(conversation) && - (new DateTime.now_local()).difference(last_interface_interaction[conversation]) >= 1.5 * TimeSpan.MINUTE) { + (new DateTime.now_utc()).difference(last_interface_interaction[conversation]) >= 1.5 * TimeSpan.MINUTE) { iter.unset(); send_chat_state_notification(conversation, Xep.ChatStateNotifications.STATE_GONE); } diff --git a/libdino/src/service/connection_manager.vala b/libdino/src/service/connection_manager.vala index f7333bbd..2be16a21 100644 --- a/libdino/src/service/connection_manager.vala +++ b/libdino/src/service/connection_manager.vala @@ -155,7 +155,7 @@ public class ConnectionManager { } stream.log = new Core.XmppLog(account.bare_jid.to_string(), log_options); - Connection connection = new Connection(stream, new DateTime.now_local()); + Connection connection = new Connection(stream, new DateTime.now_utc()); connections[account] = connection; change_connection_state(account, ConnectionState.CONNECTING); stream.attached_modules.connect((stream) => { diff --git a/libdino/src/service/conversation_manager.vala b/libdino/src/service/conversation_manager.vala index 81d846e0..0f827e26 100644 --- a/libdino/src/service/conversation_manager.vala +++ b/libdino/src/service/conversation_manager.vala @@ -86,7 +86,7 @@ public class ConversationManager : StreamInteractionModule, Object { public void start_conversation(Conversation conversation, bool push_front = false) { if (push_front) { - conversation.last_active = new DateTime.now_local(); + conversation.last_active = new DateTime.now_utc(); if (conversation.active) conversation_activated(conversation); } if (!conversation.active) { diff --git a/libdino/src/service/message_processor.vala b/libdino/src/service/message_processor.vala index 4bb30ce6..25e8f91a 100644 --- a/libdino/src/service/message_processor.vala +++ b/libdino/src/service/message_processor.vala @@ -85,7 +85,7 @@ public class MessageProcessor : StreamInteractionModule, Object { 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; - if (new_message.local_time == null || new_message.local_time.compare(new DateTime.now_local()) > 0) new_message.local_time = new DateTime.now_local(); + if (new_message.local_time == null || new_message.local_time.compare(new DateTime.now_utc()) > 0) new_message.local_time = new DateTime.now_utc(); Xep.DelayedDelivery.MessageFlag? delayed_message_flag = Xep.DelayedDelivery.MessageFlag.get_flag(message); if (delayed_message_flag != null) new_message.time = delayed_message_flag.datetime; @@ -163,8 +163,8 @@ public class MessageProcessor : StreamInteractionModule, Object { message.stanza_id = random_uuid(); message.account = conversation.account; message.body = text; - message.time = new DateTime.now_local(); - message.local_time = new DateTime.now_local(); + message.time = new DateTime.now_utc(); + message.local_time = new DateTime.now_utc(); message.direction = Entities.Message.DIRECTION_SENT; message.counterpart = conversation.counterpart; if (conversation.type_ in new Conversation.Type[]{Conversation.Type.GROUPCHAT, Conversation.Type.GROUPCHAT_PM}) { diff --git a/libdino/src/service/presence_manager.vala b/libdino/src/service/presence_manager.vala index ad2db89f..298fa234 100644 --- a/libdino/src/service/presence_manager.vala +++ b/libdino/src/service/presence_manager.vala @@ -30,10 +30,10 @@ public class PresenceManager : StreamInteractionModule, Object { if (stream != null) { Xmpp.Presence.Stanza? presence = stream.get_flag(Presence.Flag.IDENTITY).get_presence(jid.to_string()); if (presence != null) { - return new Show(jid, presence.show, new DateTime.now_local()); + return new Show(jid, presence.show, new DateTime.now_utc()); } } - return new Show(jid, Show.OFFLINE, new DateTime.now_local()); + return new Show(jid, Show.OFFLINE, new DateTime.now_utc()); } public HashMap>? get_shows(Jid jid, Account account) { @@ -116,7 +116,7 @@ public class PresenceManager : StreamInteractionModule, Object { } private void add_show(Account account, Jid jid, string s) { - Show show = new Show(jid, s, new DateTime.now_local()); + Show show = new Show(jid, s, new DateTime.now_utc()); lock (shows) { if (!shows.has_key(jid)) { shows[jid] = new HashMap>(); @@ -148,4 +148,4 @@ public class Show : Object { this.datetime = datetime; } } -} \ No newline at end of file +} diff --git a/main/src/ui/conversation_selector/conversation_row.vala b/main/src/ui/conversation_selector/conversation_row.vala index ecad3467..d9432583 100644 --- a/main/src/ui/conversation_selector/conversation_row.vala +++ b/main/src/ui/conversation_selector/conversation_row.vala @@ -56,7 +56,7 @@ public abstract class ConversationRow : ListBoxRow { Entities.Message? message = stream_interactor.get_module(MessageStorage.IDENTITY).get_last_message(conversation); if (message != null) { update_message(message.body.replace("\n", " ")); - update_time(message.time.to_local()); + update_time(message.time.to_utc()); } } @@ -163,7 +163,7 @@ public abstract class ConversationRow : ListBoxRow { } private static string get_relative_time(DateTime datetime) { - DateTime now = new DateTime.now_local(); + DateTime now = new DateTime.now_utc(); TimeSpan timespan = now.difference(datetime); if (timespan > 365 * TimeSpan.DAY) { return datetime.get_year().to_string(); diff --git a/main/src/ui/conversation_summary/conversation_view.vala b/main/src/ui/conversation_summary/conversation_view.vala index 370f7943..9379e8ba 100644 --- a/main/src/ui/conversation_summary/conversation_view.vala +++ b/main/src/ui/conversation_summary/conversation_view.vala @@ -134,11 +134,11 @@ public class ConversationView : Box, Plugins.ConversationItemCollection { Dino.Application app = Dino.Application.get_default(); if (item_skeletons.size == 1) { foreach (Plugins.ConversationItemPopulator populator in app.plugin_registry.conversation_item_populators) { - populator.populate_between_widgets(conversation, item.sort_time, new DateTime.now_utc()); + populator.populate_timespan(conversation, item.sort_time, new DateTime.now_utc()); } } else { foreach (Plugins.ConversationItemPopulator populator in app.plugin_registry.conversation_item_populators) { - populator.populate_between_widgets(conversation, item.sort_time, meta_items.higher(item).sort_time); + populator.populate_timespan(conversation, item.sort_time, meta_items.higher(item).sort_time); } } } diff --git a/main/src/ui/conversation_summary/file_populator.vala b/main/src/ui/conversation_summary/file_populator.vala index bdaeaa41..9046155a 100644 --- a/main/src/ui/conversation_summary/file_populator.vala +++ b/main/src/ui/conversation_summary/file_populator.vala @@ -31,15 +31,15 @@ class FilePopulator : Plugins.ConversationItemPopulator, Object { public void close(Conversation conversation) { } - public void populate_timespan(Conversation conversation, DateTime from, DateTime to) { } - - public void populate_between_widgets(Conversation conversation, DateTime from, DateTime to) { + public void populate_timespan(Conversation conversation, DateTime from, DateTime to) { Gee.List transfers = stream_interactor.get_module(FileManager.IDENTITY).get_file_transfers(conversation.account, conversation.counterpart, from, to); foreach (FileTransfer transfer in transfers) { insert_file(transfer); } } + public void populate_between_widgets(Conversation conversation, DateTime from, DateTime to) { } + private void insert_file(FileTransfer transfer) { if (transfer.mime_type.has_prefix("image")) { item_collection.insert_item(new ImageItem(stream_interactor, transfer)); diff --git a/main/src/ui/util/helper.vala b/main/src/ui/util/helper.vala index c94752ed..a4f800f8 100644 --- a/main/src/ui/util/helper.vala +++ b/main/src/ui/util/helper.vala @@ -126,7 +126,7 @@ public static bool is_dark_theme(Gtk.Widget widget) { public static bool is_24h_format() { GLib.Settings settings = new GLib.Settings("org.gnome.desktop.interface"); string settings_format = settings.get_string("clock-format"); - string p_format = (new DateTime.now_local()).format("%p"); + string p_format = (new DateTime.now_utc()).format("%p"); return settings_format == "24h" || p_format == " "; } diff --git a/plugins/signal-protocol/src/context.vala b/plugins/signal-protocol/src/context.vala index 38ac3662..c36bf010 100644 --- a/plugins/signal-protocol/src/context.vala +++ b/plugins/signal-protocol/src/context.vala @@ -34,7 +34,7 @@ public class Context { } public SignedPreKeyRecord generate_signed_pre_key(IdentityKeyPair identity_key_pair, int32 id, uint64 timestamp = 0) throws Error { - if (timestamp == 0) timestamp = new DateTime.now_local().to_unix(); + if (timestamp == 0) timestamp = new DateTime.now_utc().to_unix(); SignedPreKeyRecord res; throw_by_code(Protocol.KeyHelper.generate_signed_pre_key(out res, identity_key_pair, id, timestamp, native_context)); return res; @@ -98,4 +98,4 @@ public class Context { } } -} \ No newline at end of file +} diff --git a/plugins/signal-protocol/tests/session_builder.vala b/plugins/signal-protocol/tests/session_builder.vala index 246cbd1c..c9f9c828 100644 --- a/plugins/signal-protocol/tests/session_builder.vala +++ b/plugins/signal-protocol/tests/session_builder.vala @@ -95,7 +95,7 @@ class SessionBuilderTest : Gee.TestCase { PreKeyRecord bob_pre_key_record = new PreKeyRecord(bob_pre_key.pre_key_id, bob_pre_key_pair); bob_store.store_pre_key(bob_pre_key_record); - SignedPreKeyRecord bob_signed_pre_key_record = new SignedPreKeyRecord(22, new DateTime.now_local().to_unix(), bob_signed_pre_key_pair, bob_signed_pre_key_signature); + SignedPreKeyRecord bob_signed_pre_key_record = new SignedPreKeyRecord(22, new DateTime.now_utc().to_unix(), bob_signed_pre_key_pair, bob_signed_pre_key_signature); bob_store.store_signed_pre_key(bob_signed_pre_key_record); /* Create Bob's session cipher and decrypt the message from Alice */ @@ -163,7 +163,7 @@ class SessionBuilderTest : Gee.TestCase { bob_pre_key_record = new PreKeyRecord(bob_pre_key.pre_key_id, bob_pre_key_pair); bob_store.store_pre_key(bob_pre_key_record); - bob_signed_pre_key_record = new SignedPreKeyRecord(23, new DateTime.now_local().to_unix(), bob_signed_pre_key_pair, bob_signed_pre_key_signature); + bob_signed_pre_key_record = new SignedPreKeyRecord(23, new DateTime.now_utc().to_unix(), bob_signed_pre_key_pair, bob_signed_pre_key_signature); bob_store.store_signed_pre_key(bob_signed_pre_key_record); /* Have Alice process Bob's pre key bundle */ @@ -262,7 +262,7 @@ class SessionBuilderTest : Gee.TestCase { /* Add Bob's pre keys to Bob's data store */ PreKeyRecord bob_pre_key_record = new PreKeyRecord(bob_pre_key.pre_key_id, bob_pre_key_pair); bob_store.store_pre_key(bob_pre_key_record); - SignedPreKeyRecord bob_signed_pre_key_record = new SignedPreKeyRecord(22, new DateTime.now_local().to_unix(), bob_signed_pre_key_pair, bob_signed_pre_key_signature); + SignedPreKeyRecord bob_signed_pre_key_record = new SignedPreKeyRecord(22, new DateTime.now_utc().to_unix(), bob_signed_pre_key_pair, bob_signed_pre_key_signature); bob_store.store_signed_pre_key(bob_signed_pre_key_record); /* @@ -393,4 +393,4 @@ class SessionBuilderTest : Gee.TestCase { */ } -} \ No newline at end of file +} -- cgit v1.2.3-70-g09d2