From d8505b2ae0b674bff70efbe02d73ded495cda84d Mon Sep 17 00:00:00 2001
From: Steffen van Bergerem <svbergerem@online.de>
Date: Wed, 29 Jul 2015 01:48:57 +0200
Subject: [PATCH] Fix conversations view with no contacts

closes #6266
---
 Changelog.md                                        |  1 +
 .../app/views/conversations_form_view.js            | 10 ++++++++++
 app/assets/stylesheets/conversations.scss           |  5 +++++
 config/locales/javascript/javascript.en.yml         |  2 ++
 features/desktop/conversations.feature              | 13 ++++++++++---
 5 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/Changelog.md b/Changelog.md
index 2ac86920b5..85667ef29c 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -10,6 +10,7 @@
 * Fix indentation and a link title on the default home page [#6212](https://github.com/diaspora/diaspora/pull/6212)
 * Bring peeping Tom on the 404 page back [#6226](https://github.com/diaspora/diaspora/pull/6226)
 * Fix mobile photos index page [#6243](https://github.com/diaspora/diaspora/pull/6243)
+* Fix conversations view with no contacts [#6266](https://github.com/diaspora/diaspora/pull/6266)
 
 ## Features
 
diff --git a/app/assets/javascripts/app/views/conversations_form_view.js b/app/assets/javascripts/app/views/conversations_form_view.js
index d1d2a3e323..5289241dc8 100644
--- a/app/assets/javascripts/app/views/conversations_form_view.js
+++ b/app/assets/javascripts/app/views/conversations_form_view.js
@@ -8,6 +8,10 @@ app.views.ConversationsForm = Backbone.View.extend({
 
   initialize: function(opts) {
     this.contacts = _.has(opts, "contacts") ? opts.contacts : null;
+    if(!this.contacts || this.contacts.length === 0) {
+      this.displayNoContactsMessage();
+      return;
+    }
     this.prefill = [];
     if (_.has(opts, "prefillName") && _.has(opts, "prefillValue")) {
       this.prefill = [{name : opts.prefillName,
@@ -31,6 +35,12 @@ app.views.ConversationsForm = Backbone.View.extend({
     }).focus();
   },
 
+  displayNoContactsMessage: function() {
+    $("form#new_conversation").replaceWith(
+      "<div class=\"well text-center\">" + Diaspora.I18n.t("conversation.new.no_contacts") + "</div>"
+    );
+  },
+
   keyDown : function(evt) {
     if( evt.keyCode === 13 && evt.ctrlKey ) {
       $(evt.target).parents("form").submit();
diff --git a/app/assets/stylesheets/conversations.scss b/app/assets/stylesheets/conversations.scss
index f37a0d3c1f..fba151f6eb 100644
--- a/app/assets/stylesheets/conversations.scss
+++ b/app/assets/stylesheets/conversations.scss
@@ -202,6 +202,11 @@
 
 #conversation_new {
   label { font-weight: bold; }
+
+  .well {
+    font-weight: bold;
+    margin-top: 25px;
+  }
 }
 
 #no_conversations,
diff --git a/config/locales/javascript/javascript.en.yml b/config/locales/javascript/javascript.en.yml
index d856b716f0..c7f01c680e 100644
--- a/config/locales/javascript/javascript.en.yml
+++ b/config/locales/javascript/javascript.en.yml
@@ -158,6 +158,8 @@ en:
 
     conversation:
       participants: "Participants"
+      new:
+        no_contacts: "You need to add some contacts before you can start a conversation."
 
     notifications:
       mark_read: "Mark read"
diff --git a/features/desktop/conversations.feature b/features/desktop/conversations.feature
index b9fc82d28c..d1186ae6b7 100644
--- a/features/desktop/conversations.feature
+++ b/features/desktop/conversations.feature
@@ -8,10 +8,16 @@ Feature: private conversations
     Given a user named "Robert Grimm" with email "bob@bob.bob"
     And a user named "Alice Awesome" with email "alice@alice.alice"
     And a user with username "robert_grimm" is connected with "alice_awesome"
-    When I sign in as "bob@bob.bob"
+
+  Scenario: open the conversations page without any contacts
+    Given a user with email "eve@eve.eve"
+    When I sign in as "eve@eve.eve"
+    And I am on the conversations page
+    Then I should see "You need to add some contacts before you can start a conversation"
 
   Scenario: send a message
-    Given I send a message with subject "Greetings" and text "hello, alice!" to "Alice Awesome"
+    When I sign in as "bob@bob.bob"
+    And I send a message with subject "Greetings" and text "hello, alice!" to "Alice Awesome"
     Then I should see "Greetings" within "#conversation_inbox"
     And I should see "Greetings" within "#conversation_show"
     And I should see "less than a minute ago" within "#conversation_inbox"
@@ -26,7 +32,8 @@ Feature: private conversations
     Then I should see "hey, how you doing?" within ".stream_container"
 
   Scenario: send a message using keyboard shortcuts
-    Given I send a message with subject "Greetings" and text "hello, alice!" to "Alice Awesome" using keyboard shortcuts
+    When I sign in as "bob@bob.bob"
+    And I send a message with subject "Greetings" and text "hello, alice!" to "Alice Awesome" using keyboard shortcuts
     Then I should see "Greetings" within "#conversation_inbox"
     And I should see "Greetings" within "#conversation_show"
     And "Alice Awesome" should be part of active conversation
-- 
GitLab