Esempio n. 1
0
        /// <summary>
        /// Ask Signal for group name according to its ID and store it for further use.
        /// </summary>
        /// <param name="groupId"></param>
        /// <returns></returns>
        public async Task <string> GetGroupName(byte[] groupId)
        {
            try
            {
                var groups = groupsNames.GetAll();
                var group  = groups.FirstOrDefault(x => x.groupId.SequenceEqual(groupId));
                if (group == null || DateTime.Now.Subtract(group.lastSync).TotalDays >= 1)
                {
                    Log.Write($"Fetching group name for {string.Join(",", groupId)}");
                    Log.Write($"Groups names in memory: {groups.Count.ToString()}", Log.LogLevel.DEBUG);

                    return(await Task.Run(() =>
                    {
                        string groupName = _service.getGroupName(groupId);

                        if (group != null)
                        {
                            groupsNames.Remove(group);
                        }

                        groupsNames.Add(new GroupIdentification()
                        {
                            groupId = groupId,
                            groupName = groupName,
                            lastSync = DateTime.Now
                        });

                        Log.Write($"Group members: {string.Join(", ", _service.getGroupMembers(groupId))}", Log.LogLevel.DEBUG);

                        return groupName;
                    }));
                }
                else
                {
                    Log.Write($"Loaded name {group.groupName} for {string.Join(",", groupId)}", Log.LogLevel.DEBUG);
                    return(group.groupName);
                }
            }
            catch (Exception e)
            {
                Log.Write($"{e.Message} | StackTrace: {e.StackTrace}", Log.LogLevel.ERROR);
                return("");
            }
        }