Skip to content

Commit

Permalink
handlegmessages: improve logging around sims
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Sep 30, 2024
1 parent 2a67a72 commit ccb3c66
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 12 deletions.
15 changes: 14 additions & 1 deletion pkg/connector/dbmeta.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ import (
"encoding/json"
"fmt"
"slices"
"strings"
"sync"

"go.mau.fi/util/jsontime"
"golang.org/x/exp/maps"
"maunium.net/go/mautrix/bridgev2/database"

"go.mau.fi/mautrix-gmessages/pkg/libgm"
Expand Down Expand Up @@ -100,6 +102,7 @@ type bridgeStateSIMMeta struct {
ColorHex string `json:"color_hex"`
ParticipantID string `json:"participant_id"`
RCSEnabled bool `json:"rcs_enabled"`
PhoneNumber string `json:"phone_number"`
}

type serializableUserLoginMetadata struct {
Expand Down Expand Up @@ -178,14 +181,24 @@ func (ulm *UserLoginMetadata) GetSIMsForBridgeState() []bridgeStateSIMMeta {
for _, sim := range ulm.simMetadata {
data = append(data, bridgeStateSIMMeta{
CarrierName: sim.GetSIMData().GetCarrierName(),
ColorHex: sim.GetSIMData().GetHexHash(),
ColorHex: sim.GetSIMData().GetColorHex(),
ParticipantID: sim.GetSIMParticipant().GetID(),
RCSEnabled: sim.GetRCSChats().GetEnabled(),
PhoneNumber: sim.GetSIMData().GetFormattedPhoneNumber(),
})
}
slices.SortFunc(data, func(a, b bridgeStateSIMMeta) int {
return strings.Compare(a.ParticipantID, b.ParticipantID)
})
return data
}

func (ulm *UserLoginMetadata) GetSIMs() []*gmproto.SIMCard {
ulm.lock.RLock()
defer ulm.lock.RUnlock()
return maps.Values(ulm.simMetadata)
}

func (ulm *UserLoginMetadata) GetSIM(participantID string) *gmproto.SIMCard {
ulm.lock.Lock()
defer ulm.lock.Unlock()
Expand Down
5 changes: 5 additions & 0 deletions pkg/connector/handlegmessages.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ func (gc *GMClient) handleGMEvent(rawEvt any) {
Str("message_id", evt.GetMessageID()).
Str("message_status", evt.GetMessageStatus().GetStatus().String()).
Int64("message_ts", evt.GetTimestamp()).
Int64("message_type", evt.GetType()).
Str("tmp_id", evt.GetTmpID()).
Bool("is_old", evt.IsOld).
Msg("Received message")
Expand Down Expand Up @@ -315,6 +316,10 @@ func (gc *GMClient) handleSettings(ctx context.Context, settings *gmproto.Settin
changed = true
}
if changed {
log.Debug().
Any("sims", gc.Meta.GetSIMs()).
Any("rcs_settings", gc.Meta.Settings).
Msg("Settings changed, saving")
err := gc.UserLogin.Save(ctx)
if err != nil {
log.Err(err).Msg("Failed to save SIM details")
Expand Down
2 changes: 1 addition & 1 deletion pkg/libgm/gmproto/conversations.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/libgm/gmproto/conversations.proto
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ message Message {
string conversationID = 7;
string participantID = 9;
repeated MessageInfo messageInfo = 10;
int64 type = 11;
int64 type = 11; // 1 = sms, 2 = downloaded mms, 3 = undownloaded mms, 4 = rcs?
string tmpID = 12;
optional string subject = 14;
int64 someInt = 16;
Expand Down
22 changes: 15 additions & 7 deletions pkg/libgm/gmproto/settings.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified pkg/libgm/gmproto/settings.pb.raw
Binary file not shown.
5 changes: 3 additions & 2 deletions pkg/libgm/gmproto/settings.proto
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ message SIMPayload {

message SIMData {
SIMPayload SIMPayload = 1;
bool bool1 = 2;
bool bool1 = 2; // maybe isDefault?
string carrierName = 3;
string hexHash = 4;
string colorHex = 4;
int64 int1 = 5;
string formattedPhoneNumber = 6;
}

message UnknownMessage {
Expand Down

0 comments on commit ccb3c66

Please sign in to comment.