Created
July 29, 2010 22:32
-
-
Save jegade/499424 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// On every Multipipe | |
multipipe: function(pipe, options) { | |
// Private Status Channel | |
var privat_status = "status" + this.options.user_id; | |
if (this.options.debug) { | |
console.log('A new Multi pipe is created. Pipe object : ', pipe.name); | |
} | |
if (pipe.properties.name == privat_status) { | |
// add existing users | |
options.users.each(function(user) { | |
if (user.properties.user_id != this.user.properties.user_id && user.properties.state != 'invisible' ) { | |
this.contacts.set(user.properties.user_id, { | |
'state' : user.properties.state, | |
'firstname': user.properties.firstname, | |
'lastname' : user.properties.lastname | |
}); | |
} | |
}.bind(this)); | |
// Anzahl der Kontakte setzen | |
// this.contacts.getLength(); | |
// Event für neue Kontakte | |
pipe.addEvent('userJoin', function(user, pipe) { | |
if (this.user.properties.user_id != user.properties.user_id ) { | |
if ( !this.contacts.has(user.properties.user_id ) && user.properties.state != 'invisible') { | |
this.contacts.set(user.properties.user_id, { | |
'state': user.properties.state, | |
'firstname': user.properties.firstname, | |
'lastname' : user.properties.lastname | |
}); | |
this.notify(user.properties.firstname + " " + user.properties.lastname + " hat sich angemeldet"); | |
// Anzahl der Kontakte setzen | |
this.setContactsCount(this.contacts.getLength()); | |
} | |
} | |
}.bind(this)); | |
// Event für Kontakte die verlassen | |
pipe.addEvent('userLeft', function(user, pipe) { | |
if ( this.contacts.has(user.properties.user_id )) { | |
this.contacts.erase(user.properties.user_id); | |
this.notify(user.properties.firstname + " " + user.properties.lastname + " hat sich abgemeldet"); | |
this.setContactsCount(this.contacts.getLength()); | |
} | |
}.bind(this)); | |
} | |
}, | |
// Anzahl Kontakt setzen | |
setContactsCount: function(count) { | |
this.contacts_count = count; | |
if (count == 1) { | |
this.imbar_contacts.set('text', "Ein Kontakt online"); | |
} else if (this.contacts_count == 0) { | |
this.imbar_contacts.set('text', "Kein Kontakt online"); | |
} else { | |
this.imbar_contacts.set('text', count + " Kontakte online"); | |
} | |
this.imbar_contacts.highlight(); | |
}, | |
// Display notifications | |
notify: function(message) { | |
this.imbar_notify.set('text', message); | |
this.imbar_notify.highlight(); | |
}, | |
// Update the state-view (chatme (green), online (green), away (orange), busy (red), invisible (darkgrey), offline (black) ) | |
setState: function(state) { | |
this.state = state; | |
this.imbar_state.set('html', state); | |
this.imbar_state.setStyle('color', this.states.get(state)); | |
}, | |
// Auswahldialog Status | |
selectState: function(e) { | |
var event = new Event(e); | |
event.stop(); | |
var selectbox = new Element('ul', { 'id': 'imbar_state_select' }); | |
this.selectbox = selectbox; | |
this.states.each(function(color, xstate, states) { | |
var opt = new Element('li', { 'text': xstate }); | |
var sta = new Element('span', { 'text': ' ■ ' } ); | |
sta.setStyle('color', color); | |
sta.inject(opt,'top'); | |
opt.addEvent('click', this.setIMStatus.bindWithEvent(this, xstate)); | |
opt.inject(selectbox); | |
if (this.state == xstate) { | |
opt.setStyle('font-weight', 'bold'); | |
} | |
}.bind(this)); | |
selectbox.inject(this.imbar); | |
selectbox.addEvent('outerclick', function(e) { selectbox.destroy() }); | |
}, | |
// Auswahldialog Kontakts | |
selectContacts: function(e) { | |
var event = new Event(e); | |
event.stop(); | |
var contactbox = new Element('ul', { | |
'id': 'imbar_contact_select' | |
}); | |
this.contactbox = contactbox; | |
this.contacts.each(function(user, user_id, contact) { | |
if (this.user.properties.user_id != user_id && user.state != 'invisible' ) { | |
var color = this.states.get(user.state); | |
var opt = new Element('li', { | |
'text': user.firstname + " " + user.lastname | |
}); | |
var sta = new Element('span', { 'text': ' ■ ' } ); | |
sta.setStyle('color', color); | |
sta.inject(opt, 'top') ; | |
opt.addEvent('click', this.startDialog.bindWithEvent(this, user_id)); | |
opt.inject(contactbox); | |
} | |
}.bind(this)); | |
contactbox.inject(this.imbar); | |
}, | |
contactChangeStatus: function(raw, pipe) { | |
var state = raw.data.state; | |
var old = raw.data.old; | |
var user = raw.data.from; | |
if ( state == 'invisible' ) { | |
state = 'offline'; | |
this.contacts.erase(user.properties.user_id) | |
this.setContactsCount(this.contacts.getLength()); | |
} else { | |
this.contacts.set(user.properties.user_id, { | |
'state': state, | |
'firstname': user.properties.firstname, | |
'lastname': user.properties.lastname | |
}); | |
} | |
this.notify(user.properties.firstname + " " + user.properties.lastname + " ist nun " + state); | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment