示例#1
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);
        }
示例#2
0
        internal void UpdateConversation(DbConversation conversation, YamsterModelEventCollector eventCollector)
        {
            this.ConversationId = conversation.ConversationId;

            var users = new List <YamsterUser>(conversation.ParticipantUserIds.Count);

            foreach (long userId in conversation.ParticipantUserIds)
            {
                var user = YamsterCache.FetchUserById(userId, eventCollector);
                users.Add(user);
            }
            this.participants = new YamsterUserSet(users);
            eventCollector.NotifyAfterUpdate(this);
        }
示例#3
0
        void ProcessDbConversation(DbConversation record)
        {
            // Does the thread exist yet?
            YamsterThread thread;

            if (threadsByConversationId.TryGetValue(record.ConversationId, out thread))
            {
                var eventCollector = new YamsterModelEventCollector();
                thread.UpdateConversation(record, eventCollector);
                eventCollector.FireEvents();
            }
            else
            {
                // Stash the conversation and deal with it later
                unresolvedConversationsById[record.ConversationId] = record;
            }
        }
示例#4
0
        void ReadCsvFiles()
        {
            using (var csvReader = new CsvReader(Path.Combine(this.FolderPath, "Networks.csv")))
            {
                int col_Id  = csvReader.GetColumnIndex("id");
                int col_Url = csvReader.GetColumnIndex("url");

                while (csvReader.ReadNextLine())
                {
                    csvReader.WrapExceptions(() =>
                    {
                        networkId  = long.Parse(csvReader[col_Id]);
                        networkUrl = csvReader[col_Url];
                    });
                }
            }

            using (var csvReader = new CsvReader(Path.Combine(this.FolderPath, "Groups.csv")))
            {
                int col_Id          = csvReader.GetColumnIndex("id");
                int col_Name        = csvReader.GetColumnIndex("name");
                int col_Description = csvReader.GetColumnIndex("description");
                int col_Private     = csvReader.GetColumnIndex("private");
                int col_Deleted     = csvReader.GetColumnIndex("deleted");

                while (csvReader.ReadNextLine())
                {
                    DbGroup group     = new DbGroup();
                    bool    isDeleted = false;
                    csvReader.WrapExceptions(() =>
                    {
                        group.GroupId          = long.Parse(csvReader[col_Id]);
                        group.GroupName        = csvReader[col_Name];
                        group.GroupDescription = csvReader[col_Description];

                        // TODO: How to recognize DbGroupPrivacy.Restricted?
                        bool isPrivate = bool.Parse(csvReader[col_Private]);
                        group.Privacy  = isPrivate ? DbGroupPrivacy.Private : DbGroupPrivacy.Public;

                        group.WebUrl = networkUrl + "/#/threads/inGroup?type=in_group&feedId=" + group.GroupId;

                        // TODO: How to obtain MugshotUrl?

                        isDeleted = bool.Parse(csvReader[col_Deleted]);
                    });

                    groupsById.Add(group.GroupId, group);

                    if (isDeleted)
                    {
                        deletedGroups.Add(group.GroupId);
                    }
                }
            }

            using (var csvReader = new CsvReader(Path.Combine(this.FolderPath, "Users.csv")))
            {
                int col_Id       = csvReader.GetColumnIndex("id");
                int col_Name     = csvReader.GetColumnIndex("name");
                int col_JobTitle = csvReader.GetColumnIndex("job_title");
                int col_Email    = csvReader.GetColumnIndex("email");
                int col_State    = csvReader.GetColumnIndex("state");

                while (csvReader.ReadNextLine())
                {
                    DbUser user      = new DbUser();
                    bool   isDeleted = false;
                    csvReader.WrapExceptions(() =>
                    {
                        user.UserId = long.Parse(csvReader[col_Id]);
                        // TODO: Is there a way to obtain the correct alias?
                        user.Alias    = csvReader[col_Email].Replace('@', '_');
                        user.Email    = csvReader[col_Email];
                        user.FullName = csvReader[col_Name];
                        user.JobTitle = csvReader[col_JobTitle];

                        // TODO: We need the alias to calculate user.WebUrl

                        // TODO: user.MugshotUrl

                        isDeleted = csvReader[col_State].Trim().ToUpper() == "SOFT_DELETE";
                    });

                    usersById.Add(user.UserId, user);

                    if (isDeleted)
                    {
                        deletedUsers.Add(user.UserId);
                    }
                }
            }

            using (var csvReader = new CsvReader(Path.Combine(this.FolderPath, "Messages.csv")))
            {
                int col_Id             = csvReader.GetColumnIndex("id");
                int col_GroupId        = csvReader.GetColumnIndex("group_id");
                int col_ThreadId       = csvReader.GetColumnIndex("thread_id");
                int col_ConversationId = csvReader.GetColumnIndex("conversation_id");

                int col_InPrivateGroup        = csvReader.GetColumnIndex("in_private_group");
                int col_InPrivateConversation = csvReader.GetColumnIndex("in_private_conversation");
                int col_Participants          = csvReader.GetColumnIndex("participants");

                int col_CreatedAt   = csvReader.GetColumnIndex("created_at");
                int col_SenderId    = csvReader.GetColumnIndex("sender_id");
                int col_RepliedToId = csvReader.GetColumnIndex("replied_to_id");
                int col_Body        = csvReader.GetColumnIndex("body");
                int col_DeletedAt   = csvReader.GetColumnIndex("deleted_at");

                while (csvReader.ReadNextLine())
                {
                    DbMessage message   = new DbMessage();
                    bool      isDeleted = false;
                    csvReader.WrapExceptions(() =>
                    {
                        message.MessageId = long.Parse(csvReader[col_Id]);
                        message.GroupId   = ParseLongWithDefault(csvReader[col_GroupId], YamsterGroup.AllCompanyGroupId);
                        message.ThreadId  = long.Parse(csvReader[col_ThreadId]);

                        bool inPrivateGroup        = bool.Parse(csvReader[col_InPrivateGroup]);
                        bool inPrivateConversation = bool.Parse(csvReader[col_InPrivateConversation]);

                        if (inPrivateConversation)
                        {
                            // This is apparently broken
                            // long conversationId = ParseLongWithDefault(csvReader[col_ConversationId], 0);
                            long conversationId = message.ThreadId;

                            DbConversation conversation;
                            if (!conversationsById.TryGetValue(conversationId, out conversation))
                            {
                                conversation = new DbConversation();
                                conversation.ConversationId = conversationId;
                                ParseParticipants(conversation.ParticipantUserIds, csvReader[col_Participants]);
                                conversationsById.Add(conversationId, conversation);
                            }

                            message.ConversationId = conversationId;
                            message.GroupId        = YamsterGroup.ConversationsGroupId;
                        }

                        message.CreatedDate        = DateTime.Parse(csvReader[col_CreatedAt]);
                        message.SenderUserId       = long.Parse(csvReader[col_SenderId]);
                        message.MessageIdRepliedTo = ParseLongWithDefault(csvReader[col_RepliedToId], 0);

                        // TODO: Likes?

                        // TODO: Parse message.NotifiedUserIds from "CC" line
                        message.Body   = csvReader[col_Body];
                        message.WebUrl = networkUrl + "/messages/" + message.MessageId;

                        // TODO: Attachments?

                        message.MessageType = DbMessageType.Update;

                        isDeleted = !string.IsNullOrWhiteSpace(csvReader[col_DeletedAt]);
                    });

                    messagesById.Add(message.MessageId, message);

                    if (isDeleted)
                    {
                        deletedMessages.Add(message.MessageId);
                    }
                    else
                    {
                        if (message.ConversationId != 0)
                        {
                            notDeletedConversations.Add(message.ConversationId);
                        }
                    }
                }
            }
        }