Ejemplo n.º 1
0
        public static SignalGroup GetOrCreateGroupLocked(string groupId, long timestamp)
        {
            SignalGroup dbgroup;

            lock (DBLock)
            {
                using (var ctx = new SignalDBContext())
                {
                    dbgroup = ctx.Groups
                              .Where(g => g.ThreadId == groupId)
                              .Include(g => g.GroupMemberships)
                              .ThenInclude(gm => gm.Contact)
                              .SingleOrDefault();
                    if (dbgroup == null)
                    {
                        dbgroup = new SignalGroup()
                        {
                            ThreadId            = groupId,
                            ThreadDisplayName   = "Unknown group",
                            LastActiveTimestamp = timestamp,
                            AvatarFile          = null,
                            UnreadCount         = 0,
                            CanReceive          = false,
                            GroupMemberships    = new List <GroupMembership>()
                        };
                        ctx.Add(dbgroup);
                        ctx.SaveChanges();
                    }
                }
            }
            return(dbgroup);
        }
Ejemplo n.º 2
0
        public static SignalGroup InsertOrUpdateGroupLocked(string groupId, string displayname, string avatarfile, bool canReceive, long timestamp, MainPageViewModel mpvm)
        {
            SignalGroup dbgroup;
            bool        is_new = false;

            lock (DBLock)
            {
                using (var ctx = new SignalDBContext())
                {
                    dbgroup = ctx.Groups
                              .Where(g => g.ThreadId == groupId)
                              .Include(g => g.GroupMemberships)
                              .ThenInclude(gm => gm.Contact)
                              .SingleOrDefault();
                    if (dbgroup == null)
                    {
                        is_new  = true;
                        dbgroup = new SignalGroup()
                        {
                            ThreadId            = groupId,
                            ThreadDisplayName   = displayname,
                            LastActiveTimestamp = timestamp,
                            AvatarFile          = avatarfile,
                            UnreadCount         = 0,
                            CanReceive          = canReceive,
                            GroupMemberships    = new List <GroupMembership>()
                        };
                        ctx.Add(dbgroup);
                    }
                    else
                    {
                        dbgroup.ThreadDisplayName   = displayname;
                        dbgroup.LastActiveTimestamp = timestamp;
                        dbgroup.AvatarFile          = avatarfile;
                        dbgroup.CanReceive          = true;
                    }
                    ctx.SaveChanges();
                }
                if (is_new)
                {
                    Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                    {
                        mpvm.AddThread(dbgroup);
                    }).AsTask().Wait();
                }
                else
                {
                    Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                    {
                        mpvm.UIUpdateThread(dbgroup);
                    }).AsTask().Wait();
                }
            }
            return(dbgroup);
        }
Ejemplo n.º 3
0
        public static SignalGroup InsertOrUpdateGroupLocked(string groupId, string displayname, string avatarfile, bool canReceive, long timestamp)
        {
            SignalGroup dbgroup;

            lock (DBLock)
            {
                using (var ctx = new SignalDBContext())
                {
                    dbgroup = ctx.Groups
                              .Where(g => g.ThreadId == groupId)
                              .Include(g => g.GroupMemberships)
                              .ThenInclude(gm => gm.Contact)
                              .SingleOrDefault();
                    if (dbgroup == null)
                    {
                        dbgroup = new SignalGroup()
                        {
                            ThreadId            = groupId,
                            ThreadDisplayName   = displayname,
                            LastActiveTimestamp = timestamp,
                            AvatarFile          = avatarfile,
                            UnreadCount         = 0,
                            CanReceive          = canReceive,
                            GroupMemberships    = new List <GroupMembership>()
                        };
                        ctx.Add(dbgroup);
                    }
                    else
                    {
                        dbgroup.ThreadDisplayName   = displayname;
                        dbgroup.LastActiveTimestamp = timestamp;
                        dbgroup.AvatarFile          = avatarfile;
                        dbgroup.CanReceive          = true;
                    }
                    ctx.SaveChanges();
                }
            }
            return(dbgroup);
        }