Skip to content

Commit

Permalink
handlegmessages: allow creating portal on incoming messages
Browse files Browse the repository at this point in the history
Fixes #26
  • Loading branch information
tulir committed Aug 29, 2024
1 parent 6abf636 commit e753f4a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/connector/chatinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,15 @@ func (gc *GMClient) GetChatInfo(ctx context.Context, portal *bridgev2.Portal) (*
if err != nil {
return nil, err
}
zerolog.Ctx(ctx).Info().Str("conversation_id", conversationID).Msg("Manually fetching chat info")
conv, err := gc.Client.GetConversation(conversationID)
if err != nil {
return nil, err
}
switch conv.GetStatus() {
case gmproto.ConversationStatus_SPAM_FOLDER, gmproto.ConversationStatus_BLOCKED_FOLDER, gmproto.ConversationStatus_DELETED:
return nil, fmt.Errorf("conversation is in a blocked status: %s", conv.GetStatus())
}
return gc.wrapChatInfo(ctx, conv), nil
}

Expand Down
17 changes: 17 additions & 0 deletions pkg/connector/handlegmessages.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ var (
_ bridgev2.RemoteMessageWithTransactionID = (*MessageEvent)(nil)
_ bridgev2.RemoteMessageUpsert = (*MessageEvent)(nil)
_ bridgev2.RemoteMessageRemove = (*MessageEvent)(nil)
_ bridgev2.RemoteEventThatMayCreatePortal = (*MessageEvent)(nil)
_ bridgev2.RemoteEventWithTimestamp = (*MessageEvent)(nil)
)

Expand All @@ -552,6 +553,22 @@ func (m *MessageEvent) GetPortalKey() networkid.PortalKey {
return m.g.MakePortalKey(m.ConversationID)
}

func (m *MessageEvent) ShouldCreatePortal() bool {
switch m.GetMessageStatus().GetStatus() {
case gmproto.MessageStatusType_INCOMING_COMPLETE, gmproto.MessageStatusType_OUTGOING_COMPLETE,
gmproto.MessageStatusType_OUTGOING_DELIVERED, gmproto.MessageStatusType_OUTGOING_DISPLAYED:
m.g.UserLogin.Log.Warn().
Str("message_id", m.MessageID).
Str("conversation_id", m.ConversationID).
Str("participant_id", m.ParticipantID).
Str("status", m.GetMessageStatus().GetStatus().String()).
Msg("Portal doesn't exist for normal message, allowing creation")
return true
default:
return false
}
}

func (m *MessageEvent) AddLogContext(c zerolog.Context) zerolog.Context {
return c.
Str("message_id", m.MessageID).
Expand Down

0 comments on commit e753f4a

Please sign in to comment.