{"action":"created","comment":{"url":"https://api.github.com/repos/monicahq/monica/pulls/comments/213895603","pull_request_review_id":150827953,"id":213895603,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIxMzg5NTYwMw==","diff_hunk":"@@ -0,0 +1,65 @@\n+<?php\n+\n+/**\n+ * This is a single action class, totally inspired by\n+ * https://medium.com/@remi_collin/keeping-your-laravel-applications-dry-with-single-action-classes-6a950ec54d1d.\n+ */\n+\n+namespace App\\Services\\Contact\\Conversation;\n+\n+use App\\Services\\BaseService;\n+use App\\Models\\Contact\\Contact;\n+use App\\Models\\Contact\\Conversation;\n+use Illuminate\\Database\\QueryException;\n+use App\\Models\\Contact\\ContactFieldType;\n+use Illuminate\\Database\\Eloquent\\ModelNotFoundException;\n+\n+class CreateConversation extends BaseService\n+{\n+    /**\n+     * The structure that the method expects to receive as parameter.\n+     *\n+     * @var array\n+     */\n+    private $structure = [\n+        'happened_at',\n+        'account_id',\n+        'contact_id',\n+        'contact_field_type_id',\n+    ];\n+\n+    /**\n+     * Create a conversation.\n+     *\n+     * @param array $data\n+     * @return Conversation\n+     */\n+    public function execute(array $data): Conversation\n+    {\n+        if (! $this->validateDataStructure($data, $this->structure)) {\n+            throw new \\Exception('Missing parameters');\n+        }\n+\n+        try {\n+            Contact::where('account_id', $data['account_id'])\n+                    ->where($data['contact_id']);\n+        } catch (ModelNotFoundException $e) {\n+            throw $e;\n+        }\n+\n+        try {\n+            ContactFieldType::where('account_id', $data['account_id'])\n+                            ->findOrFail($data['contact_field_type_id']);\n+        } catch (ModelNotFoundException $e) {\n+            throw $e;\n+        }\n+\n+        try {\n+            $conversation = Conversation::create($data);\n+        } catch (QueryException $e) {\n+            throw $e;","path":"app/Services/Contact/Conversation/CreateConversation.php","position":60,"original_position":60,"commit_id":"67390da09b23d78f7ee95eaa66ffa0158c49a5bd","original_commit_id":"67390da09b23d78f7ee95eaa66ffa0158c49a5bd","user":{"login":"sonarcloud[bot]","id":39514782,"node_id":"MDM6Qm90Mzk1MTQ3ODI=","avatar_url":"https://avatars2.githubusercontent.com/in/12526?v=4","gravatar_id":"","url":"https://api.github.com/users/sonarcloud%5Bbot%5D","html_url":"https://github.com/apps/sonarcloud","followers_url":"https://api.github.com/users/sonarcloud%5Bbot%5D/followers","following_url":"https://api.github.com/users/sonarcloud%5Bbot%5D/following{/other_user}","gists_url":"https://api.github.com/users/sonarcloud%5Bbot%5D/gists{/gist_id}","starred_url":"https://api.github.com/users/sonarcloud%5Bbot%5D/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sonarcloud%5Bbot%5D/subscriptions","organizations_url":"https://api.github.com/users/sonarcloud%5Bbot%5D/orgs","repos_url":"https://api.github.com/users/sonarcloud%5Bbot%5D/repos","events_url":"https://api.github.com/users/sonarcloud%5Bbot%5D/events{/privacy}","received_events_url":"https://api.github.com/users/sonarcloud%5Bbot%5D/received_events","type":"Bot","site_admin":false},"body":"![Code Smell](https://sonarsource.github.io/sonar-github/code_smell.png 'Code Smell') Code Smell: Add logic to this catch clause or eliminate it and rethrow the exception automatically. ([php:S2737](https://sonarcloud.io/organizations/monicahq/rules#rule_key=php%3AS2737))\n\n[See it in SonarCloud](https://sonarcloud.io/project/issues?id=monica&pullRequest=1629&issues=AWV-iR6tXKENQn1SzgPF&open=AWV-iR6tXKENQn1SzgPF)\n\n[ISSUE_KEY]: AWV-iR6tXKENQn1SzgPF","created_at":"2018-08-30T03:41:20Z","updated_at":"2018-08-30T03:41:22Z","html_url":"https://github.com/monicahq/monica/pull/1629#discussion_r213895603","pull_request_url":"https://api.github.com/repos/monicahq/monica/pulls/1629","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/monicahq/monica/pulls/comments/213895603"},"html":{"href":"https://github.com/monicahq/monica/pull/1629#discussion_r213895603"},"pull_request":{"href":"https://api.github.com/repos/monicahq/monica/pulls/1629"}}},"pull_request":{"url":"https://api.github.com/repos/monicahq/monica/pulls/1629","id":204657719,"node_id":"MDExOlB1bGxSZXF1ZXN0MjA0NjU3NzE5","html_url":"https://github.com/monicahq/monica/pull/1629","diff_url":"https://github.com/monicahq/monica/pull/1629.diff","patch_url":"https://github.com/monicahq/monica/pull/1629.patch","issue_url":"https://api.github.com/repos/monicahq/monica/issues/1629","number":1629,"state":"open","locked":false,"title":"feat: Conversations [wip]","user":{"login":"djaiss","id":61099,"node_id":"MDQ6VXNlcjYxMDk5","avatar_url":"https://avatars3.githubusercontent.com/u/61099?v=4","gravatar_id":"","url":"https://api.github.com/users/djaiss","html_url":"https://github.com/djaiss","followers_url":"https://api.github.com/users/djaiss/followers","following_url":"https://api.github.com/users/djaiss/following{/other_user}","gists_url":"https://api.github.com/users/djaiss/gists{/gist_id}","starred_url":"https://api.github.com/users/djaiss/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/djaiss/subscriptions","organizations_url":"https://api.github.com/users/djaiss/orgs","repos_url":"https://api.github.com/users/djaiss/repos","events_url":"https://api.github.com/users/djaiss/events{/privacy}","received_events_url":"https://api.github.com/users/djaiss/received_events","type":"User","site_admin":false},"body":"This PR adds the concept of **conversations**.\r\n\r\nRight now we can log phone calls. It's useful, but it's limited. What if we could log every communication with a contact? Each communication is a conversation. A conversation has one or more messages. The idea is to let users record conversations made on social media (FB, Whatsapp,...), interactions through SMS, meeting notes, phone calls, email,...\r\n\r\nAll this presented in a nice and friendly way. That way, I can remember for instance that I've had a nice conversation with a good friend of mine at this date, and we've talked about X.\r\n\r\nThis will close https://github.com/monicahq/monica/issues/917\r\n\r\nFor this first iteration, **we won't migrate existing phone calls** and we'll keep the calls feature, otherwise it will break the mobile application\r\n\r\n- [ ] Order conversations list by date\r\n- [ ] Crop last message if it's too long for display\r\n- [ ] Make sure it works in responsive mode\r\n- [x] When deleting a contact field type, make sure we delete conversations too\r\n- [ ] Add Conversations on dashboard\r\n- [x] Daily Statistics calculation on the instance\r\n- [x] Cypress tests\r\n- [x] Make sure all exceptions are taken into account in the frontend\r\n- [x] Impact on notion of modules\r\n\r\n![image](https://user-images.githubusercontent.com/61099/44416117-109cc680-a540-11e8-83e3-6faea76aaf0b.png)\r\n\r\n\r\n## Technical discussion\r\n\r\nThis PR uses the notion of service, and especially the notion of [single action classes](https://medium.com/@remi_collin/keeping-your-laravel-applications-dry-with-single-action-classes-6a950ec54d1d). The idea is to have one class per action.\r\nIt's very useful as it will let us write less code at the end. By using a class separated from your model, we can have the logic at one place, and call this logic from both the API and the web version, without having to write the backend twice.\r\n\r\n### Checklist\r\n\r\n#### Code-related tasks\r\n- [x] Tests added for this feature/bug.\r\n- [ ] Impact on the seeders.\r\n- [ ] Impact on the API.\r\n\r\n#### If the code changes the SQL schema\r\n- [ ] Impact on account export.\r\n- [ ] Impact on importing data with `vCard` and `.csv` files.\r\n- [ ] Impact on account reset and deletion.\r\n\r\n#### Other tasks\r\n- [ ] [CHANGELOG](https://github.com/monicahq/monica/blob/master/CHANGELOG) entry added, if necessary, under `UNRELEASED`.\r\n","created_at":"2018-07-29T19:34:30Z","updated_at":"2018-08-30T03:41:22Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c69773c351d5f1c38e35b487eead3c7b3d97ed82","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":{"url":"https://api.github.com/repos/monicahq/monica/milestones/8","html_url":"https://github.com/monicahq/monica/milestone/8","labels_url":"https://api.github.com/repos/monicahq/monica/milestones/8/labels","id":3561734,"node_id":"MDk6TWlsZXN0b25lMzU2MTczNA==","number":8,"title":"2.7","description":null,"creator":{"login":"djaiss","id":61099,"node_id":"MDQ6VXNlcjYxMDk5","avatar_url":"https://avatars3.githubusercontent.com/u/61099?v=4","gravatar_id":"","url":"https://api.github.com/users/djaiss","html_url":"https://github.com/djaiss","followers_url":"https://api.github.com/users/djaiss/followers","following_url":"https://api.github.com/users/djaiss/following{/other_user}","gists_url":"https://api.github.com/users/djaiss/gists{/gist_id}","starred_url":"https://api.github.com/users/djaiss/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/djaiss/subscriptions","organizations_url":"https://api.github.com/users/djaiss/orgs","repos_url":"https://api.github.com/users/djaiss/repos","events_url":"https://api.github.com/users/djaiss/events{/privacy}","received_events_url":"https://api.github.com/users/djaiss/received_events","type":"User","site_admin":false},"open_issues":10,"closed_issues":1,"state":"open","created_at":"2018-08-10T19:19:45Z","updated_at":"2018-08-27T15:19:48Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/monicahq/monica/pulls/1629/commits","review_comments_url":"https://api.github.com/repos/monicahq/monica/pulls/1629/comments","review_comment_url":"https://api.github.com/repos/monicahq/monica/pulls/comments{/number}","comments_url":"https://api.github.com/repos/monicahq/monica/issues/1629/comments","statuses_url":"https://api.github.com/repos/monicahq/monica/statuses/67390da09b23d78f7ee95eaa66ffa0158c49a5bd","head":{"label":"monicahq:2018-07-26-feat-conversations","ref":"2018-07-26-feat-conversations","sha":"67390da09b23d78f7ee95eaa66ffa0158c49a5bd","user":{"login":"monicahq","id":25832602,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI1ODMyNjAy","avatar_url":"https://avatars3.githubusercontent.com/u/25832602?v=4","gravatar_id":"","url":"https://api.github.com/users/monicahq","html_url":"https://github.com/monicahq","followers_url":"https://api.github.com/users/monicahq/followers","following_url":"https://api.github.com/users/monicahq/following{/other_user}","gists_url":"https://api.github.com/users/monicahq/gists{/gist_id}","starred_url":"https://api.github.com/users/monicahq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/monicahq/subscriptions","organizations_url":"https://api.github.com/users/monicahq/orgs","repos_url":"https://api.github.com/users/monicahq/repos","events_url":"https://api.github.com/users/monicahq/events{/privacy}","received_events_url":"https://api.github.com/users/monicahq/received_events","type":"Organization","site_admin":false},"repo":{"id":82238168,"node_id":"MDEwOlJlcG9zaXRvcnk4MjIzODE2OA==","name":"monica","full_name":"monicahq/monica","owner":{"login":"monicahq","id":25832602,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI1ODMyNjAy","avatar_url":"https://avatars3.githubusercontent.com/u/25832602?v=4","gravatar_id":"","url":"https://api.github.com/users/monicahq","html_url":"https://github.com/monicahq","followers_url":"https://api.github.com/users/monicahq/followers","following_url":"https://api.github.com/users/monicahq/following{/other_user}","gists_url":"https://api.github.com/users/monicahq/gists{/gist_id}","starred_url":"https://api.github.com/users/monicahq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/monicahq/subscriptions","organizations_url":"https://api.github.com/users/monicahq/orgs","repos_url":"https://api.github.com/users/monicahq/repos","events_url":"https://api.github.com/users/monicahq/events{/privacy}","received_events_url":"https://api.github.com/users/monicahq/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/monicahq/monica","description":"Personal CRM. Remember everything about your friends and family.","fork":false,"url":"https://api.github.com/repos/monicahq/monica","forks_url":"https://api.github.com/repos/monicahq/monica/forks","keys_url":"https://api.github.com/repos/monicahq/monica/keys{/key_id}","collaborators_url":"https://api.github.com/repos/monicahq/monica/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/monicahq/monica/teams","hooks_url":"https://api.github.com/repos/monicahq/monica/hooks","issue_events_url":"https://api.github.com/repos/monicahq/monica/issues/events{/number}","events_url":"https://api.github.com/repos/monicahq/monica/events","assignees_url":"https://api.github.com/repos/monicahq/monica/assignees{/user}","branches_url":"https://api.github.com/repos/monicahq/monica/branches{/branch}","tags_url":"https://api.github.com/repos/monicahq/monica/tags","blobs_url":"https://api.github.com/repos/monicahq/monica/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/monicahq/monica/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/monicahq/monica/git/refs{/sha}","trees_url":"https://api.github.com/repos/monicahq/monica/git/trees{/sha}","statuses_url":"https://api.github.com/repos/monicahq/monica/statuses/{sha}","languages_url":"https://api.github.com/repos/monicahq/monica/languages","stargazers_url":"https://api.github.com/repos/monicahq/monica/stargazers","contributors_url":"https://api.github.com/repos/monicahq/monica/contributors","subscribers_url":"https://api.github.com/repos/monicahq/monica/subscribers","subscription_url":"https://api.github.com/repos/monicahq/monica/subscription","commits_url":"https://api.github.com/repos/monicahq/monica/commits{/sha}","git_commits_url":"https://api.github.com/repos/monicahq/monica/git/commits{/sha}","comments_url":"https://api.github.com/repos/monicahq/monica/comments{/number}","issue_comment_url":"https://api.github.com/repos/monicahq/monica/issues/comments{/number}","contents_url":"https://api.github.com/repos/monicahq/monica/contents/{+path}","compare_url":"https://api.github.com/repos/monicahq/monica/compare/{base}...{head}","merges_url":"https://api.github.com/repos/monicahq/monica/merges","archive_url":"https://api.github.com/repos/monicahq/monica/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/monicahq/monica/downloads","issues_url":"https://api.github.com/repos/monicahq/monica/issues{/number}","pulls_url":"https://api.github.com/repos/monicahq/monica/pulls{/number}","milestones_url":"https://api.github.com/repos/monicahq/monica/milestones{/number}","notifications_url":"https://api.github.com/repos/monicahq/monica/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/monicahq/monica/labels{/name}","releases_url":"https://api.github.com/repos/monicahq/monica/releases{/id}","deployments_url":"https://api.github.com/repos/monicahq/monica/deployments","created_at":"2017-02-17T00:02:58Z","updated_at":"2018-08-30T02:33:49Z","pushed_at":"2018-08-30T03:32:11Z","git_url":"git://github.com/monicahq/monica.git","ssh_url":"git@github.com:monicahq/monica.git","clone_url":"https://github.com/monicahq/monica.git","svn_url":"https://github.com/monicahq/monica","homepage":"https://monicahq.com","size":55398,"stargazers_count":4994,"watchers_count":4994,"language":"PHP","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":584,"mirror_url":null,"archived":false,"open_issues_count":302,"license":{"key":"agpl-3.0","name":"GNU Affero General Public License v3.0","spdx_id":"AGPL-3.0","url":"https://api.github.com/licenses/agpl-3.0","node_id":"MDc6TGljZW5zZTE="},"forks":584,"open_issues":302,"watchers":4994,"default_branch":"master"}},"base":{"label":"monicahq:master","ref":"master","sha":"6f1e2d7d6f276e9daa70ca44e02ac896bb94701b","user":{"login":"monicahq","id":25832602,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI1ODMyNjAy","avatar_url":"https://avatars3.githubusercontent.com/u/25832602?v=4","gravatar_id":"","url":"https://api.github.com/users/monicahq","html_url":"https://github.com/monicahq","followers_url":"https://api.github.com/users/monicahq/followers","following_url":"https://api.github.com/users/monicahq/following{/other_user}","gists_url":"https://api.github.com/users/monicahq/gists{/gist_id}","starred_url":"https://api.github.com/users/monicahq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/monicahq/subscriptions","organizations_url":"https://api.github.com/users/monicahq/orgs","repos_url":"https://api.github.com/users/monicahq/repos","events_url":"https://api.github.com/users/monicahq/events{/privacy}","received_events_url":"https://api.github.com/users/monicahq/received_events","type":"Organization","site_admin":false},"repo":{"id":82238168,"node_id":"MDEwOlJlcG9zaXRvcnk4MjIzODE2OA==","name":"monica","full_name":"monicahq/monica","owner":{"login":"monicahq","id":25832602,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI1ODMyNjAy","avatar_url":"https://avatars3.githubusercontent.com/u/25832602?v=4","gravatar_id":"","url":"https://api.github.com/users/monicahq","html_url":"https://github.com/monicahq","followers_url":"https://api.github.com/users/monicahq/followers","following_url":"https://api.github.com/users/monicahq/following{/other_user}","gists_url":"https://api.github.com/users/monicahq/gists{/gist_id}","starred_url":"https://api.github.com/users/monicahq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/monicahq/subscriptions","organizations_url":"https://api.github.com/users/monicahq/orgs","repos_url":"https://api.github.com/users/monicahq/repos","events_url":"https://api.github.com/users/monicahq/events{/privacy}","received_events_url":"https://api.github.com/users/monicahq/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/monicahq/monica","description":"Personal CRM. Remember everything about your friends and family.","fork":false,"url":"https://api.github.com/repos/monicahq/monica","forks_url":"https://api.github.com/repos/monicahq/monica/forks","keys_url":"https://api.github.com/repos/monicahq/monica/keys{/key_id}","collaborators_url":"https://api.github.com/repos/monicahq/monica/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/monicahq/monica/teams","hooks_url":"https://api.github.com/repos/monicahq/monica/hooks","issue_events_url":"https://api.github.com/repos/monicahq/monica/issues/events{/number}","events_url":"https://api.github.com/repos/monicahq/monica/events","assignees_url":"https://api.github.com/repos/monicahq/monica/assignees{/user}","branches_url":"https://api.github.com/repos/monicahq/monica/branches{/branch}","tags_url":"https://api.github.com/repos/monicahq/monica/tags","blobs_url":"https://api.github.com/repos/monicahq/monica/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/monicahq/monica/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/monicahq/monica/git/refs{/sha}","trees_url":"https://api.github.com/repos/monicahq/monica/git/trees{/sha}","statuses_url":"https://api.github.com/repos/monicahq/monica/statuses/{sha}","languages_url":"https://api.github.com/repos/monicahq/monica/languages","stargazers_url":"https://api.github.com/repos/monicahq/monica/stargazers","contributors_url":"https://api.github.com/repos/monicahq/monica/contributors","subscribers_url":"https://api.github.com/repos/monicahq/monica/subscribers","subscription_url":"https://api.github.com/repos/monicahq/monica/subscription","commits_url":"https://api.github.com/repos/monicahq/monica/commits{/sha}","git_commits_url":"https://api.github.com/repos/monicahq/monica/git/commits{/sha}","comments_url":"https://api.github.com/repos/monicahq/monica/comments{/number}","issue_comment_url":"https://api.github.com/repos/monicahq/monica/issues/comments{/number}","contents_url":"https://api.github.com/repos/monicahq/monica/contents/{+path}","compare_url":"https://api.github.com/repos/monicahq/monica/compare/{base}...{head}","merges_url":"https://api.github.com/repos/monicahq/monica/merges","archive_url":"https://api.github.com/repos/monicahq/monica/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/monicahq/monica/downloads","issues_url":"https://api.github.com/repos/monicahq/monica/issues{/number}","pulls_url":"https://api.github.com/repos/monicahq/monica/pulls{/number}","milestones_url":"https://api.github.com/repos/monicahq/monica/milestones{/number}","notifications_url":"https://api.github.com/repos/monicahq/monica/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/monicahq/monica/labels{/name}","releases_url":"https://api.github.com/repos/monicahq/monica/releases{/id}","deployments_url":"https://api.github.com/repos/monicahq/monica/deployments","created_at":"2017-02-17T00:02:58Z","updated_at":"2018-08-30T02:33:49Z","pushed_at":"2018-08-30T03:32:11Z","git_url":"git://github.com/monicahq/monica.git","ssh_url":"git@github.com:monicahq/monica.git","clone_url":"https://github.com/monicahq/monica.git","svn_url":"https://github.com/monicahq/monica","homepage":"https://monicahq.com","size":55398,"stargazers_count":4994,"watchers_count":4994,"language":"PHP","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":584,"mirror_url":null,"archived":false,"open_issues_count":302,"license":{"key":"agpl-3.0","name":"GNU Affero General Public License v3.0","spdx_id":"AGPL-3.0","url":"https://api.github.com/licenses/agpl-3.0","node_id":"MDc6TGljZW5zZTE="},"forks":584,"open_issues":302,"watchers":4994,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/monicahq/monica/pulls/1629"},"html":{"href":"https://github.com/monicahq/monica/pull/1629"},"issue":{"href":"https://api.github.com/repos/monicahq/monica/issues/1629"},"comments":{"href":"https://api.github.com/repos/monicahq/monica/issues/1629/comments"},"review_comments":{"href":"https://api.github.com/repos/monicahq/monica/pulls/1629/comments"},"review_comment":{"href":"https://api.github.com/repos/monicahq/monica/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/monicahq/monica/pulls/1629/commits"},"statuses":{"href":"https://api.github.com/repos/monicahq/monica/statuses/67390da09b23d78f7ee95eaa66ffa0158c49a5bd"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"sonarcloud"}}