1
0
mirror of https://github.com/moparisthebest/kaiwa synced 2024-11-26 19:22:18 -05:00
kaiwa/clientapp/models/muc.js

96 lines
2.5 KiB
JavaScript
Raw Normal View History

2013-09-27 01:52:54 -04:00
/*global app, me, client*/
2013-09-16 19:12:00 -04:00
"use strict";
var _ = require('underscore');
var async = require('async');
var uuid = require('node-uuid');
var HumanModel = require('human-model');
var Resources = require('./resources');
var Messages = require('./messages');
var Message = require('./message');
module.exports = HumanModel.define({
initialize: function (attrs) {
if (attrs.jid) {
this.id = attrs.jid.full;
}
},
type: 'muc',
props: {
id: ['string', true, false],
name: 'string',
autoJoin: ['bool', true, false],
nick: 'string',
jid: 'object'
},
session: {
activeContact: ['bool', true, false],
lastInteraction: 'data',
lastSentMessage: 'object',
unreadCount: ['number', true, 0],
joined: ['bool', true, false]
},
derived: {
displayName: {
deps: ['name', 'jid'],
fn: function () {
return this.name || this.jid;
}
},
displayUnreadCount: {
deps: ['unreadCount'],
fn: function () {
if (this.unreadCount > 0) {
return this.unreadCount.toString();
}
return '';
}
},
2013-09-16 19:12:00 -04:00
hasUnread: {
deps: ['unreadCount'],
fn: function () {
return this.unreadCount > 0;
}
}
},
collections: {
resources: Resources,
messages: Messages
},
addMessage: function (message, notify) {
message.owner = me.jid.bare;
if (notify && (!this.activeContact || (this.activeContact && !app.hasFocus))) {
this.unreadCount++;
2013-10-11 18:40:42 -04:00
app.notifications.create(this.displayName, {
body: message.body,
2013-09-16 19:12:00 -04:00
icon: this.avatar,
2013-10-11 18:40:42 -04:00
tag: this.id,
2013-09-16 19:12:00 -04:00
onclick: _.bind(app.navigate, app, '/chat/' + this.jid)
});
}
this.messages.add(message);
var newInteraction = new Date(message.created);
if (!this.lastInteraction || this.lastInteraction < newInteraction) {
this.lastInteraction = newInteraction;
}
},
join: function () {
if (!this.nick) {
this.nick = me.jid.local;
}
client.joinRoom(this.jid, this.nick, {
history: {
2013-10-08 11:03:58 -04:00
maxstanzas: 50
//since: this.lastInteraction
2013-09-16 19:12:00 -04:00
}
});
},
leave: function () {
client.leaveRoom(this.jid, this.nick);
}
});