-
Notifications
You must be signed in to change notification settings - Fork 80
/
muc_room_lobby_errors.go
88 lines (73 loc) · 2.96 KB
/
muc_room_lobby_errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package gui
import (
"errors"
"github.com/coyim/coyim/i18n"
)
var (
errJoinRequestFailed = errors.New("the request to join the room has failed")
errInvalidNickname = errors.New("not valid nickname")
errJoinNoConnection = errors.New("join request failed because maybe no connection available")
errJoinNicknameConflict = errors.New("join failed because the nickname is being used")
errJoinOnlyMembers = errors.New("join failed because only registered members are allowed")
errJoinNotAuthorized = errors.New("join failed because doesn't have authorization")
errServiceUnavailable = errors.New("join failed because the service is unavailable")
errUnknownError = errors.New("join failed because an unknown error occurred")
errOccupantForbidden = errors.New("join failed because the occupant is banned")
)
type mucRoomLobbyErr struct {
nickname string
errType error
}
func (e *mucRoomLobbyErr) Error() string {
return e.errType.Error()
}
func newMUCRoomLobbyErr(nickname string, errType error) error {
return &mucRoomLobbyErr{
nickname: nickname,
errType: errType,
}
}
func newRoomLobbyInvalidNicknameError() error {
return newMUCRoomLobbyErr("", errInvalidNickname)
}
func (l *roomViewLobby) joinRequestErrorEvent(err error) {
l.finishJoinRequestWithError(newMUCRoomLobbyErr("", err))
}
func (l *roomViewLobby) nicknameConflictEvent(nickname string) {
l.joinRequestErrorEvent(newMUCRoomLobbyErr(nickname, errJoinNicknameConflict))
}
func (l *roomViewLobby) registrationRequiredEvent() {
l.joinRequestErrorEvent(errJoinOnlyMembers)
}
func (l *roomViewLobby) notAuthorizedEvent() {
l.joinRequestErrorEvent(errJoinNotAuthorized)
}
func (l *roomViewLobby) serviceUnavailableEvent() {
l.joinRequestErrorEvent(errServiceUnavailable)
}
func (l *roomViewLobby) unknownErrorEvent() {
l.joinRequestErrorEvent(errUnknownError)
}
func (l *roomViewLobby) occupantForbiddenEvent() {
l.joinRequestErrorEvent(errOccupantForbidden)
}
func (l *roomViewLobby) getUserErrorMessage(err *mucRoomLobbyErr) string {
switch err.errType {
case errInvalidNickname:
return i18n.Local("You must provide a valid nickname")
case errJoinNicknameConflict:
return i18n.Local("You can't join the room using that nickname because it's already being used.")
case errJoinOnlyMembers:
return i18n.Local("Sorry, this room only allows registered members.")
case errJoinNotAuthorized:
return i18n.Local("You can't join the room because the password is not valid.")
case errServiceUnavailable:
return i18n.Local("You can't join the room because the maximum number of occupants has been reached.")
case errUnknownError:
return i18n.Local("An unknown error occurred when trying to join the room. Please try again later.")
case errOccupantForbidden:
return i18n.Local("You can't join the room because your account is currently banned.")
default:
return i18n.Local("An error occurred when trying to join the room. Please check your connection or make sure the room exists.")
}
}