Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Solved
  • Unsolved
  • Users
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Darkly)
  • No Skin
Collapse
brainCloud Forums
  1. Home
  2. APIs
  3. Best practices for in-game mailbox

Best practices for in-game mailbox

Scheduled Pinned Locked Moved Unsolved APIs
4 Posts 2 Posters 586 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    armitage
    wrote on last edited by armitage
    #1

    I didn't see an in-game mailbox referenced in the docs, but it seems this is achievable by using Global Entities to push messages from the system via API Hooks (like a "welcome gift" that is sent after a first-time authentication, or a tournament prize after a tournament concludes), and a User Entity to track if a message was read or the Item Bundle was claimed.

    It seems Custom Entities are an even better fit for this, since then, we can search for players that are, say > level 20, and push a special mail message to them, right?

    Is this the most best way to approach an in-game mailbox in brainCloud, and what hurdles might I run into by handling it this way? Would this let me safely bypass the limitations around awarding Items for milestones/quests?

    Here is my code for a "GetMailbox" cloud script, for reference:

    "use strict";
    
    function main() {
        var entityProxy = bridge.getEntityServiceProxy();       // for user entities (tracker)
        var globalProxy = bridge.getGlobalEntityServiceProxy(); // for global entities (server mail)
        
        // fetch global mail manifest using global proxy
        var globalMails =[];
        var globalRes = globalProxy.getList({ "entityType": "globalMail" }, {}, 50);
        if (globalRes.data.entityList) {
            for (var i = 0; i < globalRes.data.entityList.length; i++) {
                globalMails.push(globalRes.data.entityList[i].data);
            }
        }
    
        // fetch user's personal mailbox tracker
        var userRes = entityProxy.getList({ "entityType": "mailbox" }, {}, 1);
        var mailboxEntity;
        
        if (userRes.data.entityList && userRes.data.entityList.length > 0) {
            mailboxEntity = userRes.data.entityList[0].data;
            
            // safety: ensure arrays exist if entity was somehow corrupted
            if (!mailboxEntity.claimedGlobalIds) mailboxEntity.claimedGlobalIds =[];
            if (!mailboxEntity.personalMail) mailboxEntity.personalMail =[];
        } else {
            // create if it doesn't exist
            mailboxEntity = { claimedGlobalIds: [], personalMail:[] };
            entityProxy.createEntity("mailbox", mailboxEntity, null);
        }
    
        // merge/format for client
        var mergedInbox =[];
    
        // global mail
        for (var g = 0; g < globalMails.length; g++) {
            var gMail = globalMails[g];
            // if msg ID is in claimed list, mark as read/claimed
            gMail.isClaimed = (mailboxEntity.claimedGlobalIds.indexOf(gMail.messageId) !== -1);
            gMail.isRead = gMail.isClaimed; 
            gMail.type = "GLOBAL";
            mergedInbox.push(gMail);
        }
    
        // personal mail
        for (var p = 0; p < mailboxEntity.personalMail.length; p++) {
            var pMail = mailboxEntity.personalMail[p];
            pMail.type = "PERSONAL";
            mergedInbox.push(pMail);
        }
    
        return { messages: mergedInbox };
    }
    
    main();
    
    1 Reply Last reply
    0
    • Paul WinterhalderP Offline
      Paul WinterhalderP Offline
      Paul Winterhalder
      brainCloudAdmin
      wrote on last edited by
      #2

      Hi - you custom entity based solution for this is sound.

      You also might want to check on the messaging system - which has an "inbox" and a concept of whether entries have been "read" or not. It might do what you are looking for more directly?

      1 Reply Last reply
      0
      • A Offline
        A Offline
        armitage
        wrote on last edited by
        #3

        Thanks for confirming, Paul.

        I considered Messaging, but I saw 'bulk messaging' to all users was still in the works. Even if we could msg all players, for something like a "maintenance apology gift", pushing a single Global Entity versus iterating through every profile ID to send a msg seemed like the better option--BUT, I'm still learning, so I could be wrong.

        1 Reply Last reply
        0
        • Paul WinterhalderP Offline
          Paul WinterhalderP Offline
          Paul Winterhalder
          brainCloudAdmin
          wrote on last edited by
          #4

          Agreed @armitage - the bulk messaging feature is planned for the use case you describe... (and yup - still coming 🙂 ).

          1 Reply Last reply
          0

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better 💗

          Register Login
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Solved
          • Unsolved
          • Users