{"id":95736,"date":"2022-02-15T17:41:49","date_gmt":"2022-02-15T17:41:49","guid":{"rendered":"http:\/\/www.quintadosilval.pt\/?p=95736"},"modified":"2022-02-15T17:48:07","modified_gmt":"2022-02-15T17:48:07","slug":"generate-a-note-in-talk-area-roomid-message-post","status":"publish","type":"post","link":"https:\/\/www.quintadosilval.pt\/en\/generate-a-note-in-talk-area-roomid-message-post\/","title":{"rendered":"Generate a note in talk area (\/:roomId\/message) [POST consult]"},"content":{"rendered":"<p><title>Generate a note in talk area (\/:roomId\/message) [POST consult]<\/title><\/p>\n<p>A very important factor to see here&#8217;s userIds, type comes from req.body while userId which getting aliased as chatInitiatorId is coming from req compliment of the decode middleware.<\/p>\n<p>Should you decide remember, we attached app.use(&#8220;\/room&#8221;, decode, <a href=\"https:\/\/besthookupwebsites.net\/coffee-meets-bagel-review\/\">coffee meets bagel<\/a> chatRoomRouter); in our server\/index.js file. What this means is this route \/room\/initiate is actually authenticated. So const < userId:>= req; could be the id on the present consumer logged around.<\/p>\n<p>We just phone the initiateChat method from ChatRoomModel and go it allUserIds, sort, chatInitiator . Whatever result will come we just go they with the individual.<!--more--><\/p>\n<p>However before we establish a note we need to generate an unit for the chatmessages . Therefore why don&#8217;t we do that first. In your brands folder develop a file also known as ChatMessage.js and create listed here content material to they:<\/p>\n<ul>\n<li>We a MESSAGE_TYPES object that has only one type called book<\/li>\n<li>Our company is defining all of our outline for chatmessage and readByRecipient<\/li>\n<li>After that we&#8217;re composing our static way of  createPostInChatRoom<\/li>\n<\/ul>\n<p>I&#8217;m sure this is exactly lots of articles, but simply bear beside me. Let&#8217;s just write the operator the course that creates this message.<\/p>\n<p>The route explained within routes\/chatRoom.js API (&#8216;\/:roomId\/message&#8217;, chatRoom.postMessage) let&#8217;s choose their operator in controllers\/chatRoom.js and determine they:<\/p>\n<ul>\n<li>$complement<\/li>\n<li>$final<\/li>\n<li>$addToSet<\/li>\n<li>$lookup<\/li>\n<li>$relax<\/li>\n<li>$class<\/li>\n<\/ul>\n<h2>Read discussion for a talk area by it&#8217;s id [Get request]<\/h2>\n<p>For your path .get(&#8216;\/:roomId&#8217;, chatRoom.getConversationByRoomId) in routes\/chatRoom.js available the controller from inside the file controllers\/chatRoom.js and incorporate the next articles to your chat place:<\/p>\n<p>After which at last, visit your ChatMessage product in models\/ChatMessage.js and write a fresh fixed way labeled as getConversationByRoomId :<\/p>\n<h2>Tag an entire talk as browse (element much like WhatsApp)<\/h2>\n<p>When the other person try signed in in addition they view a conversation for a bedroom id, we should instead draw that dialogue as read from their part.<\/p>\n<p>All we&#8217;re performing the following is first examining in the event the space exists or perhaps not. When it do, we go ahead further. We consume the req.user.id as currentLoggedUser and move they to the next function:<\/p>\n<p>A potential utilize circumstances is the fact that the individual might not have look at the last 15 communications as soon as they start a particular space discussion. They should all be marked as see. Therefore we&#8217;re by using the this.updateMany purpose by mongoose.<\/p>\n<p>This states I want to pick all the information articles in the chatmessages range where chatRoomId suits and readByRecipients selection doesn&#8217;t. The userId that i will be moving to this work try currentUserOnlineId .<\/p>\n<p>Next we would like to determine mongoose never to just update 1st record it locates, but additionally to modify every information where state fits. Thus carrying this out:<\/p>\n<h2>Bonus Part<\/h2>\n<p>Reach out to myself on twitter with your opinions a\u20ac\u201c i might like to listen to when you yourself have any ideas for advancements: twitter\/adeelibr<\/p>\n<p>Should you decide preferred to the post, be sure to do supply the github repository a celebrity and sign up for my personal youtube station.<\/p>\n<p>Learn to code free of charge. freeCodeCamp&#8217;s open provider curriculum provides aided above 40,000 individuals become jobs as developers. Start out<\/p>\n<p>The goal: to help individuals figure out how to code for free. We make this happen by generating many video clips, posts, and entertaining coding lessons &#8211; all free towards public. We supply 1000s of freeCodeCamp learn teams across the world.<\/p>\n<p>In your root folder develop a brand new folder known as config . Inside that folder generate a file labeled as index.js and put the following contents:<\/p>\n<p>Right here we are telling it that firstName try of sort sequence. In the event that individual forgets to include this appreciate while showing up in API, or if perhaps the kind is not string, it will toss a mistake.<\/p>\n<p>We get the userId from your req.params . Any time you remember from the video clip earlier in the day, req.params could be the \/: explained in our courses section.<\/p>\n<p>We&#8217;re going to get that individual id additionally the clients id (an individual&#8217;s own distinctive socket id that brings about if they generate an association with your make).<\/p>\n<p>The audience is making use of the make-validation library here to confirm an individual&#8217;s request. For the initiate API, we expect the user to send a myriad of people in addition to establish whatever the chat-room definitely being developed.<\/p>\n","protected":false},"excerpt":{"rendered":"<p> [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[11833],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Generate a note in talk area (\/:roomId\/message) [POST consult] - Quinta Do Silval<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/www.quintadosilval.pt\/en\/generate-a-note-in-talk-area-roomid-message-post\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Generate a note in talk area (\/:roomId\/message) [POST consult] - Quinta Do Silval\" \/>\n<meta property=\"og:description\" content=\"[&hellip;]\" \/>\n<meta property=\"og:url\" content=\"http:\/\/www.quintadosilval.pt\/en\/generate-a-note-in-talk-area-roomid-message-post\/\" \/>\n<meta property=\"og:site_name\" content=\"Quinta Do Silval\" \/>\n<meta property=\"article:published_time\" content=\"2022-02-15T17:41:49+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-02-15T17:48:07+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"http:\/\/www.quintadosilval.pt\/en\/generate-a-note-in-talk-area-roomid-message-post\/\",\"url\":\"http:\/\/www.quintadosilval.pt\/en\/generate-a-note-in-talk-area-roomid-message-post\/\",\"name\":\"Generate a note in talk area (\/:roomId\/message) [POST consult] - Quinta Do Silval\",\"isPartOf\":{\"@id\":\"https:\/\/www.quintadosilval.pt\/en\/#website\"},\"datePublished\":\"2022-02-15T17:41:49+00:00\",\"dateModified\":\"2022-02-15T17:48:07+00:00\",\"author\":{\"@id\":\"https:\/\/www.quintadosilval.pt\/en\/#\/schema\/person\/91082182c7332352c59ae672ed0c9852\"},\"breadcrumb\":{\"@id\":\"http:\/\/www.quintadosilval.pt\/en\/generate-a-note-in-talk-area-roomid-message-post\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/www.quintadosilval.pt\/en\/generate-a-note-in-talk-area-roomid-message-post\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/www.quintadosilval.pt\/en\/generate-a-note-in-talk-area-roomid-message-post\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"In\u00edcio\",\"item\":\"https:\/\/www.quintadosilval.pt\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Generate a note in talk area (\/:roomId\/message) [POST consult]\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.quintadosilval.pt\/en\/#website\",\"url\":\"https:\/\/www.quintadosilval.pt\/en\/\",\"name\":\"Quinta Do Silval\",\"description\":\"Official Page Quinta do Silval\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.quintadosilval.pt\/en\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.quintadosilval.pt\/en\/#\/schema\/person\/91082182c7332352c59ae672ed0c9852\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.quintadosilval.pt\/en\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/13e1d3b398f1b72b1f2d7d53a6c64370?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/13e1d3b398f1b72b1f2d7d53a6c64370?s=96&d=mm&r=g\",\"caption\":\"admin\"},\"url\":\"https:\/\/www.quintadosilval.pt\/en\/author\/admin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Generate a note in talk area (\/:roomId\/message) [POST consult] - Quinta Do Silval","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/www.quintadosilval.pt\/en\/generate-a-note-in-talk-area-roomid-message-post\/","og_locale":"en_US","og_type":"article","og_title":"Generate a note in talk area (\/:roomId\/message) [POST consult] - Quinta Do Silval","og_description":"[&hellip;]","og_url":"http:\/\/www.quintadosilval.pt\/en\/generate-a-note-in-talk-area-roomid-message-post\/","og_site_name":"Quinta Do Silval","article_published_time":"2022-02-15T17:41:49+00:00","article_modified_time":"2022-02-15T17:48:07+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"http:\/\/www.quintadosilval.pt\/en\/generate-a-note-in-talk-area-roomid-message-post\/","url":"http:\/\/www.quintadosilval.pt\/en\/generate-a-note-in-talk-area-roomid-message-post\/","name":"Generate a note in talk area (\/:roomId\/message) [POST consult] - Quinta Do Silval","isPartOf":{"@id":"https:\/\/www.quintadosilval.pt\/en\/#website"},"datePublished":"2022-02-15T17:41:49+00:00","dateModified":"2022-02-15T17:48:07+00:00","author":{"@id":"https:\/\/www.quintadosilval.pt\/en\/#\/schema\/person\/91082182c7332352c59ae672ed0c9852"},"breadcrumb":{"@id":"http:\/\/www.quintadosilval.pt\/en\/generate-a-note-in-talk-area-roomid-message-post\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.quintadosilval.pt\/en\/generate-a-note-in-talk-area-roomid-message-post\/"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/www.quintadosilval.pt\/en\/generate-a-note-in-talk-area-roomid-message-post\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"In\u00edcio","item":"https:\/\/www.quintadosilval.pt\/en\/"},{"@type":"ListItem","position":2,"name":"Generate a note in talk area (\/:roomId\/message) [POST consult]"}]},{"@type":"WebSite","@id":"https:\/\/www.quintadosilval.pt\/en\/#website","url":"https:\/\/www.quintadosilval.pt\/en\/","name":"Quinta Do Silval","description":"Official Page Quinta do Silval","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.quintadosilval.pt\/en\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.quintadosilval.pt\/en\/#\/schema\/person\/91082182c7332352c59ae672ed0c9852","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.quintadosilval.pt\/en\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/13e1d3b398f1b72b1f2d7d53a6c64370?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/13e1d3b398f1b72b1f2d7d53a6c64370?s=96&d=mm&r=g","caption":"admin"},"url":"https:\/\/www.quintadosilval.pt\/en\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.quintadosilval.pt\/en\/wp-json\/wp\/v2\/posts\/95736"}],"collection":[{"href":"https:\/\/www.quintadosilval.pt\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.quintadosilval.pt\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.quintadosilval.pt\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.quintadosilval.pt\/en\/wp-json\/wp\/v2\/comments?post=95736"}],"version-history":[{"count":1,"href":"https:\/\/www.quintadosilval.pt\/en\/wp-json\/wp\/v2\/posts\/95736\/revisions"}],"predecessor-version":[{"id":95737,"href":"https:\/\/www.quintadosilval.pt\/en\/wp-json\/wp\/v2\/posts\/95736\/revisions\/95737"}],"wp:attachment":[{"href":"https:\/\/www.quintadosilval.pt\/en\/wp-json\/wp\/v2\/media?parent=95736"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.quintadosilval.pt\/en\/wp-json\/wp\/v2\/categories?post=95736"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.quintadosilval.pt\/en\/wp-json\/wp\/v2\/tags?post=95736"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}