Create from a database row representation
(row: SessionRow)
| 668 | |
| 669 | /// Create from a database row representation |
| 670 | pub fn from_row(row: SessionRow) -> Self { |
| 671 | let summary = if row.summary_additions.is_some() |
| 672 | || row.summary_deletions.is_some() |
| 673 | || row.summary_files.is_some() |
| 674 | { |
| 675 | Some(SessionSummary { |
| 676 | additions: row.summary_additions.unwrap_or(0), |
| 677 | deletions: row.summary_deletions.unwrap_or(0), |
| 678 | files: row.summary_files.unwrap_or(0), |
| 679 | diffs: None, |
| 680 | }) |
| 681 | } else { |
| 682 | None |
| 683 | }; |
| 684 | |
| 685 | let share = row.share_url.map(|url| SessionShare { url }); |
| 686 | |
| 687 | let status = if row.time_archived.is_some() { |
| 688 | SessionStatus::Archived |
| 689 | } else if row.time_compacting.is_some() { |
| 690 | SessionStatus::Compacting |
| 691 | } else { |
| 692 | SessionStatus::Active |
| 693 | }; |
| 694 | |
| 695 | let created_at = DateTime::from_timestamp_millis(row.time_created).unwrap_or_else(Utc::now); |
| 696 | let updated_at = DateTime::from_timestamp_millis(row.time_updated).unwrap_or_else(Utc::now); |
| 697 | |
| 698 | Self { |
| 699 | id: row.id, |
| 700 | slug: row.slug, |
| 701 | project_id: row.project_id, |
| 702 | directory: row.directory, |
| 703 | parent_id: row.parent_id, |
| 704 | title: row.title, |
| 705 | version: row.version, |
| 706 | time: SessionTime { |
| 707 | created: row.time_created, |
| 708 | updated: row.time_updated, |
| 709 | compacting: row.time_compacting, |
| 710 | archived: row.time_archived, |
| 711 | }, |
| 712 | messages: Vec::new(), |
| 713 | summary, |
| 714 | share, |
| 715 | revert: row.revert, |
| 716 | permission: row.permission, |
| 717 | usage: None, |
| 718 | status, |
| 719 | metadata: HashMap::new(), |
| 720 | created_at, |
| 721 | updated_at, |
| 722 | } |
| 723 | } |
| 724 | } |
| 725 | |
| 726 | /// Database row representation |