Skip to content

Commit dd2d312

Browse files
committed
feat: room invitation
1 parent 257fe76 commit dd2d312

File tree

4 files changed

+44
-7
lines changed

4 files changed

+44
-7
lines changed

wechaty-puppet/schemas/room_invitation.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import "time"
55
type RoomInvitationPayload struct {
66
Id string `json:"id"`
77
InviterId string `json:"inviterId"`
8+
RoomId string `json:"roomId"`
89
Topic string `json:"topic"`
910
Avatar string `json:"avatar"`
1011
Invitation string `json:"invitation"`

wechaty/interface/room_invitation.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package _interface
22

33
import (
4-
"github.com/wechaty/go-wechaty/wechaty-puppet/schemas"
54
"time"
5+
6+
"github.com/wechaty/go-wechaty/wechaty-puppet/schemas"
67
)
78

89
type IRoomInvitationFactory interface {
@@ -16,10 +17,12 @@ type IRoomInvitation interface {
1617
ToStringAsync() (string, error)
1718
Accept() error
1819
Inviter() (IContact, error)
20+
Room() (IRoom, error)
1921
Topic() (string, error)
2022
MemberCount() (int, error)
2123
MemberList() ([]IContact, error)
2224
Date() (time.Time, error)
2325
Age() (time.Duration, error)
2426
ToJson() (string, error)
27+
RawPayload() (schemas.RoomInvitationPayload, error)
2528
}

wechaty/user/room_invitation.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"time"
77

8+
"github.com/wechaty/go-wechaty/wechaty-puppet/schemas"
89
_interface "github.com/wechaty/go-wechaty/wechaty/interface"
910
)
1011

@@ -98,6 +99,15 @@ func (ri *RoomInvitation) MemberList() ([]_interface.IContact, error) {
9899
return contactList, nil
99100
}
100101

102+
// Room get the room from room invitation
103+
func (ri *RoomInvitation) Room() (_interface.IRoom, error) {
104+
payload, err := ri.GetPuppet().RoomInvitationPayload(ri.id)
105+
if err != nil {
106+
return nil, err
107+
}
108+
return ri.GetWechaty().Room().Load(payload.RoomId), nil
109+
}
110+
101111
// Date get the invitation time
102112
func (ri *RoomInvitation) Date() (time.Time, error) {
103113
payload, err := ri.GetPuppet().RoomInvitationPayload(ri.id)
@@ -124,3 +134,12 @@ func (ri *RoomInvitation) ToJson() (string, error) {
124134
marshal, err := json.Marshal(payload)
125135
return string(marshal), err
126136
}
137+
138+
func (ri *RoomInvitation) RawPayload() (schemas.RoomInvitationPayload, error) {
139+
payload, err := ri.GetPuppet().RoomInvitationPayload(ri.id)
140+
if err != nil {
141+
return schemas.RoomInvitationPayload{}, err
142+
}
143+
144+
return *payload, nil
145+
}

wechaty/wechaty.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,21 @@ import (
2626
"context"
2727
"errors"
2828
"fmt"
29+
"os"
30+
"os/signal"
31+
"reflect"
32+
"runtime/debug"
33+
"time"
34+
2935
"github.com/lucsky/cuid"
36+
3037
wp "github.com/wechaty/go-wechaty/wechaty-puppet"
3138
puppetservice "github.com/wechaty/go-wechaty/wechaty-puppet-service"
3239
"github.com/wechaty/go-wechaty/wechaty-puppet/events"
3340
mc "github.com/wechaty/go-wechaty/wechaty-puppet/memory-card"
3441
"github.com/wechaty/go-wechaty/wechaty-puppet/schemas"
3542
"github.com/wechaty/go-wechaty/wechaty/factory"
36-
"github.com/wechaty/go-wechaty/wechaty/interface"
37-
"os"
38-
"os/signal"
39-
"reflect"
40-
"runtime/debug"
41-
"time"
43+
_interface "github.com/wechaty/go-wechaty/wechaty/interface"
4244
)
4345

4446
// Wechaty ...
@@ -380,6 +382,18 @@ func (w *Wechaty) initPuppetEventBridge() {
380382
case schemas.PuppetEventNameRoomInvite:
381383
w.puppet.On(name, func(i ...interface{}) {
382384
roomInvitation := w.roomInvitation.Load(i[0].(*schemas.EventRoomInvitePayload).RoomInvitationId)
385+
room, err := roomInvitation.Room()
386+
if err != nil {
387+
log.Errorf("emit roominvite room.Room() err: %s\n", err.Error())
388+
w.emit(schemas.PuppetEventNameError, NewContext(), err)
389+
return
390+
}
391+
if err := room.Ready(false); err != nil {
392+
log.Errorf("emit roominvite room.Ready() err: %s\n", err.Error())
393+
w.emit(schemas.PuppetEventNameError, NewContext(), err)
394+
return
395+
}
396+
383397
w.emit(name, NewContext(), roomInvitation)
384398
})
385399
case schemas.PuppetEventNameRoomJoin:

0 commit comments

Comments
 (0)