Skip to content
Extraits de code Groupes Projets
web-socket-receiver.js 1,41 ko
Newer Older
  • Learn to ignore specific revisions
  • var WSR = WebSocketReceiver = {
    
      initialize: function(url) {
    
        WSR.socket = new WebSocket(url);
    
        WSR.socket.onmessage = WSR.onMessage;
        WSR.socket.onopen = function() {
          WSR.socket.send(location.pathname);
    
      onMessage: function(evt) {
    
        var message = $.parseJSON(evt.data);
    
        if(message["class"].match(/^notifications$/)) {
          Diaspora.page.notifications.showNotification(message);
    
        else {
          switch(message["class"]) {
            case "retractions":
              ContentUpdater.removePostFromStream(message.post_guid);
              break;
            case "comments":
              ContentUpdater.addCommentToPost(message.post_guid, message.comment_guid, message.html);
              break;
            case "likes":
              ContentUpdater.addLikesToPost(message.post_guid, message.html);
              break;
            default:
              if(WSR.onPageForAspects(message.aspects_ids)) {
                ContentUpdater.addPostToStream(message.html);
              }
              break;
    
      onPageForAspects: function(aspectIds) {
        var streamIds = $("#main_stream").attr("data-guids"),
    
        $.each(aspectIds, function(index, value) {
    
          if(WebSocketReceiver.onStreamForAspect(value, streamIds)) {
    
    lfortin's avatar
    lfortin a validé
            found = true;
    
        return found;
      },
    
    
      onStreamForAspect: function(aspectId, streamIds) {
        return (streamIds.search(aspectId) != -1);