Exemplo n.º 1
0
        public void InsertArchiveMessage(JsonMessage message, DateTime lastFetchedUtc)
        {
            long groupId;

            if (message.IsDirectMessage)
            {
                groupId = YamsterGroup.ConversationsGroupId;
            }
            else
            {
                groupId = message.GroupId ?? YamsterGroup.AllCompanyGroupId;
            }

            DbArchiveMessageRecord archiveRecord = new DbArchiveMessageRecord();

            archiveRecord.Id             = message.Id;
            archiveRecord.ThreadId       = message.ThreadId;
            archiveRecord.GroupId        = groupId;
            archiveRecord.LastFetchedUtc = lastFetchedUtc;
            archiveRecord.Json           = message.RawJson;
            ArchiveMessages.InsertRecord(archiveRecord, SQLiteConflictResolution.Replace);

            if (MessageInserted != null)
            {
                MessageInserted(this, new ArchiveInsertEventArgs <DbArchiveMessageRecord>(archiveRecord));
            }
        }
Exemplo n.º 2
0
 public void SetObjectVersion(string objectName, int version)
 {
     Versions.InsertRecord(new DbVersion()
     {
         ObjectName = objectName, Version = version
     },
                           SQLiteConflictResolution.Replace);
 }
Exemplo n.º 3
0
        void UpdateConversation(DbArchiveRecord archiveConversationRef)
        {
            JsonConversationReference conversationRef = SQLiteJsonConverter.LoadFromJson <JsonConversationReference>(
                archiveConversationRef.Json);

            DbConversation coreConversation = new DbConversation();

            coreConversation.LastFetchedUtc = archiveConversationRef.LastFetchedUtc;
            coreConversation.ConversationId = conversationRef.Id;
            coreConversation.ParticipantUserIds.AssignFrom(conversationRef.Participants.Select(x => x.Id));

            Conversations.InsertRecord(coreConversation, SQLiteConflictResolution.Replace);
        }
Exemplo n.º 4
0
        public void UpdateJsonSyncingFeed(long groupId, JsonSyncingFeed state)
        {
            DbSyncingFeed row = new DbSyncingFeed();

            row.FeedId = groupId;

            // Update the aggregated properties
            row.LastUpdateUtc      = state.LastUpdateUtc;
            row.LastCheckNewUtc    = state.LastCheckNewUtc;
            row.ReachedEmptyResult = state.ReachedEmptyResult;
            row.HasSpanGaps        = state.HasSpanGaps;

            row.Json = SQLiteJsonConverter.SaveToJson(state);
            SyncingFeeds.InsertRecord(row, SQLiteConflictResolution.Replace);
        }
Exemplo n.º 5
0
        void UpdateGroup(DbArchiveRecord archiveGroupRef)
        {
            JsonGroupReference groupRef = SQLiteJsonConverter.LoadFromJson <JsonGroupReference>(archiveGroupRef.Json);

            bool incompleteRecord = false;

            DbGroup coreGroup = new DbGroup();

            coreGroup.LastFetchedUtc   = archiveGroupRef.LastFetchedUtc;
            coreGroup.GroupId          = groupRef.Id;
            coreGroup.GroupName        = groupRef.FullName ?? "";
            coreGroup.GroupDescription = groupRef.Description ?? "";

            if (!Enum.TryParse <DbGroupPrivacy>(groupRef.Privacy, true, out coreGroup.Privacy))
            {
                if (!string.IsNullOrEmpty(groupRef.Privacy))
                {
                    throw new YamsterProtocolException(string.Format("Unsupported group privacy \"{0}\"", coreGroup.Privacy));
                }
                coreGroup.Privacy = DbGroupPrivacy.Unknown;
                incompleteRecord  = true;
            }

            coreGroup.WebUrl     = groupRef.WebUrl ?? "";
            coreGroup.MugshotUrl = groupRef.MugshotUrl ?? "";

            // If the record is incomplete, don't overwrite an existing record that might have complete data
            // TODO: this merging should be more fine-grained
            Groups.InsertRecord(coreGroup, incompleteRecord ? SQLiteConflictResolution.Ignore : SQLiteConflictResolution.Replace);

            DbGroupState groupState = new DbGroupState()
            {
                GroupId = groupRef.Id
            };

            GroupStates.InsertRecord(groupState, SQLiteConflictResolution.Ignore);
        }
Exemplo n.º 6
0
        void UpdateMessage(DbArchiveMessageRecord archiveMessage)
        {
            JsonMessage message = SQLiteJsonConverter.LoadFromJson <JsonMessage>(archiveMessage.Json);

            DbMessage coreMessage = new DbMessage();

            coreMessage.LastFetchedUtc = archiveMessage.LastFetchedUtc;
            coreMessage.MessageId      = message.Id;

            coreMessage.GroupId            = archiveMessage.GroupId;
            coreMessage.ThreadId           = message.ThreadId;
            coreMessage.ConversationId     = message.ConversationId;
            coreMessage.CreatedDate        = message.Created;
            coreMessage.SenderUserId       = message.SenderId;
            coreMessage.MessageIdRepliedTo = message.RepliedToId ?? 0;

            coreMessage.LikingUserIds.AssignFrom(message.Likes.Users.Select(x => x.UserId));
            foreach (var likingUser in message.Likes.Users)
            {
                // We don't get a proper UserReference for liking users, but we do get
                // some basic information.  Write this to the Users table *only* if there
                // is not already some real data there.
                DbUser coreUser = new DbUser();
                coreUser.LastFetchedUtc = archiveMessage.LastFetchedUtc;
                coreUser.UserId         = likingUser.UserId;
                coreUser.FullName       = likingUser.FullName ?? "";
                coreUser.JobTitle       = "";
                coreUser.WebUrl         = ""; // we could infer this from likingUser.Alias
                coreUser.MugshotUrl     = "";

                // Ignore = only write if there isn't already an existing record
                Users.InsertRecord(coreUser, SQLiteConflictResolution.Ignore);
            }

            coreMessage.LikesCount = message.Likes.Count;
            coreMessage.NotifiedUserIds.AssignFrom(message.NotifiedUserIds ?? new long[0]);
            coreMessage.Body   = message.Body.Plain ?? "";
            coreMessage.WebUrl = message.Permalink ?? "";

            var firstImageAttachment = message.Attachments.Where(x => x.AttachmentType == "image").FirstOrDefault();

            if (firstImageAttachment != null)
            {
                coreMessage.AttachmentFilename          = firstImageAttachment.Name;
                coreMessage.AttachmentWebUrl            = firstImageAttachment.WebUrl;
                coreMessage.AttachmentScaledUrlTemplate = firstImageAttachment.ScaledUrlTemplate;
                coreMessage.AttachmentWidth             = firstImageAttachment.Width ?? 0;
                coreMessage.AttachmentHeight            = firstImageAttachment.Height ?? 0;
            }


            if (!Enum.TryParse(message.MessageType, true, out coreMessage.MessageType))
            {
                coreMessage.MessageType = DbMessageType.Unknown;
            }

            Messages.InsertRecord(coreMessage, SQLiteConflictResolution.Replace);

            DbMessageState messageState = new DbMessageState()
            {
                MessageId = archiveMessage.Id
            };

            MessageStates.InsertRecord(messageState, SQLiteConflictResolution.Ignore);

            // Ensure that every message has a corresponding DbThreadState for its thread
            DbThreadState threadState = new DbThreadState()
            {
                ThreadId = coreMessage.ThreadId
            };

            ThreadStates.InsertRecord(threadState, SQLiteConflictResolution.Ignore);
        }