One-to-One Messaging with Ably

i know there’s already a question with the same title. but i have something more to say

What are my main goals:

  • I’m trying to let any user from my app to connect to any other user securely, so that no 3rd person can see their messages. just like any normal messaging system (i.e. WhatsApp, Messenger, Discord DM, Instagram DM). Groups won’t be available

What I’ve found so far:

  • The answer in the above linked question says

    The most logical method would be to have a single channel for each
    1-to-1 chat (so chat:user1:user2), as this guarantees you have:

    • A consistent message order between the 2
    • It’s easy to get the history or any one conversation, as it’s available via a single
      chat request. Generally, the logical division
      of chats as channels makes any processing you’d want to do on chats
      simple

    What issue I’ve found in the existing answer:

    • I could be wrong, but i guess the channel name won’t be same for both of the users. cuz in
      practice, what we’ll have to do in the code is chat:<sender_id>:<recipient_id>. and as the
      sender_id & recipient_ids are different for each of the users, they won’t be landing in
      the same channel. hence, they won’t be connected with each other.

      What I can think of as the possible solution:

      • maybe we can alphabetically sort the user IDs and then make a string
        out of it for the channel name. so both users get the same channel
        name. This approach have a security issue. cuz any other user can grab
        user_1 & user_2 IDs, alphabetically sort it, and enter their chat
        room easily
      • we can create a hash using user_1 & user_2 IDs (after alphabetical sort) along with a
        salt. if we can ensure that our hashing algorithm always generates the same hash string for
        a given plain text, we can make sure that both of the users are landing on the same channel
        and getting connected. besides, no malicious user will be able to recreate this hash even
        if they have the user IDs, as they don’t have the salt

Tho this approach creates a secure channel name, but we still don’t have any way to get all the channels available for a particular user. and we’ll need this to show the list of all the available chat-rooms for that user (we usually see that in the left side of the screen in popular messaging platforms. i.e. WhatsApp, Messenger, Discord, Instagram Web Version). I guess we might need this to implement the notification system as well. Not sure on this. Haven’t dived deep about how to implement push notification in the web with ably yet

So my ultimate questions are:

  1. Is my approach good?
  2. If no, what should be the best and secure approach?
  3. If yes, how can I show my users their available chat-rooms?

My tech stacks:

  1. NextJS@14
  2. [email protected]

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật