Ejemplo n.º 1
0
  test('#getChannelForMessage returns the channel for a given message', function(assert) {
    const space = Space.create();
    const channel = Channel.create({ sockethubChannelId: '*****@*****.**' });
    const comsStub = Service.create({ spaces: [space] });
    const service = this.owner.factoryFor('service:sockethub-xmpp').create({ coms: comsStub });

    space.get('channels').pushObject(channel);

    const message = {
      actor: {
        '@id': 'some_user@some-server.com/hyperchannel',
        '@type': 'person',
        displayName: 'some_user'
      },
      target: {
        '@id': '*****@*****.**',
        '@type': 'room',
        displayName: '*****@*****.**'
      },
      object: {
        '@type': 'message',
        content: 'hello world'
      }
    };

    assert.equal(service.getChannelForMessage(space, message), channel);
  });
Ejemplo n.º 2
0
  test('#handlePresenceUpdate adds new users to the channel', function(assert) {
    const channel = Channel.create({ sockethubChannelId: 'some-channel' });
    const space = Space.create();
    const comsStub = Service.create({ spaces: [space] });
    const service = this.owner.factoryFor('service:sockethub-xmpp').create({ coms: comsStub });

    space.get('channels').pushObject(channel);

    const presenceUpdate = {
      actor: {
        displayName: 'new_user'
      },
      target: {
        '@id': 'some-channel',
        '@type': 'room'
      },
      object: {
        presence: 'online'
      }
    };

    service.handlePresenceUpdate(presenceUpdate);

    assert.ok(channel.get('userList').includes('new_user'));
  });
Ejemplo n.º 3
0
  test('#addMessageToChannel adds the message to the channel', function(assert) {
    const space = Space.create();
    const channel = Channel.create({ sockethubChannelId: '*****@*****.**' });
    const comsStub = Service.create({ spaces: [space] });
    const service = this.owner.factoryFor('service:sockethub-xmpp').create({ coms: comsStub });

    space.get('channels').pushObject(channel);

    const message = {
      actor: {
        '@id': 'some_user@some-server.com/hyperchannel',
        '@type': 'person',
        displayName: 'some_user'
      },
      target: {
        '@id': '*****@*****.**',
        '@type': 'room',
        displayName: '*****@*****.**'
      },
      object: {
        '@type': 'message',
        content: 'hello world'
      }
    };

    service.addMessageToChannel(message);

    assert.equal(channel.get('messages.lastObject.content'), 'hello world');
  });
Ejemplo n.º 4
0
  test('#joinChannel calls join on the appropriate transport service', function(assert) {
    const xmppStub = {
      join: function() { }
    };
    const joinStub = this.stub(xmppStub, 'join');
    const service = this.owner.factoryFor('service:coms').create({ xmpp: xmppStub });

    const space = Space.create();
    space.set('protocol', 'XMPP');
    const channel = Channel.create({});

    service.joinChannel(space, channel, 'room');

    assert.ok(joinStub.calledOnce);
    assert.ok(joinStub.calledWith(space, channel, 'room'));
  });
Ejemplo n.º 5
0
  test('#updateChannelUserList updates the users and connects the channel', function(assert) {
    const observeMessage = {
      "@type": "observe",
      "actor": {
          "@id": "irc://irc.freenode.net/#kosmos",
          "@type": "room",
          "displayName": "#kosmos"
      },
      "context": "irc",
      "object": {
          "@type": "attendance",
          "members": [
              "derbumi",
              "galfert",
              "gregkare",
              "raucao",
              "slvrbckt"
          ]
      },
      "published": "2017-06-23T15:44:54.383Z"
    };

    const space = Space.create();
    space.setProperties({
      protocol: 'IRC',
      name: 'Freenode',
      server: { hostname: 'irc.freenode.net' }
    });
    const channel = Channel.create({
      name: '#kosmos',
      sockethubChannelId: 'irc://irc.freenode.net/#kosmos',
      space: space,
      connected: false
    });

    space.get('channels').pushObject(channel);

    const service = this.owner.factoryFor('service:coms').create({ spaces: [space] });

    service.updateChannelUserList(observeMessage);

    assert.ok(channel.get('connected'));
    assert.equal(channel.get('userList').length, 5);
  });
Ejemplo n.º 6
0
  createChannel: function(space, channelName) {
    const platform = this.getServiceForSockethubPlatform(space.get('protocol'));

    const channel = Channel.create({
      space: space,
      name: channelName,
      sockethubChannelId: platform.generateChannelId(space, channelName)
    });

    this.joinChannel(space, channel, "room");
    space.get('channels').pushObject(channel);

    // TODO Do we need this on startup? Could overwrite updates from remote.
    this.storage.saveSpace(space);

    if (channel.get('isLogged')) {
      this.loadLastMessages(space, channel, moment.utc(), 2).catch(() => {});
    }

    return channel;
  },
Ejemplo n.º 7
0
  test('#transferMessage calls transferMessage on the appropriate transport service', function(assert) {
    const xmppStub = {
      transferMessage: function(space, target, content) {
        assert.equal(space.get('name'), 'Testspace');
        assert.equal(target['@id'], 'testspace-testchannel');
        assert.equal(target['@type'], 'room');
        assert.equal(target.displayName, 'testchannel');
        assert.equal(content, 'hello world');
      }
    };

    const service = this.owner.factoryFor('service:coms').create({ xmpp: xmppStub });

    const space = Space.create();
    space.setProperties({ protocol: 'XMPP', name: 'Testspace' });
    const channel = Channel.create({
      name: 'testchannel',
      sockethubChannelId: 'testspace-testchannel',
      isUserChannel: false
    });

    service.transferMessage(space, channel, 'hello world');
  });