conversation.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package types
  2. import "time"
  3. // ConversationEventData builds a conversation fetchEvents payload.
  4. func ConversationEventData(operation string, conversations []map[string]interface{}) map[string]interface{} {
  5. if conversations == nil {
  6. conversations = []map[string]interface{}{}
  7. }
  8. return map[string]interface{}{
  9. "operation": operation,
  10. "conversations": conversations,
  11. }
  12. }
  13. // ConversationGroupEntry builds one group-chat conversation object for the Web
  14. // AIM client's conversation "list". The presence of the imserv field is what
  15. // makes the client render the entry under "Group Chats" (its aa() predicate);
  16. // displayID gives the room its name without a getSettings round-trip.
  17. func ConversationGroupEntry(imserv, displayID string, memberCount int) map[string]interface{} {
  18. entry := map[string]interface{}{
  19. "imserv": imserv,
  20. "aimId": imserv,
  21. "active": 0,
  22. "memberCounts": memberCount,
  23. }
  24. if displayID != "" {
  25. entry["displayId"] = displayID
  26. }
  27. return entry
  28. }
  29. // ConversationEntry builds one conversation object for the Web AIM client.
  30. //
  31. // An empty displayID is omitted rather than sent blank: the client falls back to
  32. // the name it already has for aimID, whereas any value present here replaces it.
  33. func ConversationEntry(aimID, displayID, message, msgID, sender string, sent bool, unread int) map[string]interface{} {
  34. entry := map[string]interface{}{
  35. "aimId": aimID,
  36. "active": 0,
  37. "unreadCount": unread,
  38. }
  39. if displayID != "" {
  40. entry["displayId"] = displayID
  41. }
  42. if message != "" {
  43. entry["lastIM"] = map[string]interface{}{
  44. "message": message,
  45. "msgId": msgID,
  46. "sender": sender,
  47. "sent": sent,
  48. "timestamp": float64(time.Now().Unix()),
  49. }
  50. }
  51. return entry
  52. }