Dont use system time for clock value in create group chat event
This commit is contained in:
parent
4d2ecb0055
commit
7be1fcb978
|
@ -637,13 +637,17 @@ func (m *Messenger) CreateGroupChatWithMembers(ctx context.Context, name string,
|
|||
logger := m.logger.With(zap.String("site", "CreateGroupChatWithMembers"))
|
||||
logger.Info("Creating group chat", zap.String("name", name), zap.Any("members", members))
|
||||
chat := CreateGroupChat(m.getTimesource())
|
||||
group, err := v1protocol.NewGroupWithCreator(name, m.identity)
|
||||
|
||||
clock, _ := chat.NextClockAndTimestamp(m.getTimesource())
|
||||
|
||||
group, err := v1protocol.NewGroupWithCreator(name, clock, m.identity)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
chat.LastClockValue = clock
|
||||
chat.updateChatFromProtocolGroup(group)
|
||||
|
||||
clock, _ := chat.NextClockAndTimestamp(m.getTimesource())
|
||||
clock, _ = chat.NextClockAndTimestamp(m.getTimesource())
|
||||
// Add members
|
||||
event := v1protocol.NewMembersAddedEvent(members, clock)
|
||||
event.ChatID = chat.ID
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/google/uuid"
|
||||
|
@ -232,9 +231,8 @@ func NewGroupWithEvents(chatID string, events []MembershipUpdateEvent) (*Group,
|
|||
return newGroup(chatID, events)
|
||||
}
|
||||
|
||||
func NewGroupWithCreator(name string, creator *ecdsa.PrivateKey) (*Group, error) {
|
||||
func NewGroupWithCreator(name string, clock uint64, creator *ecdsa.PrivateKey) (*Group, error) {
|
||||
chatID := groupChatID(&creator.PublicKey)
|
||||
clock := TimestampInMsFromTime(time.Now())
|
||||
chatCreated := NewChatCreatedEvent(name, clock)
|
||||
chatCreated.ChatID = chatID
|
||||
err := chatCreated.Sign(creator)
|
||||
|
|
|
@ -64,7 +64,7 @@ func TestSignMembershipUpdate(t *testing.T) {
|
|||
func TestGroupCreator(t *testing.T) {
|
||||
key, err := crypto.GenerateKey()
|
||||
require.NoError(t, err)
|
||||
g, err := NewGroupWithCreator("abc", key)
|
||||
g, err := NewGroupWithCreator("abc", 20, key)
|
||||
require.NoError(t, err)
|
||||
creator, err := g.creator()
|
||||
require.NoError(t, err)
|
||||
|
|
Loading…
Reference in New Issue