conversation.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. package types
  2. import "time"
  3. // EventTypeConversation is the fetchEvents type for chat list sync.
  4. const EventTypeConversation EventType = "conversation"
  5. // ConversationEventData builds a conversation fetchEvents payload.
  6. func ConversationEventData(operation string, conversations []map[string]interface{}) map[string]interface{} {
  7. if conversations == nil {
  8. conversations = []map[string]interface{}{}
  9. }
  10. return map[string]interface{}{
  11. "operation": operation,
  12. "conversations": conversations,
  13. }
  14. }
  15. // ConversationEntry builds one conversation object for the Web AIM client.
  16. func ConversationEntry(aimID, displayID, message, msgID, sender string, sent bool, unread int) map[string]interface{} {
  17. entry := map[string]interface{}{
  18. "aimId": aimID,
  19. "displayId": displayID,
  20. "active": 0,
  21. "unreadCount": unread,
  22. }
  23. if message != "" {
  24. entry["lastIM"] = map[string]interface{}{
  25. "message": message,
  26. "msgId": msgID,
  27. "sender": sender,
  28. "sent": sent,
  29. "timestamp": float64(time.Now().Unix()),
  30. }
  31. }
  32. return entry
  33. }