Exemple #1
0
    /// <summary>
    /// Get a single module by name with only the fields required for system blah blah blah
    /// </summary>
    /// <param name="search"></param>
    /// <param name="name"></param>
    /// <param name="userId"></param>
    /// <returns></returns>
    public static async Task <ContentView?> GetModuleForSystemByNameAsync(this IGenericSearch search, string name, long userId = -1)
    {
        var request = new SearchRequest()
        {
            type   = "content",
            fields = "~votes,permissions,keywords,values",
            query  = "name = @name and contentType = @type and !notdeleted()"
        };
        var values = new Dictionary <string, object> {
            { "name", name },
            { "type", InternalContentType.module }
        };

        List <ContentView> modules = new List <ContentView>();

        if (userId < 0)
        {
            modules = await search.SearchSingleTypeUnrestricted <ContentView>(request, values);
        }
        else
        {
            modules = await search.SearchSingleType <ContentView>(userId, request, values);
        }

        return(modules.FirstOrDefault(x => x.name == name && x.contentType == InternalContentType.module));
    }
    public async Task SendMessage_UserMessage(long sender, long receiver, long reader, bool exists)
    {
        var roomId  = 1 + (int)ContentVariations.AccessByAll;
        var modview = new ContentView()
        {
            name        = "test", text = @"
            subcommands = {[""""]={[""arguments""]={""first_int""}} }
            function command_(uid, receiver)
                usermessage(receiver, ""hey"")
                -- usermessage(uid + 1, ""hey NO"")
            end",
            contentType = InternalContentType.module
        };
        var mod      = service.UpdateModule(modview);
        var result   = service.RunCommand("test", receiver.ToString(), sender, roomId);
        var messages = await searcher.SearchSingleType <MessageView>(reader, new SearchRequest()
        { //This excludes the existing module messages because checking for specific module
            type   = "message",
            fields = "*",
            query  = "module = @module and contentId = @cid"
        }, new Dictionary <string, object> {
            { "cid", roomId },
            { "module", "test" }
        });

        if (exists)
        {
            Assert.Single(messages);
            Assert.Equal("hey", messages.First().text);
            Assert.Equal("test", messages.First().module);
            Assert.Equal(receiver, messages.First().receiveUserId);
            Assert.Equal(sender, messages.First().createUserId);
        }
        else
        {
            Assert.Empty(messages);
        }
    }