fix: emails sending despite online status

Closes #140
This commit is contained in:
talksik
2026-04-09 16:30:07 -07:00
parent 66aec4478f
commit 762c0ccf6e
7 changed files with 432 additions and 123 deletions
+9 -11
View File
@@ -26,7 +26,7 @@ const (
// Minimum time a message must be unread before we consider notifying // Minimum time a message must be unread before we consider notifying
unreadThreshold = 10 * time.Minute unreadThreshold = 10 * time.Minute
// Minimum time between emails to the same user // Minimum time between emails to the same user
emailCooldown = 1 * time.Hour emailCooldown = 12 * time.Hour
) )
func main() { func main() {
@@ -107,17 +107,15 @@ func runNotificationCycle(
behindCounts := map[string]int{} behindCounts := map[string]int{}
latestActivity := map[string]time.Time{} latestActivity := map[string]time.Time{}
// Get all currently connected humans (empty channel_ids = all connections) // Get all currently connected humans
allOnline := map[string]bool{} allOnline := map[string]bool{}
presenceResp, err := pusherSvc.BulkGetPresence(ctx, &pbpusher.BulkGetPresenceRequest{}) onlineResp, err := pusherSvc.GetOnlineHumanIds(ctx, &pbpusher.GetOnlineHumanIdsRequest{})
if err != nil { if err != nil {
slog.Error("failed to get connected humans", "error", err) return fmt.Errorf("failed to get online humans: %w", 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 online presence", "onlineCount", len(onlineResp.HumanIds), "humanIds", onlineResp.HumanIds)
slog.Info("gathered bulk presence", "# of humans present", fmt.Sprintf("%d", len(ch.HumanIds))) for _, id := range onlineResp.HumanIds {
for _, id := range ch.HumanIds { allOnline[id] = true
allOnline[id] = true
}
} }
for _, net := range networks { for _, net := range networks {
@@ -288,7 +286,7 @@ func buildEmailHTML(name string, count int, streamsWord string) string {
<p>You have unread messages in <strong>%d %s</strong> on Flowy.llink.</p> <p>You have unread messages in <strong>%d %s</strong> on Flowy.llink.</p>
<p>Open the app to catch up with your team.</p> <p>Open the app to catch up with your team.</p>
<p style="color: #666; font-size: 13px; margin-top: 32px;"> <p style="color: #666; font-size: 13px; margin-top: 32px;">
Best,<br>Flowy Team Best,<br>Flowy Team <br>Note: disable email notifications from in-app settings.
</p> </p>
</body> </body>
</html>`, name, count, streamsWord) </html>`, name, count, streamsWord)
+283 -73
View File
@@ -20,29 +20,26 @@ const (
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
) )
type BulkGetPresenceRequest struct { type GetOnlineHumanIdsRequest struct {
state protoimpl.MessageState state protoimpl.MessageState
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields 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() { func (x *GetOnlineHumanIdsRequest) Reset() {
*x = BulkGetPresenceRequest{} *x = GetOnlineHumanIdsRequest{}
mi := &file_llink_pusher_pusher_proto_msgTypes[0] mi := &file_llink_pusher_pusher_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi) ms.StoreMessageInfo(mi)
} }
func (x *BulkGetPresenceRequest) String() string { func (x *GetOnlineHumanIdsRequest) String() string {
return protoimpl.X.MessageStringOf(x) 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] mi := &file_llink_pusher_pusher_proto_msgTypes[0]
if x != nil { if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
@@ -54,19 +51,192 @@ func (x *BulkGetPresenceRequest) ProtoReflect() protoreflect.Message {
return mi.MessageOf(x) return mi.MessageOf(x)
} }
// Deprecated: Use BulkGetPresenceRequest.ProtoReflect.Descriptor instead. // Deprecated: Use GetOnlineHumanIdsRequest.ProtoReflect.Descriptor instead.
func (*BulkGetPresenceRequest) Descriptor() ([]byte, []int) { func (*GetOnlineHumanIdsRequest) Descriptor() ([]byte, []int) {
return file_llink_pusher_pusher_proto_rawDescGZIP(), []int{0} 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 { if x != nil {
return x.ChannelIds return x.ChannelIds
} }
return nil return nil
} }
type BulkGetPresenceResponse struct { type GetChannelPresenceResponse struct {
state protoimpl.MessageState state protoimpl.MessageState
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields 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"` 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() { func (x *GetChannelPresenceResponse) Reset() {
*x = BulkGetPresenceResponse{} *x = GetChannelPresenceResponse{}
mi := &file_llink_pusher_pusher_proto_msgTypes[1] mi := &file_llink_pusher_pusher_proto_msgTypes[5]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi) ms.StoreMessageInfo(mi)
} }
func (x *BulkGetPresenceResponse) String() string { func (x *GetChannelPresenceResponse) String() string {
return protoimpl.X.MessageStringOf(x) return protoimpl.X.MessageStringOf(x)
} }
func (*BulkGetPresenceResponse) ProtoMessage() {} func (*GetChannelPresenceResponse) ProtoMessage() {}
func (x *BulkGetPresenceResponse) ProtoReflect() protoreflect.Message { func (x *GetChannelPresenceResponse) ProtoReflect() protoreflect.Message {
mi := &file_llink_pusher_pusher_proto_msgTypes[1] mi := &file_llink_pusher_pusher_proto_msgTypes[5]
if x != nil { if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil { if ms.LoadMessageInfo() == nil {
@@ -99,12 +269,12 @@ func (x *BulkGetPresenceResponse) ProtoReflect() protoreflect.Message {
return mi.MessageOf(x) return mi.MessageOf(x)
} }
// Deprecated: Use BulkGetPresenceResponse.ProtoReflect.Descriptor instead. // Deprecated: Use GetChannelPresenceResponse.ProtoReflect.Descriptor instead.
func (*BulkGetPresenceResponse) Descriptor() ([]byte, []int) { func (*GetChannelPresenceResponse) Descriptor() ([]byte, []int) {
return file_llink_pusher_pusher_proto_rawDescGZIP(), []int{1} 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 { if x != nil {
return x.Presences return x.Presences
} }
@@ -121,7 +291,7 @@ type ChannelPresence struct {
func (x *ChannelPresence) Reset() { func (x *ChannelPresence) Reset() {
*x = ChannelPresence{} *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 := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi) ms.StoreMessageInfo(mi)
} }
@@ -133,7 +303,7 @@ func (x *ChannelPresence) String() string {
func (*ChannelPresence) ProtoMessage() {} func (*ChannelPresence) ProtoMessage() {}
func (x *ChannelPresence) ProtoReflect() protoreflect.Message { 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 { if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil { if ms.LoadMessageInfo() == nil {
@@ -146,7 +316,7 @@ func (x *ChannelPresence) ProtoReflect() protoreflect.Message {
// Deprecated: Use ChannelPresence.ProtoReflect.Descriptor instead. // Deprecated: Use ChannelPresence.ProtoReflect.Descriptor instead.
func (*ChannelPresence) Descriptor() ([]byte, []int) { 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 { 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{ var file_llink_pusher_pusher_proto_rawDesc = []byte{
0x0a, 0x19, 0x6c, 0x6c, 0x69, 0x6e, 0x6b, 0x2f, 0x70, 0x75, 0x73, 0x68, 0x65, 0x72, 0x2f, 0x70, 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, 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, 0x6e, 0x6b, 0x2e, 0x70, 0x75, 0x73, 0x68, 0x65, 0x72, 0x22, 0x1a, 0x0a, 0x18, 0x47, 0x65, 0x74,
0x6b, 0x47, 0x65, 0x74, 0x50, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x4f, 0x6e, 0x6c, 0x69, 0x6e, 0x65, 0x48, 0x75, 0x6d, 0x61, 0x6e, 0x49, 0x64, 0x73, 0x52, 0x65,
0x65, 0x73, 0x74, 0x12, 0x1f, 0x0a, 0x0b, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x69, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x38, 0x0a, 0x19, 0x47, 0x65, 0x74, 0x4f, 0x6e, 0x6c, 0x69,
0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0a, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6e, 0x65, 0x48, 0x75, 0x6d, 0x61, 0x6e, 0x49, 0x64, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e,
0x6c, 0x49, 0x64, 0x73, 0x22, 0xca, 0x01, 0x0a, 0x17, 0x42, 0x75, 0x6c, 0x6b, 0x47, 0x65, 0x74, 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, 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, 0x12, 0x55, 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, 0x03, 0x28, 0x0b, 0x32, 0x37, 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, 0x65, 0x72, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x65,
0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x50, 0x72, 0x65, 0x73, 0x65, 0x73, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x50, 0x72,
0x6e, 0x63, 0x65, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x09, 0x70, 0x72, 0x65, 0x73, 0x65, 0x65, 0x73, 0x65, 0x6e, 0x63, 0x65, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x09, 0x70, 0x72,
0x6e, 0x63, 0x65, 0x73, 0x1a, 0x5b, 0x0a, 0x0e, 0x50, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x63, 0x65, 0x65, 0x73, 0x65, 0x6e, 0x63, 0x65, 0x73, 0x1a, 0x5b, 0x0a, 0x0e, 0x50, 0x72, 0x65, 0x73, 0x65,
0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x6e, 0x63, 0x65, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79,
0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x33, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x33, 0x0a, 0x05, 0x76,
0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x6c, 0x6c, 0x69, 0x6e, 0x6b, 0x2e, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x6c, 0x6c, 0x69,
0x70, 0x75, 0x73, 0x68, 0x65, 0x72, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6e, 0x6b, 0x2e, 0x70, 0x75, 0x73, 0x68, 0x65, 0x72, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65,
0x65, 0x73, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x6c, 0x50, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65,
0x01, 0x22, 0x2e, 0x0a, 0x0f, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x65, 0x73, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x2e, 0x0a, 0x0f, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50,
0x65, 0x6e, 0x63, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x68, 0x75, 0x6d, 0x61, 0x6e, 0x5f, 0x69, 0x64, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x63, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x68, 0x75, 0x6d, 0x61, 0x6e,
0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x08, 0x68, 0x75, 0x6d, 0x61, 0x6e, 0x49, 0x64, 0x5f, 0x69, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x08, 0x68, 0x75, 0x6d, 0x61,
0x73, 0x32, 0x6f, 0x0a, 0x0d, 0x50, 0x75, 0x73, 0x68, 0x65, 0x72, 0x53, 0x65, 0x72, 0x76, 0x69, 0x6e, 0x49, 0x64, 0x73, 0x32, 0xa9, 0x02, 0x0a, 0x0d, 0x50, 0x75, 0x73, 0x68, 0x65, 0x72, 0x53,
0x63, 0x65, 0x12, 0x5e, 0x0a, 0x0f, 0x42, 0x75, 0x6c, 0x6b, 0x47, 0x65, 0x74, 0x50, 0x72, 0x65, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x64, 0x0a, 0x11, 0x47, 0x65, 0x74, 0x4f, 0x6e, 0x6c,
0x73, 0x65, 0x6e, 0x63, 0x65, 0x12, 0x24, 0x2e, 0x6c, 0x6c, 0x69, 0x6e, 0x6b, 0x2e, 0x70, 0x75, 0x69, 0x6e, 0x65, 0x48, 0x75, 0x6d, 0x61, 0x6e, 0x49, 0x64, 0x73, 0x12, 0x26, 0x2e, 0x6c, 0x6c,
0x73, 0x68, 0x65, 0x72, 0x2e, 0x42, 0x75, 0x6c, 0x6b, 0x47, 0x65, 0x74, 0x50, 0x72, 0x65, 0x73, 0x69, 0x6e, 0x6b, 0x2e, 0x70, 0x75, 0x73, 0x68, 0x65, 0x72, 0x2e, 0x47, 0x65, 0x74, 0x4f, 0x6e,
0x65, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x25, 0x2e, 0x6c, 0x6c, 0x6c, 0x69, 0x6e, 0x65, 0x48, 0x75, 0x6d, 0x61, 0x6e, 0x49, 0x64, 0x73, 0x52, 0x65, 0x71, 0x75,
0x69, 0x6e, 0x6b, 0x2e, 0x70, 0x75, 0x73, 0x68, 0x65, 0x72, 0x2e, 0x42, 0x75, 0x6c, 0x6b, 0x47, 0x65, 0x73, 0x74, 0x1a, 0x27, 0x2e, 0x6c, 0x6c, 0x69, 0x6e, 0x6b, 0x2e, 0x70, 0x75, 0x73, 0x68,
0x65, 0x74, 0x50, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x65, 0x72, 0x2e, 0x47, 0x65, 0x74, 0x4f, 0x6e, 0x6c, 0x69, 0x6e, 0x65, 0x48, 0x75, 0x6d, 0x61,
0x73, 0x65, 0x42, 0x3c, 0x5a, 0x3a, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x6e, 0x49, 0x64, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x49, 0x0a, 0x08,
0x2f, 0x66, 0x6c, 0x6f, 0x77, 0x79, 0x2d, 0x6c, 0x69, 0x76, 0x65, 0x2f, 0x6c, 0x6c, 0x69, 0x6e, 0x49, 0x73, 0x4f, 0x6e, 0x6c, 0x69, 0x6e, 0x65, 0x12, 0x1d, 0x2e, 0x6c, 0x6c, 0x69, 0x6e, 0x6b,
0x6b, 0x2f, 0x67, 0x65, 0x6e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x6c, 0x6c, 0x69, 0x6e, 0x6b, 0x2e, 0x70, 0x75, 0x73, 0x68, 0x65, 0x72, 0x2e, 0x49, 0x73, 0x4f, 0x6e, 0x6c, 0x69, 0x6e, 0x65,
0x2f, 0x70, 0x75, 0x73, 0x68, 0x65, 0x72, 0x3b, 0x70, 0x62, 0x70, 0x75, 0x73, 0x68, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1e, 0x2e, 0x6c, 0x6c, 0x69, 0x6e, 0x6b, 0x2e,
0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, 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 ( var (
@@ -207,23 +407,33 @@ func file_llink_pusher_pusher_proto_rawDescGZIP() []byte {
return file_llink_pusher_pusher_proto_rawDescData 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{ var file_llink_pusher_pusher_proto_goTypes = []any{
(*BulkGetPresenceRequest)(nil), // 0: llink.pusher.BulkGetPresenceRequest (*GetOnlineHumanIdsRequest)(nil), // 0: llink.pusher.GetOnlineHumanIdsRequest
(*BulkGetPresenceResponse)(nil), // 1: llink.pusher.BulkGetPresenceResponse (*GetOnlineHumanIdsResponse)(nil), // 1: llink.pusher.GetOnlineHumanIdsResponse
(*ChannelPresence)(nil), // 2: llink.pusher.ChannelPresence (*IsOnlineRequest)(nil), // 2: llink.pusher.IsOnlineRequest
nil, // 3: llink.pusher.BulkGetPresenceResponse.PresencesEntry (*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{ var file_llink_pusher_pusher_proto_depIdxs = []int32{
3, // 0: llink.pusher.BulkGetPresenceResponse.presences:type_name -> llink.pusher.BulkGetPresenceResponse.PresencesEntry 7, // 0: llink.pusher.IsOnlineResponse.online:type_name -> llink.pusher.IsOnlineResponse.OnlineEntry
2, // 1: llink.pusher.BulkGetPresenceResponse.PresencesEntry.value:type_name -> llink.pusher.ChannelPresence 8, // 1: llink.pusher.GetChannelPresenceResponse.presences:type_name -> llink.pusher.GetChannelPresenceResponse.PresencesEntry
0, // 2: llink.pusher.PusherService.BulkGetPresence:input_type -> llink.pusher.BulkGetPresenceRequest 6, // 2: llink.pusher.GetChannelPresenceResponse.PresencesEntry.value:type_name -> llink.pusher.ChannelPresence
1, // 3: llink.pusher.PusherService.BulkGetPresence:output_type -> llink.pusher.BulkGetPresenceResponse 0, // 3: llink.pusher.PusherService.GetOnlineHumanIds:input_type -> llink.pusher.GetOnlineHumanIdsRequest
3, // [3:4] is the sub-list for method output_type 2, // 4: llink.pusher.PusherService.IsOnline:input_type -> llink.pusher.IsOnlineRequest
2, // [2:3] is the sub-list for method input_type 4, // 5: llink.pusher.PusherService.GetChannelPresence:input_type -> llink.pusher.GetChannelPresenceRequest
2, // [2:2] is the sub-list for extension type_name 1, // 6: llink.pusher.PusherService.GetOnlineHumanIds:output_type -> llink.pusher.GetOnlineHumanIdsResponse
2, // [2:2] is the sub-list for extension extendee 3, // 7: llink.pusher.PusherService.IsOnline:output_type -> llink.pusher.IsOnlineResponse
0, // [0:2] is the sub-list for field type_name 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() } func init() { file_llink_pusher_pusher_proto_init() }
@@ -237,7 +447,7 @@ func file_llink_pusher_pusher_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(), GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_llink_pusher_pusher_proto_rawDesc, RawDescriptor: file_llink_pusher_pusher_proto_rawDesc,
NumEnums: 0, NumEnums: 0,
NumMessages: 4, NumMessages: 9,
NumExtensions: 0, NumExtensions: 0,
NumServices: 1, NumServices: 1,
}, },
+97 -21
View File
@@ -19,17 +19,21 @@ import (
const _ = grpc.SupportPackageIsVersion9 const _ = grpc.SupportPackageIsVersion9
const ( 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. // 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. // 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 { type PusherServiceClient interface {
// BulkGetPresence returns presence for the given channels. // Returns all currently connected human IDs.
// When channel_ids is empty, returns all connected humanIDs across all channels GetOnlineHumanIds(ctx context.Context, in *GetOnlineHumanIdsRequest, opts ...grpc.CallOption) (*GetOnlineHumanIdsResponse, error)
// under the key "_all" — useful for checking overall online status. // Returns whether specific humans are currently online.
BulkGetPresence(ctx context.Context, in *BulkGetPresenceRequest, opts ...grpc.CallOption) (*BulkGetPresenceResponse, error) 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 { type pusherServiceClient struct {
@@ -40,10 +44,30 @@ func NewPusherServiceClient(cc grpc.ClientConnInterface) PusherServiceClient {
return &pusherServiceClient{cc} 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...) cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(BulkGetPresenceResponse) out := new(GetOnlineHumanIdsResponse)
err := c.cc.Invoke(ctx, PusherService_BulkGetPresence_FullMethodName, in, out, cOpts...) 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 { if err != nil {
return nil, err return nil, err
} }
@@ -54,10 +78,12 @@ func (c *pusherServiceClient) BulkGetPresence(ctx context.Context, in *BulkGetPr
// All implementations must embed UnimplementedPusherServiceServer // All implementations must embed UnimplementedPusherServiceServer
// for forward compatibility. // for forward compatibility.
type PusherServiceServer interface { type PusherServiceServer interface {
// BulkGetPresence returns presence for the given channels. // Returns all currently connected human IDs.
// When channel_ids is empty, returns all connected humanIDs across all channels GetOnlineHumanIds(context.Context, *GetOnlineHumanIdsRequest) (*GetOnlineHumanIdsResponse, error)
// under the key "_all" — useful for checking overall online status. // Returns whether specific humans are currently online.
BulkGetPresence(context.Context, *BulkGetPresenceRequest) (*BulkGetPresenceResponse, error) IsOnline(context.Context, *IsOnlineRequest) (*IsOnlineResponse, error)
// Returns presence (human IDs) for specific channels.
GetChannelPresence(context.Context, *GetChannelPresenceRequest) (*GetChannelPresenceResponse, error)
mustEmbedUnimplementedPusherServiceServer() mustEmbedUnimplementedPusherServiceServer()
} }
@@ -68,8 +94,14 @@ type PusherServiceServer interface {
// pointer dereference when methods are called. // pointer dereference when methods are called.
type UnimplementedPusherServiceServer struct{} type UnimplementedPusherServiceServer struct{}
func (UnimplementedPusherServiceServer) BulkGetPresence(context.Context, *BulkGetPresenceRequest) (*BulkGetPresenceResponse, error) { func (UnimplementedPusherServiceServer) GetOnlineHumanIds(context.Context, *GetOnlineHumanIdsRequest) (*GetOnlineHumanIdsResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method BulkGetPresence not implemented") 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) mustEmbedUnimplementedPusherServiceServer() {}
func (UnimplementedPusherServiceServer) testEmbeddedByValue() {} func (UnimplementedPusherServiceServer) testEmbeddedByValue() {}
@@ -92,20 +124,56 @@ func RegisterPusherServiceServer(s grpc.ServiceRegistrar, srv PusherServiceServe
s.RegisterService(&PusherService_ServiceDesc, srv) s.RegisterService(&PusherService_ServiceDesc, srv)
} }
func _PusherService_BulkGetPresence_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { func _PusherService_GetOnlineHumanIds_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(BulkGetPresenceRequest) in := new(GetOnlineHumanIdsRequest)
if err := dec(in); err != nil { if err := dec(in); err != nil {
return nil, err return nil, err
} }
if interceptor == nil { if interceptor == nil {
return srv.(PusherServiceServer).BulkGetPresence(ctx, in) return srv.(PusherServiceServer).GetOnlineHumanIds(ctx, in)
} }
info := &grpc.UnaryServerInfo{ info := &grpc.UnaryServerInfo{
Server: srv, Server: srv,
FullMethod: PusherService_BulkGetPresence_FullMethodName, FullMethod: PusherService_GetOnlineHumanIds_FullMethodName,
} }
handler := func(ctx context.Context, req interface{}) (interface{}, error) { 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) return interceptor(ctx, in, info, handler)
} }
@@ -118,8 +186,16 @@ var PusherService_ServiceDesc = grpc.ServiceDesc{
HandlerType: (*PusherServiceServer)(nil), HandlerType: (*PusherServiceServer)(nil),
Methods: []grpc.MethodDesc{ Methods: []grpc.MethodDesc{
{ {
MethodName: "BulkGetPresence", MethodName: "GetOnlineHumanIds",
Handler: _PusherService_BulkGetPresence_Handler, Handler: _PusherService_GetOnlineHumanIds_Handler,
},
{
MethodName: "IsOnline",
Handler: _PusherService_IsOnline_Handler,
},
{
MethodName: "GetChannelPresence",
Handler: _PusherService_GetChannelPresence_Handler,
}, },
}, },
Streams: []grpc.StreamDesc{}, Streams: []grpc.StreamDesc{},
+7
View File
@@ -38,6 +38,13 @@ func (a *Authorizer) Authorize(ctx context.Context, channelID, humanID string) e
return a.authorizeNetwork(ctx, rest, humanID) return a.authorizeNetwork(ctx, rest, humanID)
case "stream": case "stream":
return a.authorizeStream(ctx, rest, humanID) 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: default:
return ErrUnauthorized return ErrUnauthorized
} }
+5
View File
@@ -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. // disconnect sends a connection to the disconnect channel.
func (h *Hub) disconnect(conn *Conn) { func (h *Hub) disconnect(conn *Conn) {
h.disconnectCh <- conn h.disconnectCh <- conn
+30 -17
View File
@@ -62,6 +62,9 @@ func (s *Server) HandleWebSocket(w http.ResponseWriter, r *http.Request) {
ctx, cancel := context.WithCancel(r.Context()) ctx, cancel := context.WithCancel(r.Context())
defer cancel() 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 // WritePump runs in a separate goroutine
go conn.WritePump(ctx) 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) slog.Info("websocket disconnected", "connId", connID, "humanId", session.HumanId)
} }
// BulkGetPresence implements the gRPC PusherService. // GetOnlineHumanIds returns all currently connected human IDs.
// When channel_ids is empty, returns all connected humanIDs across all channels func (s *Server) GetOnlineHumanIds(ctx context.Context, _ *pbpusher.GetOnlineHumanIdsRequest) (*pbpusher.GetOnlineHumanIdsResponse, error) {
// under the key "_all" — useful for checking overall online status. humanIDs, err := s.bridge.GetAllConnectedHumanIDs(ctx)
func (s *Server) BulkGetPresence(ctx context.Context, req *pbpusher.BulkGetPresenceRequest) (*pbpusher.BulkGetPresenceResponse, error) { if err != nil {
// Empty channel_ids → return all connected humans return nil, err
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
} }
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) presence, err := s.bridge.GetPresence(ctx, req.ChannelIds)
if err != nil { if err != nil {
return nil, err return nil, err
} }
resp := &pbpusher.GetChannelPresenceResponse{
resp := &pbpusher.BulkGetPresenceResponse{
Presences: make(map[string]*pbpusher.ChannelPresence, len(presence)), Presences: make(map[string]*pbpusher.ChannelPresence, len(presence)),
} }
for chID, humanIDs := range presence { for chID, humanIDs := range presence {