Skip to content

Commit

Permalink
Fill text hash for outgoing messages
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Jul 15, 2024
1 parent 07315c6 commit 3739db5
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions portal.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ func (portal *Portal) isOutgoingMessage(msg *gmproto.Message) *database.Message
Timestamp: time.UnixMicro(msg.GetTimestamp()),
SenderID: msg.ParticipantID,
PartCount: len(msg.GetMessageInfo()),
TextHash: getTextHash(msg),
}, out.ID, nil, true)
}
return nil
Expand All @@ -451,6 +452,25 @@ func hasInProgressMedia(msg *gmproto.Message) bool {
return false
}

func getTextHash(msg *gmproto.Message) string {
textHasher := sha256.New()
textHasher.Write([]byte(msg.GetSubject()))
textHasher.Write([]byte{0x00})
hasText := len(msg.GetSubject()) > 0
for _, part := range msg.GetMessageInfo() {
switch data := part.Data.(type) {
case *gmproto.MessageInfo_MessageContent:
hasText = true
textHasher.Write([]byte(data.MessageContent.GetContent()))
textHasher.Write([]byte{0x00})
}
}
if hasText {
return hex.EncodeToString(textHasher.Sum(nil))
}
return ""
}

func checkMessageWasEdited(msg *gmproto.Message, dbMsg *database.Message) (edited bool, changes *zerolog.Event) {
textHasher := sha256.New()
textHasher.Write([]byte(msg.GetSubject()))
Expand Down

0 comments on commit 3739db5

Please sign in to comment.