]> git.giacomolli.uk - onechat/blobdiff - whatsapp.go
Check the width of comment lines
[onechat] / whatsapp.go
index 57bfab078301a01907a3c6d898421f24c37df814..4950d280319be4ec6e99db7af475126216e685d4 100644 (file)
@@ -2,6 +2,7 @@ package main
 
 import (
        "context"
 
 import (
        "context"
+       "crypto/sha256"
        "database/sql"
        "errors"
        "fmt"
        "database/sql"
        "errors"
        "fmt"
@@ -466,7 +467,7 @@ func (w *WhatsApp) Find(ctx context.Context, name string) (string, error) {
 // Send returns the answer of whatsapp_send for text and an optional stored
 // image to chat, with the durable send id that whatsappSend describes.
 func (w *WhatsApp) Send(ctx context.Context, id, chat, text, image string) (string, error) {
 // Send returns the answer of whatsapp_send for text and an optional stored
 // image to chat, with the durable send id that whatsappSend describes.
 func (w *WhatsApp) Send(ctx context.Context, id, chat, text, image string) (string, error) {
-       return whatsappSend(ctx, w.link(), w.groups, w.state, w.inbox.images, w.clock, id, chat, text, image)
+       return whatsappSend(ctx, w.link(), w.groups, w.state, w.inbox.images, w.logger, w.clock, id, chat, text, image)
 }
 
 func (w *WhatsApp) sessionPath() string {
 }
 
 func (w *WhatsApp) sessionPath() string {
@@ -1144,6 +1145,14 @@ func whatsappOwnIDs(ids ...string) []string {
        return own
 }
 
        return own
 }
 
+// whatsappChatHash returns a short hash of chat for the daemon log, so that a
+// log line can tell chats apart without a phone number.
+func whatsappChatHash(chat types.JID) string {
+       digest := sha256.Sum256([]byte(chat.ToNonAD().String()))
+
+       return fmt.Sprintf("%x", digest[:6])
+}
+
 // whatsappRedact replaces each of the own IDs own in text with OWN.
 func whatsappRedact(own []string, text string) string {
        for _, id := range own {
 // whatsappRedact replaces each of the own IDs own in text with OWN.
 func whatsappRedact(own []string, text string) string {
        for _, id := range own {