本文整理汇总了Golang中github.com/matrix-org/bullettime/core/types.Id函数的典型用法代码示例。如果您正苦于以下问题:Golang Id函数的具体用法?Golang Id怎么用?Golang Id使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Id函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: AddAlias
func (s *aliasStore) AddAlias(alias ct.Alias, room ct.RoomId) types.Error {
inserted, err := s.idMap.Insert(ct.Id(alias), ct.Id(room))
if err != nil {
return types.InternalError(err)
}
if !inserted {
return types.RoomInUseError("room alias '" + alias.String() + "' already exists")
}
return nil
}
示例2: RemoveAlias
func (s *aliasStore) RemoveAlias(alias ct.Alias, room ct.RoomId) types.Error {
deleted, err := s.idMap.Delete(ct.Id(alias), ct.Id(room))
if err != nil {
return types.InternalError(err)
}
if !deleted {
return types.NotFoundError("room alias '" + alias.String() + "' doesn't exist")
}
return nil
}
示例3: AddMember
func (db *memberStore) AddMember(roomId ct.RoomId, userId ct.UserId) types.Error {
inserted, err := db.idMap.Put(ct.Id(roomId), ct.Id(userId))
if err != nil {
return types.InternalError(err)
}
if !inserted {
msg := fmt.Sprintf("user %s is already a member of the room %s", userId, roomId)
return types.ServerError(msg)
}
return nil
}
示例4: RemoveMember
func (db *memberStore) RemoveMember(roomId ct.RoomId, userId ct.UserId) types.Error {
deleted, err := db.idMap.Delete(ct.Id(roomId), ct.Id(userId))
if err != nil {
return types.InternalError(err)
}
if !deleted {
msg := fmt.Sprintf("user %s is not a member of the room %s", userId, roomId)
return types.ServerError(msg)
}
return nil
}
示例5: SetRoomState
func (db *roomDb) SetRoomState(roomId types.RoomId, userId types.UserId, content types.TypedContent, stateKey string) (*matrixTypes.State, matrixTypes.Error) {
db.roomsLock.RLock()
defer db.roomsLock.RUnlock()
room := db.rooms[roomId]
if room == nil {
return nil, matrixTypes.NotFoundError("room '" + roomId.String() + "' doesn't exist")
}
var eventId = types.DeriveEventId(utils.RandomString(16), types.Id(userId))
stateId := stateId{content.GetEventType(), stateKey}
state := new(matrixTypes.State)
state.EventId = eventId
state.RoomId = roomId
state.UserId = userId
state.EventType = content.GetEventType()
state.StateKey = stateKey
state.Timestamp = types.Timestamp{time.Now()}
state.Content = content
state.OldState = (*matrixTypes.OldState)(room.states[stateId])
room.stateLock.Lock()
defer room.stateLock.Unlock()
room.states[stateId] = state
return state, nil
}
示例6: Send
func (b *fanInTestBuffer) Send(id string, user string, expectedIndex uint64) {
index, err := b.buffer.Send(types.EventInfo{
EventId: types.Id(types.NewEventId(id, "test")),
Sender: types.Id(types.NewUserId("tester", "test")),
ContextId: types.Id(types.NewRoomId("room1", "test")),
EventType: "m.test",
}, types.Id(types.NewUserId(user, "test")))
if err != nil {
debug.PrintStack()
b.t.Fatal("error pushing signal: ", err)
}
if index != expectedIndex {
debug.PrintStack()
b.t.Fatal("invalid index, expected %d but got %d", expectedIndex, index)
}
}
示例7: UserPasswordHash
func (db *userDb) UserPasswordHash(id ct.UserId) (string, types.Error) {
value, err := db.State(ct.Id(id), passwordHashKey)
if err != nil {
return "", types.InternalError(err)
}
return string(value), nil
}
示例8: Select
func (b *fanOutTestBuffer) Select(user string, from, to, expectedFromIndex, expectedToIndex uint64, expected ...string) {
signals, fromIndex, toIndex, err := b.buffer.SelectForwards(types.Id(types.NewUserId(user, "test")), from, to)
if err != nil {
debug.PrintStack()
b.t.Fatal("failed to get signal range: ", err)
}
if len(signals) != len(expected) {
debug.PrintStack()
b.t.Fatalf("invalid signal count, expected %d but got %d", len(expected), len(signals))
}
if expectedFromIndex != fromIndex {
debug.PrintStack()
b.t.Fatalf("invalid from index, expected %d but got %d", expectedFromIndex, fromIndex)
}
if expectedToIndex != toIndex {
debug.PrintStack()
b.t.Fatalf("invalid to index, expected %d but got %d", expectedToIndex, toIndex)
}
for i, signal := range signals {
if signal.EventId.Id != expected[i] {
debug.PrintStack()
b.t.Fatalf("invalid event id: expected %s, got %s", expected[i], signal.EventId.Id)
}
}
}
示例9: Room
func (s *aliasStore) Room(alias ct.Alias) (*ct.RoomId, types.Error) {
room, err := s.idMap.Lookup(ct.Id(alias))
if err != nil {
return nil, types.InternalError(err)
}
return (*ct.RoomId)(room), nil
}
示例10: Aliases
func (s *aliasStore) Aliases(room ct.RoomId) ([]ct.Alias, types.Error) {
ids, err := s.idMap.ReverseLookup(ct.Id(room))
if err != nil {
return nil, types.InternalError(err)
}
aliases := *(*[]ct.Alias)(unsafe.Pointer(&ids))
return aliases, nil
}
示例11: Push
func (b *fanOutTestBuffer) Push(id string, expectedIndex uint64, users ...string) {
userIds := make([]types.Id, len(users))
for i, user := range users {
userIds[i] = types.Id(types.NewUserId(user, "test"))
}
index, err := b.buffer.Send(types.EventInfo{
EventId: types.Id(types.NewEventId(id, "test")),
Sender: types.Id(types.NewUserId("tester", "test")),
ContextId: types.Id(types.NewRoomId("room1", "test")),
EventType: "m.test",
}, userIds)
if err != nil {
b.t.Fatal("error pushing signal: ", err)
}
if index != expectedIndex {
debug.PrintStack()
b.t.Fatal("invalid index, expected %d but got %d", expectedIndex, index)
}
}
示例12: Peers
func (db *memberStore) Peers(userId ct.UserId) (map[ct.UserId]struct{}, types.Error) {
peers := map[ct.UserId]struct{}{}
rooms, err := db.idMap.ReverseLookup(ct.Id(userId))
if err != nil {
return nil, types.InternalError(err)
}
for _, room := range rooms {
members, err := db.idMap.Lookup(room)
if err != nil {
return nil, types.InternalError(err)
}
for _, member := range members {
peers[ct.UserId(member)] = struct{}{}
}
}
return peers, nil
}
示例13: sendMessage
func (s roomService) sendMessage(
room ct.RoomId,
user ct.UserId,
content types.TypedContent,
) (*types.Message, types.Error) {
log.Printf("Sending message: %#v, %#v, %#v, %#v", room, user, content)
message := new(types.Message)
message.EventId = ct.DeriveEventId(utils.RandomString(16), ct.Id(user))
message.RoomId = room
message.UserId = user
message.EventType = content.GetEventType()
message.Timestamp = ct.Timestamp{time.Now()}
message.Content = content
_, err := s.eventSink.Send(message)
if err != nil {
return nil, err
}
return message, nil
}
示例14: Event
func (s *messageStream) Event(
user ct.UserId,
eventId ct.EventId,
) (types.Event, types.Error) {
s.lock.RLock()
indexed := s.byId[ct.Id(eventId)]
s.lock.RUnlock()
extraUser := extraUserForEvent(indexed.event)
if extraUser != nil && *extraUser == user {
return indexed.event, nil
}
rooms, err := s.members.Rooms(user)
if err != nil {
return nil, err
}
for _, room := range rooms {
if room == *indexed.event.GetRoomId() {
return indexed.event, nil
}
}
return nil, nil
}
示例15: GetEventKey
func (e *TypingEvent) GetEventKey() ct.Id {
return ct.Id(e.RoomId)
}