"messages:uid:fromuid:to:touid" not working as expected?



  • Hi, @psychobunny helped me set up my first plugin that will grab/record chat statistics (ex. how many times user1 has messaged user2). I believe NodeBB attempts to record that information here but a bug is keeping it from doing it correctly. I'm guessing it's cause the uids[] array is sorted. So for example, if user1 (uid:1) sends a message to user2 (uid:2), NodeBB correctly saves it into "messages:uid:1:to:2" but now if user2 sends a message to user1, NodeBB again saves it into "messages:uid:1:to:2" even though it's suppose to be "messages:uid:2:to:1". I went ahead and replaced that line with this one "async.apply(db.sortedSetAdd, 'messages:uid:' + fromuid + ':to:' + touid, timestamp, mid)" and it seems like it's working correctly now. Is that the correct/safe way to fix the bug?


  • Admin Staff

    No, when uid 1 and uid 2 are having a conversation all the messages are saved in messages:uid:' + uids[0] + ':to:' + uids[1] the uids array is populated at the top of that function with var uids = sortUids(fromuid, touid); so the lower uid is always the first.



  • ohh ok.. I just thought the other way made more sense since user2 sent the message "to" user1. so saving it as "user2:to:user1" instead of "user1:to:user2" was more intuitive. sorry 🙂


Log in to reply
 

Suggested Topics

  • 4
  • 3
  • 8
  • 1
  • 10
| |