public async Task HandleEventAsync(EventFriendshipPayload eventData)
 {
     var friendship = await Friendship.Load(eventData.FriendshipId);
 }
Ejemplo n.º 2
0
        protected void InitPuppetEventBridge(Puppet puppet)
        {
            _logger.LogInformation("init puppet event bridge");
            _ = puppet.OnDong(payload => EmitDong(payload.Data))
                .OnError(payload => EmitError(payload.Exception))
                .OnHeartbeat(payload => EmitHearbeat(payload.Data))
                .OnFriendship(async payload =>
            {
                var friendship = Friendship.Load(payload.FriendshipId);
                await friendship.Ready();
                _ = EmitFriendship(friendship);
                _ = friendship.Contact.Emit("friendship", friendship);
            })
                .OnLogin(async payload =>
            {
                var contact = ContactSelf.Load(payload.ContactId);
                await contact.Ready();
                _ = EmitLogin(contact);
            })
                .OnLogout(async payload =>
            {
                var contact = ContactSelf.Load(payload.ContactId);
                await contact.Ready();
                _ = EmitLogout(contact, payload.Data);
            })
                .OnMessage(async payload =>
            {
                var message = Message.Load(payload.MessageId);
                await message.Ready;
                _        = EmitMessage(message);
                var room = message.Room;
                if (room != null)
                {
                    _ = room.EmitMessage(message);
                }
            }).OnReady(payload =>
            {
                _ = Emit("ready");
                _readyState.IsOn = true;
            })
                .OnRoomInvite(payload =>
            {
                var roomInvitation = RoomInvitation.Load(payload.RoomInvitationId);
                _ = EmitRoomInvite(roomInvitation);
            })
                .OnRoomJoin(async payload =>
            {
                var room = Room.Load(payload.RoomId);
                await room.Sync();

                var inviteeList = payload
                                  .InviteeIdList
                                  .Select(Contact.Load)
                                  .ToList();
                await Task.WhenAll(inviteeList.Select(c => c.Ready()));

                var inviter = Contact.Load(payload.InviterId);
                await inviter.Ready();
                var date = payload.Timestamp.TimestampToDateTime();

                _ = EmitRoomJoin(room, inviteeList, inviter, date);
                _ = room.EmitJoin(inviteeList, inviter, date);
            })
                .OnRoomLeave(async payload =>
            {
                var room = Room.Load(payload.RoomId);
                await room.Sync();

                var leaverList = payload.RemoverIdList.Select(Contact.Load).ToList();
                await Task.WhenAll(leaverList.Select(c => c.Ready()));

                var remover = Contact.Load(payload.RemoverId);
                await remover.Ready();

                var date = payload.Timestamp.TimestampToDateTime();

                _ = EmitRoomLeave(room, leaverList, remover, date);
                _ = room.EmitLeave(leaverList, remover, date);

                var selftId = Puppet.SelfId;
                if (!string.IsNullOrEmpty(selftId) && payload.RemoverIdList.Contains(selftId))
                {
                    await Puppet.RoomPayloadDirty(payload.RoomId);
                    await Puppet.RoomMemberPayloadDirty(payload.RoomId);
                }
            }).OnRoomTopic(async payload =>
            {
                var room = Room.Load(payload.RoomId);
                await room.Sync();

                var changer = Contact.Load(payload.ChangerId);
                await changer.Ready();
                var date = payload.Timestamp.TimestampToDateTime();

                _ = EmitRoomTopic(room, payload.NewTopic, payload.OldTopic, changer, date);
            })
                .OnScan(payload => _ = EmitScan(payload.Data ?? "", payload.Status, payload.Data));
        }