diff --git a/go/cmd/emailnotifierjob/main.go b/go/cmd/emailnotifierjob/main.go index 325cdc3..2a227c8 100644 --- a/go/cmd/emailnotifierjob/main.go +++ b/go/cmd/emailnotifierjob/main.go @@ -26,7 +26,7 @@ const ( // Minimum time a message must be unread before we consider notifying unreadThreshold = 10 * time.Minute // Minimum time between emails to the same user - emailCooldown = 1 * time.Hour + emailCooldown = 12 * time.Hour ) func main() { @@ -107,17 +107,15 @@ func runNotificationCycle( behindCounts := map[string]int{} latestActivity := map[string]time.Time{} - // Get all currently connected humans (empty channel_ids = all connections) + // Get all currently connected humans allOnline := map[string]bool{} - presenceResp, err := pusherSvc.BulkGetPresence(ctx, &pbpusher.BulkGetPresenceRequest{}) + onlineResp, err := pusherSvc.GetOnlineHumanIds(ctx, &pbpusher.GetOnlineHumanIdsRequest{}) if err != nil { - slog.Error("failed to get connected humans", "error", err) - // Continue without presence data — worst case we send an email to someone who's online - } else if ch, ok := presenceResp.Presences["_all"]; ok { - slog.Info("gathered bulk presence", "# of humans present", fmt.Sprintf("%d", len(ch.HumanIds))) - for _, id := range ch.HumanIds { - allOnline[id] = true - } + return fmt.Errorf("failed to get online humans: %w", err) + } + slog.Info("gathered online presence", "onlineCount", len(onlineResp.HumanIds), "humanIds", onlineResp.HumanIds) + for _, id := range onlineResp.HumanIds { + allOnline[id] = true } for _, net := range networks { @@ -288,7 +286,7 @@ func buildEmailHTML(name string, count int, streamsWord string) string {

You have unread messages in %d %s on Flowy.llink.

Open the app to catch up with your team.

- Best,
Flowy Team + Best,
Flowy Team
Note: disable email notifications from in-app settings.

`, name, count, streamsWord) diff --git a/go/genproto/llink/pusher/pusher.pb.go b/go/genproto/llink/pusher/pusher.pb.go index 727ec72..66c0ff8 100644 --- a/go/genproto/llink/pusher/pusher.pb.go +++ b/go/genproto/llink/pusher/pusher.pb.go @@ -20,29 +20,26 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) -type BulkGetPresenceRequest struct { +type GetOnlineHumanIdsRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - - // Channel IDs to query. Empty means "all connected humans". - ChannelIds []string `protobuf:"bytes,1,rep,name=channel_ids,json=channelIds,proto3" json:"channel_ids,omitempty"` } -func (x *BulkGetPresenceRequest) Reset() { - *x = BulkGetPresenceRequest{} +func (x *GetOnlineHumanIdsRequest) Reset() { + *x = GetOnlineHumanIdsRequest{} mi := &file_llink_pusher_pusher_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } -func (x *BulkGetPresenceRequest) String() string { +func (x *GetOnlineHumanIdsRequest) String() string { return protoimpl.X.MessageStringOf(x) } -func (*BulkGetPresenceRequest) ProtoMessage() {} +func (*GetOnlineHumanIdsRequest) ProtoMessage() {} -func (x *BulkGetPresenceRequest) ProtoReflect() protoreflect.Message { +func (x *GetOnlineHumanIdsRequest) ProtoReflect() protoreflect.Message { mi := &file_llink_pusher_pusher_proto_msgTypes[0] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -54,19 +51,192 @@ func (x *BulkGetPresenceRequest) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use BulkGetPresenceRequest.ProtoReflect.Descriptor instead. -func (*BulkGetPresenceRequest) Descriptor() ([]byte, []int) { +// Deprecated: Use GetOnlineHumanIdsRequest.ProtoReflect.Descriptor instead. +func (*GetOnlineHumanIdsRequest) Descriptor() ([]byte, []int) { return file_llink_pusher_pusher_proto_rawDescGZIP(), []int{0} } -func (x *BulkGetPresenceRequest) GetChannelIds() []string { +type GetOnlineHumanIdsResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + HumanIds []string `protobuf:"bytes,1,rep,name=human_ids,json=humanIds,proto3" json:"human_ids,omitempty"` +} + +func (x *GetOnlineHumanIdsResponse) Reset() { + *x = GetOnlineHumanIdsResponse{} + mi := &file_llink_pusher_pusher_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *GetOnlineHumanIdsResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetOnlineHumanIdsResponse) ProtoMessage() {} + +func (x *GetOnlineHumanIdsResponse) ProtoReflect() protoreflect.Message { + mi := &file_llink_pusher_pusher_proto_msgTypes[1] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetOnlineHumanIdsResponse.ProtoReflect.Descriptor instead. +func (*GetOnlineHumanIdsResponse) Descriptor() ([]byte, []int) { + return file_llink_pusher_pusher_proto_rawDescGZIP(), []int{1} +} + +func (x *GetOnlineHumanIdsResponse) GetHumanIds() []string { + if x != nil { + return x.HumanIds + } + return nil +} + +type IsOnlineRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + HumanIds []string `protobuf:"bytes,1,rep,name=human_ids,json=humanIds,proto3" json:"human_ids,omitempty"` +} + +func (x *IsOnlineRequest) Reset() { + *x = IsOnlineRequest{} + mi := &file_llink_pusher_pusher_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *IsOnlineRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*IsOnlineRequest) ProtoMessage() {} + +func (x *IsOnlineRequest) ProtoReflect() protoreflect.Message { + mi := &file_llink_pusher_pusher_proto_msgTypes[2] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use IsOnlineRequest.ProtoReflect.Descriptor instead. +func (*IsOnlineRequest) Descriptor() ([]byte, []int) { + return file_llink_pusher_pusher_proto_rawDescGZIP(), []int{2} +} + +func (x *IsOnlineRequest) GetHumanIds() []string { + if x != nil { + return x.HumanIds + } + return nil +} + +type IsOnlineResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Online map[string]bool `protobuf:"bytes,1,rep,name=online,proto3" json:"online,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` +} + +func (x *IsOnlineResponse) Reset() { + *x = IsOnlineResponse{} + mi := &file_llink_pusher_pusher_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *IsOnlineResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*IsOnlineResponse) ProtoMessage() {} + +func (x *IsOnlineResponse) ProtoReflect() protoreflect.Message { + mi := &file_llink_pusher_pusher_proto_msgTypes[3] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use IsOnlineResponse.ProtoReflect.Descriptor instead. +func (*IsOnlineResponse) Descriptor() ([]byte, []int) { + return file_llink_pusher_pusher_proto_rawDescGZIP(), []int{3} +} + +func (x *IsOnlineResponse) GetOnline() map[string]bool { + if x != nil { + return x.Online + } + return nil +} + +type GetChannelPresenceRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + ChannelIds []string `protobuf:"bytes,1,rep,name=channel_ids,json=channelIds,proto3" json:"channel_ids,omitempty"` +} + +func (x *GetChannelPresenceRequest) Reset() { + *x = GetChannelPresenceRequest{} + mi := &file_llink_pusher_pusher_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *GetChannelPresenceRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetChannelPresenceRequest) ProtoMessage() {} + +func (x *GetChannelPresenceRequest) ProtoReflect() protoreflect.Message { + mi := &file_llink_pusher_pusher_proto_msgTypes[4] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetChannelPresenceRequest.ProtoReflect.Descriptor instead. +func (*GetChannelPresenceRequest) Descriptor() ([]byte, []int) { + return file_llink_pusher_pusher_proto_rawDescGZIP(), []int{4} +} + +func (x *GetChannelPresenceRequest) GetChannelIds() []string { if x != nil { return x.ChannelIds } return nil } -type BulkGetPresenceResponse struct { +type GetChannelPresenceResponse struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields @@ -74,21 +244,21 @@ type BulkGetPresenceResponse struct { Presences map[string]*ChannelPresence `protobuf:"bytes,1,rep,name=presences,proto3" json:"presences,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` } -func (x *BulkGetPresenceResponse) Reset() { - *x = BulkGetPresenceResponse{} - mi := &file_llink_pusher_pusher_proto_msgTypes[1] +func (x *GetChannelPresenceResponse) Reset() { + *x = GetChannelPresenceResponse{} + mi := &file_llink_pusher_pusher_proto_msgTypes[5] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } -func (x *BulkGetPresenceResponse) String() string { +func (x *GetChannelPresenceResponse) String() string { return protoimpl.X.MessageStringOf(x) } -func (*BulkGetPresenceResponse) ProtoMessage() {} +func (*GetChannelPresenceResponse) ProtoMessage() {} -func (x *BulkGetPresenceResponse) ProtoReflect() protoreflect.Message { - mi := &file_llink_pusher_pusher_proto_msgTypes[1] +func (x *GetChannelPresenceResponse) ProtoReflect() protoreflect.Message { + mi := &file_llink_pusher_pusher_proto_msgTypes[5] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -99,12 +269,12 @@ func (x *BulkGetPresenceResponse) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use BulkGetPresenceResponse.ProtoReflect.Descriptor instead. -func (*BulkGetPresenceResponse) Descriptor() ([]byte, []int) { - return file_llink_pusher_pusher_proto_rawDescGZIP(), []int{1} +// Deprecated: Use GetChannelPresenceResponse.ProtoReflect.Descriptor instead. +func (*GetChannelPresenceResponse) Descriptor() ([]byte, []int) { + return file_llink_pusher_pusher_proto_rawDescGZIP(), []int{5} } -func (x *BulkGetPresenceResponse) GetPresences() map[string]*ChannelPresence { +func (x *GetChannelPresenceResponse) GetPresences() map[string]*ChannelPresence { if x != nil { return x.Presences } @@ -121,7 +291,7 @@ type ChannelPresence struct { func (x *ChannelPresence) Reset() { *x = ChannelPresence{} - mi := &file_llink_pusher_pusher_proto_msgTypes[2] + mi := &file_llink_pusher_pusher_proto_msgTypes[6] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -133,7 +303,7 @@ func (x *ChannelPresence) String() string { func (*ChannelPresence) ProtoMessage() {} func (x *ChannelPresence) ProtoReflect() protoreflect.Message { - mi := &file_llink_pusher_pusher_proto_msgTypes[2] + mi := &file_llink_pusher_pusher_proto_msgTypes[6] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -146,7 +316,7 @@ func (x *ChannelPresence) ProtoReflect() protoreflect.Message { // Deprecated: Use ChannelPresence.ProtoReflect.Descriptor instead. func (*ChannelPresence) Descriptor() ([]byte, []int) { - return file_llink_pusher_pusher_proto_rawDescGZIP(), []int{2} + return file_llink_pusher_pusher_proto_rawDescGZIP(), []int{6} } func (x *ChannelPresence) GetHumanIds() []string { @@ -161,38 +331,68 @@ var File_llink_pusher_pusher_proto protoreflect.FileDescriptor var file_llink_pusher_pusher_proto_rawDesc = []byte{ 0x0a, 0x19, 0x6c, 0x6c, 0x69, 0x6e, 0x6b, 0x2f, 0x70, 0x75, 0x73, 0x68, 0x65, 0x72, 0x2f, 0x70, 0x75, 0x73, 0x68, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0c, 0x6c, 0x6c, 0x69, - 0x6e, 0x6b, 0x2e, 0x70, 0x75, 0x73, 0x68, 0x65, 0x72, 0x22, 0x39, 0x0a, 0x16, 0x42, 0x75, 0x6c, - 0x6b, 0x47, 0x65, 0x74, 0x50, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x12, 0x1f, 0x0a, 0x0b, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x69, - 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0a, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, - 0x6c, 0x49, 0x64, 0x73, 0x22, 0xca, 0x01, 0x0a, 0x17, 0x42, 0x75, 0x6c, 0x6b, 0x47, 0x65, 0x74, + 0x6e, 0x6b, 0x2e, 0x70, 0x75, 0x73, 0x68, 0x65, 0x72, 0x22, 0x1a, 0x0a, 0x18, 0x47, 0x65, 0x74, + 0x4f, 0x6e, 0x6c, 0x69, 0x6e, 0x65, 0x48, 0x75, 0x6d, 0x61, 0x6e, 0x49, 0x64, 0x73, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x38, 0x0a, 0x19, 0x47, 0x65, 0x74, 0x4f, 0x6e, 0x6c, 0x69, + 0x6e, 0x65, 0x48, 0x75, 0x6d, 0x61, 0x6e, 0x49, 0x64, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x68, 0x75, 0x6d, 0x61, 0x6e, 0x5f, 0x69, 0x64, 0x73, 0x18, + 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x08, 0x68, 0x75, 0x6d, 0x61, 0x6e, 0x49, 0x64, 0x73, 0x22, + 0x2e, 0x0a, 0x0f, 0x49, 0x73, 0x4f, 0x6e, 0x6c, 0x69, 0x6e, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x68, 0x75, 0x6d, 0x61, 0x6e, 0x5f, 0x69, 0x64, 0x73, 0x18, + 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x08, 0x68, 0x75, 0x6d, 0x61, 0x6e, 0x49, 0x64, 0x73, 0x22, + 0x91, 0x01, 0x0a, 0x10, 0x49, 0x73, 0x4f, 0x6e, 0x6c, 0x69, 0x6e, 0x65, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x42, 0x0a, 0x06, 0x6f, 0x6e, 0x6c, 0x69, 0x6e, 0x65, 0x18, 0x01, + 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2a, 0x2e, 0x6c, 0x6c, 0x69, 0x6e, 0x6b, 0x2e, 0x70, 0x75, 0x73, + 0x68, 0x65, 0x72, 0x2e, 0x49, 0x73, 0x4f, 0x6e, 0x6c, 0x69, 0x6e, 0x65, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x4f, 0x6e, 0x6c, 0x69, 0x6e, 0x65, 0x45, 0x6e, 0x74, 0x72, 0x79, + 0x52, 0x06, 0x6f, 0x6e, 0x6c, 0x69, 0x6e, 0x65, 0x1a, 0x39, 0x0a, 0x0b, 0x4f, 0x6e, 0x6c, 0x69, + 0x6e, 0x65, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, + 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, + 0x02, 0x38, 0x01, 0x22, 0x3c, 0x0a, 0x19, 0x47, 0x65, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, + 0x6c, 0x50, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x12, 0x1f, 0x0a, 0x0b, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x69, 0x64, 0x73, 0x18, + 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0a, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x49, 0x64, + 0x73, 0x22, 0xd0, 0x01, 0x0a, 0x1a, 0x47, 0x65, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x12, 0x52, 0x0a, 0x09, 0x70, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x63, 0x65, 0x73, 0x18, 0x01, 0x20, - 0x03, 0x28, 0x0b, 0x32, 0x34, 0x2e, 0x6c, 0x6c, 0x69, 0x6e, 0x6b, 0x2e, 0x70, 0x75, 0x73, 0x68, - 0x65, 0x72, 0x2e, 0x42, 0x75, 0x6c, 0x6b, 0x47, 0x65, 0x74, 0x50, 0x72, 0x65, 0x73, 0x65, 0x6e, - 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x50, 0x72, 0x65, 0x73, 0x65, - 0x6e, 0x63, 0x65, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x09, 0x70, 0x72, 0x65, 0x73, 0x65, - 0x6e, 0x63, 0x65, 0x73, 0x1a, 0x5b, 0x0a, 0x0e, 0x50, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x63, 0x65, - 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x33, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, - 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x6c, 0x6c, 0x69, 0x6e, 0x6b, 0x2e, - 0x70, 0x75, 0x73, 0x68, 0x65, 0x72, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, - 0x65, 0x73, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, - 0x01, 0x22, 0x2e, 0x0a, 0x0f, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x65, 0x73, - 0x65, 0x6e, 0x63, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x68, 0x75, 0x6d, 0x61, 0x6e, 0x5f, 0x69, 0x64, - 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x08, 0x68, 0x75, 0x6d, 0x61, 0x6e, 0x49, 0x64, - 0x73, 0x32, 0x6f, 0x0a, 0x0d, 0x50, 0x75, 0x73, 0x68, 0x65, 0x72, 0x53, 0x65, 0x72, 0x76, 0x69, - 0x63, 0x65, 0x12, 0x5e, 0x0a, 0x0f, 0x42, 0x75, 0x6c, 0x6b, 0x47, 0x65, 0x74, 0x50, 0x72, 0x65, - 0x73, 0x65, 0x6e, 0x63, 0x65, 0x12, 0x24, 0x2e, 0x6c, 0x6c, 0x69, 0x6e, 0x6b, 0x2e, 0x70, 0x75, - 0x73, 0x68, 0x65, 0x72, 0x2e, 0x42, 0x75, 0x6c, 0x6b, 0x47, 0x65, 0x74, 0x50, 0x72, 0x65, 0x73, - 0x65, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x25, 0x2e, 0x6c, 0x6c, - 0x69, 0x6e, 0x6b, 0x2e, 0x70, 0x75, 0x73, 0x68, 0x65, 0x72, 0x2e, 0x42, 0x75, 0x6c, 0x6b, 0x47, - 0x65, 0x74, 0x50, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x42, 0x3c, 0x5a, 0x3a, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, - 0x2f, 0x66, 0x6c, 0x6f, 0x77, 0x79, 0x2d, 0x6c, 0x69, 0x76, 0x65, 0x2f, 0x6c, 0x6c, 0x69, 0x6e, - 0x6b, 0x2f, 0x67, 0x65, 0x6e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x6c, 0x6c, 0x69, 0x6e, 0x6b, - 0x2f, 0x70, 0x75, 0x73, 0x68, 0x65, 0x72, 0x3b, 0x70, 0x62, 0x70, 0x75, 0x73, 0x68, 0x65, 0x72, - 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x12, 0x55, 0x0a, 0x09, 0x70, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x63, 0x65, 0x73, 0x18, 0x01, 0x20, + 0x03, 0x28, 0x0b, 0x32, 0x37, 0x2e, 0x6c, 0x6c, 0x69, 0x6e, 0x6b, 0x2e, 0x70, 0x75, 0x73, 0x68, + 0x65, 0x72, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x65, + 0x73, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x50, 0x72, + 0x65, 0x73, 0x65, 0x6e, 0x63, 0x65, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x09, 0x70, 0x72, + 0x65, 0x73, 0x65, 0x6e, 0x63, 0x65, 0x73, 0x1a, 0x5b, 0x0a, 0x0e, 0x50, 0x72, 0x65, 0x73, 0x65, + 0x6e, 0x63, 0x65, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x33, 0x0a, 0x05, 0x76, + 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x6c, 0x6c, 0x69, + 0x6e, 0x6b, 0x2e, 0x70, 0x75, 0x73, 0x68, 0x65, 0x72, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, + 0x6c, 0x50, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, + 0x3a, 0x02, 0x38, 0x01, 0x22, 0x2e, 0x0a, 0x0f, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, + 0x72, 0x65, 0x73, 0x65, 0x6e, 0x63, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x68, 0x75, 0x6d, 0x61, 0x6e, + 0x5f, 0x69, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x08, 0x68, 0x75, 0x6d, 0x61, + 0x6e, 0x49, 0x64, 0x73, 0x32, 0xa9, 0x02, 0x0a, 0x0d, 0x50, 0x75, 0x73, 0x68, 0x65, 0x72, 0x53, + 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x64, 0x0a, 0x11, 0x47, 0x65, 0x74, 0x4f, 0x6e, 0x6c, + 0x69, 0x6e, 0x65, 0x48, 0x75, 0x6d, 0x61, 0x6e, 0x49, 0x64, 0x73, 0x12, 0x26, 0x2e, 0x6c, 0x6c, + 0x69, 0x6e, 0x6b, 0x2e, 0x70, 0x75, 0x73, 0x68, 0x65, 0x72, 0x2e, 0x47, 0x65, 0x74, 0x4f, 0x6e, + 0x6c, 0x69, 0x6e, 0x65, 0x48, 0x75, 0x6d, 0x61, 0x6e, 0x49, 0x64, 0x73, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x1a, 0x27, 0x2e, 0x6c, 0x6c, 0x69, 0x6e, 0x6b, 0x2e, 0x70, 0x75, 0x73, 0x68, + 0x65, 0x72, 0x2e, 0x47, 0x65, 0x74, 0x4f, 0x6e, 0x6c, 0x69, 0x6e, 0x65, 0x48, 0x75, 0x6d, 0x61, + 0x6e, 0x49, 0x64, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x49, 0x0a, 0x08, + 0x49, 0x73, 0x4f, 0x6e, 0x6c, 0x69, 0x6e, 0x65, 0x12, 0x1d, 0x2e, 0x6c, 0x6c, 0x69, 0x6e, 0x6b, + 0x2e, 0x70, 0x75, 0x73, 0x68, 0x65, 0x72, 0x2e, 0x49, 0x73, 0x4f, 0x6e, 0x6c, 0x69, 0x6e, 0x65, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1e, 0x2e, 0x6c, 0x6c, 0x69, 0x6e, 0x6b, 0x2e, + 0x70, 0x75, 0x73, 0x68, 0x65, 0x72, 0x2e, 0x49, 0x73, 0x4f, 0x6e, 0x6c, 0x69, 0x6e, 0x65, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x67, 0x0a, 0x12, 0x47, 0x65, 0x74, 0x43, 0x68, + 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x63, 0x65, 0x12, 0x27, 0x2e, + 0x6c, 0x6c, 0x69, 0x6e, 0x6b, 0x2e, 0x70, 0x75, 0x73, 0x68, 0x65, 0x72, 0x2e, 0x47, 0x65, 0x74, + 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x63, 0x65, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x28, 0x2e, 0x6c, 0x6c, 0x69, 0x6e, 0x6b, 0x2e, 0x70, + 0x75, 0x73, 0x68, 0x65, 0x72, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, + 0x50, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x42, 0x3c, 0x5a, 0x3a, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x66, + 0x6c, 0x6f, 0x77, 0x79, 0x2d, 0x6c, 0x69, 0x76, 0x65, 0x2f, 0x6c, 0x6c, 0x69, 0x6e, 0x6b, 0x2f, + 0x67, 0x65, 0x6e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x6c, 0x6c, 0x69, 0x6e, 0x6b, 0x2f, 0x70, + 0x75, 0x73, 0x68, 0x65, 0x72, 0x3b, 0x70, 0x62, 0x70, 0x75, 0x73, 0x68, 0x65, 0x72, 0x62, 0x06, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -207,23 +407,33 @@ func file_llink_pusher_pusher_proto_rawDescGZIP() []byte { return file_llink_pusher_pusher_proto_rawDescData } -var file_llink_pusher_pusher_proto_msgTypes = make([]protoimpl.MessageInfo, 4) +var file_llink_pusher_pusher_proto_msgTypes = make([]protoimpl.MessageInfo, 9) var file_llink_pusher_pusher_proto_goTypes = []any{ - (*BulkGetPresenceRequest)(nil), // 0: llink.pusher.BulkGetPresenceRequest - (*BulkGetPresenceResponse)(nil), // 1: llink.pusher.BulkGetPresenceResponse - (*ChannelPresence)(nil), // 2: llink.pusher.ChannelPresence - nil, // 3: llink.pusher.BulkGetPresenceResponse.PresencesEntry + (*GetOnlineHumanIdsRequest)(nil), // 0: llink.pusher.GetOnlineHumanIdsRequest + (*GetOnlineHumanIdsResponse)(nil), // 1: llink.pusher.GetOnlineHumanIdsResponse + (*IsOnlineRequest)(nil), // 2: llink.pusher.IsOnlineRequest + (*IsOnlineResponse)(nil), // 3: llink.pusher.IsOnlineResponse + (*GetChannelPresenceRequest)(nil), // 4: llink.pusher.GetChannelPresenceRequest + (*GetChannelPresenceResponse)(nil), // 5: llink.pusher.GetChannelPresenceResponse + (*ChannelPresence)(nil), // 6: llink.pusher.ChannelPresence + nil, // 7: llink.pusher.IsOnlineResponse.OnlineEntry + nil, // 8: llink.pusher.GetChannelPresenceResponse.PresencesEntry } var file_llink_pusher_pusher_proto_depIdxs = []int32{ - 3, // 0: llink.pusher.BulkGetPresenceResponse.presences:type_name -> llink.pusher.BulkGetPresenceResponse.PresencesEntry - 2, // 1: llink.pusher.BulkGetPresenceResponse.PresencesEntry.value:type_name -> llink.pusher.ChannelPresence - 0, // 2: llink.pusher.PusherService.BulkGetPresence:input_type -> llink.pusher.BulkGetPresenceRequest - 1, // 3: llink.pusher.PusherService.BulkGetPresence:output_type -> llink.pusher.BulkGetPresenceResponse - 3, // [3:4] is the sub-list for method output_type - 2, // [2:3] is the sub-list for method input_type - 2, // [2:2] is the sub-list for extension type_name - 2, // [2:2] is the sub-list for extension extendee - 0, // [0:2] is the sub-list for field type_name + 7, // 0: llink.pusher.IsOnlineResponse.online:type_name -> llink.pusher.IsOnlineResponse.OnlineEntry + 8, // 1: llink.pusher.GetChannelPresenceResponse.presences:type_name -> llink.pusher.GetChannelPresenceResponse.PresencesEntry + 6, // 2: llink.pusher.GetChannelPresenceResponse.PresencesEntry.value:type_name -> llink.pusher.ChannelPresence + 0, // 3: llink.pusher.PusherService.GetOnlineHumanIds:input_type -> llink.pusher.GetOnlineHumanIdsRequest + 2, // 4: llink.pusher.PusherService.IsOnline:input_type -> llink.pusher.IsOnlineRequest + 4, // 5: llink.pusher.PusherService.GetChannelPresence:input_type -> llink.pusher.GetChannelPresenceRequest + 1, // 6: llink.pusher.PusherService.GetOnlineHumanIds:output_type -> llink.pusher.GetOnlineHumanIdsResponse + 3, // 7: llink.pusher.PusherService.IsOnline:output_type -> llink.pusher.IsOnlineResponse + 5, // 8: llink.pusher.PusherService.GetChannelPresence:output_type -> llink.pusher.GetChannelPresenceResponse + 6, // [6:9] is the sub-list for method output_type + 3, // [3:6] is the sub-list for method input_type + 3, // [3:3] is the sub-list for extension type_name + 3, // [3:3] is the sub-list for extension extendee + 0, // [0:3] is the sub-list for field type_name } func init() { file_llink_pusher_pusher_proto_init() } @@ -237,7 +447,7 @@ func file_llink_pusher_pusher_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_llink_pusher_pusher_proto_rawDesc, NumEnums: 0, - NumMessages: 4, + NumMessages: 9, NumExtensions: 0, NumServices: 1, }, diff --git a/go/genproto/llink/pusher/pusher_grpc.pb.go b/go/genproto/llink/pusher/pusher_grpc.pb.go index 0cf7816..ee22c3d 100644 --- a/go/genproto/llink/pusher/pusher_grpc.pb.go +++ b/go/genproto/llink/pusher/pusher_grpc.pb.go @@ -19,17 +19,21 @@ import ( const _ = grpc.SupportPackageIsVersion9 const ( - PusherService_BulkGetPresence_FullMethodName = "/llink.pusher.PusherService/BulkGetPresence" + PusherService_GetOnlineHumanIds_FullMethodName = "/llink.pusher.PusherService/GetOnlineHumanIds" + PusherService_IsOnline_FullMethodName = "/llink.pusher.PusherService/IsOnline" + PusherService_GetChannelPresence_FullMethodName = "/llink.pusher.PusherService/GetChannelPresence" ) // PusherServiceClient is the client API for PusherService service. // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. type PusherServiceClient interface { - // BulkGetPresence returns presence for the given channels. - // When channel_ids is empty, returns all connected humanIDs across all channels - // under the key "_all" — useful for checking overall online status. - BulkGetPresence(ctx context.Context, in *BulkGetPresenceRequest, opts ...grpc.CallOption) (*BulkGetPresenceResponse, error) + // Returns all currently connected human IDs. + GetOnlineHumanIds(ctx context.Context, in *GetOnlineHumanIdsRequest, opts ...grpc.CallOption) (*GetOnlineHumanIdsResponse, error) + // Returns whether specific humans are currently online. + IsOnline(ctx context.Context, in *IsOnlineRequest, opts ...grpc.CallOption) (*IsOnlineResponse, error) + // Returns presence (human IDs) for specific channels. + GetChannelPresence(ctx context.Context, in *GetChannelPresenceRequest, opts ...grpc.CallOption) (*GetChannelPresenceResponse, error) } type pusherServiceClient struct { @@ -40,10 +44,30 @@ func NewPusherServiceClient(cc grpc.ClientConnInterface) PusherServiceClient { return &pusherServiceClient{cc} } -func (c *pusherServiceClient) BulkGetPresence(ctx context.Context, in *BulkGetPresenceRequest, opts ...grpc.CallOption) (*BulkGetPresenceResponse, error) { +func (c *pusherServiceClient) GetOnlineHumanIds(ctx context.Context, in *GetOnlineHumanIdsRequest, opts ...grpc.CallOption) (*GetOnlineHumanIdsResponse, error) { cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) - out := new(BulkGetPresenceResponse) - err := c.cc.Invoke(ctx, PusherService_BulkGetPresence_FullMethodName, in, out, cOpts...) + out := new(GetOnlineHumanIdsResponse) + err := c.cc.Invoke(ctx, PusherService_GetOnlineHumanIds_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *pusherServiceClient) IsOnline(ctx context.Context, in *IsOnlineRequest, opts ...grpc.CallOption) (*IsOnlineResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(IsOnlineResponse) + err := c.cc.Invoke(ctx, PusherService_IsOnline_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *pusherServiceClient) GetChannelPresence(ctx context.Context, in *GetChannelPresenceRequest, opts ...grpc.CallOption) (*GetChannelPresenceResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(GetChannelPresenceResponse) + err := c.cc.Invoke(ctx, PusherService_GetChannelPresence_FullMethodName, in, out, cOpts...) if err != nil { return nil, err } @@ -54,10 +78,12 @@ func (c *pusherServiceClient) BulkGetPresence(ctx context.Context, in *BulkGetPr // All implementations must embed UnimplementedPusherServiceServer // for forward compatibility. type PusherServiceServer interface { - // BulkGetPresence returns presence for the given channels. - // When channel_ids is empty, returns all connected humanIDs across all channels - // under the key "_all" — useful for checking overall online status. - BulkGetPresence(context.Context, *BulkGetPresenceRequest) (*BulkGetPresenceResponse, error) + // Returns all currently connected human IDs. + GetOnlineHumanIds(context.Context, *GetOnlineHumanIdsRequest) (*GetOnlineHumanIdsResponse, error) + // Returns whether specific humans are currently online. + IsOnline(context.Context, *IsOnlineRequest) (*IsOnlineResponse, error) + // Returns presence (human IDs) for specific channels. + GetChannelPresence(context.Context, *GetChannelPresenceRequest) (*GetChannelPresenceResponse, error) mustEmbedUnimplementedPusherServiceServer() } @@ -68,8 +94,14 @@ type PusherServiceServer interface { // pointer dereference when methods are called. type UnimplementedPusherServiceServer struct{} -func (UnimplementedPusherServiceServer) BulkGetPresence(context.Context, *BulkGetPresenceRequest) (*BulkGetPresenceResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method BulkGetPresence not implemented") +func (UnimplementedPusherServiceServer) GetOnlineHumanIds(context.Context, *GetOnlineHumanIdsRequest) (*GetOnlineHumanIdsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetOnlineHumanIds not implemented") +} +func (UnimplementedPusherServiceServer) IsOnline(context.Context, *IsOnlineRequest) (*IsOnlineResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method IsOnline not implemented") +} +func (UnimplementedPusherServiceServer) GetChannelPresence(context.Context, *GetChannelPresenceRequest) (*GetChannelPresenceResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetChannelPresence not implemented") } func (UnimplementedPusherServiceServer) mustEmbedUnimplementedPusherServiceServer() {} func (UnimplementedPusherServiceServer) testEmbeddedByValue() {} @@ -92,20 +124,56 @@ func RegisterPusherServiceServer(s grpc.ServiceRegistrar, srv PusherServiceServe s.RegisterService(&PusherService_ServiceDesc, srv) } -func _PusherService_BulkGetPresence_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(BulkGetPresenceRequest) +func _PusherService_GetOnlineHumanIds_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetOnlineHumanIdsRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(PusherServiceServer).BulkGetPresence(ctx, in) + return srv.(PusherServiceServer).GetOnlineHumanIds(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: PusherService_BulkGetPresence_FullMethodName, + FullMethod: PusherService_GetOnlineHumanIds_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(PusherServiceServer).BulkGetPresence(ctx, req.(*BulkGetPresenceRequest)) + return srv.(PusherServiceServer).GetOnlineHumanIds(ctx, req.(*GetOnlineHumanIdsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _PusherService_IsOnline_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(IsOnlineRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(PusherServiceServer).IsOnline(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: PusherService_IsOnline_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(PusherServiceServer).IsOnline(ctx, req.(*IsOnlineRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _PusherService_GetChannelPresence_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetChannelPresenceRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(PusherServiceServer).GetChannelPresence(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: PusherService_GetChannelPresence_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(PusherServiceServer).GetChannelPresence(ctx, req.(*GetChannelPresenceRequest)) } return interceptor(ctx, in, info, handler) } @@ -118,8 +186,16 @@ var PusherService_ServiceDesc = grpc.ServiceDesc{ HandlerType: (*PusherServiceServer)(nil), Methods: []grpc.MethodDesc{ { - MethodName: "BulkGetPresence", - Handler: _PusherService_BulkGetPresence_Handler, + MethodName: "GetOnlineHumanIds", + Handler: _PusherService_GetOnlineHumanIds_Handler, + }, + { + MethodName: "IsOnline", + Handler: _PusherService_IsOnline_Handler, + }, + { + MethodName: "GetChannelPresence", + Handler: _PusherService_GetChannelPresence_Handler, }, }, Streams: []grpc.StreamDesc{}, diff --git a/go/internal/pusher/authorizer.go b/go/internal/pusher/authorizer.go index b0c4c3d..9f60089 100644 --- a/go/internal/pusher/authorizer.go +++ b/go/internal/pusher/authorizer.go @@ -38,6 +38,13 @@ func (a *Authorizer) Authorize(ctx context.Context, channelID, humanID string) e return a.authorizeNetwork(ctx, rest, humanID) case "stream": return a.authorizeStream(ctx, rest, humanID) + case "_presence": + // Always allowed — used for global online presence tracking. + // The channel ID is _presence:{humanId}, so verify the humanId matches. + if rest != humanID { + return ErrUnauthorized + } + return nil default: return ErrUnauthorized } diff --git a/go/internal/pusher/hub.go b/go/internal/pusher/hub.go index 689d455..480e019 100644 --- a/go/internal/pusher/hub.go +++ b/go/internal/pusher/hub.go @@ -231,6 +231,11 @@ func (h *Hub) handleRemoteEvent(evt *remoteEvent) { } } +// Subscribe enqueues a subscribe request for the given connection and channel. +func (h *Hub) Subscribe(conn *Conn, channelID string) { + h.subscribeCh <- &subscribeRequest{conn: conn, channelID: channelID} +} + // disconnect sends a connection to the disconnect channel. func (h *Hub) disconnect(conn *Conn) { h.disconnectCh <- conn diff --git a/go/internal/pusher/server.go b/go/internal/pusher/server.go index a4dfb4c..37b997f 100644 --- a/go/internal/pusher/server.go +++ b/go/internal/pusher/server.go @@ -62,6 +62,9 @@ func (s *Server) HandleWebSocket(w http.ResponseWriter, r *http.Request) { ctx, cancel := context.WithCancel(r.Context()) defer cancel() + // Auto-subscribe to presence channel so this user appears online + s.hub.Subscribe(conn, "_presence:"+session.HumanId) + // WritePump runs in a separate goroutine go conn.WritePump(ctx) @@ -71,29 +74,39 @@ func (s *Server) HandleWebSocket(w http.ResponseWriter, r *http.Request) { slog.Info("websocket disconnected", "connId", connID, "humanId", session.HumanId) } -// BulkGetPresence implements the gRPC PusherService. -// When channel_ids is empty, returns all connected humanIDs across all channels -// under the key "_all" — useful for checking overall online status. -func (s *Server) BulkGetPresence(ctx context.Context, req *pbpusher.BulkGetPresenceRequest) (*pbpusher.BulkGetPresenceResponse, error) { - // Empty channel_ids → return all connected humans - if len(req.ChannelIds) == 0 { - humanIDs, err := s.bridge.GetAllConnectedHumanIDs(ctx) - if err != nil { - return nil, err - } - return &pbpusher.BulkGetPresenceResponse{ - Presences: map[string]*pbpusher.ChannelPresence{ - "_all": {HumanIds: humanIDs}, - }, - }, nil +// GetOnlineHumanIds returns all currently connected human IDs. +func (s *Server) GetOnlineHumanIds(ctx context.Context, _ *pbpusher.GetOnlineHumanIdsRequest) (*pbpusher.GetOnlineHumanIdsResponse, error) { + humanIDs, err := s.bridge.GetAllConnectedHumanIDs(ctx) + if err != nil { + return nil, err } + return &pbpusher.GetOnlineHumanIdsResponse{HumanIds: humanIDs}, nil +} +// IsOnline checks whether specific humans are currently online. +func (s *Server) IsOnline(ctx context.Context, req *pbpusher.IsOnlineRequest) (*pbpusher.IsOnlineResponse, error) { + allOnline, err := s.bridge.GetAllConnectedHumanIDs(ctx) + if err != nil { + return nil, err + } + onlineSet := make(map[string]bool, len(allOnline)) + for _, id := range allOnline { + onlineSet[id] = true + } + result := make(map[string]bool, len(req.HumanIds)) + for _, id := range req.HumanIds { + result[id] = onlineSet[id] + } + return &pbpusher.IsOnlineResponse{Online: result}, nil +} + +// GetChannelPresence returns presence (human IDs) for specific channels. +func (s *Server) GetChannelPresence(ctx context.Context, req *pbpusher.GetChannelPresenceRequest) (*pbpusher.GetChannelPresenceResponse, error) { presence, err := s.bridge.GetPresence(ctx, req.ChannelIds) if err != nil { return nil, err } - - resp := &pbpusher.BulkGetPresenceResponse{ + resp := &pbpusher.GetChannelPresenceResponse{ Presences: make(map[string]*pbpusher.ChannelPresence, len(presence)), } for chID, humanIDs := range presence { diff --git a/go/protocol b/go/protocol index a8683c0..4caa29f 160000 --- a/go/protocol +++ b/go/protocol @@ -1 +1 @@ -Subproject commit a8683c0397d1144506078f6a8bb6991e2d6c4140 +Subproject commit 4caa29f5201d8c7ec86424e7bd3fbf151a262bdd