Skip to content

Instantly share code, notes, and snippets.

View gregblake's full-sized avatar
👨‍💻

Greg Blake gregblake

👨‍💻
View GitHub Profile
@gregblake
gregblake / unread.rb
Created September 17, 2020 14:38
Unread key on the state endpoint
[3] pry(main)> Connect::Notification.summary_for(effective_user)
=> {:reactions=>0,
:users=>{2=>19, 618=>17},
:rooms=>
{138=>{:messages=>10, :mentions=>0, :mentions_direct=>0, :mentions_all=>0},
1976=>{:messages=>1, :mentions=>1, :mentions_direct=>1, :mentions_all=>0},
10278=>{:messages=>3, :mentions=>3, :mentions_direct=>2, :mentions_all=>1},
10783=>{:messages=>23, :mentions=>0, :mentions_direct=>0, :mentions_all=>0},
19319=>{:messages=>148, :mentions=>5, :mentions_direct=>0, :mentions_all=>5},
23514=>{:messages=>130, :mentions=>13, :mentions_direct=>0, :mentions_all=>13},
@gregblake
gregblake / testing_connect_notifications.md
Last active August 7, 2023 14:40
How to Test Connect Notifications

How to Test Connect Notifications

Overview

Connect has 3 types of conversations: 1-on-1's, Rooms, and Group Conversations. The rules for are different for displaying notifications for each conversation type.

Connect mobile clients have an APP-level preference that enables/disables message previews on the lock screen. This preference is enabled by default (which means that the contents of the message will be visible on the notification itself). But this can be disabled, and the notification displays placeholder text (like "Greg mentioned you in Rebel Alliance").

Conversation Types

1-on-1 and Group Conversations are straight forward. The notifications should always be displayed to the user, and the "is Connecting with you" style text always remains the same for each conversation type.

Note: if notification previews are enabled, then the notification should display the contents of the message.

@gregblake
gregblake / payload.rb
Created August 27, 2020 13:16
New room_info key on the mobile notification payload
{:data=>
{:aps=>{:"content-available"=>true, :sound=>""},
:"message-type"=>"connect",
:"as-of"=>"2020-08-27T09:15:17-04:00",
:"nitro-environment"=>"development",
:user_id=>33868,
:connect_message_id=>59955711,
:message_prefetch=>true,
:connect_message=>
{:messages=>
@gregblake
gregblake / alternative.diff
Created August 7, 2020 12:48
Alternative Solution
diff --git a/components/connect-web-ui/src/components/ConversationTitle/EditRoomAudiencesForm.jsx b/components/connect-web-ui/src/components/ConversationTitle/EditRoomAudiencesForm.jsx
index c3977d1cb3..6d27c4610a 100644
--- a/components/connect-web-ui/src/components/ConversationTitle/EditRoomAudiencesForm.jsx
+++ b/components/connect-web-ui/src/components/ConversationTitle/EditRoomAudiencesForm.jsx
@@ -17,7 +17,8 @@ export const EditRoomAudiencesForm = ({ audience, hideAudienceForm, loadingLooka
const removeAudience = (id, fieldName) => {
onChange({
...audience,
- userIds: undefined,
+ id: undefined,
@gregblake
gregblake / wget.sh
Created August 6, 2020 10:36
wget webpacker-4.2.2.tgz returns a 200 locally
❯ wget https://registry.yarnpkg.com/@rails/webpacker/-/webpacker-4.2.2.tgz
--2020-08-06 06:28:08-- https://registry.yarnpkg.com/@rails/webpacker/-/webpacker-4.2.2.tgz
Resolving registry.yarnpkg.com (registry.yarnpkg.com)... 2606:4700::6810:1823, 2606:4700::6810:1723, 2606:4700::6810:1a23, ...
Connecting to registry.yarnpkg.com (registry.yarnpkg.com)|2606:4700::6810:1823|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 27462 (27K) [application/octet-stream]
Saving to: ‘webpacker-4.2.2.tgz’
webpacker-4.2.2.tgz 100%[==============================>] 26.82K --.-KB/s in 0.002s
@gregblake
gregblake / mysql8_connect_specs.md
Last active July 27, 2020 11:46
MySql 8.0 Updgrade -- Failing Connect Specs

The specs are testing Connect::Message.with_context. This method is used in Connect search. When you click on one of the messages in a set of search results, you can view that message, with context of the conversation (messages written in that conversation immediately before and after the message you selected).

It looks like the specs are breaking on MySql 8.0 because the messages are being returned in a different order than what's expected.

For example, on ./spec/models/connect/message_spec.rb:249, it expected messages in this order:

id: 1418
id: 1420
id: 1421
@gregblake
gregblake / room_memberships.gql
Last active June 29, 2020 19:24
GraphQL request to update room memberships
mutation {
updatedRoom: updateConnectRoom(
id: 32246,
memberships: [{ titleId: 60 }, {userId: 31995} ]
) {
id
name
memberships { id titleId userId territoryId }
}
}
@gregblake
gregblake / message_chaining.rb
Created May 27, 2020 11:00
Message Chaining
[22] pry(main)> Connect::Room.find(1976).messages.pluck(:id, :prev_message_id)
Connect::Room Load (2.0ms) SELECT `connect_rooms`.* FROM `connect_rooms` WHERE `connect_rooms`.`id` = 1976 LIMIT 1
(4.7ms) SELECT `connect_messages`.`id`, `connect_messages`.`prev_message_id` FROM `connect_messages` LEFT OUTER JOIN `connect_message_reactions` ON `connect_message_reactions`.`connect_message_id` = `connect_messages`.`id` LEFT OUTER JOIN `connect_message_shared_files` ON `connect_message_shared_files`.`connect_message_id` = `connect_messages`.`id` LEFT OUTER JOIN `connect_message_mentions` ON `connect_message_mentions`.`connect_message_id` = `connect_messages`.`id` LEFT OUTER JOIN `users` ON `users`.`id` = `connect_message_mentions`.`user_id` WHERE `connect_messages`.`to_id` = 1976 AND `connect_messages`.`to_type` = 'Connect::Room'
=> [[53250783, nil],
[53250784, 53250783],
[53250786, 53250784],
[53252325, 53250786],
[53252326, 53252325],
[53252327, 53252326],
[53252328, 53252327],
@gregblake
gregblake / group_membership_params.rb
Created May 26, 2020 18:28
Group Membership Params
# This request will create group memberships for department_id's 1 & 2, as well as territory_id 1.
group_memberships = [
{ territory_id: nil, branch_id: nil, role_id: nil, department_id: 1, title_id: nil },
{ territory_id: 1, branch_id: nil, role_id: nil, department_id: 2, title_id: nil }
]
@gregblake
gregblake / random.rb
Created May 22, 2020 17:28
Random Generator: Rebel Alliance Members
# This determines who gives their standup update first.
["Lucas", "Lucas Feijo", "lucas.feijo"].sample