示例#1
0
        public User(
            ConversationInfo info,
            string userId   = null,
            string username = null,
            BearerAccessToken spotifyAccessToken = null)
        {
            var now = DateTime.UtcNow;

            (string id, string pk) = EncodeIds(info, userId ?? info.FromId);

            Id           = id;
            PartitionKey = pk;
            Type         = TypeName;

            UserId        = userId ?? info.FromId;
            Username      = username ?? info.FromName;
            ChannelId     = info.ChannelId;
            ChannelTeamId = info.ChannelTeamId;
            CreatedDate   = now;

            if (spotifyAccessToken != null)
            {
                SpotifyAuth = new Auth {
                    BearerAccessToken = spotifyAccessToken, CreatedDate = now
                };
            }
        }
示例#2
0
        /// <summary>
        /// Encodes the Id and Partition Key into a format suitable for a <see cref="CosmosEntity"/>
        /// </summary>
        /// <param name="channelId">A Channel Id that identifies the Bot channel, i.e. "msteams", "slack".</param>
        /// <param name="userId">The User Id provided by the Bot Channel</param>
        /// <returns>An Id, PK tuple.</returns>
        internal static (string id, string pk) EncodeIds(ConversationInfo info, string userId)
        {
            // ringo:{channel_id}:{channel_team_id.ToLower()}:user:user_id.ToLower()}
            string id = $"{RingoBotHelper.RingoBotName}:{info.ChannelId}:{info.ChannelTeamId}:user:{CryptoHelper.Base62Encode(userId)}"
                        .ToLower();

            return(id, id);
        }
示例#3
0
        /// <summary>
        /// Encodes the Id and Partition Key into a format suitable for a <see cref="CosmosEntity"/>
        /// </summary>
        /// <param name="hashtag">Hashtag</param>
        /// <param name="info">Conversation Info</param>
        /// <param name="username">Username for User Station. Must be null for Conversation Station</param>
        internal static (string id, string pk) EncodeIds(ConversationInfo info, string hashtag, string username = null)
        {
            if (!string.IsNullOrEmpty(username))
            {
                // User Station
                // ringo:{channel_id}:{channel_team_id.ToLower()}:station:user:{lower_word(user_name)}
                string id = $"{RingoBotHelper.RingoBotName}:{info.ChannelId}:{info.ChannelTeamId}:station:user:{RingoBotHelper.LowerWord(username)}"
                            .ToLower();
                return(id, id);
            }

            // Conversation Station
            // ringo:{channel_id}:{channel_team_id.ToLower()}:station:conversation:{lower_word(conversation_name)}[:hashtag:{lower_word(hashtag)}]
            string pk = $"{RingoBotHelper.RingoBotName}:{info.ChannelId}:{info.ChannelTeamId}:station:conversation:{RingoBotHelper.LowerWord(info.ConversationName)}"
                        .ToLower();

            return($"{pk}:hashtag:{RingoBotHelper.LowerWord(hashtag)}", pk);
        }
示例#4
0
        public Station(ConversationInfo info, string hashtag, Album album, Playlist playlist, User owner, string username = null)
        {
            (string id, string pk) = EncodeIds(info, hashtag, username);
            Id           = id;
            PartitionKey = pk;
            Type         = TypeName;

            string name = album?.Name ?? playlist?.Name;

            Name          = name;
            Hashtag       = hashtag;
            Album         = album;
            Playlist      = playlist;
            Owner         = owner;
            CreatedDate   = DateTime.UtcNow;
            IsActive      = true;
            IsUserStation = !string.IsNullOrEmpty(username);
            ListenerCount = 1;

            ActiveListeners = new[] { new Listener(this, owner) };
        }
示例#5
0
 internal static (string id, string pk) EncodeIds(ConversationInfo info) => EncodeIds(info, info.FromId);