예제 #1
0
        protected override Task AuthorizeAsync(IChatCredential credential)
        {
            var model = new GGMessage <ReqGGChatAuth>
            {
                Type = "auth"
            };

            if (credential == null)
            {
                model.Data.UserId = 0;
            }
            else
            {
                if (int.TryParse(credential.User, out int userId))
                {
                    model.Data.UserId = userId;
                    model.Data.Token  = credential.Token.Unsecure();
                }
                else
                {
                    throw new InvalidOperationException(
                              "Invalid conversion IChatCredential.User to int.");
                }
            }

            return(SendModelAsync(model));
        }
예제 #2
0
        protected override Task InternalUnJoinChannel(Channel channel)
        {
            var model = new GGMessage <ResGGChatUnJoin>
            {
                Type = "unjoin",
                Data =
                {
                    ChannelId = channel.Id.Value
                }
            };

            return(SendModelAsync(model));
        }
예제 #3
0
        protected override Task InternalSendMessageAsync(string text, Channel channel)
        {
            // TODO : add IChatOptions
            var model = new GGMessage <ReqGGSendMessage>()
            {
                Type = "send_message",
                Data =
                {
                    ChannelId = channel.Id.Value,
                    Mobile    =                0,
                    Text      = text
                                // icon = ???
                                // mobile = ???
                                // color = ???
                }
            };

            return(SendModelAsync(model));
        }
예제 #4
0
        protected async override Task InternalJoinChannel(Channel channel)
        {
            if (channel.Id.HasValue)
            {
                var model = new GGMessage <ReqGGChatJoin>
                {
                    Type = "join",
                    Data =
                    {
                        ChannelId = channel.Id.Value,
                        Hidden    = 0
                    }
                };

                await SendModelAsync(model).ConfigureAwait(false);
            }
            else
            {
                throw new InvalidOperationException("ChannelId is null.");
            }
        }