Browse Source

Adding Error Checking

pull/220/head
Sarah Jamie Lewis 1 year ago
parent
commit
27e42afbbf
1 changed files with 19 additions and 7 deletions
  1. +19
    -7
      storage/profile_store.go

+ 19
- 7
storage/profile_store.go View File

@@ -126,7 +126,6 @@ func (ps *profileStore) eventHandler() {
ps.profile.Name = ev.Data[event.ProfileName]
ps.profile.SetAttribute("name", ev.Data[event.ProfileName])
ps.save()

case event.SetAttribute:
ps.profile.SetAttribute(ev.Data[event.Key], ev.Data[event.Data])
ps.save()
@@ -135,26 +134,39 @@ func (ps *profileStore) eventHandler() {
if exists {
contact.SetAttribute(ev.Data[event.Key], ev.Data[event.Data])
ps.save()
} else {
log.Errorf("error setting attribute on peer %v peer does not exist", ev)
}
case event.SetGroupAttribute:
group, exists := ps.profile.Groups[ev.Data[event.GroupID]]
if exists {
group.SetAttribute(ev.Data[event.Key], ev.Data[event.Data])
ps.save()
} else {
log.Errorf("error setting attribute on group %v group does not exist", ev)
}
case event.NewGroupInvite:
var gci protocol.GroupChatInvite
proto.Unmarshal([]byte(ev.Data[event.GroupInvite]), &gci)
ps.profile.ProcessInvite(&gci, ev.Data[event.RemotePeer])
ps.save()
group := ps.profile.Groups[gci.GetGroupName()]
ps.streamStores[group.GroupID] = NewStreamStore(ps.directory, group.LocalID, ps.password)
err := proto.Unmarshal([]byte(ev.Data[event.GroupInvite]), &gci)
if err == nil {
ps.profile.ProcessInvite(&gci, ev.Data[event.RemotePeer])
ps.save()
group := ps.profile.Groups[gci.GetGroupName()]
ps.streamStores[group.GroupID] = NewStreamStore(ps.directory, group.LocalID, ps.password)
} else {
log.Errorf("error storing new group invite: %v %v", ev, err)
}
case event.NewMessageFromGroup:
groupid := ev.Data[event.GroupID]
received, _ := time.Parse(time.RFC3339Nano, ev.Data[event.TimestampReceived])
sent, _ := time.Parse(time.RFC3339Nano, ev.Data[event.TimestampSent])
message := model.Message{Received: received, Timestamp: sent, Message: ev.Data[event.Data], PeerID: ev.Data[event.RemotePeer], Signature: []byte(ev.Data[event.Signature]), PreviousMessageSig: []byte(ev.Data[event.PreviousSignature])}
ps.streamStores[groupid].Write(message)
ss, exists := ps.streamStores[groupid]
if exists {
ss.Write(message)
} else {
log.Errorf("error storing new group message: %v stream store does not exist", ev)
}
default:
return
}


Loading…
Cancel
Save