Code Monkey home page Code Monkey logo

chat-sdk-js's People

Contributors

akiroz avatar b123400 avatar carmenlau avatar cheungpat avatar david90 avatar howawong avatar rayrw avatar rickmak avatar steven-chan avatar tensiuyan avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

chat-sdk-js's Issues

Utility Function for Typing Indicator with Input Box

Refs #28 by @akiroz

Tasks

  • Consider can we have something similar with iOS and Android SDK?
  • Add it to JS SDK, update API doc
  • Add it to Quick Start and Guide

Proposal by @akiroz

import skygearChat from 'skygear-chat';

// http://stackoverflow.com/questions/36871299/how-to-extend-function-with-es6-classes
class ExtensibleFunction extends Function {
  constructor(f) {
    return Object.setPrototypeOf(f, new.target.prototype);
  }
}

// TypingIndicator.js
export default class extends ExtensibleFunction {
  constructor(conversation, debounceTime = 3000) {
    super(() => {
      if(this.debounceTimer) {
        this.startTyping();
      } else {
        this.resetTimer();
      }   
    }); 
    this.conversation = conversation;
    this.debounceTime = debounceTime;
    this.debounceTimer = null;
  }
  startTyping() {
    this.debounceTimer = setTimeout(
      this.stopTyping,
      this.debounceTime
    );  
    skygearChat.sendTypingIndicator(
      this.conversation, 'begin'
    );  
  }
  resetTimer() {
    clearTimeout(this.debounceTimer);
    this.debounceTimer = setTimeout(
      this.stopTyping,
      this.debounceTime
    );  
  }
  stopTyping() {
    this.debounceTimer = null;
    skygearChat.sendTypingIndicator(
      this.conversation, 'finished'
    );  
  }
}

Usage

import TypingIndicator from 'TypingIndicator.js';
const typing = new TypingIndicator(currentConversation);
<input type=text onChange=typing />

Align `event` / `state` at typingIndicator API

sendTypingIndicator(conversation, state)

vs

subscribeTypingIndicator() / subscribeAllTypingIndicator(), the callback return "event"

Either call it state, or event, we should align it!

getUnreadCount() API inconsistant with doc

Expected:

public getUnreadCount(): Promise<number>
getUnreadCount return the total unread message count of current user

Actual:

public getUnreadCount(): Promise<Object>
returns the total unread count of conversations and messages of the current user
when there are no conversations, returns this:

{
  conversation: 0,
  message: null
}

object is returned by chat:total_unread lambda.

ManagedMessageList

Two features:

  1. Handle initial fetch of message, subscribe to message event together, to provide a data model for message list for a conversion, and a proxy for relevant message event.

  2. Handle offline cache of message history.

Add unread_count to Conversation

Currently the unread_count attribute is only available in the UserConversation record.
This should be available in Conversation records returned by getConversaton().

Skygear container in Skygear Chat cannot be configured in react-native

Platform: React-Native

import skygear from 'skygear/react-native';
import skygearChat from 'skygear-chat';

skygear.config({...}).then(() => {
  skygearChat.createDirectConversation(...);  // I would get api key not configured error here
});

I think the reason is that, skygear-chat import skygear from 'skygear', while the app import skygear from 'skygear/react-native', so they are two separate skygear containers.

Add last_message to Conversation

Currently the last_message transient include is only available in the UserConversation record returned by getUserConversations().

This should be available in Conversation records returned by getConversaton().

Provide more intuitive APIs

I think much more of the client logic can be encapsulated into the SDK.... It's currently extremely hard to use.
IMO, the SDK's API should be based on ease of use and not ease of implementation..... :(

Things like "list of conversations that belongs to the current user" and "current conversation" should be part of the SDK, it's unlikely that a chat app will not have a list of chats or more than 1 current chat.

Some APIs are quite chaotic like: userConversation.$transient.conversation.$transient.last_message.body it almost seem like a hack / workaround.

[Discuss] Potential use of option for getUserConversations

Currently when we call getUserConversations, we can specify includeLastMessage: boolean, page: number, pageSize: number using positional argument.

The problem is, when I just want to specify "pageSize", I have to specify"includeLastMessage" and "page" as well although I just want to leave them as default.

For example, if I want to set the pageSize as 20, then I have to call getUserConversations(true, 1, 20).

Can we explore the use of option here to avoid the confusion?

leaveConversation not working

Not sure if this is a back-end bug or SDK misuse of lambda, leave it here for now.

leave conversation:
screenshot from 2017-02-13 17-44-49

get user conversations:
screenshot from 2017-02-13 17-47-45

the conversation still exists:
screenshot from 2017-02-13 17-47-34

Subscribe message by conversation

subscribe will listen on all conversation events.... That's rarely what we want in practice, it should filter out messages for a specific conversion just like subscribeTypingIndicator.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.