test('it creates a message instance from a Sockethub message object', function(assert) {
    let result = channelMessageFromSockethubObject(sockethubMessageObject);

    assert.ok(result instanceof Message);
    assert.deepEqual(result.getProperties('type', 'nickname', 'content'), {
      type: 'message-chat',
      nickname: 'raucao',
      content: 'airberlin flight AB 1234 is ready for boarding'
    });
    assert.equal(new Date(result.get('date')).toISOString(),
                 new Date('2017-06-14T06:32:42.025Z').toISOString());
  });
  test('it creates an action message instance from a Sockethub message object', function(assert) {
    sockethubMessageObject.object['@type'] = 'me';
    sockethubMessageObject.object.content = 'boards the plane';
    let result = channelMessageFromSockethubObject(sockethubMessageObject);

    assert.ok(result instanceof Message);
    assert.deepEqual(result.getProperties('type', 'nickname', 'content'), {
      type: 'message-chat-me',
      nickname: 'raucao',
      content: 'boards the plane'
    });
    assert.equal(new Date(result.get('date')).toISOString(),
                 new Date('2017-06-14T06:32:42.025Z').toISOString());
  });
示例#3
0
   * @public
   */
  addMessageToChannel(message) {
    if (isEmpty(message.object.content)) {
      return;
    }

    const space = this.getSpaceForMessage(message);

    if (isEmpty(space)) {
      console.warn('Could not find space for message', message);
      return;
    }

    const channel = this.getChannelForMessage(space, message);
    const channelMessage = channelMessageFromSockethubObject(message);

    // TODO should check for message and update sent status if exists
    if (channelMessage.get('nickname') !== space.get('userNickname')) {
      channel.addMessage(channelMessage);
    }
  },

  /**
   * Ask for a channel's attendance list (users currently joined)
   *
   * @param {Space} space
   * @param {Channel} channel
   * @public
   */
  observeChannel(space, channel) {