浏览代码

Handle identity changes properly. Fixes #384

Tulir Asokan 3 年之前
父节点
当前提交
a8beec8754
共有 4 个文件被更改,包括 40 次插入16 次删除
  1. 3 3
      go.mod
  2. 6 5
      go.sum
  3. 10 5
      portal.go
  4. 21 3
      user.go

+ 3 - 3
go.mod

@@ -8,7 +8,7 @@ require (
 	github.com/mattn/go-sqlite3 v1.14.9
 	github.com/prometheus/client_golang v1.11.0
 	github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
-	go.mau.fi/whatsmeow v0.0.0-20211108174035-d6fe7ad15eb0
+	go.mau.fi/whatsmeow v0.0.0-20211109154617-2fabbeecad6a
 	golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d
 	google.golang.org/protobuf v1.27.1
 	gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
@@ -33,8 +33,8 @@ require (
 	github.com/tidwall/match v1.1.1 // indirect
 	github.com/tidwall/pretty v1.2.0 // indirect
 	github.com/tidwall/sjson v1.2.3 // indirect
-	go.mau.fi/libsignal v0.0.0-20211024113310-f9fc6a1855f2 // indirect
-	golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect
+	go.mau.fi/libsignal v0.0.0-20211109153248-a67163214910 // indirect
+	golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa // indirect
 	golang.org/x/net v0.0.0-20211020060615-d418f374d309 // indirect
 	golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 // indirect
 	gopkg.in/yaml.v2 v2.4.0 // indirect

+ 6 - 5
go.sum

@@ -137,17 +137,18 @@ github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs=
 github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
 github.com/tidwall/sjson v1.2.3 h1:5+deguEhHSEjmuICXZ21uSSsXotWMA0orU783+Z7Cp8=
 github.com/tidwall/sjson v1.2.3/go.mod h1:5WdjKx3AQMvCJ4RG6/2UYT7dLrGvJUV1x4jdTAyGvZs=
-go.mau.fi/libsignal v0.0.0-20211024113310-f9fc6a1855f2 h1:xpQTMgJGGaF+c8jV/LA/FVXAPJxZbSAGeflOc+Ly6uQ=
-go.mau.fi/libsignal v0.0.0-20211024113310-f9fc6a1855f2/go.mod h1:3XlVlwOfp8f9Wri+C1D4ORqgUsN4ZvunJOoPjQMBhos=
-go.mau.fi/whatsmeow v0.0.0-20211108174035-d6fe7ad15eb0 h1:bx+s5QfIek3MLO4U4k9G6Hv8b0Po/h3eDZfVagE7kTk=
-go.mau.fi/whatsmeow v0.0.0-20211108174035-d6fe7ad15eb0/go.mod h1:ODEmmqeUn9eBDQHFc1S902YA3YFLtmaBujYRRFl53jI=
+go.mau.fi/libsignal v0.0.0-20211109153248-a67163214910 h1:9FFhG0OmkuMau5UEaTgiUQ+7cSbtbOQ7hiWKdN8OI3I=
+go.mau.fi/libsignal v0.0.0-20211109153248-a67163214910/go.mod h1:AufGrvVh+00Nc07Jm4hTquh7yleZyn20tKJI2wCPAKg=
+go.mau.fi/whatsmeow v0.0.0-20211109154617-2fabbeecad6a h1:ZDFmCqUXbayxtVgSIY75Odx6y2Il7d9LGFgLcFlEtrY=
+go.mau.fi/whatsmeow v0.0.0-20211109154617-2fabbeecad6a/go.mod h1:8jUjOAi3xtGubxcZgG8uSHpAdyQXBRbWAfxkctX/4y4=
 golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
 golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
 golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
 golang.org/x/crypto v0.0.0-20200115085410-6d4e4cb37c7d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
 golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
-golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 h1:7I4JAnoQBe7ZtJcBaYHi5UtiO8tQHbUSXxL+pnGRANg=
 golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
+golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa h1:idItI2DDfCokpg0N51B2VtiLdJ4vAuXC9fnCb2gACo4=
+golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
 golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d h1:RNPAfi2nHY7C2srAV8A49jpsYr0ADedCk1wq6fTMTvs=
 golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
 golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=

+ 10 - 5
portal.go

@@ -162,10 +162,11 @@ func (bridge *Bridge) NewPortal(dbPortal *database.Portal) *Portal {
 const recentlyHandledLength = 100
 
 type fakeMessage struct {
-	Sender types.JID
-	Text   string
-	ID     string
-	Time   time.Time
+	Sender    types.JID
+	Text      string
+	ID        string
+	Time      time.Time
+	Important bool
 }
 
 type PortalMessage struct {
@@ -364,8 +365,12 @@ func (portal *Portal) handleFakeMessage(msg fakeMessage) {
 		portal.log.Debugfln("Not handling %s (fake): user doesn't have double puppeting enabled", msg.ID)
 		return
 	}
+	msgType := event.MsgNotice
+	if msg.Important {
+		msgType = event.MsgText
+	}
 	resp, err := portal.sendMessage(intent, event.EventMessage, &event.MessageEventContent{
-		MsgType: event.MsgText,
+		MsgType: msgType,
 		Body:    msg.Text,
 	}, nil, msg.Time.UnixMilli())
 	if err != nil {

+ 21 - 3
user.go

@@ -22,6 +22,7 @@ import (
 	"errors"
 	"fmt"
 	"net/http"
+	"strconv"
 	"sync"
 	"time"
 
@@ -353,9 +354,11 @@ func (user *User) handleCallStart(sender types.JID, id, callType string, ts time
 	}
 	portal.messages <- PortalMessage{
 		fake: &fakeMessage{
-			Sender: sender,
-			Text:   text,
-			ID:     id,
+			Sender:    sender,
+			Text:      text,
+			ID:        id,
+			Time:      ts,
+			Important: true,
 		},
 		source: user,
 	}
@@ -433,6 +436,21 @@ func (user *User) HandleEvent(event interface{}) {
 		user.handleCallStart(v.CallCreator, v.CallID, "", v.Timestamp)
 	case *events.CallOfferNotice:
 		user.handleCallStart(v.CallCreator, v.CallID, v.Type, v.Timestamp)
+	case *events.IdentityChange:
+		puppet := user.bridge.GetPuppetByJID(v.JID)
+		portal := user.GetPortalByJID(v.JID)
+		if len(portal.MXID) > 0 {
+			portal.messages <- PortalMessage{
+				fake: &fakeMessage{
+					Sender:    v.JID,
+					Text:      fmt.Sprintf("Your security code with %s changed.", puppet.Displayname),
+					ID:        strconv.FormatInt(v.Timestamp.Unix(), 10),
+					Time:      v.Timestamp,
+					Important: false,
+				},
+				source: user,
+			}
+		}
 	case *events.CallTerminate, *events.CallRelayLatency, *events.CallAccept, *events.UnknownCallEvent:
 		// ignore
 	case *events.UndecryptableMessage: