Skip to content

Commit 0d8c3f9

Browse files
committed
Add Snapshot::appendTimelineItem methode
1 parent 9020cdd commit 0d8c3f9

File tree

5 files changed

+13
-21
lines changed

5 files changed

+13
-21
lines changed

bug/op_add_comment.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,17 @@ func (op *AddCommentOperation) Id() entity.Id {
3030
func (op *AddCommentOperation) Apply(snapshot *Snapshot) {
3131
snapshot.addActor(op.Author_)
3232
snapshot.addParticipant(op.Author_)
33-
3433
comment := Comment{
3534
id: entity.CombineIds(snapshot.Id(), op.Id()),
3635
Message: op.Message,
3736
Author: op.Author_,
3837
Files: op.Files,
3938
UnixTime: timestamp.Timestamp(op.UnixTime),
4039
}
41-
4240
snapshot.appendComment(comment)
43-
44-
item := &AddCommentTimelineItem{
41+
snapshot.appendTimelineItem(&AddCommentTimelineItem{
4542
CommentTimelineItem: NewCommentTimelineItem(comment),
46-
}
47-
48-
snapshot.timeline = append(snapshot.timeline, item)
43+
})
4944
}
5045

5146
func (op *AddCommentOperation) GetFiles() []repository.Hash {

bug/op_label_change.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,13 @@ func (op *LabelChangeOperation) Apply(snapshot *Snapshot) {
3838
snapshot.removeLabel(label)
3939
}
4040

41-
item := &LabelChangeTimelineItem{
41+
snapshot.appendTimelineItem(&LabelChangeTimelineItem{
4242
id: op.Id(),
4343
Author: op.Author_,
4444
UnixTime: timestamp.Timestamp(op.UnixTime),
4545
Added: op.Added,
4646
Removed: op.Removed,
47-
}
48-
49-
snapshot.timeline = append(snapshot.timeline, item)
47+
})
5048
}
5149

5250
func (op *LabelChangeOperation) Validate() error {

bug/op_set_status.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,12 @@ func (op *SetStatusOperation) Id() entity.Id {
2525
func (op *SetStatusOperation) Apply(snapshot *Snapshot) {
2626
snapshot.setStatusTo(op.Status)
2727
snapshot.addActor(op.Author_)
28-
29-
item := &SetStatusTimelineItem{
28+
snapshot.appendTimelineItem(&SetStatusTimelineItem{
3029
id: op.Id(),
3130
Author: op.Author_,
3231
UnixTime: timestamp.Timestamp(op.UnixTime),
3332
Status: op.Status,
34-
}
35-
36-
snapshot.timeline = append(snapshot.timeline, item)
33+
})
3734
}
3835

3936
func (op *SetStatusOperation) Validate() error {

bug/op_set_title.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,13 @@ func (op *SetTitleOperation) Id() entity.Id {
2727
func (op *SetTitleOperation) Apply(snapshot *Snapshot) {
2828
snapshot.changeTitleTo(op.Title)
2929
snapshot.addActor(op.Author_)
30-
31-
item := &SetTitleTimelineItem{
30+
snapshot.appendTimelineItem(&SetTitleTimelineItem{
3231
id: op.Id(),
3332
Author: op.Author_,
3433
UnixTime: timestamp.Timestamp(op.UnixTime),
3534
Title: op.Title,
3635
Was: op.Was,
37-
}
38-
39-
snapshot.timeline = append(snapshot.timeline, item)
36+
})
4037
}
4138

4239
func (op *SetTitleOperation) Validate() error {

bug/snapshot.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@ func (snap *Snapshot) addParticipant(participant identity.Interface) {
165165
snap.participants = append(snap.participants, participant)
166166
}
167167

168+
// Append the supplied timelineitem to the snapshots timeline
169+
func (snap *Snapshot) appendTimelineItem(item TimelineItem) {
170+
snap.timeline = append(snap.timeline, item)
171+
}
172+
168173
// HasParticipant return true if the id is a participant
169174
func (snap *Snapshot) HasParticipant(id entity.Id) bool {
170175
for _, p := range snap.participants {

0 commit comments

Comments
 (0)