Code Monkey home page Code Monkey logo

ti.chatwidget's Introduction

ti.chatwidget

A widget for adding chat to your Titanium app

Currently not fully functional yet. Features right now:

  • add messages
  • remove messages
  • adjust messages

Chatting itself (input) is not yet supported.

This widget is being developed live on stream https://twitch.tv/wraldpyk

Join the #Twitch channel on https://tislack.org to get notified when going live.

How to

  • Include the code as a widget in your alloy app
  • Include the widget in an empty window
<Widget src="chat" id="chat" />
  • Add messages using the default structure

Default message structure:

{
  id: 1,
  message: "Hello, World!",
  me: true,
  dateTime: '2019-03-07 14:46:04'
}

dateTime needs to be parsable by momentjs, me determines wether the message is on the right or on the left (ping-pong layout)

  • add the message
$.chat.addMessages(array);
$.chat.addMessage(message);
  • update messages
$.chat.updateMessage(message);
  • remove messages
$.chat.removeMessage(message);

For update you can pass a stripped out message object, it only needs the to-be-updated property and the id.

For remove only the id is required.

New messages

A new message will be added if the user types it in the box. An event will trigger for this new message. It is your responsibility to submit this message to the server and update the ID of the message after submit has been succesful.

  • Add event listener
<TextField id="chatBox" onReturn="sendMessage" />

This function will get the following object:

    message {
        "dateTime": "2019-03-11T16:12:22+01:00",
        "day": 20190311,
        "id": 1552317142742,
        "me": true;
        "message": "My Message";
        "timestamp": 1552317142;
    };
    updateId: function(oldId, newId)
  }

Call updateId function with the generated (oldId) ID and the server generated newId. This way you can keep control over the newly created message.

If server fails to create message in chat you could always call removeMessage with oldId

ti.chatwidget's People

Contributors

topener avatar

Watchers

Brenton House avatar

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.