Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8159187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:49:51+00:00 2026-06-06T17:49:51+00:00

I get the last messages sent to the room which will be also displayed

  • 0

I get the last messages sent to the room which will be also displayed in the View but if a new message comes in the Strophe event handler does not fire although I see incoming message stanza over the wire (xmlInput on the connection).

What could be the reason for that?

After connecting I create the MessageList and register the Strophe handler:

 Messages = new MessageList();
 XMPPConnection.addHandler(Messages.onMessageReceived, null, "message", "groupchat");
 XMPPConnection.send($pres({to: "room@conference.server.local/user1"}).c("x", {xmlns: "http://jabber.org/protocol/muc"}));
 window.App = new AppView();

And the MVC:

// ----------------- Message Model  ----------------   
var Message = Backbone.Model.extend({
  body: "default message",

  initialize: function(body) {
      if (body) {
        this.set({body: body});
      }
  }      
});

// ----------------- Message Collection  ----------------   
var MessageList = Backbone.Collection.extend({
 model: Message,

 initialize: function(body) {       
 },

 onMessageReceived: function(body) {
     var message = new Message($(body).text());
     Messages.add(message);
     return true;
 }           
});

  // ---------------- Message View -------------------  
var MessageView = Backbone.View.extend({
  tagName: "li",

  template: _.template($("#message-template").html()),
  events: {},
  initialize: function() {
      this.model.bind("change", this.render, this);
   //   this.model.bind("remove", this.remove, this);
  },

  render: function() {
      this.$el.html(this.template(this.model.toJSON()));
      return this;    
  }        
});  

// ---------------- App View -------------------  
var AppView = Backbone.View.extend({
    el: $("#myapp"),

    initialize: function() {              
       Messages.bind("add", this.addOneMessage, this);
       this.main = $('#main');
    },

    addOneMessage: function(message) {
        var view = new MessageView({model: message});
        this.$("#message-list").append(view.render().el);
    },
 });
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T17:49:53+00:00Added an answer on June 6, 2026 at 5:49 pm

    There are a few things going wrong, here are some tips:

    Your Message model should be written as:

    var Message = Backbone.Model.extend({
      defaults: {
          body: "default message",
      }
    });
    

    there’s no need for the initialize, if you pass attributes they will be assigned.

    Your collection:

    var MessageList = Backbone.Collection.extend({
        model: Message,
    });
    

    I would also put the onMessageReceived outside the the MessageList:

     var onMessageReceived = function(body) {
         Messages.add({body: $(body).text()});
         return true;
     }           
    

    Your MessageView can be simpler, MUC messages do not change, they just get added:

    var MessageView = Backbone.View.extend({
      tagName: "li",
    
      template: _.template($("#message-template").html()),
      render: function() {
          this.$el.html(this.template(this.model.toJSON()));
          return this;    
      }        
    });  
    

    Hopefully this gives you enough to go on…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a contact form on site which used to work, but since last
I'm trying to use the message middleware in Django, but the view does not
how to get last row of excel in POI and append blank row and
How to get Last Index Of % in a string in .NET ? I
How to get last page no like stackoverflow.com pagination in Sql server 2005
How would I get last 12 digits of a string using mysql? Let's say
How can I get last year's start and end date using PHP code? Is
There is an example on php.net how to get last two domain segments in
I have some date and I want to get last x day before this
I need to get the last string content of the url between / and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.