From 446e86d4ad798655aa1a83aebc86f9f2431484df Mon Sep 17 00:00:00 2001 From: fiaxh Date: Sat, 29 Dec 2018 19:15:25 +0100 Subject: Check FileTransfer's mime_type for null (unknown) when handeling it fixes #479 --- main/src/ui/conversation_selector/conversation_row.vala | 5 +++-- main/src/ui/conversation_summary/content_item_widget_factory.vala | 2 +- main/src/ui/notifications.vala | 5 +++-- plugins/http-files/src/file_provider.vala | 1 - plugins/omemo/src/file_provider.vala | 1 - 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/main/src/ui/conversation_selector/conversation_row.vala b/main/src/ui/conversation_selector/conversation_row.vala index 88234006..2d41d044 100644 --- a/main/src/ui/conversation_selector/conversation_row.vala +++ b/main/src/ui/conversation_selector/conversation_row.vala @@ -150,10 +150,11 @@ public class ConversationRow : ListBoxRow { nick_label.label = transfer.direction == Message.DIRECTION_SENT ? _("Me") + ": " : ""; } + bool file_is_image = transfer.mime_type != null && transfer.mime_type.has_prefix("image"); if (transfer.direction == Message.DIRECTION_SENT) { - message_label.label = "" + (transfer.mime_type.has_prefix("image") ? _("Image sent") : _("File sent") ) + ""; + message_label.label = "" + (file_is_image ? _("Image sent") : _("File sent") ) + ""; } else { - message_label.label = "" +(transfer.mime_type.has_prefix("image") ? _("Image received") : _("File received") ) + ""; + message_label.label = "" + (file_is_image ? _("Image received") : _("File received") ) + ""; } break; } diff --git a/main/src/ui/conversation_summary/content_item_widget_factory.vala b/main/src/ui/conversation_summary/content_item_widget_factory.vala index d8d21ebd..4a625cc5 100644 --- a/main/src/ui/conversation_summary/content_item_widget_factory.vala +++ b/main/src/ui/conversation_summary/content_item_widget_factory.vala @@ -194,7 +194,7 @@ public class FileItemWidgetGenerator : WidgetGenerator, Object { private Widget getDefaultWidget(FileTransfer file_transfer) { Box main_box = new Box(Orientation.HORIZONTAL, 4) { halign=Align.START, visible=true }; - string? icon_name = ContentType.get_generic_icon_name(file_transfer.mime_type); + string? icon_name = file_transfer.mime_type != null ? ContentType.get_generic_icon_name(file_transfer.mime_type) : null; Image content_type_image = new Image.from_icon_name(icon_name, IconSize.DND) { visible=true }; main_box.add(content_type_image); diff --git a/main/src/ui/notifications.vala b/main/src/ui/notifications.vala index 77a290a0..277a7a09 100644 --- a/main/src/ui/notifications.vala +++ b/main/src/ui/notifications.vala @@ -62,10 +62,11 @@ public class Notifications : Object { FileItem file_item = content_item as FileItem; FileTransfer transfer = file_item.file_transfer; + bool file_is_image = transfer.mime_type != null && transfer.mime_type.has_prefix("image"); if (transfer.direction == Message.DIRECTION_SENT) { - text = transfer.mime_type.has_prefix("image") ? _("Image sent") : _("File sent"); + text = file_is_image ? _("Image sent") : _("File sent"); } else { - text = transfer.mime_type.has_prefix("image") ? _("Image received") : _("File received"); + text = file_is_image ? _("Image received") : _("File received"); } break; } diff --git a/plugins/http-files/src/file_provider.vala b/plugins/http-files/src/file_provider.vala index 82ccc710..553068cc 100644 --- a/plugins/http-files/src/file_provider.vala +++ b/plugins/http-files/src/file_provider.vala @@ -56,7 +56,6 @@ public class FileProvider : Dino.FileProvider, Object { file_transfer.local_time = message.local_time; file_transfer.direction = message.direction; file_transfer.file_name = message.body.substring(message.body.last_index_of("/") + 1); - file_transfer.mime_type = null; file_transfer.size = -1; file_transfer.state = FileTransfer.State.NOT_STARTED; file_transfer.provider = 0; diff --git a/plugins/omemo/src/file_provider.vala b/plugins/omemo/src/file_provider.vala index 0e11c8f4..49b42e92 100644 --- a/plugins/omemo/src/file_provider.vala +++ b/plugins/omemo/src/file_provider.vala @@ -58,7 +58,6 @@ public class FileProvider : Dino.FileProvider, Object { file_transfer.local_time = message.local_time; file_transfer.direction = message.direction; file_transfer.file_name = url_without_hash.substring(url_without_hash.last_index_of("/") + 1); - file_transfer.mime_type = null; file_transfer.size = -1; file_transfer.state = FileTransfer.State.NOT_STARTED; file_transfer.provider = 0; -- cgit v1.2.3-70-g09d2