git_bug/entities/identity/snapshot/
history_step.rs

1// git-bug-rs - A rust library for interfacing with git-bug repositories
2//
3// Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de>
4// SPDX-License-Identifier: GPL-3.0-or-later
5//
6// This file is part of git-bug-rs/git-gub.
7//
8// You should have received a copy of the License along with this program.
9// If not, see <https://www.gnu.org/licenses/agpl.txt>.
10
11//! Implementation of the [`HistoryStep`] trait for use in
12//! [`Identities`][`super::Identity`].
13
14use url::Url;
15
16use crate::replica::entity::{
17    identity::IdentityStub, snapshot::timeline::history_step::HistoryStep, timestamp::TimeStamp,
18};
19
20/// The possible steps in the history of an [`Identity`][`super::Identity`].
21#[derive(Debug, Clone)]
22pub enum IdentityHistoryStep {
23    /// A name change in the history.
24    Name(NameHistoryStep),
25
26    /// An email change in the history.
27    Email(EmailHistoryStep),
28
29    /// An login name change in the history.
30    LoginName(LoginNameHistoryStep),
31
32    /// An avatar URL change in the history.
33    AvatarUrl(AvatarUrlHistoryStep),
34
35    /// A metadata change in the history.
36    Metadata(MetadataHistoryStep),
37}
38
39impl HistoryStep for IdentityHistoryStep {
40    fn author(&self) -> IdentityStub {
41        match self {
42            IdentityHistoryStep::Name(a) => a.author,
43            IdentityHistoryStep::Email(a) => a.author,
44            IdentityHistoryStep::LoginName(a) => a.author,
45            IdentityHistoryStep::AvatarUrl(a) => a.author,
46            IdentityHistoryStep::Metadata(a) => a.author,
47        }
48    }
49
50    fn at(&self) -> TimeStamp {
51        match self {
52            IdentityHistoryStep::Name(name_history_step) => name_history_step.at,
53            IdentityHistoryStep::Email(email_history_step) => email_history_step.at,
54            IdentityHistoryStep::LoginName(login_name_history_step) => login_name_history_step.at,
55            IdentityHistoryStep::AvatarUrl(avatar_url_history_step) => avatar_url_history_step.at,
56            IdentityHistoryStep::Metadata(metadata_history_step) => metadata_history_step.at,
57        }
58    }
59}
60
61/// One version of the [`Identity's`][`super::Identity`] name in the history.
62#[derive(Debug, Clone)]
63pub struct NameHistoryStep {
64    /// The author of the change.
65    pub author: IdentityStub,
66
67    /// The new name.
68    pub name: String,
69
70    /// When this change happened.
71    pub at: TimeStamp,
72}
73
74/// One version of the [`Identity's`][`super::Identity`] email in the history.
75#[derive(Debug, Clone)]
76pub struct EmailHistoryStep {
77    /// The author of the change.
78    pub author: IdentityStub,
79
80    /// The new email.
81    pub email: String,
82
83    /// When this change happened.
84    pub at: TimeStamp,
85}
86
87/// One version of the [`Identity's`][`super::Identity`] login name in the
88/// history.
89#[derive(Debug, Clone)]
90pub struct LoginNameHistoryStep {
91    /// The author of the change.
92    pub author: IdentityStub,
93
94    /// The new email.
95    pub login_name: String,
96
97    /// When this change happened.
98    pub at: TimeStamp,
99}
100
101/// One version of the [`Identity's`][`super::Identity`] avatar URL in the
102/// history.
103#[derive(Debug, Clone)]
104pub struct AvatarUrlHistoryStep {
105    /// The author of the change.
106    pub author: IdentityStub,
107
108    /// The new URL.
109    pub avatar_url: Url,
110
111    /// When this change happened.
112    pub at: TimeStamp,
113}
114
115/// One version of the [`Identity's`][`super::Identity`] metadata in the
116/// history.
117#[derive(Debug, Clone)]
118pub struct MetadataHistoryStep {
119    /// The author of the change.
120    pub author: IdentityStub,
121
122    /// The new metadata.
123    pub metadata: Vec<(String, String)>,
124
125    /// When this change happened.
126    pub at: TimeStamp,
127}