-
-
Notifications
You must be signed in to change notification settings - Fork 53
handlemeta: handle instagram message request #243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rnons
wants to merge
7
commits into
main
Choose a base branch
from
rnons/plat-35395
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
707a8b1
handlemeta: handle message request
rnons 4c1b13d
handle spam and simplify
rnons a899bf9
implement HandleMatrixAcceptMessageRequest
rnons da9d486
Update pkg/connector/events.go
rnons 235a999
use graphql api to fetch message requests
rnons 095e3d8
Merge remote-tracking branch 'origin/main' into rnons/plat-35395
rnons ab63d2e
startMessageRequestSync seems not needed
rnons File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,7 +69,7 @@ func (evt *VerifyThreadExistsEvent) GetType() bridgev2.RemoteEventType { | |
| } | ||
|
|
||
| func (evt *VerifyThreadExistsEvent) ShouldCreatePortal() bool { | ||
| return evt.FolderName != folderPending && evt.FolderName != folderSpam | ||
| return evt.FolderName != folderSpam | ||
| } | ||
|
|
||
| func (evt *VerifyThreadExistsEvent) GetPortalKey() networkid.PortalKey { | ||
|
|
@@ -112,7 +112,9 @@ func (evt *VerifyThreadExistsEvent) GetChatInfo(ctx context.Context, portal *bri | |
| zerolog.Ctx(ctx).Trace().Any("response", resp).Msg("Requested full thread info") | ||
| } | ||
| } | ||
| return evt.m.makeMinimalChatInfo(evt.ThreadKey, evt.ThreadType, evt.ParentThreadKey), nil | ||
| chatInfo := evt.m.makeMinimalChatInfo(evt.ThreadKey, evt.ThreadType, evt.ParentThreadKey) | ||
| chatInfo.MessageRequest = ptr.Ptr(evt.FolderName == folderPending) | ||
| return chatInfo, nil | ||
| } | ||
|
|
||
| type FBMessageEvent struct { | ||
|
|
@@ -546,6 +548,7 @@ func (evt *WAMessageEvent) ConvertEdit(ctx context.Context, portal *bridgev2.Por | |
|
|
||
| type FBChatResync struct { | ||
| Raw *table.LSDeleteThenInsertThread | ||
| Update *table.LSUpdateOrInsertThread | ||
| PortalKey networkid.PortalKey | ||
| Info *bridgev2.ChatInfo | ||
| Members map[int64]bridgev2.ChatMember | ||
|
|
@@ -578,26 +581,50 @@ func (r *FBChatResync) PortalReceiverIsUncertain() bool { | |
| } | ||
|
|
||
| func (r *FBChatResync) ShouldCreatePortal() bool { | ||
| if r.Raw == nil { | ||
| if r.Raw != nil && r.Raw.FolderName == folderSpam { | ||
| return false | ||
| } else if r.Update != nil && r.Update.FolderName == folderSpam { | ||
| return false | ||
| } else if r.Raw == nil && r.Update == nil { | ||
| // Backfill-only resyncs don't carry folder metadata, so they can't | ||
| // reliably decide portal creation here. | ||
| return false | ||
| } | ||
| if r.Info != nil && r.Info.MessageRequest != nil && *r.Info.MessageRequest { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we check spam first? Is it possible to have a folder be a request and marked as spam? |
||
| return true | ||
| } | ||
| if r.Raw != nil { | ||
| return r.Raw.FolderName != folderPending | ||
| } | ||
| return r.Raw.FolderName != folderPending && r.Raw.FolderName != folderSpam | ||
| return r.Update.FolderName != folderPending | ||
| } | ||
|
|
||
| func (r *FBChatResync) AddLogContext(c zerolog.Context) zerolog.Context { | ||
| if r.UpsertID != 0 { | ||
| c = c.Int64("global_upsert_counter", r.UpsertID) | ||
| } | ||
| if r.Raw == nil { | ||
| return c | ||
| var threadID int64 | ||
| var threadType table.ThreadType | ||
| var threadFolder string | ||
| if r.Raw != nil { | ||
| threadID = r.Raw.ThreadKey | ||
| threadType = r.Raw.ThreadType | ||
| threadFolder = r.Raw.FolderName | ||
| } else if r.Update != nil { | ||
| threadID = r.Update.ThreadKey | ||
| threadType = r.Update.ThreadType | ||
| threadFolder = r.Update.FolderName | ||
| } else { | ||
| threadID = metaid.ParseFBPortalID(r.PortalKey.ID) | ||
| threadFolder = "unknown" | ||
| } | ||
| c = c. | ||
| Int64("thread_id", r.Raw.ThreadKey). | ||
| Int("thread_type", int(r.Raw.ThreadType)). | ||
| Int64("thread_id", threadID). | ||
| Int("thread_type", int(threadType)). | ||
| Dict("debug_info", zerolog.Dict(). | ||
| Str("thread_folder", r.Raw.FolderName). | ||
| Int64("ig_folder", r.Raw.IgFolder). | ||
| Int64("group_notification_settings", r.Raw.GroupNotificationSettings)) | ||
| Str("thread_folder", threadFolder). | ||
| Int64("ig_folder", r.getIGFolder()). | ||
| Int64("group_notification_settings", r.getGroupNotificationSettings())) | ||
| return c | ||
| } | ||
|
|
||
|
|
@@ -606,7 +633,7 @@ func (r *FBChatResync) GetSender() bridgev2.EventSender { | |
| } | ||
|
|
||
| func (r *FBChatResync) GetChatInfo(ctx context.Context, portal *bridgev2.Portal) (*bridgev2.ChatInfo, error) { | ||
| if r.Raw == nil { | ||
| if r.Info == nil { | ||
| return nil, nil | ||
| } | ||
| if len(r.Members) > 0 && !r.filled { | ||
|
|
@@ -639,10 +666,11 @@ func (r *FBChatResync) GetChatInfo(ctx context.Context, portal *bridgev2.Portal) | |
| func (r *FBChatResync) CheckNeedsBackfill(ctx context.Context, lastMessage *database.Message) (bool, error) { | ||
| // Check for forward backfill if we're handling a remote update, we need to fill any gap between | ||
| // the last message we know of and the last activity timestamp specified on the thread. | ||
| if r.Backfill == nil && r.Raw != nil && lastMessage != nil && r.Raw.LastActivityTimestampMs > lastMessage.Timestamp.UnixMilli() { | ||
| lastActivity := r.getLastActivityTimestampMs() | ||
| if r.Backfill == nil && lastActivity != 0 && lastMessage != nil && lastActivity > lastMessage.Timestamp.UnixMilli() { | ||
| zerolog.Ctx(ctx).Debug(). | ||
| Int64("last_message_ts", lastMessage.Timestamp.UnixMilli()). | ||
| Int64("thread_last_activity_ts", r.Raw.LastActivityTimestampMs). | ||
| Int64("thread_last_activity_ts", lastActivity). | ||
| Msg("Thread has newer activity than last known message, triggering forward backfill") | ||
| return true, nil | ||
| } | ||
|
|
@@ -669,6 +697,33 @@ func (r *FBChatResync) GetBundledBackfillData() any { | |
| return r.Backfill | ||
| } | ||
|
|
||
| func (r *FBChatResync) getLastActivityTimestampMs() int64 { | ||
| if r.Raw != nil { | ||
| return r.Raw.LastActivityTimestampMs | ||
| } else if r.Update != nil { | ||
| return r.Update.LastActivityTimestampMs | ||
| } | ||
| return 0 | ||
| } | ||
|
|
||
| func (r *FBChatResync) getIGFolder() int64 { | ||
| if r.Raw != nil { | ||
| return r.Raw.IgFolder | ||
| } else if r.Update != nil { | ||
| return r.Update.IgFolder | ||
| } | ||
| return 0 | ||
| } | ||
|
|
||
| func (r *FBChatResync) getGroupNotificationSettings() int64 { | ||
| if r.Raw != nil { | ||
| return r.Raw.GroupNotificationSettings | ||
| } else if r.Update != nil { | ||
| return r.Update.GroupNotificationSettings | ||
| } | ||
| return 0 | ||
| } | ||
|
|
||
| type FBFolderResync struct { | ||
| PortalKey networkid.PortalKey | ||
| LSUpsertFolder *table.LSUpsertFolder | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| package connector | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| "github.com/rs/zerolog" | ||
| ) | ||
|
|
||
| func (m *MetaClient) syncInstagramMessageRequests(ctx context.Context) error { | ||
| if !m.LoginMeta.Platform.IsInstagram() { | ||
| return nil | ||
| } else if m.Client == nil || m.Client.Instagram == nil { | ||
| return fmt.Errorf("instagram client is not available") | ||
| } | ||
|
|
||
| threads, err := m.Client.Instagram.FetchMessageRequests(ctx) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| log := zerolog.Ctx(ctx) | ||
| log.Debug().Int("thread_count", len(threads)).Msg("Queueing Instagram message requests") | ||
| for _, thread := range threads { | ||
| m.UserLogin.QueueRemoteEvent(&VerifyThreadExistsEvent{ | ||
| LSVerifyThreadExists: thread, | ||
| m: m, | ||
| }) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func (m *MetaClient) startMessageRequestSync(ctx context.Context) { | ||
| if !m.LoginMeta.Platform.IsInstagram() { | ||
| return | ||
| } | ||
| go func() { | ||
| if err := m.syncInstagramMessageRequests(ctx); err != nil { | ||
| m.UserLogin.Log.Err(err).Msg("Instagram message request sync failed") | ||
| } | ||
| }() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the extra call required? If message requests are already pushed while online and included in the 20 recent chats that are in the initial table after full reconnects, then I don't think we really need the extra request.
Could maybe be made configurable to sync everything?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated, you're right, removed the extra call