Applied implementation of chat-space

Introduction

This article summarizes the application implementation of the so-called chat-space that appears in a certain programming school. When I graduated from school, I remembered that there was an application implementation, so I wrote an article.

Immediately, what an application implementation is is to make sure that you don't even search for users you've added to a group. 画面収録 2020-06-14 22.54.10.mov.gif

What is the flow of operation of this function?

① Enter the keyword (input).

② When an event occurs, get the user's id displayed in the chat member as an array (ids)

③ After that, just pass input and ids during Ajax communication and search for users who do not include ids.

If the above is described in the source code, it will be as follows (only the changed part is displayed).

 let input = $("#user-search-field").val();
    let ids = [];
    $.each( $(".chat-group-user").find("input"), function(key,value){
      ids.push(  $(value).attr("value") );
    })
    $.ajax({
      type: "GET",
      url: "/users",
      data: { keyword: input,ids: ids },
      dataType: "json"
    })
 def index
    @users = User.search(params[:keyword], params[:ids])
    respond_to do |format|
      format.html
      format.json
    end
end
  def self.search(input, ids)
    return nil if input == ""
    User.where(['name LIKE ?', "%#{input}%"] ).where.not(id: ids).limit(10)
  end

Recommended Posts

Applied implementation of chat-space
Implementation of GKAccessPoint
Implementation of flash messages
Implementation of search function
Implementation of pagination function
Rails implementation of ajax removal
[Swift] Simple implementation of UIImageView
Implementation of sequential search function
[Swift] Implementation of ultra-simple billing
Implementation of like function (Ajax)
[Rails 6] Implementation of search function
Implementation of image preview function
[Java] Implementation of Faistel Network
Implementation of XLPagerTabStrip with TabBarController
[Rails] Implementation of category function
Implementation of category pull-down function
Implementation of unit test code
Implementation of gzip in java
[Rails] Implementation of tutorial function
[Rails] Implementation of like function
Implementation of tri-tree in Java
Implementation of HashMap in kotlin
[Rails] Implementation of user logic deletion
[Rails] Implementation of CSV import function
[Rails] Asynchronous implementation of like function
[Rails] Implementation of image preview function
Implementation of ls command in Ruby
Easy implementation of Android file browsing
[Rails] About implementation of like function
[Rails] Implementation of user withdrawal function
[Rails] Implementation of CSV export function
Implementation of asynchronous processing in Tomcat
Implementation of validation using regular expressions
[Rails] Implementation of many-to-many category functions
Default implementation of Object.equals () and Object.hashCode ()
Implementation of like function in Java
[Android] Implementation of side-scrolling ListView using RecyclerView
Whereabouts of JAXB Reference implementation and DatatypeConverterImpl
Implementation of user authentication function using devise (2)
[Swift 5] Implementation of membership registration with Firebase
Implementation of multi-tenant asynchronous processing in Tomcat
Rails [For beginners] Implementation of comment function
[Rails 6] Implementation of SNS (Twitter) sharing function
Implementation of tabs using TabLayout and ViewPager
Implementation of user authentication function using devise (3)
[Vue.js] Implementation of menu function Implementation version rails6
[Ruby on rails] Implementation of like function
[Rails] Implementation of validation that maintains uniqueness
[Vue.js] Implementation of menu function Vue.js introduction rails6
[Implementation] Eliminate the ominous smell of code