package gatewayrpc import ( "context" pb "github.com/samcharles93/archie-core/internal/contracts/gateway/v1" "github.com/samcharles93/archie-core/internal/domain/messaging" ) // addressRecords restores the canonical fields the wire drops -- role and // conversation address -- from the owning session, which is where the // server derived them from on the way out. A missing session yields zero // values, matching the store's LEFT JOIN for orphaned rows. func addressRecords(ctx context.Context, client pb.ChatServiceClient, id string, msgs []*pb.Message) ([]messaging.Message, error) { var botUser string var conv messaging.ConversationID v, err := client.GetSession(ctx, &pb.GetSessionRequest{SessionId: id}) if err != nil { return nil, err } if v.Found { sc := sessionValue(v.Session) botUser = sc.Source.BotUser conv = messaging.ConversationID{ChannelID: sc.Source.ChannelID, ThreadID: sc.Source.ThreadID} } out := make([]messaging.Message, 0, len(msgs)) for _, m := range msgs { stored := storedValue(m) stored.ConversationID = conv stored.Role = messaging.RoleForSender(stored.Sender, botUser) out = append(out, stored) } return out, nil }