1

I'm developing a website with angular-meteor and I've faced a strange problem. On every page I have a chat block, the messages are stored in collection chatMessages and displayed correctly. The problem is that every time I edit current user (manual mongo document edition or updating inside meteor's method) my app removes all subscriptions. As the result, messages disapper from the chat. But not only chat messages disappear. I used this piece of code to understand what's the cause of the problem, but I can barely understand it. Here's the most interesting parts from browser console output:

// On page load
send Object {
    msg: "sub",
    id: "EPgQwMiDggM7wafCN",
    name: "chatMessages",
    params: Array[0]
}
receive Object {
    msg: "added",
    collection: "chatMessages",
    id: "G6tv76ZSJYXmnsrAY",
    fields: Object
}

// Calling 'createArenaRoom' method
send Object {
    msg: "method",
    method: "createArenaRoom",
    params: Array[1],
    id: "8",
    randomSeed: "516b5128615f1c7849f2"
}

// User updated
receive Object {
    msg: "changed",
    collection: "users",
    id: "sQnaLPj2FvH692rQM",
    fields: Object
}

// ??? WHY ????
send Object {
    msg: "unsub",
    id: "EPgQwMiDggM7wafCN"
}
receive Object {
    msg: "removed",
    collection: "chatMessages",
    id: "G6tv76ZSJYXmnsrAY"
}
receive Object {
    msg: "nosub",
    id: "EPgQwMiDggM7wafCN"
}

By the way, data is not removed from mongo. If I refresh the page, it chat messages and everything else appear again.

Any help would be appreciated.

Community
  • 1
  • 1
starky
  • 640
  • 5
  • 13

1 Answers1

1

Finally I found out the cause of the problem. In my main.html I had something like this:

<div ng-if="$root.loggingIn" class="loading-screen"></div>
<myapp ng-if="!$root.loggingIn"></myapp>

This was made to prevent component's code execution before current user's data is available. I removed ng-if="!$root.loggingIn" from myapp directive and the problem disappeared. I can only guess why it caused such a strange behaviour. Now I use this.autorun() in components to wait for user data.

starky
  • 640
  • 5
  • 13